diff options
author | Tomaz Canabrava <tomaz.canabrava@gmail.com> | 2015-05-29 22:22:24 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-05-29 20:59:11 -0700 |
commit | ac6a7ab24e087cc150a7eff0ff6e7e4f8c52ce9a (patch) | |
tree | 4aa3130a235a11f5fb6b39c1f791e643ae524a18 | |
parent | d6e61b74fc140ca5a6cb1de3c6b6435b3701aa5b (diff) | |
download | subsurface-ac6a7ab24e087cc150a7eff0ff6e7e4f8c52ce9a.tar.gz |
Update DiveLocationModel when thread finishes
This patch updates the DiveLocationModel when the
GeoLoockupInformationThread finishes, and also selects
the correct index for the displayed dive.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-models/divelocationmodel.cpp | 6 | ||||
-rw-r--r-- | qt-models/divelocationmodel.h | 4 | ||||
-rw-r--r-- | qt-ui/locationinformation.cpp | 2 | ||||
-rw-r--r-- | qt-ui/maintab.cpp | 15 | ||||
-rw-r--r-- | qt-ui/maintab.h | 2 |
5 files changed, 25 insertions, 4 deletions
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp index a5303da49..973452b16 100644 --- a/qt-models/divelocationmodel.cpp +++ b/qt-models/divelocationmodel.cpp @@ -1,6 +1,12 @@ #include "divelocationmodel.h" #include "dive.h" +LocationInformationModel *LocationInformationModel::instance() +{ + static LocationInformationModel *self = new LocationInformationModel(); + return self; +} + LocationInformationModel::LocationInformationModel(QObject *obj) : QAbstractListModel(obj), internalRowCount(0) { } diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h index 1bf7cedfd..ee5f3c362 100644 --- a/qt-models/divelocationmodel.h +++ b/qt-models/divelocationmodel.h @@ -6,11 +6,13 @@ class LocationInformationModel : public QAbstractListModel { Q_OBJECT public: - LocationInformationModel(QObject *obj = 0); + static LocationInformationModel *instance(); int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index = QModelIndex(), int role = Qt::DisplayRole) const; +public slots: void update(); private: + LocationInformationModel(QObject *obj = 0); int internalRowCount; }; diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 1ba7fd402..657a6f3f5 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -28,7 +28,7 @@ LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBo ui.diveSiteMessage->setText(tr("Dive site management")); ui.diveSiteMessage->addAction(closeAction); - ui.currentLocation->setModel(new LocationInformationModel()); + ui.currentLocation->setModel(LocationInformationModel::instance()); connect(ui.currentLocation, SIGNAL(currentIndexChanged(int)), this, SLOT(setCurrentDiveSite(int))); connect(this, SIGNAL(startFilterDiveSite(uint32_t)), MultiFilterSortModel::instance(), SLOT(startFilterDiveSite(uint32_t))); connect(this, SIGNAL(stopFilterDiveSite()), MultiFilterSortModel::instance(), SLOT(stopFilterDiveSite())); diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index e6cf8bc13..5b5c10115 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -20,7 +20,7 @@ #include "weightmodel.h" #include "divepicturemodel.h" #include "divecomputerextradatamodel.h" - +#include "divelocationmodel.h" #if defined(FBSUPPORT) #include "socialnetworks.h" #endif @@ -97,6 +97,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), connect(ui.cylinders->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editCylinderWidget(QModelIndex))); connect(ui.weights->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editWeightWidget(QModelIndex))); + ui.location->setModel(LocationInformationModel::instance()); ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this)); ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::USE, new TankUseDelegate(this)); ui.weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate(this)); @@ -199,6 +200,12 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui.waitingSpinner->setInnerRadius(5); ui.waitingSpinner->setRevolutionsPerSecond(1); + connect(ReverseGeoLookupThread::instance(), SIGNAL(finished()), + LocationInformationModel::instance(), SLOT(update())); + + connect(ReverseGeoLookupThread::instance(), &QThread::finished, + this, &MainTab::setCurrentLocationIndex); + acceptingEdit = false; } @@ -213,6 +220,12 @@ MainTab::~MainTab() } } +void MainTab::setCurrentLocationIndex() +{ + if (current_dive) + ui.location->setCurrentText(get_dive_site_by_uuid(current_dive->dive_site_uuid)->name); +} + void MainTab::enableGeoLookupEdition() { ui.waitingSpinner->stop(); diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 23be96efa..466733b8b 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -97,7 +97,7 @@ slots: void showLocation(); void enableGeoLookupEdition(); void disableGeoLookupEdition(); - + void setCurrentLocationIndex(); private: Ui::MainTab ui; WeightModel *weightModel; |