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>
This commit is contained in:
Berthold Stoeger 2020-11-14 17:42:59 +01:00 committed by Dirk Hohndel
parent 52d5125926
commit 38a784f5af
5 changed files with 83 additions and 36 deletions

View file

@ -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