aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-04-15 20:15:40 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-16 23:46:19 +1200
commitf09177e87283b0d53cb2b2e20cbe086098389957 (patch)
treefbd9b83ddd388889f722c75897b57b2eed7bdd27 /desktop-widgets
parent15b2dbede4bb7907d687cf72d54b4ecdd7cc42a9 (diff)
downloadsubsurface-f09177e87283b0d53cb2b2e20cbe086098389957.tar.gz
Cleanup: remove global DiveLocationLineEdit variable
DiveLocationLineEdit stored a pointer to itself in a global variable so that the DiveLocationModel can access it to access the filter text. Instead, on change simply pass the filter text down from DiveLocationLineEdit to DiveLocationModel. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/locationinformation.cpp24
-rw-r--r--desktop-widgets/locationinformation.h2
2 files changed, 15 insertions, 11 deletions
diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp
index 74dfb3e64..fe8b6b516 100644
--- a/desktop-widgets/locationinformation.cpp
+++ b/desktop-widgets/locationinformation.cpp
@@ -256,11 +256,15 @@ void LocationInformationWidget::reverseGeocode()
Command::editDiveSiteTaxonomy(diveSite, taxonomy);
}
-DiveLocationFilterProxyModel::DiveLocationFilterProxyModel(QObject*)
+DiveLocationFilterProxyModel::DiveLocationFilterProxyModel(QObject *)
{
}
-DiveLocationLineEdit *location_line_edit = 0;
+void DiveLocationFilterProxyModel::setFilter(const QString &filterIn)
+{
+ filter = filterIn;
+ invalidate();
+}
bool DiveLocationFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex&) const
{
@@ -268,7 +272,7 @@ bool DiveLocationFilterProxyModel::filterAcceptsRow(int source_row, const QModel
return true;
QString sourceString = sourceModel()->index(source_row, LocationInformationModel::NAME).data(Qt::DisplayRole).toString();
- return sourceString.toLower().contains(location_line_edit->text().toLower());
+ return sourceString.contains(filter, Qt::CaseInsensitive);
}
bool DiveLocationFilterProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
@@ -276,7 +280,7 @@ bool DiveLocationFilterProxyModel::lessThan(const QModelIndex &source_left, cons
return source_left.data().toString() < source_right.data().toString();
}
-DiveLocationModel::DiveLocationModel(QObject*)
+DiveLocationModel::DiveLocationModel(QObject *)
{
resetModel();
}
@@ -343,8 +347,6 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) : QLineEdit(parent),
currType(NO_DIVE_SITE),
currDs(nullptr)
{
- location_line_edit = this;
-
proxy->setSourceModel(model);
proxy->setFilterKeyColumn(LocationInformationModel::NAME);
@@ -452,7 +454,7 @@ static struct dive_site *get_dive_site_name_start_which_str(const QString &str)
return NULL;
}
-void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString&)
+void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString &name)
{
// This function fills the first two entries with potential names of
// a dive site to be generated. The first entry is simply the entered
@@ -460,21 +462,21 @@ void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString&)
// with the entered text.
QModelIndex i0 = model->index(0, LocationInformationModel::NAME);
QModelIndex i1 = model->index(1, LocationInformationModel::NAME);
- model->setData(i0, text());
+ model->setData(i0, name);
// Note: if i1_name stays empty, the line will automatically
// be filtered out by the proxy filter, as it does not contain
// the user entered text.
QString i1_name;
- if (struct dive_site *ds = get_dive_site_name_start_which_str(text())) {
+ if (struct dive_site *ds = get_dive_site_name_start_which_str(name)) {
const QString orig_name = QString(ds->name).toLower();
- const QString new_name = text().toLower();
+ const QString new_name = name.toLower();
if (new_name != orig_name)
i1_name = QString(ds->name);
}
model->setData(i1, i1_name);
- proxy->invalidate();
+ proxy->setFilter(name);
fixPopupPosition();
if (!view->isVisible())
view->show();
diff --git a/desktop-widgets/locationinformation.h b/desktop-widgets/locationinformation.h
index 84066af71..434da29ae 100644
--- a/desktop-widgets/locationinformation.h
+++ b/desktop-widgets/locationinformation.h
@@ -45,10 +45,12 @@ private:
class DiveLocationFilterProxyModel : public QSortFilterProxyModel {
Q_OBJECT
+ QString filter;
public:
DiveLocationFilterProxyModel(QObject *parent = 0);
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override;
+ void setFilter(const QString &filter);
};
class DiveLocationModel : public QAbstractTableModel {