mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Cleanup: turn GpsListModel into standard singleton
GpsListModel was one of those "special" singletons that could be created explicitly with new. This would make sense if a parameter were passed to the constructor. We only passed null, so one might as well turn that into a classical singleton with default constructor. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
36d42a6a57
commit
2a9a3dda20
3 changed files with 5 additions and 9 deletions
|
@ -3,11 +3,8 @@
|
||||||
#include "core/qthelper.h"
|
#include "core/qthelper.h"
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
GpsListModel *GpsListModel::m_instance = NULL;
|
GpsListModel::GpsListModel()
|
||||||
|
|
||||||
GpsListModel::GpsListModel(QObject *parent) : QAbstractListModel(parent)
|
|
||||||
{
|
{
|
||||||
m_instance = this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpsListModel::update()
|
void GpsListModel::update()
|
||||||
|
@ -65,6 +62,7 @@ QHash<int, QByteArray> GpsListModel::roleNames() const
|
||||||
|
|
||||||
GpsListModel *GpsListModel::instance()
|
GpsListModel *GpsListModel::instance()
|
||||||
{
|
{
|
||||||
return m_instance;
|
static GpsListModel self;
|
||||||
|
return &self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
static GpsListModel *instance();
|
static GpsListModel *instance();
|
||||||
GpsListModel(QObject *parent = 0);
|
GpsListModel();
|
||||||
void clear();
|
void clear();
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
QHash<int, QByteArray> roleNames() const;
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
@ -28,7 +28,6 @@ public:
|
||||||
void update();
|
void update();
|
||||||
private:
|
private:
|
||||||
QVector<gpsTracker> m_gpsFixes;
|
QVector<gpsTracker> m_gpsFixes;
|
||||||
static GpsListModel *m_instance;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GPSLISTMODEL_H
|
#endif // GPSLISTMODEL_H
|
||||||
|
|
|
@ -97,9 +97,8 @@ void run_ui()
|
||||||
#endif // __APPLE__ not Q_OS_IOS
|
#endif // __APPLE__ not Q_OS_IOS
|
||||||
engine.addImportPath("qrc://imports");
|
engine.addImportPath("qrc://imports");
|
||||||
DiveListSortModel *sortModel = new DiveListSortModel(0);
|
DiveListSortModel *sortModel = new DiveListSortModel(0);
|
||||||
GpsListModel gpsListModel;
|
|
||||||
QSortFilterProxyModel *gpsSortModel = new QSortFilterProxyModel(nullptr);
|
QSortFilterProxyModel *gpsSortModel = new QSortFilterProxyModel(nullptr);
|
||||||
gpsSortModel->setSourceModel(&gpsListModel);
|
gpsSortModel->setSourceModel(GpsListModel::instance());
|
||||||
gpsSortModel->setDynamicSortFilter(true);
|
gpsSortModel->setDynamicSortFilter(true);
|
||||||
gpsSortModel->setSortRole(GpsListModel::GpsWhenRole);
|
gpsSortModel->setSortRole(GpsListModel::GpsWhenRole);
|
||||||
gpsSortModel->sort(0, Qt::DescendingOrder);
|
gpsSortModel->sort(0, Qt::DescendingOrder);
|
||||||
|
|
Loading…
Add table
Reference in a new issue