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>
This commit is contained in:
Berthold Stoeger 2019-04-15 20:15:40 +02:00 committed by Dirk Hohndel
parent 15b2dbede4
commit f09177e872
2 changed files with 15 additions and 11 deletions

View file

@ -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();

View file

@ -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 {