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>
This commit is contained in:
Boris Barbulovski 2014-02-12 15:22:54 +01:00 committed by Dirk Hohndel
parent cc37d2e94a
commit c86822c2f4
18 changed files with 104 additions and 96 deletions

View file

@ -48,8 +48,8 @@ int main(int argc, char **argv)
files.push_back( QString(prefs.default_filename) ); files.push_back( QString(prefs.default_filename) );
} }
parse_xml_exit(); parse_xml_exit();
mainWindow()->loadFiles(files); MainWindow::instance()->loadFiles(files);
mainWindow()->importFiles(importedFiles); MainWindow::instance()->importFiles(importedFiles);
if (!quit) if (!quit)
run_ui(); run_ui();
exit_ui(); exit_ui();

View file

@ -22,7 +22,7 @@ void DiveComputerManagementDialog::init()
DiveComputerManagementDialog* DiveComputerManagementDialog::instance() DiveComputerManagementDialog* DiveComputerManagementDialog::instance()
{ {
static DiveComputerManagementDialog *self = new DiveComputerManagementDialog(mainWindow()); static DiveComputerManagementDialog *self = new DiveComputerManagementDialog(MainWindow::instance());
self->setAttribute(Qt::WA_QuitOnClose, false); self->setAttribute(Qt::WA_QuitOnClose, false);
return self; return self;
} }

View file

@ -518,7 +518,7 @@ void DiveListView::mergeDives()
} }
} }
} }
mainWindow()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
} }
void DiveListView::merge_trip(const QModelIndex &a, int offset) void DiveListView::merge_trip(const QModelIndex &a, int offset)
@ -648,10 +648,10 @@ void DiveListView::markDiveInvalid()
// d->invalid = true; // d->invalid = true;
} }
if (amount_selected == 0) { if (amount_selected == 0) {
mainWindow()->cleanUpEmpty(); MainWindow::instance()->cleanUpEmpty();
} }
mark_divelist_changed(true); mark_divelist_changed(true);
mainWindow()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
if (prefs.display_invalid_dives == false) { if (prefs.display_invalid_dives == false) {
clearSelection(); clearSelection();
// select top dive that isn't marked invalid // select top dive that isn't marked invalid
@ -679,10 +679,10 @@ void DiveListView::deleteDive()
lastDiveNr = i; lastDiveNr = i;
} }
if (amount_selected == 0) { if (amount_selected == 0) {
mainWindow()->cleanUpEmpty(); MainWindow::instance()->cleanUpEmpty();
} }
mark_divelist_changed(true); mark_divelist_changed(true);
mainWindow()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
if (lastDiveNr != -1) { if (lastDiveNr != -1) {
clearSelection(); clearSelection();
selectDive(lastDiveNr); selectDive(lastDiveNr);
@ -769,7 +769,7 @@ void DiveListView::saveSelectedDivesAs()
} }
settings.endGroup(); 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()) if (fileName.isEmpty())
return; return;
@ -842,25 +842,25 @@ void DiveListView::loadImages()
if (dive->when > imagetime) { if (dive->when > imagetime) {
; // Before dive ; // Before dive
add_event(&(dive->dc), 0, 123, 0, 0, fileNames.at(i).toUtf8().data()); add_event(&(dive->dc), 0, 123, 0, 0, fileNames.at(i).toUtf8().data());
mainWindow()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
mark_divelist_changed(true); mark_divelist_changed(true);
} }
else if (dive->when + dive->duration.seconds < imagetime){ else if (dive->when + dive->duration.seconds < imagetime){
; // After dive ; // After dive
add_event(&(dive->dc), dive->duration.seconds, 123, 0, 0, fileNames.at(i).toUtf8().data()); add_event(&(dive->dc), dive->duration.seconds, 123, 0, 0, fileNames.at(i).toUtf8().data());
mainWindow()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
mark_divelist_changed(true); mark_divelist_changed(true);
} }
else { else {
add_event(&(dive->dc), imagetime - dive->when, 123, 0, 0, fileNames.at(i).toUtf8().data()); add_event(&(dive->dc), imagetime - dive->when, 123, 0, 0, fileNames.at(i).toUtf8().data());
mainWindow()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
mark_divelist_changed(true); mark_divelist_changed(true);
} }
if (!dive->latitude.udeg && !IS_FP_SAME(exif.GeoLocation.Latitude, 0.0)){ if (!dive->latitude.udeg && !IS_FP_SAME(exif.GeoLocation.Latitude, 0.0)){
dive->latitude.udeg = lrint(1000000.0 * exif.GeoLocation.Latitude); dive->latitude.udeg = lrint(1000000.0 * exif.GeoLocation.Latitude);
dive->longitude.udeg = lrint(1000000.0 * exif.GeoLocation.Longitude); dive->longitude.udeg = lrint(1000000.0 * exif.GeoLocation.Longitude);
mark_divelist_changed(true); mark_divelist_changed(true);
mainWindow()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
} }
} }
} }

View file

@ -68,7 +68,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv", specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
&error); &error);
if (error != NULL) { if (error != NULL) {
mainWindow()->showError(error); MainWindow::instance()->showError(error);
free(error); free(error);
error = NULL; error = NULL;
} }
@ -87,7 +87,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
VALUE_IF_CHECKED(Tags), VALUE_IF_CHECKED(Tags),
&error); &error);
if (error != NULL) { if (error != NULL) {
mainWindow()->showError(error); MainWindow::instance()->showError(error);
free(error); free(error);
error = NULL; error = NULL;
} }
@ -95,7 +95,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
} }
process_dives(true, false); process_dives(true, false);
mainWindow()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
} }
#define SET_VALUE_AND_CHECKBOX(CSV, BOX, VAL) ({\ #define SET_VALUE_AND_CHECKBOX(CSV, BOX, VAL) ({\

View file

@ -371,7 +371,7 @@ void DivePlannerGraphics::decreaseDepth()
Q_FOREACH(DiveHandler *d, handles) { Q_FOREACH(DiveHandler *d, handles) {
if (depthLine->valueAt(d->pos()) > depthLine->maximum() - M_OR_FT(10,30)) { if (depthLine->valueAt(d->pos()) > depthLine->maximum() - M_OR_FT(10,30)) {
QMessageBox::warning(mainWindow(), QMessageBox::warning(MainWindow::instance(),
tr("Handler Position Error"), tr("Handler Position Error"),
tr("One or more of your stops will be lost with this operations, \n" tr("One or more of your stops will be lost with this operations, \n"
"Please, remove them first.")); "Please, remove them first."));
@ -979,9 +979,9 @@ DivePlannerWidget::DivePlannerWidget(QWidget* parent, Qt::WindowFlags f): QWidge
// Creating the plan // Creating the plan
connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan())); connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan()));
connect(ui.buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan())); connect(ui.buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan()));
connect(plannerModel, SIGNAL(planCreated()), mainWindow(), SLOT(showProfile())); connect(plannerModel, SIGNAL(planCreated()), MainWindow::instance(), SLOT(showProfile()));
connect(plannerModel, SIGNAL(planCreated()), mainWindow(), SLOT(refreshDisplay())); connect(plannerModel, SIGNAL(planCreated()), MainWindow::instance(), SLOT(refreshDisplay()));
connect(plannerModel, SIGNAL(planCanceled()), mainWindow(), SLOT(showProfile())); connect(plannerModel, SIGNAL(planCanceled()), MainWindow::instance(), SLOT(showProfile()));
/* set defaults. */ /* set defaults. */
ui.startTime->setTime( QTime(1, 0) ); ui.startTime->setTime( QTime(1, 0) );
@ -1298,7 +1298,7 @@ struct diveplan DivePlannerPointsModel::getDiveplan()
void DivePlannerPointsModel::cancelPlan() void DivePlannerPointsModel::cancelPlan()
{ {
if (mode == PLAN && rowCount()) { 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.")), tr("You are about to discard your plan.")),
QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard) != QMessageBox::Discard) { QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard) != QMessageBox::Discard) {
return; return;

View file

@ -269,7 +269,7 @@ void DownloadFromDCWidget::on_ok_clicked()
connect(thread, SIGNAL(finished()), connect(thread, SIGNAL(finished()),
this, SLOT(onDownloadThreadFinished()), Qt::QueuedConnection); this, SLOT(onDownloadThreadFinished()), Qt::QueuedConnection);
MainWindow *w = mainWindow(); MainWindow *w = MainWindow::instance();
connect(thread, SIGNAL(finished()), w, SLOT(refreshDisplay())); connect(thread, SIGNAL(finished()), w, SLOT(refreshDisplay()));
// before we start, remember where the dive_table ended // before we start, remember where the dive_table ended

View file

@ -108,7 +108,7 @@ void GlobeGPS::contextMenuEvent(QContextMenuEvent* ev)
void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit) void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit)
{ {
// don't mess with the selection while the user is editing a dive // don't mess with the selection while the user is editing a dive
if (mainWindow()->information()->isEditing()) if (MainWindow::instance()->information()->isEditing())
return; return;
GeoDataCoordinates here(lon, lat, unit); GeoDataCoordinates here(lon, lat, unit);
@ -151,10 +151,10 @@ void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit)
if (selectedDiveIds.empty()) if (selectedDiveIds.empty())
return; return;
if (clear) { if (clear) {
mainWindow()->dive_list()->unselectDives(); MainWindow::instance()->dive_list()->unselectDives();
clear = false; clear = false;
} }
mainWindow()->dive_list()->selectDives(selectedDiveIds); MainWindow::instance()->dive_list()->selectDives(selectedDiveIds);
} }
void GlobeGPS::repopulateLabels() void GlobeGPS::repopulateLabels()
@ -210,7 +210,7 @@ void GlobeGPS::centerOn(dive* dive)
qreal longitude = dive->longitude.udeg / 1000000.0; qreal longitude = dive->longitude.udeg / 1000000.0;
qreal latitude = dive->latitude.udeg / 1000000.0; qreal latitude = dive->latitude.udeg / 1000000.0;
if (!longitude || !latitude || mainWindow()->information()->isEditing()) { if (!longitude || !latitude || MainWindow::instance()->information()->isEditing()) {
prepareForGetDiveCoordinates(); prepareForGetDiveCoordinates();
return; return;
} }
@ -249,7 +249,7 @@ void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::U
{ {
messageWidget->hide(); messageWidget->hide();
if (mainWindow()->dive_list()->selectionModel()->selection().isEmpty()) if (MainWindow::instance()->dive_list()->selectionModel()->selection().isEmpty())
return; return;
// convert to degrees if in radian. // convert to degrees if in radian.
@ -270,7 +270,7 @@ void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::U
centerOn(lon, lat, true); centerOn(lon, lat, true);
editingDiveLocation = false; editingDiveLocation = false;
mark_divelist_changed(true); mark_divelist_changed(true);
mainWindow()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
} }
void GlobeGPS::mousePressEvent(QMouseEvent* event) 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); 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 // there could be two scenarios that got us here; let's check if we are editing a dive
if (mainWindow()->information()->isEditing() && clickOnGlobe) { if (MainWindow::instance()->information()->isEditing() && clickOnGlobe) {
mainWindow()->information()->updateCoordinatesText(lat, lon); MainWindow::instance()->information()->updateCoordinatesText(lat, lon);
repopulateLabels(); repopulateLabels();
} else if (clickOnGlobe) { } else if (clickOnGlobe) {
changeDiveGeoPosition(lon, lat, GeoDataCoordinates::Degree); changeDiveGeoPosition(lon, lat, GeoDataCoordinates::Degree);

View file

@ -234,14 +234,14 @@ void MainTab::enableEdition(EditMode newEditMode)
strcmp(current_dive->dc.model, "manually added dive") == 0) { strcmp(current_dive->dc.model, "manually added dive") == 0) {
// editCurrentDive will call enableEdition with newEditMode == MANUALLY_ADDED_DIVE // editCurrentDive will call enableEdition with newEditMode == MANUALLY_ADDED_DIVE
// so exit this function here after editCurrentDive() returns // so exit this function here after editCurrentDive() returns
mainWindow()->editCurrentDive(); MainWindow::instance()->editCurrentDive();
return; return;
} }
mainWindow()->dive_list()->setEnabled(false); MainWindow::instance()->dive_list()->setEnabled(false);
mainWindow()->globe()->prepareForGetDiveCoordinates(); MainWindow::instance()->globe()->prepareForGetDiveCoordinates();
// We may be editing one or more dives here. backup everything. // We may be editing one or more dives here. backup everything.
notesBackup.clear(); 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 // we are editing trip location and notes
displayMessage(tr("This trip is being edited.")); displayMessage(tr("This trip is being edited."));
notesBackup[NULL].notes = ui.notes->toPlainText(); notesBackup[NULL].notes = ui.notes->toPlainText();
@ -399,7 +399,7 @@ void MainTab::updateDiveInfo(int dive)
if (d) { if (d) {
updateGpsCoordinates(d); updateGpsCoordinates(d);
ui.dateTimeEdit->setDateTime(QDateTime::fromTime_t(d->when).toUTC()); 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")); setTabText(0, tr("Trip Notes"));
// only use trip relevant fields // only use trip relevant fields
ui.coordinates->setVisible(false); ui.coordinates->setVisible(false);
@ -421,7 +421,7 @@ void MainTab::updateDiveInfo(int dive)
ui.waterTempLabel->setVisible(false); ui.waterTempLabel->setVisible(false);
ui.watertemp->setVisible(false); ui.watertemp->setVisible(false);
// rename the remaining fields and fill data from selected trip // 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.LocationLabel->setText(tr("Trip Location"));
ui.location->setText(currentTrip->location); ui.location->setText(currentTrip->location);
ui.NotesLabel->setText(tr("Trip Notes")); ui.NotesLabel->setText(tr("Trip Notes"));
@ -572,13 +572,13 @@ void MainTab::reload()
void MainTab::acceptChanges() void MainTab::acceptChanges()
{ {
mainWindow()->dive_list()->setEnabled(true); MainWindow::instance()->dive_list()->setEnabled(true);
tabBar()->setTabIcon(0, QIcon()); // Notes tabBar()->setTabIcon(0, QIcon()); // Notes
tabBar()->setTabIcon(1, QIcon()); // Equipment tabBar()->setTabIcon(1, QIcon()); // Equipment
hideMessage(); hideMessage();
ui.equipmentTab->setEnabled(true); ui.equipmentTab->setEnabled(true);
/* now figure out if things have changed */ /* 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() || if (notesBackup[NULL].notes != ui.notes->toPlainText() ||
notesBackup[NULL].location != ui.location->text()) notesBackup[NULL].location != ui.location->text())
mark_divelist_changed(true); mark_divelist_changed(true);
@ -602,7 +602,7 @@ void MainTab::acceptChanges()
} }
if (notesBackup[curr].location != ui.location->text() || if (notesBackup[curr].location != ui.location->text() ||
notesBackup[curr].coordinates != ui.coordinates->text()) { notesBackup[curr].coordinates != ui.coordinates->text()) {
mainWindow()->globe()->reload(); MainWindow::instance()->globe()->reload();
} }
if (notesBackup[curr].tags != ui.tagWidget->text()) 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) 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; current_dive->number = get_dive(dive_table.nr - 2)->number + 1;
DivePlannerPointsModel::instance()->cancelPlan(); DivePlannerPointsModel::instance()->cancelPlan();
mainWindow()->showProfile(); MainWindow::instance()->showProfile();
mark_divelist_changed(true); mark_divelist_changed(true);
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
} }
@ -654,10 +654,10 @@ void MainTab::acceptChanges()
if (d) if (d)
fixup_dive(d); fixup_dive(d);
} }
int scrolledBy = mainWindow()->dive_list()->verticalScrollBar()->sliderPosition(); int scrolledBy = MainWindow::instance()->dive_list()->verticalScrollBar()->sliderPosition();
resetPallete(); resetPallete();
if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) { 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 ); struct dive *d = get_dive(dive_table.nr -1 );
// mark the dive as remembered (abusing the selected flag) // mark the dive as remembered (abusing the selected flag)
// and then clear that flag out on the other side of the sort_table() // and then clear that flag out on the other side of the sort_table()
@ -671,17 +671,17 @@ void MainTab::acceptChanges()
} }
} }
editMode = NONE; editMode = NONE;
mainWindow()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
mainWindow()->dive_list()->selectDive( i, true ); MainWindow::instance()->dive_list()->selectDive( i, true );
} else { } else {
editMode = NONE; editMode = NONE;
mainWindow()->dive_list()->rememberSelection(); MainWindow::instance()->dive_list()->rememberSelection();
sort_table(&dive_table); sort_table(&dive_table);
mainWindow()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
mainWindow()->dive_list()->restoreSelection(); MainWindow::instance()->dive_list()->restoreSelection();
} }
mainWindow()->dive_list()->verticalScrollBar()->setSliderPosition(scrolledBy); MainWindow::instance()->dive_list()->verticalScrollBar()->setSliderPosition(scrolledBy);
mainWindow()->dive_list()->setFocus(); MainWindow::instance()->dive_list()->setFocus();
} }
void MainTab::resetPallete() void MainTab::resetPallete()
@ -715,8 +715,8 @@ void MainTab::rejectChanges()
tabBar()->setTabIcon(0, QIcon()); // Notes tabBar()->setTabIcon(0, QIcon()); // Notes
tabBar()->setTabIcon(1, QIcon()); // Equipment tabBar()->setTabIcon(1, QIcon()); // Equipment
mainWindow()->dive_list()->setEnabled(true); MainWindow::instance()->dive_list()->setEnabled(true);
if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) { if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) {
ui.notes->setText(notesBackup[NULL].notes ); ui.notes->setText(notesBackup[NULL].notes );
ui.location->setText(notesBackup[NULL].location); ui.location->setText(notesBackup[NULL].location);
} else { } else {
@ -777,8 +777,8 @@ void MainTab::rejectChanges()
updateGpsCoordinates(curr); updateGpsCoordinates(curr);
if (lastMode == ADD) { if (lastMode == ADD) {
delete_single_dive(selected_dive); delete_single_dive(selected_dive);
mainWindow()->dive_list()->reload(DiveTripModel::CURRENT); MainWindow::instance()->dive_list()->reload(DiveTripModel::CURRENT);
mainWindow()->dive_list()->restoreSelection(); MainWindow::instance()->dive_list()->restoreSelection();
} }
if (selected_dive >= 0) { if (selected_dive >= 0) {
multiEditEquipmentPlaceholder = *get_dive(selected_dive); multiEditEquipmentPlaceholder = *get_dive(selected_dive);
@ -792,20 +792,20 @@ void MainTab::rejectChanges()
} }
hideMessage(); hideMessage();
mainWindow()->dive_list()->setEnabled(true); MainWindow::instance()->dive_list()->setEnabled(true);
notesBackup.clear(); notesBackup.clear();
resetPallete(); resetPallete();
editMode = NONE; editMode = NONE;
mainWindow()->globe()->reload(); MainWindow::instance()->globe()->reload();
if (lastMode == ADD || lastMode == MANUALLY_ADDED_DIVE) { if (lastMode == ADD || lastMode == MANUALLY_ADDED_DIVE) {
// more clean up // more clean up
updateDiveInfo(selected_dive); 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 // 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); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
} }
mainWindow()->dive_list()->setFocus(); MainWindow::instance()->dive_list()->setFocus();
} }
#undef EDIT_TEXT2 #undef EDIT_TEXT2
@ -888,9 +888,9 @@ void MainTab::on_location_textChanged(const QString& text)
{ {
if (editMode == NONE) if (editMode == NONE)
return; 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 // 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); EDIT_TEXT(currentTrip->location, text);
} else if (editMode == DIVE || editMode == ADD || editMode == MANUALLY_ADDED_DIVE) { } else if (editMode == DIVE || editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
if (!ui.coordinates->isModified() || if (!ui.coordinates->isModified() ||
@ -911,7 +911,7 @@ void MainTab::on_location_textChanged(const QString& text)
} }
} }
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) ); EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) );
mainWindow()->globe()->repopulateLabels(); MainWindow::instance()->globe()->repopulateLabels();
} }
markChangedWidget(ui.location); markChangedWidget(ui.location);
} }
@ -926,9 +926,9 @@ void MainTab::on_notes_textChanged()
{ {
if (editMode == NONE) if (editMode == NONE)
return; 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 // 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()); EDIT_TEXT(currentTrip->notes, ui.notes->toPlainText());
} else if (editMode == DIVE || editMode == ADD || editMode == MANUALLY_ADDED_DIVE) { } else if (editMode == DIVE || editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->notes, ui.notes->toPlainText()) ); EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->notes, ui.notes->toPlainText()) );

View file

@ -36,12 +36,7 @@
#include "printdialog.h" #include "printdialog.h"
#include "divelogimportdialog.h" #include "divelogimportdialog.h"
static MainWindow* instance = 0; MainWindow *MainWindow::m_Instance = NULL;
MainWindow* mainWindow()
{
return instance;
}
MainWindow::MainWindow() : QMainWindow(), MainWindow::MainWindow() : QMainWindow(),
actionNextDive(0), actionNextDive(0),
@ -49,7 +44,7 @@ MainWindow::MainWindow() : QMainWindow(),
helpView(0), helpView(0),
state(VIEWALL) state(VIEWALL)
{ {
instance = this; m_Instance = this;
ui.setupUi(this); ui.setupUi(this);
setWindowIcon(QIcon(":subsurface-icon")); setWindowIcon(QIcon(":subsurface-icon"));
connect(ui.ListWidget, SIGNAL(currentDiveChanged(int)), this, SLOT(current_dive_changed(int))); connect(ui.ListWidget, SIGNAL(currentDiveChanged(int)), this, SLOT(current_dive_changed(int)));
@ -79,6 +74,16 @@ MainWindow::MainWindow() : QMainWindow(),
#endif #endif
} }
MainWindow::~MainWindow()
{
m_Instance = NULL;
}
MainWindow *MainWindow::instance()
{
return m_Instance;
}
// this gets called after we download dives from a divecomputer // this gets called after we download dives from a divecomputer
void MainWindow::refreshDisplay(bool recreateDiveList) void MainWindow::refreshDisplay(bool recreateDiveList)
{ {

View file

@ -41,6 +41,8 @@ public:
enum CurrentState{ VIEWALL, GLOBE_MAXIMIZED, INFO_MAXIMIZED, PROFILE_MAXIMIZED, LIST_MAXIMIZED}; enum CurrentState{ VIEWALL, GLOBE_MAXIMIZED, INFO_MAXIMIZED, PROFILE_MAXIMIZED, LIST_MAXIMIZED};
MainWindow(); MainWindow();
virtual ~MainWindow();
static MainWindow *instance();
ProfileGraphicsView *graphics(); ProfileGraphicsView *graphics();
MainTab *information(); MainTab *information();
DiveListView *dive_list(); DiveListView *dive_list();
@ -135,6 +137,7 @@ private:
UserManual *helpView; UserManual *helpView;
CurrentState state; CurrentState state;
QString filter(); QString filter();
static MainWindow *m_Instance;
bool askSaveChanges(); bool askSaveChanges();
void writeSettings(); void writeSettings();
void redrawProfile(); void redrawProfile();

View file

@ -334,7 +334,7 @@ void CylindersModel::remove(const QModelIndex& index)
} }
cylinder_t *cyl = &current->cylinder[index.row()]; cylinder_t *cyl = &current->cylinder[index.row()];
if (DivePlannerPointsModel::instance()->tankInUse(cyl->gasmix.o2.permille, cyl->gasmix.he.permille)) { 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("Cylinder cannot be removed"),
tr("This gas in use. Only cylinders that are not used in the dive can be removed.")), tr("This gas in use. Only cylinders that are not used in the dive can be removed.")),
QMessageBox::Ok); QMessageBox::Ok);

View file

@ -8,7 +8,7 @@
PreferencesDialog* PreferencesDialog::instance() PreferencesDialog* PreferencesDialog::instance()
{ {
static PreferencesDialog *dialog = new PreferencesDialog(mainWindow()); static PreferencesDialog *dialog = new PreferencesDialog(MainWindow::instance());
dialog->setAttribute(Qt::WA_QuitOnClose, false); dialog->setAttribute(Qt::WA_QuitOnClose, false);
LanguageModel::instance(); LanguageModel::instance();
return dialog; return dialog;
@ -209,7 +209,7 @@ void PreferencesDialog::syncSettings()
bool useSystemLang = s.value("UseSystemLanguage", true).toBool(); bool useSystemLang = s.value("UseSystemLanguage", true).toBool();
if (useSystemLang != ui.languageSystemDefault->isChecked() || if (useSystemLang != ui.languageSystemDefault->isChecked() ||
(!useSystemLang && s.value("UiLanguage").toString() != ui.languageView->currentIndex().data(Qt::UserRole))) { (!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.")); tr("To correctly load a new language you must restart Subsurface."));
} }
s.setValue("UseSystemLanguage", ui.languageSystemDefault->isChecked()); s.setValue("UseSystemLanguage", ui.languageSystemDefault->isChecked());

View file

@ -131,7 +131,7 @@ void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
painter.scale(scaleX, scaleY); painter.scale(scaleX, scaleY);
// setup the profile widget // setup the profile widget
ProfileGraphicsView *profile = mainWindow()->graphics(); ProfileGraphicsView *profile = MainWindow::instance()->graphics();
const int profileFrameStyle = profile->frameStyle(); const int profileFrameStyle = profile->frameStyle();
profile->setFrameStyle(QFrame::NoFrame); profile->setFrameStyle(QFrame::NoFrame);
profile->clear(); profile->clear();

View file

@ -88,7 +88,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
QTableView *diveDepthTableView = new QTableView(); QTableView *diveDepthTableView = new QTableView();
diveDepthTableView->setModel(dataModel); diveDepthTableView->setModel(dataModel);
mainWindow()->tabWidget()->addTab(diveDepthTableView, "Depth Model"); MainWindow::instance()->tabWidget()->addTab(diveDepthTableView, "Depth Model");
#endif #endif
} }

View file

@ -196,7 +196,7 @@ void ProfileGraphicsView::changeGas()
add_gas_switch_event(current_dive, current_dc, seconds, get_gasidx(current_dive, o2, he)); 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 // this means we potentially have a new tank that is being used and needs to be shown
fixup_dive(current_dive); fixup_dive(current_dive);
mainWindow()->information()->updateDiveInfo(selected_dive); MainWindow::instance()->information()->updateDiveInfo(selected_dive);
mark_divelist_changed(true); mark_divelist_changed(true);
plot(current_dive, true); plot(current_dive, true);
} }
@ -207,7 +207,7 @@ void ProfileGraphicsView::hideEvents()
EventItem *item = static_cast<EventItem*>(action->data().value<void*>()); EventItem *item = static_cast<EventItem*>(action->data().value<void*>());
struct event *event = item->ev; 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 events"),
tr("Hide all %1 events?").arg(event->name)), tr("Hide all %1 events?").arg(event->name)),
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
@ -237,7 +237,7 @@ void ProfileGraphicsView::removeEvent()
EventItem *item = static_cast<EventItem*>(action->data().value<void*>()); EventItem *item = static_cast<EventItem*>(action->data().value<void*>());
struct event *event = item->ev; 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("Remove the selected event?"),
tr("%1 @ %2:%3").arg(event->name) tr("%1 @ %2:%3").arg(event->name)
.arg(event->time.seconds / 60) .arg(event->time.seconds / 60)
@ -375,13 +375,13 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
diveId = d ? d->id : 0; diveId = d ? d->id : 0;
diveDC = d ? dc : NULL; diveDC = d ? dc : NULL;
if (!isVisible() || !d || !mainWindow()) { if (!isVisible() || !d || !MainWindow::instance()) {
return; return;
} }
setBackgroundBrush(getColor(BACKGROUND)); setBackgroundBrush(getColor(BACKGROUND));
// best place to put the focus stealer code. // 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); scene()->setSceneRect(0,0, viewport()->width()-50, viewport()->height()-50);
toolTip = new ToolTipItem(); toolTip = new ToolTipItem();
@ -546,7 +546,7 @@ void ProfileGraphicsView::addControlItems(struct dive *d)
if (defaultDC == "manually added dive" || defaultDC == "planned dive") { if (defaultDC == "manually added dive" || defaultDC == "planned dive") {
QAction *editAction = new QAction(QIcon(":edit"), tr("Edit"), this); QAction *editAction = new QAction(QIcon(":edit"), tr("Edit"), this);
toolBar->addAction(editAction); toolBar->addAction(editAction);
connect(editAction, SIGNAL(triggered()), mainWindow(), SLOT(editCurrentDive())); connect(editAction, SIGNAL(triggered()), MainWindow::instance(), SLOT(editCurrentDive()));
} }
toolBarProxy = scene()->addWidget(toolBar); toolBarProxy = scene()->addWidget(toolBar);
toolBarProxy->setPos(mapToScene(TOOLBAR_POS)); toolBarProxy->setPos(mapToScene(TOOLBAR_POS));
@ -1628,7 +1628,7 @@ GraphicsTextEditor::GraphicsTextEditor(QGraphicsItem* parent): QGraphicsTextItem
void GraphicsTextEditor::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) void GraphicsTextEditor::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
{ {
// Remove the proxy filter so we can focus here. // Remove the proxy filter so we can focus here.
mainWindow()->graphics()->setFocusProxy(0); MainWindow::instance()->graphics()->setFocusProxy(0);
setTextInteractionFlags(Qt::TextEditorInteraction | Qt::TextEditable); 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) { if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
setTextInteractionFlags(Qt::NoTextInteraction); setTextInteractionFlags(Qt::NoTextInteraction);
emit editingFinished( toPlainText() ); emit editingFinished( toPlainText() );
mainWindow()->graphics()->setFocusProxy(mainWindow()->dive_list()); MainWindow::instance()->graphics()->setFocusProxy(MainWindow::instance()->dive_list());
return; return;
} }
emit textChanged( toPlainText() ); emit textChanged( toPlainText() );

View file

@ -107,7 +107,7 @@ void MinMaxAvgWidget::setMinimum(const QString& minimum)
RenumberDialog* RenumberDialog::instance() RenumberDialog* RenumberDialog::instance()
{ {
static RenumberDialog* self = new RenumberDialog(mainWindow()); static RenumberDialog* self = new RenumberDialog(MainWindow::instance());
return self; return self;
} }
@ -127,7 +127,7 @@ RenumberDialog::RenumberDialog(QWidget *parent): QDialog(parent)
ShiftTimesDialog* ShiftTimesDialog::instance() ShiftTimesDialog* ShiftTimesDialog::instance()
{ {
static ShiftTimesDialog* self = new ShiftTimesDialog(mainWindow()); static ShiftTimesDialog* self = new ShiftTimesDialog(MainWindow::instance());
return self; return self;
} }
@ -144,9 +144,9 @@ void ShiftTimesDialog::buttonClicked(QAbstractButton* button)
shift_times(amount); shift_times(amount);
sort_table(&dive_table); sort_table(&dive_table);
mark_divelist_changed(true); mark_divelist_changed(true);
mainWindow()->dive_list()->rememberSelection(); MainWindow::instance()->dive_list()->rememberSelection();
mainWindow()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
mainWindow()->dive_list()->restoreSelection(); MainWindow::instance()->dive_list()->restoreSelection();
} }
} }
} }

View file

@ -333,9 +333,9 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton* button)
/* now merge the data in the gps_location table into the dive_table */ /* now merge the data in the gps_location table into the dive_table */
if (merge_locations_into_dives()) { if (merge_locations_into_dives()) {
mark_divelist_changed(true); mark_divelist_changed(true);
mainWindow()->globe()->repopulateLabels(); MainWindow::instance()->globe()->repopulateLabels();
mainWindow()->globe()->centerOn(current_dive); MainWindow::instance()->globe()->centerOn(current_dive);
mainWindow()->information()->updateDiveInfo(selected_dive); MainWindow::instance()->information()->updateDiveInfo(selected_dive);
} }
/* store last entered uid in config */ /* store last entered uid in config */
@ -558,7 +558,7 @@ out:
DivelogsDeWebServices* DivelogsDeWebServices::instance() DivelogsDeWebServices* DivelogsDeWebServices::instance()
{ {
static DivelogsDeWebServices *self = new DivelogsDeWebServices(mainWindow()); static DivelogsDeWebServices *self = new DivelogsDeWebServices(MainWindow::instance());
self->setAttribute(Qt::WA_QuitOnClose, false); self->setAttribute(Qt::WA_QuitOnClose, false);
return self; return self;
} }
@ -586,7 +586,7 @@ void DivelogsDeWebServices::prepareDivesForUpload()
return; return;
} }
} }
mainWindow()->showError(errorText); MainWindow::instance()->showError(errorText);
} }
void DivelogsDeWebServices::uploadDives(QIODevice *dldContent) void DivelogsDeWebServices::uploadDives(QIODevice *dldContent)
@ -855,11 +855,11 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton* button)
char *error = NULL; char *error = NULL;
parse_file(QFile::encodeName(zipFile.fileName()), &error); parse_file(QFile::encodeName(zipFile.fileName()), &error);
if (error != NULL) { if (error != NULL) {
mainWindow()->showError(error); MainWindow::instance()->showError(error);
free(error); free(error);
} }
process_dives(true, false); process_dives(true, false);
mainWindow()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
/* store last entered user/pass in config */ /* store last entered user/pass in config */
QSettings s; QSettings s;

View file

@ -6,7 +6,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QDebug> #include <QDebug>
#define tr(_arg) mainWindow()->information()->tr(_arg) #define tr(_arg) MainWindow::instance()->information()->tr(_arg)
DiveComputerList::DiveComputerList() DiveComputerList::DiveComputerList()
{ {