diff options
author | Boris Barbulovski <bbarbulovski@gmail.com> | 2014-02-12 15:22:54 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-02-12 11:42:59 -0800 |
commit | c86822c2f47973528b3441d633b2b9df98ed465a (patch) | |
tree | 211d6b282dab31c3956e1fb4d5aaaa9811203c62 | |
parent | cc37d2e94ae34b8f260a1426e49c0ca082226502 (diff) | |
download | subsurface-c86822c2f47973528b3441d633b2b9df98ed465a.tar.gz |
Replace mainWindow() with MainWindow::instance()
C++ style of accessing single instance class object.
Signed-off-by: Boris Barbulovski <bbarbulovski@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | main.cpp | 4 | ||||
-rw-r--r-- | qt-ui/divecomputermanagementdialog.cpp | 2 | ||||
-rw-r--r-- | qt-ui/divelistview.cpp | 20 | ||||
-rw-r--r-- | qt-ui/divelogimportdialog.cpp | 6 | ||||
-rw-r--r-- | qt-ui/diveplanner.cpp | 10 | ||||
-rw-r--r-- | qt-ui/downloadfromdivecomputer.cpp | 2 | ||||
-rw-r--r-- | qt-ui/globe.cpp | 16 | ||||
-rw-r--r-- | qt-ui/maintab.cpp | 66 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 19 | ||||
-rw-r--r-- | qt-ui/mainwindow.h | 3 | ||||
-rw-r--r-- | qt-ui/models.cpp | 2 | ||||
-rw-r--r-- | qt-ui/preferences.cpp | 4 | ||||
-rw-r--r-- | qt-ui/printlayout.cpp | 2 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.cpp | 2 | ||||
-rw-r--r-- | qt-ui/profilegraphics.cpp | 16 | ||||
-rw-r--r-- | qt-ui/simplewidgets.cpp | 10 | ||||
-rw-r--r-- | qt-ui/subsurfacewebservices.cpp | 14 | ||||
-rw-r--r-- | qthelper.cpp | 2 |
18 files changed, 104 insertions, 96 deletions
@@ -48,8 +48,8 @@ int main(int argc, char **argv) files.push_back( QString(prefs.default_filename) ); } parse_xml_exit(); - mainWindow()->loadFiles(files); - mainWindow()->importFiles(importedFiles); + MainWindow::instance()->loadFiles(files); + MainWindow::instance()->importFiles(importedFiles); if (!quit) run_ui(); exit_ui(); diff --git a/qt-ui/divecomputermanagementdialog.cpp b/qt-ui/divecomputermanagementdialog.cpp index 348f93b40..c7d7fc75b 100644 --- a/qt-ui/divecomputermanagementdialog.cpp +++ b/qt-ui/divecomputermanagementdialog.cpp @@ -22,7 +22,7 @@ void DiveComputerManagementDialog::init() DiveComputerManagementDialog* DiveComputerManagementDialog::instance() { - static DiveComputerManagementDialog *self = new DiveComputerManagementDialog(mainWindow()); + static DiveComputerManagementDialog *self = new DiveComputerManagementDialog(MainWindow::instance()); self->setAttribute(Qt::WA_QuitOnClose, false); return self; } diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 43f0b1c38..028b232c2 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -518,7 +518,7 @@ void DiveListView::mergeDives() } } } - mainWindow()->refreshDisplay(); + MainWindow::instance()->refreshDisplay(); } void DiveListView::merge_trip(const QModelIndex &a, int offset) @@ -648,10 +648,10 @@ void DiveListView::markDiveInvalid() // d->invalid = true; } if (amount_selected == 0) { - mainWindow()->cleanUpEmpty(); + MainWindow::instance()->cleanUpEmpty(); } mark_divelist_changed(true); - mainWindow()->refreshDisplay(); + MainWindow::instance()->refreshDisplay(); if (prefs.display_invalid_dives == false) { clearSelection(); // select top dive that isn't marked invalid @@ -679,10 +679,10 @@ void DiveListView::deleteDive() lastDiveNr = i; } if (amount_selected == 0) { - mainWindow()->cleanUpEmpty(); + MainWindow::instance()->cleanUpEmpty(); } mark_divelist_changed(true); - mainWindow()->refreshDisplay(); + MainWindow::instance()->refreshDisplay(); if (lastDiveNr != -1) { clearSelection(); selectDive(lastDiveNr); @@ -769,7 +769,7 @@ void DiveListView::saveSelectedDivesAs() } settings.endGroup(); - QString fileName = QFileDialog::getSaveFileName(mainWindow(), tr("Save Dives As..."), QDir::homePath()); + QString fileName = QFileDialog::getSaveFileName(MainWindow::instance(), tr("Save Dives As..."), QDir::homePath()); if (fileName.isEmpty()) return; @@ -842,25 +842,25 @@ void DiveListView::loadImages() if (dive->when > imagetime) { ; // Before dive add_event(&(dive->dc), 0, 123, 0, 0, fileNames.at(i).toUtf8().data()); - mainWindow()->refreshDisplay(); + MainWindow::instance()->refreshDisplay(); mark_divelist_changed(true); } else if (dive->when + dive->duration.seconds < imagetime){ ; // After dive add_event(&(dive->dc), dive->duration.seconds, 123, 0, 0, fileNames.at(i).toUtf8().data()); - mainWindow()->refreshDisplay(); + MainWindow::instance()->refreshDisplay(); mark_divelist_changed(true); } else { add_event(&(dive->dc), imagetime - dive->when, 123, 0, 0, fileNames.at(i).toUtf8().data()); - mainWindow()->refreshDisplay(); + MainWindow::instance()->refreshDisplay(); mark_divelist_changed(true); } if (!dive->latitude.udeg && !IS_FP_SAME(exif.GeoLocation.Latitude, 0.0)){ dive->latitude.udeg = lrint(1000000.0 * exif.GeoLocation.Latitude); dive->longitude.udeg = lrint(1000000.0 * exif.GeoLocation.Longitude); mark_divelist_changed(true); - mainWindow()->refreshDisplay(); + MainWindow::instance()->refreshDisplay(); } } } diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp index 0a513de62..3005d1584 100644 --- a/qt-ui/divelogimportdialog.cpp +++ b/qt-ui/divelogimportdialog.cpp @@ -68,7 +68,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv", &error); if (error != NULL) { - mainWindow()->showError(error); + MainWindow::instance()->showError(error); free(error); error = NULL; } @@ -87,7 +87,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() VALUE_IF_CHECKED(Tags), &error); if (error != NULL) { - mainWindow()->showError(error); + MainWindow::instance()->showError(error); free(error); error = NULL; } @@ -95,7 +95,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() } process_dives(true, false); - mainWindow()->refreshDisplay(); + MainWindow::instance()->refreshDisplay(); } #define SET_VALUE_AND_CHECKBOX(CSV, BOX, VAL) ({\ diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 2a70b8d93..225c05569 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -371,7 +371,7 @@ void DivePlannerGraphics::decreaseDepth() Q_FOREACH(DiveHandler *d, handles) { if (depthLine->valueAt(d->pos()) > depthLine->maximum() - M_OR_FT(10,30)) { - QMessageBox::warning(mainWindow(), + QMessageBox::warning(MainWindow::instance(), tr("Handler Position Error"), tr("One or more of your stops will be lost with this operations, \n" "Please, remove them first.")); @@ -979,9 +979,9 @@ DivePlannerWidget::DivePlannerWidget(QWidget* parent, Qt::WindowFlags f): QWidge // Creating the plan connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan())); connect(ui.buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan())); - connect(plannerModel, SIGNAL(planCreated()), mainWindow(), SLOT(showProfile())); - connect(plannerModel, SIGNAL(planCreated()), mainWindow(), SLOT(refreshDisplay())); - connect(plannerModel, SIGNAL(planCanceled()), mainWindow(), SLOT(showProfile())); + connect(plannerModel, SIGNAL(planCreated()), MainWindow::instance(), SLOT(showProfile())); + connect(plannerModel, SIGNAL(planCreated()), MainWindow::instance(), SLOT(refreshDisplay())); + connect(plannerModel, SIGNAL(planCanceled()), MainWindow::instance(), SLOT(showProfile())); /* set defaults. */ ui.startTime->setTime( QTime(1, 0) ); @@ -1298,7 +1298,7 @@ struct diveplan DivePlannerPointsModel::getDiveplan() void DivePlannerPointsModel::cancelPlan() { if (mode == PLAN && rowCount()) { - if (QMessageBox::warning(mainWindow(), TITLE_OR_TEXT(tr("Discard the Plan?"), + if (QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(tr("Discard the Plan?"), tr("You are about to discard your plan.")), QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard) != QMessageBox::Discard) { return; diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp index d32112224..5dc38ca0a 100644 --- a/qt-ui/downloadfromdivecomputer.cpp +++ b/qt-ui/downloadfromdivecomputer.cpp @@ -269,7 +269,7 @@ void DownloadFromDCWidget::on_ok_clicked() connect(thread, SIGNAL(finished()), this, SLOT(onDownloadThreadFinished()), Qt::QueuedConnection); - MainWindow *w = mainWindow(); + MainWindow *w = MainWindow::instance(); connect(thread, SIGNAL(finished()), w, SLOT(refreshDisplay())); // before we start, remember where the dive_table ended diff --git a/qt-ui/globe.cpp b/qt-ui/globe.cpp index b3dcc0485..240f8d904 100644 --- a/qt-ui/globe.cpp +++ b/qt-ui/globe.cpp @@ -108,7 +108,7 @@ void GlobeGPS::contextMenuEvent(QContextMenuEvent* ev) void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit) { // don't mess with the selection while the user is editing a dive - if (mainWindow()->information()->isEditing()) + if (MainWindow::instance()->information()->isEditing()) return; GeoDataCoordinates here(lon, lat, unit); @@ -151,10 +151,10 @@ void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit) if (selectedDiveIds.empty()) return; if (clear) { - mainWindow()->dive_list()->unselectDives(); + MainWindow::instance()->dive_list()->unselectDives(); clear = false; } - mainWindow()->dive_list()->selectDives(selectedDiveIds); + MainWindow::instance()->dive_list()->selectDives(selectedDiveIds); } void GlobeGPS::repopulateLabels() @@ -210,7 +210,7 @@ void GlobeGPS::centerOn(dive* dive) qreal longitude = dive->longitude.udeg / 1000000.0; qreal latitude = dive->latitude.udeg / 1000000.0; - if (!longitude || !latitude || mainWindow()->information()->isEditing()) { + if (!longitude || !latitude || MainWindow::instance()->information()->isEditing()) { prepareForGetDiveCoordinates(); return; } @@ -249,7 +249,7 @@ void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::U { messageWidget->hide(); - if (mainWindow()->dive_list()->selectionModel()->selection().isEmpty()) + if (MainWindow::instance()->dive_list()->selectionModel()->selection().isEmpty()) return; // convert to degrees if in radian. @@ -270,7 +270,7 @@ void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::U centerOn(lon, lat, true); editingDiveLocation = false; mark_divelist_changed(true); - mainWindow()->refreshDisplay(); + MainWindow::instance()->refreshDisplay(); } void GlobeGPS::mousePressEvent(QMouseEvent* event) @@ -279,8 +279,8 @@ void GlobeGPS::mousePressEvent(QMouseEvent* event) bool clickOnGlobe = geoCoordinates(event->pos().x(), event->pos().y(), lon, lat, GeoDataCoordinates::Degree); // there could be two scenarios that got us here; let's check if we are editing a dive - if (mainWindow()->information()->isEditing() && clickOnGlobe) { - mainWindow()->information()->updateCoordinatesText(lat, lon); + if (MainWindow::instance()->information()->isEditing() && clickOnGlobe) { + MainWindow::instance()->information()->updateCoordinatesText(lat, lon); repopulateLabels(); } else if (clickOnGlobe) { changeDiveGeoPosition(lon, lat, GeoDataCoordinates::Degree); diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index b65d572fd..d878a68e9 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -234,14 +234,14 @@ void MainTab::enableEdition(EditMode newEditMode) strcmp(current_dive->dc.model, "manually added dive") == 0) { // editCurrentDive will call enableEdition with newEditMode == MANUALLY_ADDED_DIVE // so exit this function here after editCurrentDive() returns - mainWindow()->editCurrentDive(); + MainWindow::instance()->editCurrentDive(); return; } - mainWindow()->dive_list()->setEnabled(false); - mainWindow()->globe()->prepareForGetDiveCoordinates(); + MainWindow::instance()->dive_list()->setEnabled(false); + MainWindow::instance()->globe()->prepareForGetDiveCoordinates(); // We may be editing one or more dives here. backup everything. notesBackup.clear(); - if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) { + if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) { // we are editing trip location and notes displayMessage(tr("This trip is being edited.")); notesBackup[NULL].notes = ui.notes->toPlainText(); @@ -399,7 +399,7 @@ void MainTab::updateDiveInfo(int dive) if (d) { updateGpsCoordinates(d); ui.dateTimeEdit->setDateTime(QDateTime::fromTime_t(d->when).toUTC()); - if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) { + if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) { setTabText(0, tr("Trip Notes")); // only use trip relevant fields ui.coordinates->setVisible(false); @@ -421,7 +421,7 @@ void MainTab::updateDiveInfo(int dive) ui.waterTempLabel->setVisible(false); ui.watertemp->setVisible(false); // rename the remaining fields and fill data from selected trip - dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips().begin(); + dive_trip_t *currentTrip = *MainWindow::instance()->dive_list()->selectedTrips().begin(); ui.LocationLabel->setText(tr("Trip Location")); ui.location->setText(currentTrip->location); ui.NotesLabel->setText(tr("Trip Notes")); @@ -572,13 +572,13 @@ void MainTab::reload() void MainTab::acceptChanges() { - mainWindow()->dive_list()->setEnabled(true); + MainWindow::instance()->dive_list()->setEnabled(true); tabBar()->setTabIcon(0, QIcon()); // Notes tabBar()->setTabIcon(1, QIcon()); // Equipment hideMessage(); ui.equipmentTab->setEnabled(true); /* now figure out if things have changed */ - if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) { + if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) { if (notesBackup[NULL].notes != ui.notes->toPlainText() || notesBackup[NULL].location != ui.location->text()) mark_divelist_changed(true); @@ -602,7 +602,7 @@ void MainTab::acceptChanges() } if (notesBackup[curr].location != ui.location->text() || notesBackup[curr].coordinates != ui.coordinates->text()) { - mainWindow()->globe()->reload(); + MainWindow::instance()->globe()->reload(); } if (notesBackup[curr].tags != ui.tagWidget->text()) @@ -644,7 +644,7 @@ void MainTab::acceptChanges() else if (selected_dive == dive_table.nr - 1 && get_dive(dive_table.nr - 2)->number) current_dive->number = get_dive(dive_table.nr - 2)->number + 1; DivePlannerPointsModel::instance()->cancelPlan(); - mainWindow()->showProfile(); + MainWindow::instance()->showProfile(); mark_divelist_changed(true); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); } @@ -654,10 +654,10 @@ void MainTab::acceptChanges() if (d) fixup_dive(d); } - int scrolledBy = mainWindow()->dive_list()->verticalScrollBar()->sliderPosition(); + int scrolledBy = MainWindow::instance()->dive_list()->verticalScrollBar()->sliderPosition(); resetPallete(); if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) { - mainWindow()->dive_list()->unselectDives(); + MainWindow::instance()->dive_list()->unselectDives(); struct dive *d = get_dive(dive_table.nr -1 ); // mark the dive as remembered (abusing the selected flag) // and then clear that flag out on the other side of the sort_table() @@ -671,17 +671,17 @@ void MainTab::acceptChanges() } } editMode = NONE; - mainWindow()->refreshDisplay(); - mainWindow()->dive_list()->selectDive( i, true ); + MainWindow::instance()->refreshDisplay(); + MainWindow::instance()->dive_list()->selectDive( i, true ); } else { editMode = NONE; - mainWindow()->dive_list()->rememberSelection(); + MainWindow::instance()->dive_list()->rememberSelection(); sort_table(&dive_table); - mainWindow()->refreshDisplay(); - mainWindow()->dive_list()->restoreSelection(); + MainWindow::instance()->refreshDisplay(); + MainWindow::instance()->dive_list()->restoreSelection(); } - mainWindow()->dive_list()->verticalScrollBar()->setSliderPosition(scrolledBy); - mainWindow()->dive_list()->setFocus(); + MainWindow::instance()->dive_list()->verticalScrollBar()->setSliderPosition(scrolledBy); + MainWindow::instance()->dive_list()->setFocus(); } void MainTab::resetPallete() @@ -715,8 +715,8 @@ void MainTab::rejectChanges() tabBar()->setTabIcon(0, QIcon()); // Notes tabBar()->setTabIcon(1, QIcon()); // Equipment - mainWindow()->dive_list()->setEnabled(true); - if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) { + MainWindow::instance()->dive_list()->setEnabled(true); + if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) { ui.notes->setText(notesBackup[NULL].notes ); ui.location->setText(notesBackup[NULL].location); } else { @@ -777,8 +777,8 @@ void MainTab::rejectChanges() updateGpsCoordinates(curr); if (lastMode == ADD) { delete_single_dive(selected_dive); - mainWindow()->dive_list()->reload(DiveTripModel::CURRENT); - mainWindow()->dive_list()->restoreSelection(); + MainWindow::instance()->dive_list()->reload(DiveTripModel::CURRENT); + MainWindow::instance()->dive_list()->restoreSelection(); } if (selected_dive >= 0) { multiEditEquipmentPlaceholder = *get_dive(selected_dive); @@ -792,20 +792,20 @@ void MainTab::rejectChanges() } hideMessage(); - mainWindow()->dive_list()->setEnabled(true); + MainWindow::instance()->dive_list()->setEnabled(true); notesBackup.clear(); resetPallete(); editMode = NONE; - mainWindow()->globe()->reload(); + MainWindow::instance()->globe()->reload(); if (lastMode == ADD || lastMode == MANUALLY_ADDED_DIVE) { // more clean up updateDiveInfo(selected_dive); - mainWindow()->showProfile(); + MainWindow::instance()->showProfile(); // we already reloaded the divelist above, so don't recreate it or we'll lose the selection - mainWindow()->refreshDisplay(false); + MainWindow::instance()->refreshDisplay(false); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); } - mainWindow()->dive_list()->setFocus(); + MainWindow::instance()->dive_list()->setFocus(); } #undef EDIT_TEXT2 @@ -888,9 +888,9 @@ void MainTab::on_location_textChanged(const QString& text) { if (editMode == NONE) return; - if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) { + if (editMode == TRIP && MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) { // we are editing a trip - dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips().begin(); + dive_trip_t *currentTrip = *MainWindow::instance()->dive_list()->selectedTrips().begin(); EDIT_TEXT(currentTrip->location, text); } else if (editMode == DIVE || editMode == ADD || editMode == MANUALLY_ADDED_DIVE) { if (!ui.coordinates->isModified() || @@ -911,7 +911,7 @@ void MainTab::on_location_textChanged(const QString& text) } } EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) ); - mainWindow()->globe()->repopulateLabels(); + MainWindow::instance()->globe()->repopulateLabels(); } markChangedWidget(ui.location); } @@ -926,9 +926,9 @@ void MainTab::on_notes_textChanged() { if (editMode == NONE) return; - if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) { + if (editMode == TRIP && MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) { // we are editing a trip - dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips().begin(); + dive_trip_t *currentTrip = *MainWindow::instance()->dive_list()->selectedTrips().begin(); EDIT_TEXT(currentTrip->notes, ui.notes->toPlainText()); } else if (editMode == DIVE || editMode == ADD || editMode == MANUALLY_ADDED_DIVE) { EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->notes, ui.notes->toPlainText()) ); diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 217c66dbb..8795b93df 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -36,12 +36,7 @@ #include "printdialog.h" #include "divelogimportdialog.h" -static MainWindow* instance = 0; - -MainWindow* mainWindow() -{ - return instance; -} +MainWindow *MainWindow::m_Instance = NULL; MainWindow::MainWindow() : QMainWindow(), actionNextDive(0), @@ -49,7 +44,7 @@ MainWindow::MainWindow() : QMainWindow(), helpView(0), state(VIEWALL) { - instance = this; + m_Instance = this; ui.setupUi(this); setWindowIcon(QIcon(":subsurface-icon")); connect(ui.ListWidget, SIGNAL(currentDiveChanged(int)), this, SLOT(current_dive_changed(int))); @@ -79,6 +74,16 @@ MainWindow::MainWindow() : QMainWindow(), #endif } +MainWindow::~MainWindow() +{ + m_Instance = NULL; +} + +MainWindow *MainWindow::instance() +{ + return m_Instance; +} + // this gets called after we download dives from a divecomputer void MainWindow::refreshDisplay(bool recreateDiveList) { diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index a1b678296..deacdec76 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -41,6 +41,8 @@ public: enum CurrentState{ VIEWALL, GLOBE_MAXIMIZED, INFO_MAXIMIZED, PROFILE_MAXIMIZED, LIST_MAXIMIZED}; MainWindow(); + virtual ~MainWindow(); + static MainWindow *instance(); ProfileGraphicsView *graphics(); MainTab *information(); DiveListView *dive_list(); @@ -135,6 +137,7 @@ private: UserManual *helpView; CurrentState state; QString filter(); + static MainWindow *m_Instance; bool askSaveChanges(); void writeSettings(); void redrawProfile(); diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 942be2e5a..66a79fc90 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -334,7 +334,7 @@ void CylindersModel::remove(const QModelIndex& index) } cylinder_t *cyl = ¤t->cylinder[index.row()]; if (DivePlannerPointsModel::instance()->tankInUse(cyl->gasmix.o2.permille, cyl->gasmix.he.permille)) { - QMessageBox::warning(mainWindow(), TITLE_OR_TEXT( + QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT( tr("Cylinder cannot be removed"), tr("This gas in use. Only cylinders that are not used in the dive can be removed.")), QMessageBox::Ok); diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp index f3a88fcd3..01f1815c2 100644 --- a/qt-ui/preferences.cpp +++ b/qt-ui/preferences.cpp @@ -8,7 +8,7 @@ PreferencesDialog* PreferencesDialog::instance() { - static PreferencesDialog *dialog = new PreferencesDialog(mainWindow()); + static PreferencesDialog *dialog = new PreferencesDialog(MainWindow::instance()); dialog->setAttribute(Qt::WA_QuitOnClose, false); LanguageModel::instance(); return dialog; @@ -209,7 +209,7 @@ void PreferencesDialog::syncSettings() bool useSystemLang = s.value("UseSystemLanguage", true).toBool(); if (useSystemLang != ui.languageSystemDefault->isChecked() || (!useSystemLang && s.value("UiLanguage").toString() != ui.languageView->currentIndex().data(Qt::UserRole))) { - QMessageBox::warning(mainWindow(), tr("Restart required"), + QMessageBox::warning(MainWindow::instance(), tr("Restart required"), tr("To correctly load a new language you must restart Subsurface.")); } s.setValue("UseSystemLanguage", ui.languageSystemDefault->isChecked()); diff --git a/qt-ui/printlayout.cpp b/qt-ui/printlayout.cpp index c76068769..ec30b8369 100644 --- a/qt-ui/printlayout.cpp +++ b/qt-ui/printlayout.cpp @@ -131,7 +131,7 @@ void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn) painter.scale(scaleX, scaleY); // setup the profile widget - ProfileGraphicsView *profile = mainWindow()->graphics(); + ProfileGraphicsView *profile = MainWindow::instance()->graphics(); const int profileFrameStyle = profile->frameStyle(); profile->setFrameStyle(QFrame::NoFrame); profile->clear(); diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index cfe8e7f82..788c2808e 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -88,7 +88,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : #ifndef QT_NO_DEBUG QTableView *diveDepthTableView = new QTableView(); diveDepthTableView->setModel(dataModel); - mainWindow()->tabWidget()->addTab(diveDepthTableView, "Depth Model"); + MainWindow::instance()->tabWidget()->addTab(diveDepthTableView, "Depth Model"); #endif } diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index 14df03eb1..6ae765d7a 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -196,7 +196,7 @@ void ProfileGraphicsView::changeGas() add_gas_switch_event(current_dive, current_dc, seconds, get_gasidx(current_dive, o2, he)); // this means we potentially have a new tank that is being used and needs to be shown fixup_dive(current_dive); - mainWindow()->information()->updateDiveInfo(selected_dive); + MainWindow::instance()->information()->updateDiveInfo(selected_dive); mark_divelist_changed(true); plot(current_dive, true); } @@ -207,7 +207,7 @@ void ProfileGraphicsView::hideEvents() EventItem *item = static_cast<EventItem*>(action->data().value<void*>()); struct event *event = item->ev; - if (QMessageBox::question(mainWindow(), TITLE_OR_TEXT( + if (QMessageBox::question(MainWindow::instance(), TITLE_OR_TEXT( tr("Hide events"), tr("Hide all %1 events?").arg(event->name)), QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { @@ -237,7 +237,7 @@ void ProfileGraphicsView::removeEvent() EventItem *item = static_cast<EventItem*>(action->data().value<void*>()); struct event *event = item->ev; - if (QMessageBox::question(mainWindow(), TITLE_OR_TEXT( + if (QMessageBox::question(MainWindow::instance(), TITLE_OR_TEXT( tr("Remove the selected event?"), tr("%1 @ %2:%3").arg(event->name) .arg(event->time.seconds / 60) @@ -375,13 +375,13 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw) diveId = d ? d->id : 0; diveDC = d ? dc : NULL; - if (!isVisible() || !d || !mainWindow()) { + if (!isVisible() || !d || !MainWindow::instance()) { return; } setBackgroundBrush(getColor(BACKGROUND)); // best place to put the focus stealer code. - setFocusProxy(mainWindow()->dive_list()); + setFocusProxy(MainWindow::instance()->dive_list()); scene()->setSceneRect(0,0, viewport()->width()-50, viewport()->height()-50); toolTip = new ToolTipItem(); @@ -546,7 +546,7 @@ void ProfileGraphicsView::addControlItems(struct dive *d) if (defaultDC == "manually added dive" || defaultDC == "planned dive") { QAction *editAction = new QAction(QIcon(":edit"), tr("Edit"), this); toolBar->addAction(editAction); - connect(editAction, SIGNAL(triggered()), mainWindow(), SLOT(editCurrentDive())); + connect(editAction, SIGNAL(triggered()), MainWindow::instance(), SLOT(editCurrentDive())); } toolBarProxy = scene()->addWidget(toolBar); toolBarProxy->setPos(mapToScene(TOOLBAR_POS)); @@ -1628,7 +1628,7 @@ GraphicsTextEditor::GraphicsTextEditor(QGraphicsItem* parent): QGraphicsTextItem void GraphicsTextEditor::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) { // Remove the proxy filter so we can focus here. - mainWindow()->graphics()->setFocusProxy(0); + MainWindow::instance()->graphics()->setFocusProxy(0); setTextInteractionFlags(Qt::TextEditorInteraction | Qt::TextEditable); } @@ -1637,7 +1637,7 @@ void GraphicsTextEditor::keyReleaseEvent(QKeyEvent* event) if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { setTextInteractionFlags(Qt::NoTextInteraction); emit editingFinished( toPlainText() ); - mainWindow()->graphics()->setFocusProxy(mainWindow()->dive_list()); + MainWindow::instance()->graphics()->setFocusProxy(MainWindow::instance()->dive_list()); return; } emit textChanged( toPlainText() ); diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp index d69425ef9..2a0b48307 100644 --- a/qt-ui/simplewidgets.cpp +++ b/qt-ui/simplewidgets.cpp @@ -107,7 +107,7 @@ void MinMaxAvgWidget::setMinimum(const QString& minimum) RenumberDialog* RenumberDialog::instance() { - static RenumberDialog* self = new RenumberDialog(mainWindow()); + static RenumberDialog* self = new RenumberDialog(MainWindow::instance()); return self; } @@ -127,7 +127,7 @@ RenumberDialog::RenumberDialog(QWidget *parent): QDialog(parent) ShiftTimesDialog* ShiftTimesDialog::instance() { - static ShiftTimesDialog* self = new ShiftTimesDialog(mainWindow()); + static ShiftTimesDialog* self = new ShiftTimesDialog(MainWindow::instance()); return self; } @@ -144,9 +144,9 @@ void ShiftTimesDialog::buttonClicked(QAbstractButton* button) shift_times(amount); sort_table(&dive_table); mark_divelist_changed(true); - mainWindow()->dive_list()->rememberSelection(); - mainWindow()->refreshDisplay(); - mainWindow()->dive_list()->restoreSelection(); + MainWindow::instance()->dive_list()->rememberSelection(); + MainWindow::instance()->refreshDisplay(); + MainWindow::instance()->dive_list()->restoreSelection(); } } } diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index 918cf53f3..86dbf5015 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -333,9 +333,9 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton* button) /* now merge the data in the gps_location table into the dive_table */ if (merge_locations_into_dives()) { mark_divelist_changed(true); - mainWindow()->globe()->repopulateLabels(); - mainWindow()->globe()->centerOn(current_dive); - mainWindow()->information()->updateDiveInfo(selected_dive); + MainWindow::instance()->globe()->repopulateLabels(); + MainWindow::instance()->globe()->centerOn(current_dive); + MainWindow::instance()->information()->updateDiveInfo(selected_dive); } /* store last entered uid in config */ @@ -558,7 +558,7 @@ out: DivelogsDeWebServices* DivelogsDeWebServices::instance() { - static DivelogsDeWebServices *self = new DivelogsDeWebServices(mainWindow()); + static DivelogsDeWebServices *self = new DivelogsDeWebServices(MainWindow::instance()); self->setAttribute(Qt::WA_QuitOnClose, false); return self; } @@ -586,7 +586,7 @@ void DivelogsDeWebServices::prepareDivesForUpload() return; } } - mainWindow()->showError(errorText); + MainWindow::instance()->showError(errorText); } void DivelogsDeWebServices::uploadDives(QIODevice *dldContent) @@ -855,11 +855,11 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton* button) char *error = NULL; parse_file(QFile::encodeName(zipFile.fileName()), &error); if (error != NULL) { - mainWindow()->showError(error); + MainWindow::instance()->showError(error); free(error); } process_dives(true, false); - mainWindow()->refreshDisplay(); + MainWindow::instance()->refreshDisplay(); /* store last entered user/pass in config */ QSettings s; diff --git a/qthelper.cpp b/qthelper.cpp index acdb7c2ee..6f15517d4 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -6,7 +6,7 @@ #include <QFileDialog> #include <QDebug> -#define tr(_arg) mainWindow()->information()->tr(_arg) +#define tr(_arg) MainWindow::instance()->information()->tr(_arg) DiveComputerList::DiveComputerList() { |