mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Update filters on refreshDisplay and remember old selecttions
Update the filters if the list of dives is updated by calling MultiFilterSortModel::instance()->myInvalidate(); This had the side effect of clearing all selections. Thus, in the repopulate() methods of the FilterModels, check those entries that were checked previously. Since all the filter models use the same code, introduce a base class FilterModelBase. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
4da6a0a732
commit
dd2466f518
3 changed files with 53 additions and 25 deletions
|
@ -445,7 +445,7 @@ MainWindow *MainWindow::instance()
|
|||
return m_Instance;
|
||||
}
|
||||
|
||||
// this gets called after we download dives from a divecomputer
|
||||
// This gets called after one or more dives were added, edited or downloaded for a dive computer
|
||||
void MainWindow::refreshDisplay(bool doRecreateDiveList)
|
||||
{
|
||||
information()->reload();
|
||||
|
@ -469,6 +469,7 @@ void MainWindow::recreateDiveList()
|
|||
BuddyFilterModel::instance()->repopulate();
|
||||
LocationFilterModel::instance()->repopulate();
|
||||
SuitsFilterModel::instance()->repopulate();
|
||||
MultiFilterSortModel::instance()->myInvalidate();
|
||||
}
|
||||
|
||||
void MainWindow::configureToolbar() {
|
||||
|
|
|
@ -78,7 +78,40 @@ CREATE_COMMON_METHODS_FOR_FILTER(SuitsFilterModel, count_dives_with_suit)
|
|||
|
||||
CREATE_INSTANCE_METHOD(MultiFilterSortModel)
|
||||
|
||||
SuitsFilterModel::SuitsFilterModel(QObject *parent) : QStringListModel(parent)
|
||||
FilterModelBase::FilterModelBase(QObject *parent) : QStringListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
// Update the stringList and the checkState array.
|
||||
// The last item is supposed to be the "Show Empty Tags" entry.
|
||||
void FilterModelBase::updateList(const QStringList &newList)
|
||||
{
|
||||
// Keep copy of old checkState array to reimport them later.
|
||||
std::vector<char> oldCheckState = checkState;
|
||||
checkState.resize(newList.count());
|
||||
std::fill(checkState.begin(), checkState.end(), false);
|
||||
anyChecked = false;
|
||||
|
||||
// Ignore last item, since this is the "Show Empty Tags" entry.
|
||||
for (int i = 0; i < rowCount() - 1; i++) {
|
||||
if (oldCheckState[i]) {
|
||||
int ind = newList.indexOf(stringList()[i]);
|
||||
if (ind >= 0 && ind < newList.count() - 1) {
|
||||
checkState[ind] = true;
|
||||
anyChecked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// On program startup, the old list is empty.
|
||||
if (rowCount() > 0 && oldCheckState.back()) {
|
||||
checkState.back() = true;
|
||||
anyChecked = true;
|
||||
}
|
||||
setStringList(newList);
|
||||
}
|
||||
|
||||
SuitsFilterModel::SuitsFilterModel(QObject *parent) : FilterModelBase(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -127,13 +160,10 @@ void SuitsFilterModel::repopulate()
|
|||
}
|
||||
qSort(list);
|
||||
list << tr("No suit set");
|
||||
setStringList(list);
|
||||
checkState.resize(list.count());
|
||||
std::fill(checkState.begin(), checkState.end(), false);
|
||||
anyChecked = false;
|
||||
updateList(list);
|
||||
}
|
||||
|
||||
TagFilterModel::TagFilterModel(QObject *parent) : QStringListModel(parent)
|
||||
TagFilterModel::TagFilterModel(QObject *parent) : FilterModelBase(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -150,10 +180,7 @@ void TagFilterModel::repopulate()
|
|||
}
|
||||
qSort(list);
|
||||
list << tr("Empty tags");
|
||||
setStringList(list);
|
||||
checkState.resize(list.count());
|
||||
std::fill(checkState.begin(), checkState.end(), false);
|
||||
anyChecked = false;
|
||||
updateList(list);
|
||||
}
|
||||
|
||||
bool TagFilterModel::doFilter(dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const
|
||||
|
@ -190,7 +217,7 @@ bool TagFilterModel::doFilter(dive *d, QModelIndex &index0, QAbstractItemModel *
|
|||
return false;
|
||||
}
|
||||
|
||||
BuddyFilterModel::BuddyFilterModel(QObject *parent) : QStringListModel(parent)
|
||||
BuddyFilterModel::BuddyFilterModel(QObject *parent) : FilterModelBase(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -243,13 +270,10 @@ void BuddyFilterModel::repopulate()
|
|||
}
|
||||
qSort(list);
|
||||
list << tr("No buddies");
|
||||
setStringList(list);
|
||||
checkState.resize(list.count());
|
||||
std::fill(checkState.begin(), checkState.end(), false);
|
||||
anyChecked = false;
|
||||
updateList(list);
|
||||
}
|
||||
|
||||
LocationFilterModel::LocationFilterModel(QObject *parent) : QStringListModel(parent)
|
||||
LocationFilterModel::LocationFilterModel(QObject *parent) : FilterModelBase(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -294,10 +318,7 @@ void LocationFilterModel::repopulate()
|
|||
}
|
||||
qSort(list);
|
||||
list << tr("No location set");
|
||||
setStringList(list);
|
||||
checkState.resize(list.count());
|
||||
std::fill(checkState.begin(), checkState.end(), false);
|
||||
anyChecked = false;
|
||||
updateList(list);
|
||||
}
|
||||
|
||||
MultiFilterSortModel::MultiFilterSortModel(QObject *parent) :
|
||||
|
|
|
@ -16,7 +16,13 @@ public:
|
|||
bool anyChecked;
|
||||
};
|
||||
|
||||
class TagFilterModel : public QStringListModel, public MultiFilterInterface {
|
||||
class FilterModelBase : public QStringListModel, public MultiFilterInterface {
|
||||
protected:
|
||||
explicit FilterModelBase(QObject *parent = 0);
|
||||
void updateList(const QStringList &new_list);
|
||||
};
|
||||
|
||||
class TagFilterModel : public FilterModelBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static TagFilterModel *instance();
|
||||
|
@ -33,7 +39,7 @@ private:
|
|||
explicit TagFilterModel(QObject *parent = 0);
|
||||
};
|
||||
|
||||
class BuddyFilterModel : public QStringListModel, public MultiFilterInterface {
|
||||
class BuddyFilterModel : public FilterModelBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static BuddyFilterModel *instance();
|
||||
|
@ -50,7 +56,7 @@ private:
|
|||
explicit BuddyFilterModel(QObject *parent = 0);
|
||||
};
|
||||
|
||||
class LocationFilterModel : public QStringListModel, public MultiFilterInterface {
|
||||
class LocationFilterModel : public FilterModelBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static LocationFilterModel *instance();
|
||||
|
@ -67,7 +73,7 @@ private:
|
|||
explicit LocationFilterModel(QObject *parent = 0);
|
||||
};
|
||||
|
||||
class SuitsFilterModel : public QStringListModel, public MultiFilterInterface {
|
||||
class SuitsFilterModel : public FilterModelBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static SuitsFilterModel *instance();
|
||||
|
|
Loading…
Add table
Reference in a new issue