mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
15b2dbede4
commit
f09177e872
2 changed files with 15 additions and 11 deletions
|
@ -256,11 +256,15 @@ void LocationInformationWidget::reverseGeocode()
|
||||||
Command::editDiveSiteTaxonomy(diveSite, taxonomy);
|
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
|
bool DiveLocationFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex&) const
|
||||||
{
|
{
|
||||||
|
@ -268,7 +272,7 @@ bool DiveLocationFilterProxyModel::filterAcceptsRow(int source_row, const QModel
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
QString sourceString = sourceModel()->index(source_row, LocationInformationModel::NAME).data(Qt::DisplayRole).toString();
|
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
|
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();
|
return source_left.data().toString() < source_right.data().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
DiveLocationModel::DiveLocationModel(QObject*)
|
DiveLocationModel::DiveLocationModel(QObject *)
|
||||||
{
|
{
|
||||||
resetModel();
|
resetModel();
|
||||||
}
|
}
|
||||||
|
@ -343,8 +347,6 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) : QLineEdit(parent),
|
||||||
currType(NO_DIVE_SITE),
|
currType(NO_DIVE_SITE),
|
||||||
currDs(nullptr)
|
currDs(nullptr)
|
||||||
{
|
{
|
||||||
location_line_edit = this;
|
|
||||||
|
|
||||||
proxy->setSourceModel(model);
|
proxy->setSourceModel(model);
|
||||||
proxy->setFilterKeyColumn(LocationInformationModel::NAME);
|
proxy->setFilterKeyColumn(LocationInformationModel::NAME);
|
||||||
|
|
||||||
|
@ -452,7 +454,7 @@ static struct dive_site *get_dive_site_name_start_which_str(const QString &str)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString&)
|
void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString &name)
|
||||||
{
|
{
|
||||||
// This function fills the first two entries with potential names of
|
// This function fills the first two entries with potential names of
|
||||||
// a dive site to be generated. The first entry is simply the entered
|
// 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.
|
// with the entered text.
|
||||||
QModelIndex i0 = model->index(0, LocationInformationModel::NAME);
|
QModelIndex i0 = model->index(0, LocationInformationModel::NAME);
|
||||||
QModelIndex i1 = model->index(1, 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
|
// Note: if i1_name stays empty, the line will automatically
|
||||||
// be filtered out by the proxy filter, as it does not contain
|
// be filtered out by the proxy filter, as it does not contain
|
||||||
// the user entered text.
|
// the user entered text.
|
||||||
QString i1_name;
|
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 orig_name = QString(ds->name).toLower();
|
||||||
const QString new_name = text().toLower();
|
const QString new_name = name.toLower();
|
||||||
if (new_name != orig_name)
|
if (new_name != orig_name)
|
||||||
i1_name = QString(ds->name);
|
i1_name = QString(ds->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
model->setData(i1, i1_name);
|
model->setData(i1, i1_name);
|
||||||
proxy->invalidate();
|
proxy->setFilter(name);
|
||||||
fixPopupPosition();
|
fixPopupPosition();
|
||||||
if (!view->isVisible())
|
if (!view->isVisible())
|
||||||
view->show();
|
view->show();
|
||||||
|
|
|
@ -45,10 +45,12 @@ private:
|
||||||
|
|
||||||
class DiveLocationFilterProxyModel : public QSortFilterProxyModel {
|
class DiveLocationFilterProxyModel : public QSortFilterProxyModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
QString filter;
|
||||||
public:
|
public:
|
||||||
DiveLocationFilterProxyModel(QObject *parent = 0);
|
DiveLocationFilterProxyModel(QObject *parent = 0);
|
||||||
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
|
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
|
||||||
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override;
|
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override;
|
||||||
|
void setFilter(const QString &filter);
|
||||||
};
|
};
|
||||||
|
|
||||||
class DiveLocationModel : public QAbstractTableModel {
|
class DiveLocationModel : public QAbstractTableModel {
|
||||||
|
|
Loading…
Add table
Reference in a new issue