aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models/completionmodels.cpp
diff options
context:
space:
mode:
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;
}