diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2015-01-06 16:37:36 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-01-06 19:37:57 -0800 |
commit | 74596cc19399f0f2444e73021b8ec4ebbf43813f (patch) | |
tree | a3422e505527e8800255f0557c53734c02d82218 | |
parent | 58e21a61606a3594be2a17f044342f7cb031c628 (diff) | |
download | subsurface-74596cc19399f0f2444e73021b8ec4ebbf43813f.tar.gz |
Add the data() method
Now we can correctly visualize the file data, and changing
the separator will update on the fly.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/divelogimportdialog.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp index 925536255..6f61ac2db 100644 --- a/qt-ui/divelogimportdialog.cpp +++ b/qt-ui/divelogimportdialog.cpp @@ -156,7 +156,15 @@ bool ColumnNameResult::setData(const QModelIndex &index, const QVariant &value, QVariant ColumnNameResult::data(const QModelIndex &index, int role) const { + if (!index.isValid()) + return QVariant(); + if (role != Qt::DisplayRole) + return QVariant(); + if (index.row() == 0) { + return (columnNames[index.column()]); + } + return QVariant(columnValues[index.row() -1][index.column()]); } int ColumnNameResult::rowCount(const QModelIndex &parent) const @@ -211,7 +219,7 @@ DiveLogImportDialog::DiveLogImportDialog(QStringList fn, QWidget *parent) : QDia for (int i = 0; !CSVApps[i].name.isNull(); ++i) ui->knownImports->addItem(CSVApps[i].name); - ui->CSVSeparator->addItems( QStringList() << tr("Separator") << tr("Tab") << ";" << ","); + ui->CSVSeparator->addItems( QStringList() << tr("Tab") << ";" << ","); ui->knownImports->setCurrentIndex(1); ColumnNameProvider *provider = new ColumnNameProvider(this); @@ -227,6 +235,8 @@ DiveLogImportDialog::DiveLogImportDialog(QStringList fn, QWidget *parent) : QDia connect(close, SIGNAL(activated()), this, SLOT(close())); QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); connect(quit, SIGNAL(activated()), parent, SLOT(close())); + + connect(ui->CSVSeparator, SIGNAL(currentIndexChanged(int)), this, SLOT(loadFileContents())); } DiveLogImportDialog::~DiveLogImportDialog() @@ -243,7 +253,9 @@ void DiveLogImportDialog::loadFileContents() { int rows = 0; while (rows < 10 || !f.atEnd()) { QString currLine = f.readLine(); - currColumns = currLine.split( ui->CSVSeparator->currentText() ); + QString separator = ui->CSVSeparator->currentText() == tr("Tab") ? "\t" + : ui->CSVSeparator->currentText(); + currColumns = currLine.split(separator); fileColumns.append(currColumns); rows += 1; } |