Filter panel: add suit and notes search fields

All the field in the Notes Panel of the main window are now supported.
This needs some testing especially for the Notes field that may contain
markup. It appears ok to me for single term searches. One would like
to think about the default search option for the Notes.
There is a vertical spacer in the Filter panel that I moved downwards
and whose function I am not quite sure of.

[Dirk Hohndel: small adjustments]

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Willem Ferguson 2019-02-28 15:35:34 -08:00 committed by Dirk Hohndel
parent 01e8a54f58
commit 10e7835290
4 changed files with 113 additions and 2 deletions

View file

@ -99,6 +99,18 @@ FilterWidget2::FilterWidget2(QWidget* parent) :
connect(ui.locationMode, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &FilterWidget2::updateFilter);
connect(ui.suit, &QLineEdit::textChanged,
this, &FilterWidget2::updateFilter);
connect(ui.suitMode, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &FilterWidget2::updateFilter);
connect(ui.dnotes, &QLineEdit::textChanged,
this, &FilterWidget2::updateFilter);
connect(ui.dnotesMode, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &FilterWidget2::updateFilter);
connect(ui.logged, &QCheckBox::stateChanged,
this, &FilterWidget2::updateLogged);
@ -136,6 +148,8 @@ void FilterWidget2::clearFilter()
ui.planned->setChecked(filterData.planned);
ui.people->clear();
ui.location->clear();
ui.suit->clear();
ui.dnotes->clear();
ui.equipment->clear();
ui.tags->clear();
ui.fromDate->setDate(filterData.fromDate.date());
@ -145,6 +159,8 @@ void FilterWidget2::clearFilter()
ui.tagsMode->setCurrentIndex((int)filterData.tagsMode);
ui.peopleMode->setCurrentIndex((int)filterData.peopleMode);
ui.locationMode->setCurrentIndex((int)filterData.locationMode);
ui.suitMode->setCurrentIndex((int)filterData.suitMode);
ui.dnotesMode->setCurrentIndex((int)filterData.dnotesMode);
ui.equipmentMode->setCurrentIndex((int)filterData.equipmentMode);
ignoreSignal = false;
@ -187,10 +203,14 @@ void FilterWidget2::updateFilter()
filterData.tags = ui.tags->text().split(",", QString::SkipEmptyParts);
filterData.people = ui.people->text().split(",", QString::SkipEmptyParts);
filterData.location = ui.location->text().split(",", QString::SkipEmptyParts);
filterData.suit = ui.suit->text().split(",", QString::SkipEmptyParts);
filterData.dnotes = ui.dnotes->text().split(",", QString::SkipEmptyParts);
filterData.equipment = ui.equipment->text().split(",", QString::SkipEmptyParts);
filterData.tagsMode = (FilterData::Mode)ui.tagsMode->currentIndex();
filterData.peopleMode = (FilterData::Mode)ui.peopleMode->currentIndex();
filterData.locationMode = (FilterData::Mode)ui.locationMode->currentIndex();
filterData.suitMode = (FilterData::Mode)ui.suitMode->currentIndex();
filterData.dnotesMode = (FilterData::Mode)ui.dnotesMode->currentIndex();
filterData.equipmentMode = (FilterData::Mode)ui.equipmentMode->currentIndex();
filterData.logged = ui.logged->isChecked();
filterData.planned = ui.planned->isChecked();

View file

@ -124,7 +124,13 @@
<item row="10" column="4" colspan="2">
<widget class="QLineEdit" name="location"/>
</item>
<item row="11" column="0">
<item row="11" column="4" colspan="2">
<widget class="QLineEdit" name="suit"/>
</item>
<item row="12" column="4" colspan="2">
<widget class="QLineEdit" name="dnotes"/>
</item>
<item row="13" column="0">
<widget class="QLabel" name="labelEquipment">
<property name="text">
<string>Equipment</string>
@ -164,6 +170,20 @@
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Suit</string>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Notes</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
@ -349,6 +369,44 @@
</widget>
</item>
<item row="11" column="1" colspan="2">
<widget class="QComboBox" name="suitMode">
<item>
<property name="text">
<string>All of</string>
</property>
</item>
<item>
<property name="text">
<string>Any of</string>
</property>
</item>
<item>
<property name="text">
<string>None of</string>
</property>
</item>
</widget>
</item>
<item row="12" column="1" colspan="2">
<widget class="QComboBox" name="dnotesMode">
<item>
<property name="text">
<string>All of</string>
</property>
</item>
<item>
<property name="text">
<string>Any of</string>
</property>
</item>
<item>
<property name="text">
<string>None of</string>
</property>
</item>
</widget>
</item>
<item row="13" column="1" colspan="2">
<widget class="QComboBox" name="equipmentMode">
<item>
<property name="text">
@ -367,7 +425,7 @@
</item>
</widget>
</item>
<item row="12" column="0">
<item row="13" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>

View file

@ -74,6 +74,27 @@ namespace {
{
return true;
}
bool hasSuits(const QStringList &suits, const struct dive *d, FilterData::Mode mode)
{
if (suits.isEmpty())
return true;
QStringList diveSuits;
if (d->suit)
diveSuits.push_back(QString(d->suit));
return check(suits, diveSuits, mode);
}
bool hasNotes(const QStringList &dnotes, const struct dive *d, FilterData::Mode mode)
{
if (dnotes.isEmpty())
return true;
QStringList diveNotes;
if (d->notes)
diveNotes.push_back(QString(d->notes));
return check(dnotes, diveNotes, mode);
}
}
MultiFilterSortModel *MultiFilterSortModel::instance()
@ -149,6 +170,14 @@ bool MultiFilterSortModel::showDive(const struct dive *d) const
if (!hasLocations(filterData.location, d, filterData.locationMode))
return false;
// Suit
if (!hasSuits(filterData.suit, d, filterData.suitMode))
return false;
// Notes
if (!hasNotes(filterData.dnotes, d, filterData.dnotesMode))
return false;
if (!hasEquipment(filterData.equipment, d, filterData.equipmentMode))
return false;

View file

@ -41,10 +41,14 @@ struct FilterData {
QStringList tags;
QStringList people;
QStringList location;
QStringList suit;
QStringList dnotes;
QStringList equipment;
Mode tagsMode = Mode::ALL_OF;
Mode peopleMode = Mode::ALL_OF;
Mode locationMode = Mode::ANY_OF;
Mode dnotesMode = Mode::ALL_OF;
Mode suitMode = Mode::ANY_OF;
Mode equipmentMode = Mode::ALL_OF;
bool logged = true;
bool planned = true;