mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
816367eb06
commit
1c06252c00
2 changed files with 21 additions and 7 deletions
|
@ -27,7 +27,7 @@ const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] =
|
||||||
ColumnNameProvider::ColumnNameProvider(QObject *parent) : QAbstractListModel(parent)
|
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")
|
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");
|
<< tr("O₂") << tr("He");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,6 @@ QVariant ColumnNameProvider::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if (role != Qt::DisplayRole)
|
if (role != Qt::DisplayRole)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
|
@ -73,6 +72,21 @@ int ColumnNameProvider::rowCount(const QModelIndex &parent) const
|
||||||
return columnNames.count();
|
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)
|
ColumnNameView::ColumnNameView(QWidget *parent)
|
||||||
{
|
{
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
|
@ -365,15 +379,14 @@ void DiveLogImportDialog::loadFileContents() {
|
||||||
ColumnNameProvider *model = (ColumnNameProvider *)ui->avaliableColumns->model();
|
ColumnNameProvider *model = (ColumnNameProvider *)ui->avaliableColumns->model();
|
||||||
columnText.replace("\"", "");
|
columnText.replace("\"", "");
|
||||||
columnText.replace("number", "#", Qt::CaseInsensitive);
|
columnText.replace("number", "#", Qt::CaseInsensitive);
|
||||||
QModelIndexList matches = model->match(model->index(0, 0), Qt::DisplayRole, columnText, Qt::MatchFixedString);
|
int idx = model->mymatch(columnText);
|
||||||
if (!matches.isEmpty()) {
|
if (idx >= 0) {
|
||||||
QString foundHeading = model->data(matches.first(), Qt::DisplayRole).toString();
|
QString foundHeading = model->data(model->index(idx, 0), Qt::DisplayRole).toString();
|
||||||
model->removeRow(matches.first().row());
|
model->removeRow(idx);
|
||||||
headers.append(foundHeading);
|
headers.append(foundHeading);
|
||||||
} else {
|
} else {
|
||||||
headers.append("");
|
headers.append("");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
f.reset();
|
f.reset();
|
||||||
int rows = 0;
|
int rows = 0;
|
||||||
|
|
|
@ -24,6 +24,7 @@ public:
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
int rowCount(const QModelIndex &parent) const;
|
int rowCount(const QModelIndex &parent) const;
|
||||||
|
int mymatch(QString value) const;
|
||||||
private:
|
private:
|
||||||
QStringList columnNames;
|
QStringList columnNames;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue