diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-01-07 12:27:20 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-01-07 12:27:20 -0800 |
commit | 1c06252c00e44a4f877da4441761932a28a6c3b8 (patch) | |
tree | 1aacb339de90d633ee7266c86ca4e6a89a0a3c03 /qt-ui/divelogimportdialog.cpp | |
parent | 816367eb06820f0a9db138d2323a05d77a446808 (diff) | |
download | subsurface-1c06252c00e44a4f877da4441761932a28a6c3b8.tar.gz |
CVS import UI: use my own match function
This makes the code simpler and allows us to do a much better job matching
the column names.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelogimportdialog.cpp')
-rw-r--r-- | qt-ui/divelogimportdialog.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp index 0eebb1a1e..aabd6df6a 100644 --- a/qt-ui/divelogimportdialog.cpp +++ b/qt-ui/divelogimportdialog.cpp @@ -27,7 +27,7 @@ const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = ColumnNameProvider::ColumnNameProvider(QObject *parent) : QAbstractListModel(parent) { columnNames << tr("Dive #") << tr("Date") << tr("Time") << tr("Duration") << tr("Location") << tr("GPS") << tr("Weight") << tr("Cyl. size") << tr("Start pressure") - << tr("End press") << tr("Max depth") << tr("Mean depth") << tr("Divemaster") << tr("Buddy") << tr("Notes") << tr("Tags") << tr("Air temp.") << tr("Water temp.") + << tr("End pressure") << tr("Max depth") << tr("Avg depth") << tr("Divemaster") << tr("Buddy") << tr("Notes") << tr("Tags") << tr("Air temp.") << tr("Water temp.") << tr("O₂") << tr("He"); } @@ -60,7 +60,6 @@ QVariant ColumnNameProvider::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); - if (role != Qt::DisplayRole) return QVariant(); @@ -73,6 +72,21 @@ int ColumnNameProvider::rowCount(const QModelIndex &parent) const return columnNames.count(); } +int ColumnNameProvider::mymatch(QString value) const +{ + QString searchString = value.toLower(); + searchString.replace("\"", "").replace(" ", "").replace(".", "").replace("\n",""); + for (int i = 0; i < columnNames.count(); i++) { + QString name = columnNames.at(i).toLower(); + name.replace("\"", "").replace(" ", "").replace(".", "").replace("\n",""); + if (searchString == name.toLower()) + return i; + } + return -1; +} + + + ColumnNameView::ColumnNameView(QWidget *parent) { setAcceptDrops(true); @@ -365,15 +379,14 @@ void DiveLogImportDialog::loadFileContents() { ColumnNameProvider *model = (ColumnNameProvider *)ui->avaliableColumns->model(); columnText.replace("\"", ""); columnText.replace("number", "#", Qt::CaseInsensitive); - QModelIndexList matches = model->match(model->index(0, 0), Qt::DisplayRole, columnText, Qt::MatchFixedString); - if (!matches.isEmpty()) { - QString foundHeading = model->data(matches.first(), Qt::DisplayRole).toString(); - model->removeRow(matches.first().row()); + int idx = model->mymatch(columnText); + if (idx >= 0) { + QString foundHeading = model->data(model->index(idx, 0), Qt::DisplayRole).toString(); + model->removeRow(idx); headers.append(foundHeading); } else { headers.append(""); } - } f.reset(); int rows = 0; |