From 5aa67c134b5f637b1e0017daa58cb915816098eb Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 19 Feb 2022 12:53:52 +0100 Subject: [PATCH] desktop: remove edit mode of maintab This was only used for profile-editing, which is now managed by the profile-widget. Signed-off-by: Berthold Stoeger --- desktop-widgets/mainwindow.cpp | 20 +---- desktop-widgets/tab-widgets/maintab.cpp | 106 ++---------------------- desktop-widgets/tab-widgets/maintab.h | 7 -- desktop-widgets/tab-widgets/maintab.ui | 3 - 4 files changed, 9 insertions(+), 127 deletions(-) diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 63564b71a..3ad2f09e7 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -438,8 +438,6 @@ void MainWindow::on_actionCloudstoragesave_triggered() if (verbose) qDebug() << "Saving cloud storage to:" << filename; - if (mainTab->isEditing()) - mainTab->acceptChanges(); mainTab->stealFocus(); // Make sure that any currently edited field is updated before saving. showProgressBar(); @@ -460,8 +458,7 @@ void MainWindow::on_actionCloudOnline_triggered() // Refuse to go online if there is an edit in progress if (!isOffline && - (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || - mainTab->isEditing())) { + (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING)) { QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before going online")); // We didn't switch to online, therefore uncheck the checkbox ui.actionCloudOnline->setChecked(false); @@ -494,8 +491,7 @@ void MainWindow::on_actionCloudOnline_triggered() bool MainWindow::okToClose(QString message) { - if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || - mainTab->isEditing() ) { + if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) { QMessageBox::warning(this, tr("Warning"), message); return false; } @@ -624,8 +620,7 @@ bool MainWindow::plannerStateClean() // we are accessing the cloud, so let's not switch into Add or Plan mode return false; - if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || - mainTab->isEditing()) { + if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) { QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to add a dive.")); return false; } @@ -1041,8 +1036,7 @@ void MainWindow::writeSettings() void MainWindow::closeEvent(QCloseEvent *event) { - if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || - mainTab->isEditing()) { + if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) { on_actionQuit_triggered(); event->ignore(); return; @@ -1189,9 +1183,6 @@ int MainWindow::file_save_as(void) if (filename.isNull() || filename.isEmpty()) return report_error("No filename to save into"); - if (mainTab->isEditing()) - mainTab->acceptChanges(); - if (save_dives(qPrintable(filename))) return -1; @@ -1213,9 +1204,6 @@ int MainWindow::file_save(void) if (is_cloud && !saveToCloudOK()) return -1; - if (mainTab->isEditing()) - mainTab->acceptChanges(); - current_default = prefs.default_filename; if (strcmp(existing_filename, current_default) == 0) { /* if we are using the default filename the directory diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index cd2a5500d..bd8c437d1 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -11,9 +11,7 @@ #include "core/qthelper.h" #include "core/trip.h" #include "qt-models/diveplannermodel.h" -#include "desktop-widgets/divelistview.h" #include "core/selection.h" -#include "desktop-widgets/diveplanner.h" #include "qt-models/divecomputerextradatamodel.h" #include "qt-models/divelocationmodel.h" #include "qt-models/filtermodels.h" @@ -33,9 +31,7 @@ #include "TabDiveSite.h" #include -#include #include -#include struct Completers { QCompleter *diveguide; @@ -50,7 +46,6 @@ static bool paletteIsDark(const QPalette &p) } MainTab::MainTab(QWidget *parent) : QTabWidget(parent), - editMode(false), ignoreInput(false), lastSelectedDive(true), lastTabSelectedDive(0), @@ -80,8 +75,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), updateDateTimeFields(); - closeMessage(); - connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &MainTab::divesChanged); connect(&diveListNotifier, &DiveListNotifier::tripChanged, this, &MainTab::tripChanged); connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &MainTab::diveSiteEdited); @@ -100,15 +93,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), // signal. However, the correct date and time format is set by the preferences dialog later. This should be fixed. connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainTab::updateDateTimeFields); - QAction *action = new QAction(tr("Apply changes"), this); - connect(action, SIGNAL(triggered(bool)), this, SLOT(acceptChanges())); - ui.diveNotesMessage->addAction(action); - - action = new QAction(tr("Discard changes"), this); - connect(action, SIGNAL(triggered(bool)), this, SLOT(rejectChanges())); - ui.diveNotesMessage->addAction(action); - - action = new QAction(tr("OK"), this); + QAction *action = new QAction(tr("OK"), this); connect(action, &QAction::triggered, this, &MainTab::closeWarning); ui.multiDiveWarningMessage->addAction(action); @@ -118,7 +103,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui.multiDiveWarningMessage->addAction(action); QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this); - connect(closeKey, SIGNAL(activated()), this, SLOT(escDetected())); + connect(closeKey, &QShortcut::activated, this, &MainTab::escDetected); if (qApp->style()->objectName() == "oxygen") setDocumentMode(true); @@ -139,7 +124,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui.buddy->setCompleter(completers.buddy); ui.diveguide->setCompleter(completers.diveguide); ui.tagWidget->setCompleter(completers.tags); - ui.diveNotesMessage->hide(); ui.multiDiveWarningMessage->hide(); ui.depth->hide(); ui.depthLabel->hide(); @@ -181,8 +165,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), label->setContentsMargins(margins); } - connect(ui.diveNotesMessage, &KMessageWidget::showAnimationFinished, - ui.location, &DiveLocationLineEdit::fixPopupPosition); connect(ui.multiDiveWarningMessage, &KMessageWidget::showAnimationFinished, ui.location, &DiveLocationLineEdit::fixPopupPosition); @@ -198,29 +180,11 @@ void MainTab::updateDateTimeFields() ui.timeEdit->setDisplayFormat(prefs.time_format); } -void MainTab::hideMessage() -{ - ui.diveNotesMessage->animatedHide(); -} - -void MainTab::closeMessage() -{ - hideMessage(); - ui.diveNotesMessage->setCloseButtonVisible(false); -} - void MainTab::closeWarning() { ui.multiDiveWarningMessage->hide(); } -void MainTab::displayMessage(QString str) -{ - ui.diveNotesMessage->setCloseButtonVisible(false); - ui.diveNotesMessage->setText(str); - ui.diveNotesMessage->animatedShow(); -} - // This function gets called if a field gets updated by an undo command. // Refresh the corresponding UI field. void MainTab::divesChanged(const QVector &dives, DiveField field) @@ -280,11 +244,6 @@ void MainTab::nextInputField(QKeyEvent *event) keyPressEvent(event); } -bool MainTab::isEditing() -{ - return editMode; -} - static bool isHtml(const QString &s) { return s.contains("refreshDiveSiteCache(); - // don't execute this while adding / planning a dive - if (editMode || DivePlannerPointsModel::instance()->isPlanner()) + // don't execute this while planning a dive + if (DivePlannerPointsModel::instance()->isPlanner()) return; // If there is no current dive, disable all widgets except the last two, @@ -472,56 +431,6 @@ void MainTab::updateDiveInfo() qDebug() << "Set the current dive site:" << current_dive->dive_site->uuid; } -void MainTab::acceptChanges() -{ - if (ui.location->hasFocus()) - stealFocus(); - - ignoreInput = true; - ui.dateEdit->setEnabled(true); - hideMessage(); - - MainWindow::instance()->showProfile(); - DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); - Command::editProfile(&displayed_dive, Command::EditProfileType::MOVE, 0); - - int scrolledBy = MainWindow::instance()->diveList->verticalScrollBar()->sliderPosition(); - MainWindow::instance()->diveList->reload(); - MainWindow::instance()->refreshDisplay(); - MainWindow::instance()->refreshProfile(); - - DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); - MainWindow::instance()->diveList->verticalScrollBar()->setSliderPosition(scrolledBy); - MainWindow::instance()->diveList->setFocus(); - MainWindow::instance()->setEnabledToolbar(true); - ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty()); - ignoreInput = false; - editMode = false; -} - -void MainTab::rejectChanges() -{ - if (QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(tr("Discard the changes?"), - tr("You are about to discard your changes.")), - QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard) != QMessageBox::Discard) { - return; - } - - ui.dateEdit->setEnabled(true); - editMode = false; - hideMessage(); - // no harm done to call cancelPlan even if we were not PLAN mode... - DivePlannerPointsModel::instance()->cancelPlan(); - - updateDiveInfo(); - - // show the profile and dive info - MainWindow::instance()->refreshDisplay(); - MainWindow::instance()->refreshProfile(); - MainWindow::instance()->setEnabledToolbar(true); - ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty()); -} - void MainTab::divesEdited(int i) { // No warning if only one dive was edited @@ -658,12 +567,7 @@ void MainTab::stealFocus() void MainTab::escDetected() { - // In edit mode, pressing escape cancels the current changes. - // In standard mode, remove focus of any active widget to - if (editMode) - rejectChanges(); - else - stealFocus(); + stealFocus(); } void MainTab::clearTabs() diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index f5ef32760..903b9ff1d 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -25,7 +25,6 @@ class MainTab : public QTabWidget { public: MainTab(QWidget *parent = 0); void clearTabs(); - bool isEditing(); void nextInputField(QKeyEvent *event); void stealFocus(); @@ -39,8 +38,6 @@ slots: void updateDateTime(const struct dive *d); void updateTripDate(const struct dive_trip *t); void updateDiveSite(struct dive *d); - void acceptChanges(); - void rejectChanges(); void on_location_diveSiteSelected(); void on_locationPopupButton_clicked(); void on_diveguide_editingFinished(); @@ -53,16 +50,12 @@ slots: void on_timeEdit_editingFinished(); void on_rating_valueChanged(int value); void on_tagWidget_editingFinished(); - void hideMessage(); - void closeMessage(); void closeWarning(); - void displayMessage(QString str); void escDetected(void); void updateDateTimeFields(); void colorsChanged(); private: Ui::MainTab ui; - bool editMode; bool ignoreInput; // When computionally editing fields, we have to ignore changed-signals BuddyCompletionModel buddyModel; DiveGuideCompletionModel diveGuideModel; diff --git a/desktop-widgets/tab-widgets/maintab.ui b/desktop-widgets/tab-widgets/maintab.ui index f9c13ad66..1bf05619b 100644 --- a/desktop-widgets/tab-widgets/maintab.ui +++ b/desktop-widgets/tab-widgets/maintab.ui @@ -14,9 +14,6 @@ Form - - -