summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--desktop-widgets/tab-widgets/TabDiveEquipment.cpp1
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp15
-rw-r--r--mobile-widgets/qmlmanager.cpp6
-rw-r--r--qt-models/completionmodels.cpp58
-rw-r--r--qt-models/completionmodels.h39
5 files changed, 83 insertions, 36 deletions
diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp
index 8a7fc63b5..5105029a3 100644
--- a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp
+++ b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp
@@ -127,7 +127,6 @@ void TabDiveEquipment::updateData()
{
cylindersModel->updateDive(current_dive);
weightModel->updateDive(current_dive);
- suitModel.updateModel();
ui.cylinders->view()->hideColumn(CylindersModel::DEPTH);
bool is_ccr = current_dive && get_dive_dc(current_dive, dc_number)->divemode == CCR;
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index 30c768c25..f519d6a0b 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -261,18 +261,12 @@ void MainTab::divesChanged(const QVector<dive *> &dives, DiveField field)
}
if (field.divesite)
updateDiveSite(current_dive);
- if (field.tags) {
- tagModel.updateModel(); // TODO: Don't do this here
+ if (field.tags)
ui.tagWidget->setText(get_taglist_string(current_dive->tag_list));
- }
- if (field.buddy) {
- buddyModel.updateModel(); // TODO: Don't do this here
+ if (field.buddy)
ui.buddy->setText(current_dive->buddy);
- }
- if (field.divemaster) {
- diveMasterModel.updateModel(); // TODO: Don't do this here
+ if (field.divemaster)
ui.divemaster->setText(current_dive->divemaster);
- }
// If duration or depth changed, the profile needs to be replotted
if (field.duration || field.depth)
@@ -499,9 +493,6 @@ void MainTab::updateDiveInfo()
void MainTab::reload()
{
- buddyModel.updateModel();
- diveMasterModel.updateModel();
- tagModel.updateModel();
}
void MainTab::refreshDisplayedDiveSite()
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 12dad8086..10f6f11e5 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -452,9 +452,9 @@ void QMLManager::selectSwipeRow(int row)
void QMLManager::updateAllGlobalLists()
{
- buddyModel.updateModel(); emit buddyListChanged();
- suitModel.updateModel(); emit suitListChanged();
- divemasterModel.updateModel(); emit divemasterListChanged();
+ emit buddyListChanged();
+ emit suitListChanged();
+ emit divemasterListChanged();
// TODO: It would be nice if we could export the list of locations via model/view instead of a Q_PROPERTY
emit locationListChanged();
}
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;
}
diff --git a/qt-models/completionmodels.h b/qt-models/completionmodels.h
index 24ba67e5f..6d271c348 100644
--- a/qt-models/completionmodels.h
+++ b/qt-models/completionmodels.h
@@ -2,30 +2,49 @@
#ifndef COMPLETIONMODELS_H
#define COMPLETIONMODELS_H
+#include "core/subsurface-qt/divelistnotifier.h"
#include <QStringListModel>
-class BuddyCompletionModel : public QStringListModel {
+struct dive;
+
+class CompletionModelBase : public QStringListModel {
Q_OBJECT
public:
+ CompletionModelBase();
+private slots:
void updateModel();
+ void divesChanged(const QVector<dive *> &dives, DiveField field);
+protected:
+ virtual QStringList getStrings() = 0;
+ virtual bool relevantDiveField(const DiveField &f) = 0;
};
-class DiveMasterCompletionModel : public QStringListModel {
+class BuddyCompletionModel final : public CompletionModelBase {
Q_OBJECT
-public:
- void updateModel();
+private:
+ QStringList getStrings() override;
+ bool relevantDiveField(const DiveField &f) override;
};
-class SuitCompletionModel : public QStringListModel {
+class DiveMasterCompletionModel final : public CompletionModelBase {
Q_OBJECT
-public:
- void updateModel();
+private:
+ QStringList getStrings() override;
+ bool relevantDiveField(const DiveField &f) override;
};
-class TagCompletionModel : public QStringListModel {
+class SuitCompletionModel final : public CompletionModelBase {
Q_OBJECT
-public:
- void updateModel();
+private:
+ QStringList getStrings() override;
+ bool relevantDiveField(const DiveField &f) override;
+};
+
+class TagCompletionModel final : public CompletionModelBase {
+ Q_OBJECT
+private:
+ QStringList getStrings() override;
+ bool relevantDiveField(const DiveField &f) override;
};
#endif // COMPLETIONMODELS_H