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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-02-19 12:53:52 +01:00
parent fce48367cd
commit 5aa67c134b
4 changed files with 9 additions and 127 deletions

View file

@ -438,8 +438,6 @@ void MainWindow::on_actionCloudstoragesave_triggered()
if (verbose) if (verbose)
qDebug() << "Saving cloud storage to:" << filename; qDebug() << "Saving cloud storage to:" << filename;
if (mainTab->isEditing())
mainTab->acceptChanges();
mainTab->stealFocus(); // Make sure that any currently edited field is updated before saving. mainTab->stealFocus(); // Make sure that any currently edited field is updated before saving.
showProgressBar(); showProgressBar();
@ -460,8 +458,7 @@ void MainWindow::on_actionCloudOnline_triggered()
// Refuse to go online if there is an edit in progress // Refuse to go online if there is an edit in progress
if (!isOffline && if (!isOffline &&
(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING)) {
mainTab->isEditing())) {
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before going online")); 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 // We didn't switch to online, therefore uncheck the checkbox
ui.actionCloudOnline->setChecked(false); ui.actionCloudOnline->setChecked(false);
@ -494,8 +491,7 @@ void MainWindow::on_actionCloudOnline_triggered()
bool MainWindow::okToClose(QString message) bool MainWindow::okToClose(QString message)
{ {
if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) {
mainTab->isEditing() ) {
QMessageBox::warning(this, tr("Warning"), message); QMessageBox::warning(this, tr("Warning"), message);
return false; return false;
} }
@ -624,8 +620,7 @@ bool MainWindow::plannerStateClean()
// we are accessing the cloud, so let's not switch into Add or Plan mode // we are accessing the cloud, so let's not switch into Add or Plan mode
return false; return false;
if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) {
mainTab->isEditing()) {
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to add a dive.")); QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to add a dive."));
return false; return false;
} }
@ -1041,8 +1036,7 @@ void MainWindow::writeSettings()
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) {
mainTab->isEditing()) {
on_actionQuit_triggered(); on_actionQuit_triggered();
event->ignore(); event->ignore();
return; return;
@ -1189,9 +1183,6 @@ int MainWindow::file_save_as(void)
if (filename.isNull() || filename.isEmpty()) if (filename.isNull() || filename.isEmpty())
return report_error("No filename to save into"); return report_error("No filename to save into");
if (mainTab->isEditing())
mainTab->acceptChanges();
if (save_dives(qPrintable(filename))) if (save_dives(qPrintable(filename)))
return -1; return -1;
@ -1213,9 +1204,6 @@ int MainWindow::file_save(void)
if (is_cloud && !saveToCloudOK()) if (is_cloud && !saveToCloudOK())
return -1; return -1;
if (mainTab->isEditing())
mainTab->acceptChanges();
current_default = prefs.default_filename; current_default = prefs.default_filename;
if (strcmp(existing_filename, current_default) == 0) { if (strcmp(existing_filename, current_default) == 0) {
/* if we are using the default filename the directory /* if we are using the default filename the directory

View file

@ -11,9 +11,7 @@
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/trip.h" #include "core/trip.h"
#include "qt-models/diveplannermodel.h" #include "qt-models/diveplannermodel.h"
#include "desktop-widgets/divelistview.h"
#include "core/selection.h" #include "core/selection.h"
#include "desktop-widgets/diveplanner.h"
#include "qt-models/divecomputerextradatamodel.h" #include "qt-models/divecomputerextradatamodel.h"
#include "qt-models/divelocationmodel.h" #include "qt-models/divelocationmodel.h"
#include "qt-models/filtermodels.h" #include "qt-models/filtermodels.h"
@ -33,9 +31,7 @@
#include "TabDiveSite.h" #include "TabDiveSite.h"
#include <QCompleter> #include <QCompleter>
#include <QScrollBar>
#include <QShortcut> #include <QShortcut>
#include <QMessageBox>
struct Completers { struct Completers {
QCompleter *diveguide; QCompleter *diveguide;
@ -50,7 +46,6 @@ static bool paletteIsDark(const QPalette &p)
} }
MainTab::MainTab(QWidget *parent) : QTabWidget(parent), MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
editMode(false),
ignoreInput(false), ignoreInput(false),
lastSelectedDive(true), lastSelectedDive(true),
lastTabSelectedDive(0), lastTabSelectedDive(0),
@ -80,8 +75,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
updateDateTimeFields(); updateDateTimeFields();
closeMessage();
connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &MainTab::divesChanged); connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &MainTab::divesChanged);
connect(&diveListNotifier, &DiveListNotifier::tripChanged, this, &MainTab::tripChanged); connect(&diveListNotifier, &DiveListNotifier::tripChanged, this, &MainTab::tripChanged);
connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &MainTab::diveSiteEdited); 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. // 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); connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainTab::updateDateTimeFields);
QAction *action = new QAction(tr("Apply changes"), this); QAction *action = new QAction(tr("OK"), 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);
connect(action, &QAction::triggered, this, &MainTab::closeWarning); connect(action, &QAction::triggered, this, &MainTab::closeWarning);
ui.multiDiveWarningMessage->addAction(action); ui.multiDiveWarningMessage->addAction(action);
@ -118,7 +103,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui.multiDiveWarningMessage->addAction(action); ui.multiDiveWarningMessage->addAction(action);
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this); 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") if (qApp->style()->objectName() == "oxygen")
setDocumentMode(true); setDocumentMode(true);
@ -139,7 +124,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui.buddy->setCompleter(completers.buddy); ui.buddy->setCompleter(completers.buddy);
ui.diveguide->setCompleter(completers.diveguide); ui.diveguide->setCompleter(completers.diveguide);
ui.tagWidget->setCompleter(completers.tags); ui.tagWidget->setCompleter(completers.tags);
ui.diveNotesMessage->hide();
ui.multiDiveWarningMessage->hide(); ui.multiDiveWarningMessage->hide();
ui.depth->hide(); ui.depth->hide();
ui.depthLabel->hide(); ui.depthLabel->hide();
@ -181,8 +165,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
label->setContentsMargins(margins); label->setContentsMargins(margins);
} }
connect(ui.diveNotesMessage, &KMessageWidget::showAnimationFinished,
ui.location, &DiveLocationLineEdit::fixPopupPosition);
connect(ui.multiDiveWarningMessage, &KMessageWidget::showAnimationFinished, connect(ui.multiDiveWarningMessage, &KMessageWidget::showAnimationFinished,
ui.location, &DiveLocationLineEdit::fixPopupPosition); ui.location, &DiveLocationLineEdit::fixPopupPosition);
@ -198,29 +180,11 @@ void MainTab::updateDateTimeFields()
ui.timeEdit->setDisplayFormat(prefs.time_format); ui.timeEdit->setDisplayFormat(prefs.time_format);
} }
void MainTab::hideMessage()
{
ui.diveNotesMessage->animatedHide();
}
void MainTab::closeMessage()
{
hideMessage();
ui.diveNotesMessage->setCloseButtonVisible(false);
}
void MainTab::closeWarning() void MainTab::closeWarning()
{ {
ui.multiDiveWarningMessage->hide(); 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. // This function gets called if a field gets updated by an undo command.
// Refresh the corresponding UI field. // Refresh the corresponding UI field.
void MainTab::divesChanged(const QVector<dive *> &dives, DiveField field) void MainTab::divesChanged(const QVector<dive *> &dives, DiveField field)
@ -280,11 +244,6 @@ void MainTab::nextInputField(QKeyEvent *event)
keyPressEvent(event); keyPressEvent(event);
} }
bool MainTab::isEditing()
{
return editMode;
}
static bool isHtml(const QString &s) static bool isHtml(const QString &s)
{ {
return s.contains("<div", Qt::CaseInsensitive) || s.contains("<table", Qt::CaseInsensitive); return s.contains("<div", Qt::CaseInsensitive) || s.contains("<table", Qt::CaseInsensitive);
@ -336,8 +295,8 @@ void MainTab::updateDiveSite(struct dive *d)
void MainTab::updateDiveInfo() void MainTab::updateDiveInfo()
{ {
ui.location->refreshDiveSiteCache(); ui.location->refreshDiveSiteCache();
// don't execute this while adding / planning a dive // don't execute this while planning a dive
if (editMode || DivePlannerPointsModel::instance()->isPlanner()) if (DivePlannerPointsModel::instance()->isPlanner())
return; return;
// If there is no current dive, disable all widgets except the last two, // 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; 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) void MainTab::divesEdited(int i)
{ {
// No warning if only one dive was edited // No warning if only one dive was edited
@ -658,12 +567,7 @@ void MainTab::stealFocus()
void MainTab::escDetected() void MainTab::escDetected()
{ {
// In edit mode, pressing escape cancels the current changes. stealFocus();
// In standard mode, remove focus of any active widget to
if (editMode)
rejectChanges();
else
stealFocus();
} }
void MainTab::clearTabs() void MainTab::clearTabs()

View file

@ -25,7 +25,6 @@ class MainTab : public QTabWidget {
public: public:
MainTab(QWidget *parent = 0); MainTab(QWidget *parent = 0);
void clearTabs(); void clearTabs();
bool isEditing();
void nextInputField(QKeyEvent *event); void nextInputField(QKeyEvent *event);
void stealFocus(); void stealFocus();
@ -39,8 +38,6 @@ slots:
void updateDateTime(const struct dive *d); void updateDateTime(const struct dive *d);
void updateTripDate(const struct dive_trip *t); void updateTripDate(const struct dive_trip *t);
void updateDiveSite(struct dive *d); void updateDiveSite(struct dive *d);
void acceptChanges();
void rejectChanges();
void on_location_diveSiteSelected(); void on_location_diveSiteSelected();
void on_locationPopupButton_clicked(); void on_locationPopupButton_clicked();
void on_diveguide_editingFinished(); void on_diveguide_editingFinished();
@ -53,16 +50,12 @@ slots:
void on_timeEdit_editingFinished(); void on_timeEdit_editingFinished();
void on_rating_valueChanged(int value); void on_rating_valueChanged(int value);
void on_tagWidget_editingFinished(); void on_tagWidget_editingFinished();
void hideMessage();
void closeMessage();
void closeWarning(); void closeWarning();
void displayMessage(QString str);
void escDetected(void); void escDetected(void);
void updateDateTimeFields(); void updateDateTimeFields();
void colorsChanged(); void colorsChanged();
private: private:
Ui::MainTab ui; Ui::MainTab ui;
bool editMode;
bool ignoreInput; // When computionally editing fields, we have to ignore changed-signals bool ignoreInput; // When computionally editing fields, we have to ignore changed-signals
BuddyCompletionModel buddyModel; BuddyCompletionModel buddyModel;
DiveGuideCompletionModel diveGuideModel; DiveGuideCompletionModel diveGuideModel;

View file

@ -14,9 +14,6 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_9"> <layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="KMessageWidget" name="diveNotesMessage"/>
</item>
<item> <item>
<widget class="KMessageWidget" name="multiDiveWarningMessage"/> <widget class="KMessageWidget" name="multiDiveWarningMessage"/>
</item> </item>