summaryrefslogtreecommitdiffstats
path: root/qt-models/completionmodels.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-11-14 17:42:59 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-11-14 10:01:50 -0800
commit38a784f5af3e19936df29e93b70a66e3741f8ea8 (patch)
tree2a6832759936eb91497d99457d8bae8c01db00a5 /qt-models/completionmodels.cpp
parent52d5125926f430a86dc14a60911b04b8072c712a (diff)
downloadsubsurface-38a784f5af3e19936df29e93b70a66e3741f8ea8.tar.gz
desktop: automatically reload completion-models
Instead of programatically reload the completion models, listen to the relevant signals in the models. To that goal, derive all the models from a base class. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/completionmodels.cpp')
-rw-r--r--qt-models/completionmodels.cpp58
1 files changed, 48 insertions, 10 deletions
diff --git a/qt-models/completionmodels.cpp b/qt-models/completionmodels.cpp
index 2ed8de204..b3d633c40 100644
--- a/qt-models/completionmodels.cpp
+++ b/qt-models/completionmodels.cpp
@@ -3,7 +3,6 @@
#include "core/dive.h"
#include "core/tag.h"
#include <QSet>
-#include <QString>
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
#define SKIP_EMPTY Qt::SkipEmptyParts
@@ -11,6 +10,24 @@
#define SKIP_EMPTY QString::SkipEmptyParts
#endif
+CompletionModelBase::CompletionModelBase()
+{
+ connect(&diveListNotifier, &DiveListNotifier::dataReset, this, &CompletionModelBase::updateModel);
+ connect(&diveListNotifier, &DiveListNotifier::divesImported, this, &CompletionModelBase::updateModel);
+ connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &CompletionModelBase::divesChanged);
+}
+
+void CompletionModelBase::updateModel()
+{
+ setStringList(getStrings());
+}
+
+void CompletionModelBase::divesChanged(const QVector<dive *> &, DiveField field)
+{
+ if (relevantDiveField(field))
+ updateModel();
+}
+
static QStringList getCSVList(char *dive::*item)
{
QSet<QString> set;
@@ -26,17 +43,27 @@ static QStringList getCSVList(char *dive::*item)
return setList;
}
-void BuddyCompletionModel::updateModel()
+QStringList BuddyCompletionModel::getStrings()
+{
+ return getCSVList(&dive::buddy);
+}
+
+bool BuddyCompletionModel::relevantDiveField(const DiveField &f)
+{
+ return f.buddy;
+}
+
+QStringList DiveMasterCompletionModel::getStrings()
{
- setStringList(getCSVList(&dive::buddy));
+ return getCSVList(&dive::divemaster);
}
-void DiveMasterCompletionModel::updateModel()
+bool DiveMasterCompletionModel::relevantDiveField(const DiveField &f)
{
- setStringList(getCSVList(&dive::divemaster));
+ return f.divemaster;
}
-void SuitCompletionModel::updateModel()
+QStringList SuitCompletionModel::getStrings()
{
QStringList list;
struct dive *dive;
@@ -47,18 +74,29 @@ void SuitCompletionModel::updateModel()
list.append(suit);
}
std::sort(list.begin(), list.end());
- setStringList(list);
+ return list;
}
-void TagCompletionModel::updateModel()
+bool SuitCompletionModel::relevantDiveField(const DiveField &f)
+{
+ return f.suit;
+}
+
+QStringList TagCompletionModel::getStrings()
{
if (g_tag_list == NULL)
- return;
+ return {};
QStringList list;
struct tag_entry *current_tag_entry = g_tag_list;
while (current_tag_entry != NULL) {
list.append(QString(current_tag_entry->tag->name));
current_tag_entry = current_tag_entry->next;
}
- setStringList(list);
+ std::sort(list.begin(), list.end());
+ return list;
+}
+
+bool TagCompletionModel::relevantDiveField(const DiveField &f)
+{
+ return f.tags;
}