Transform GlobeGPS in a static instance() class

This is needed to start easing the transition from the completely
wrong and bogus MainWindow::instance()->globe() calls. this is still
wrong, but with it I removed one level of indirection.
I did that now because I wanted to not taint the location management
when I use it to deal with the globe.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-07-30 21:51:38 -03:00 committed by Dirk Hohndel
parent 9130ff8a97
commit 7efa924067
6 changed files with 20 additions and 21 deletions

View file

@ -24,6 +24,12 @@
#include <marble/MarbleDebug.h> #include <marble/MarbleDebug.h>
#endif #endif
GlobeGPS *GlobeGPS::instance()
{
static GlobeGPS *self = new GlobeGPS();
return self;
}
GlobeGPS::GlobeGPS(QWidget *parent) : MarbleWidget(parent), GlobeGPS::GlobeGPS(QWidget *parent) : MarbleWidget(parent),
loadedDives(0), loadedDives(0),
messageWidget(new KMessageWidget(this)), 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()); 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)) if (!ds || !dive_site_has_gps_location(ds))
MainWindow::instance()->globe()->centerOnDiveSite(&displayed_dive_site); centerOnDiveSite(&displayed_dive_site);
else else
MainWindow::instance()->globe()->centerOnDiveSite(ds); centerOnDiveSite(ds);
} }
#else #else

View file

@ -21,7 +21,7 @@ class GlobeGPS : public MarbleWidget {
Q_OBJECT Q_OBJECT
public: public:
using MarbleWidget::centerOn; using MarbleWidget::centerOn;
GlobeGPS(QWidget *parent = 0); static GlobeGPS *instance();
void reload(); void reload();
bool eventFilter(QObject *, QEvent *); bool eventFilter(QObject *, QEvent *);
@ -38,6 +38,7 @@ private:
bool needResetZoom; bool needResetZoom;
bool editingDiveLocation; bool editingDiveLocation;
bool doubleClick; bool doubleClick;
GlobeGPS(QWidget *parent = 0);
signals: signals:
void coordinatesChanged(); void coordinatesChanged();

View file

@ -463,7 +463,7 @@ void MainTab::updateDiveInfo(bool clear)
// I don't like this code here - but globe() wasn't initialized on the constructor. // I don't like this code here - but globe() wasn't initialized on the constructor.
{ {
QListView *completerListview = qobject_cast<QListView*>(ui.location->completer()->popup()); QListView *completerListview = qobject_cast<QListView*>(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; EditMode rememberEM = editMode;
@ -1208,8 +1208,7 @@ void MainTab::rejectChanges()
// the user could have edited the location and then canceled the edit // the user could have edited the location and then canceled the edit
// let's get the correct location back in view // let's get the correct location back in view
#ifndef NO_MARBLE #ifndef NO_MARBLE
MainWindow::instance()->globe()->centerOnDiveSite(get_dive_site_by_uuid(displayed_dive.dive_site_uuid)); GlobeGPS::instance()->centerOnDiveSite(get_dive_site_by_uuid(displayed_dive.dive_site_uuid));
MainWindow::instance()->globe()->reload();
#endif #endif
// show the profile and dive info // show the profile and dive info
MainWindow::instance()->graphics()->replot(); MainWindow::instance()->graphics()->replot();

View file

@ -73,7 +73,7 @@ MainWindow::MainWindow() : QMainWindow(),
ProfileWidget2 *profileWidget = new ProfileWidget2(); ProfileWidget2 *profileWidget = new ProfileWidget2();
#ifndef NO_MARBLE #ifndef NO_MARBLE
GlobeGPS *globeGps = new GlobeGPS(); GlobeGPS *globeGps = GlobeGPS::instance();
#else #else
QWidget *globeGps = NULL; QWidget *globeGps = NULL;
#endif #endif
@ -174,7 +174,7 @@ MainWindow::MainWindow() : QMainWindow(),
diveListView->reload(DiveTripModel::TREE); diveListView->reload(DiveTripModel::TREE);
diveListView->reloadHeaderActions(); diveListView->reloadHeaderActions();
diveListView->setFocus(); diveListView->setFocus();
globe()->reload(); GlobeGPS::instance()->reload();
diveListView->expand(dive_list()->model()->index(0, 0)); diveListView->expand(dive_list()->model()->index(0, 0));
diveListView->scrollTo(dive_list()->model()->index(0, 0), QAbstractItemView::PositionAtCenter); diveListView->scrollTo(dive_list()->model()->index(0, 0), QAbstractItemView::PositionAtCenter);
divePlannerWidget()->settingsChanged(); divePlannerWidget()->settingsChanged();
@ -258,7 +258,7 @@ void MainWindow::refreshDisplay(bool doRecreateDiveList)
getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error);
information()->reload(); information()->reload();
TankInfoModel::instance()->update(); TankInfoModel::instance()->update();
globe()->reload(); GlobeGPS::instance()->reload();
if (doRecreateDiveList) if (doRecreateDiveList)
recreateDiveList(); recreateDiveList();
@ -286,7 +286,7 @@ void MainWindow::current_dive_changed(int divenr)
} }
graphics()->plotDive(); graphics()->plotDive();
information()->updateDiveInfo(); information()->updateDiveInfo();
globe()->reload(); GlobeGPS::instance()->reload();
} }
void MainWindow::on_actionNew_triggered() void MainWindow::on_actionNew_triggered()
@ -429,7 +429,7 @@ void MainWindow::cleanUpEmpty()
information()->updateDiveInfo(true); information()->updateDiveInfo(true);
graphics()->setEmptyState(); graphics()->setEmptyState();
dive_list()->reload(DiveTripModel::TREE); dive_list()->reload(DiveTripModel::TREE);
globe()->reload(); GlobeGPS::instance()->reload();
if (!existing_filename) if (!existing_filename)
setTitle(MWTF_DEFAULT); setTitle(MWTF_DEFAULT);
disableShortcuts(); disableShortcuts();
@ -741,7 +741,7 @@ void MainWindow::on_actionEditDive_triggered()
disableShortcuts(); disableShortcuts();
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
graphics()->setAddState(); graphics()->setAddState();
globe()->endGetDiveCoordinates(); GlobeGPS::instance()->endGetDiveCoordinates();
setApplicationState("EditDive"); setApplicationState("EditDive");
DivePlannerPointsModel::instance()->loadFromDive(current_dive); DivePlannerPointsModel::instance()->loadFromDive(current_dive);
information()->enableEdition(MainTab::MANUALLY_ADDED_DIVE); information()->enableEdition(MainTab::MANUALLY_ADDED_DIVE);
@ -1179,11 +1179,6 @@ DiveListView *MainWindow::dive_list()
return qobject_cast<DiveListView*>(applicationState["Default"].bottomLeft); return qobject_cast<DiveListView*>(applicationState["Default"].bottomLeft);
} }
GlobeGPS *MainWindow::globe()
{
return qobject_cast<GlobeGPS*>(applicationState["Default"].bottomRight);
}
MainTab *MainWindow::information() MainTab *MainWindow::information()
{ {
return qobject_cast<MainTab*>(applicationState["Default"].topLeft); return qobject_cast<MainTab*>(applicationState["Default"].topLeft);

View file

@ -26,7 +26,6 @@ class Stats;
class Equipment; class Equipment;
class QItemSelection; class QItemSelection;
class DiveListView; class DiveListView;
class GlobeGPS;
class MainTab; class MainTab;
class ProfileGraphicsView; class ProfileGraphicsView;
class QWebView; class QWebView;
@ -69,7 +68,6 @@ public:
void addRecentFile(const QStringList &newFiles); void addRecentFile(const QStringList &newFiles);
void removeRecentFile(QStringList failedFiles); void removeRecentFile(QStringList failedFiles);
DiveListView *dive_list(); DiveListView *dive_list();
GlobeGPS *globe();
DivePlannerWidget *divePlannerWidget(); DivePlannerWidget *divePlannerWidget();
PlannerSettingsWidget *divePlannerSettingsWidget(); PlannerSettingsWidget *divePlannerSettingsWidget();
LocationInformationWidget *locationInformationWidget(); LocationInformationWidget *locationInformationWidget();

View file

@ -418,8 +418,8 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton *button)
// finally now that all the extra GPS fixes that weren't used have been deleted // finally now that all the extra GPS fixes that weren't used have been deleted
// we can update the globe // we can update the globe
if (changed) { if (changed) {
MainWindow::instance()->globe()->repopulateLabels(); GlobeGPS::instance()->repopulateLabels();
MainWindow::instance()->globe()->centerOnDiveSite(get_dive_site_by_uuid(current_dive->dive_site_uuid)); GlobeGPS::instance()->centerOnDiveSite(get_dive_site_by_uuid(current_dive->dive_site_uuid));
} }
#endif #endif