diff --git a/qt-ui/globe.cpp b/qt-ui/globe.cpp index 066fdc217..4f40e22ec 100644 --- a/qt-ui/globe.cpp +++ b/qt-ui/globe.cpp @@ -24,6 +24,12 @@ #include #endif +GlobeGPS *GlobeGPS::instance() +{ + static GlobeGPS *self = new GlobeGPS(); + return self; +} + GlobeGPS::GlobeGPS(QWidget *parent) : MarbleWidget(parent), loadedDives(0), messageWidget(new KMessageWidget(this)), @@ -378,9 +384,9 @@ void GlobeGPS::centerOnIndex(const QModelIndex& idx) { struct dive_site *ds = get_dive_site_by_uuid(idx.model()->index(idx.row(), 0).data().toInt()); if (!ds || !dive_site_has_gps_location(ds)) - MainWindow::instance()->globe()->centerOnDiveSite(&displayed_dive_site); + centerOnDiveSite(&displayed_dive_site); else - MainWindow::instance()->globe()->centerOnDiveSite(ds); + centerOnDiveSite(ds); } #else diff --git a/qt-ui/globe.h b/qt-ui/globe.h index e8be53b5e..a8cb89440 100644 --- a/qt-ui/globe.h +++ b/qt-ui/globe.h @@ -21,7 +21,7 @@ class GlobeGPS : public MarbleWidget { Q_OBJECT public: using MarbleWidget::centerOn; - GlobeGPS(QWidget *parent = 0); + static GlobeGPS *instance(); void reload(); bool eventFilter(QObject *, QEvent *); @@ -38,6 +38,7 @@ private: bool needResetZoom; bool editingDiveLocation; bool doubleClick; + GlobeGPS(QWidget *parent = 0); signals: void coordinatesChanged(); diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 4b6f961c1..369a754bc 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -463,7 +463,7 @@ void MainTab::updateDiveInfo(bool clear) // I don't like this code here - but globe() wasn't initialized on the constructor. { QListView *completerListview = qobject_cast(ui.location->completer()->popup()); - connect(completerListview, SIGNAL(entered(QModelIndex)), MainWindow::instance()->globe(), SLOT(centerOnIndex(QModelIndex)), Qt::UniqueConnection); + connect(completerListview, SIGNAL(entered(QModelIndex)), GlobeGPS::instance(), SLOT(centerOnIndex(QModelIndex)), Qt::UniqueConnection); } EditMode rememberEM = editMode; @@ -1208,8 +1208,7 @@ void MainTab::rejectChanges() // the user could have edited the location and then canceled the edit // let's get the correct location back in view #ifndef NO_MARBLE - MainWindow::instance()->globe()->centerOnDiveSite(get_dive_site_by_uuid(displayed_dive.dive_site_uuid)); - MainWindow::instance()->globe()->reload(); + GlobeGPS::instance()->centerOnDiveSite(get_dive_site_by_uuid(displayed_dive.dive_site_uuid)); #endif // show the profile and dive info MainWindow::instance()->graphics()->replot(); diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index e7d53e550..4f8241586 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -73,7 +73,7 @@ MainWindow::MainWindow() : QMainWindow(), ProfileWidget2 *profileWidget = new ProfileWidget2(); #ifndef NO_MARBLE - GlobeGPS *globeGps = new GlobeGPS(); + GlobeGPS *globeGps = GlobeGPS::instance(); #else QWidget *globeGps = NULL; #endif @@ -174,7 +174,7 @@ MainWindow::MainWindow() : QMainWindow(), diveListView->reload(DiveTripModel::TREE); diveListView->reloadHeaderActions(); diveListView->setFocus(); - globe()->reload(); + GlobeGPS::instance()->reload(); diveListView->expand(dive_list()->model()->index(0, 0)); diveListView->scrollTo(dive_list()->model()->index(0, 0), QAbstractItemView::PositionAtCenter); divePlannerWidget()->settingsChanged(); @@ -258,7 +258,7 @@ void MainWindow::refreshDisplay(bool doRecreateDiveList) getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); information()->reload(); TankInfoModel::instance()->update(); - globe()->reload(); + GlobeGPS::instance()->reload(); if (doRecreateDiveList) recreateDiveList(); @@ -286,7 +286,7 @@ void MainWindow::current_dive_changed(int divenr) } graphics()->plotDive(); information()->updateDiveInfo(); - globe()->reload(); + GlobeGPS::instance()->reload(); } void MainWindow::on_actionNew_triggered() @@ -429,7 +429,7 @@ void MainWindow::cleanUpEmpty() information()->updateDiveInfo(true); graphics()->setEmptyState(); dive_list()->reload(DiveTripModel::TREE); - globe()->reload(); + GlobeGPS::instance()->reload(); if (!existing_filename) setTitle(MWTF_DEFAULT); disableShortcuts(); @@ -741,7 +741,7 @@ void MainWindow::on_actionEditDive_triggered() disableShortcuts(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); graphics()->setAddState(); - globe()->endGetDiveCoordinates(); + GlobeGPS::instance()->endGetDiveCoordinates(); setApplicationState("EditDive"); DivePlannerPointsModel::instance()->loadFromDive(current_dive); information()->enableEdition(MainTab::MANUALLY_ADDED_DIVE); @@ -1179,11 +1179,6 @@ DiveListView *MainWindow::dive_list() return qobject_cast(applicationState["Default"].bottomLeft); } -GlobeGPS *MainWindow::globe() -{ - return qobject_cast(applicationState["Default"].bottomRight); -} - MainTab *MainWindow::information() { return qobject_cast(applicationState["Default"].topLeft); diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index f3a0f221b..583dc591a 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -26,7 +26,6 @@ class Stats; class Equipment; class QItemSelection; class DiveListView; -class GlobeGPS; class MainTab; class ProfileGraphicsView; class QWebView; @@ -69,7 +68,6 @@ public: void addRecentFile(const QStringList &newFiles); void removeRecentFile(QStringList failedFiles); DiveListView *dive_list(); - GlobeGPS *globe(); DivePlannerWidget *divePlannerWidget(); PlannerSettingsWidget *divePlannerSettingsWidget(); LocationInformationWidget *locationInformationWidget(); diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index 8154ce5fb..128e199c3 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -418,8 +418,8 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton *button) // finally now that all the extra GPS fixes that weren't used have been deleted // we can update the globe if (changed) { - MainWindow::instance()->globe()->repopulateLabels(); - MainWindow::instance()->globe()->centerOnDiveSite(get_dive_site_by_uuid(current_dive->dive_site_uuid)); + GlobeGPS::instance()->repopulateLabels(); + GlobeGPS::instance()->centerOnDiveSite(get_dive_site_by_uuid(current_dive->dive_site_uuid)); } #endif