desktop/tabwidgets: replace editMode by boolean

There was only one editMode left (MANUALLY_ADDED_DIVE).
Therefore replace by a flag. This makes the code more consistent,
because the conditions "editMode != NONE" and "editMode ==
MANUALLY_ADDED_DIVE) actually meant the same thing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-03-18 22:42:47 +01:00
parent 3b9913d828
commit 20e7064658
2 changed files with 12 additions and 17 deletions

View file

@ -49,7 +49,7 @@ struct Completers {
}; };
MainTab::MainTab(QWidget *parent) : QTabWidget(parent), MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
editMode(NONE), editMode(false),
ignoreInput(false), ignoreInput(false),
lastSelectedDive(true), lastSelectedDive(true),
lastTabSelectedDive(0), lastTabSelectedDive(0),
@ -209,7 +209,7 @@ void MainTab::displayMessage(QString str)
void MainTab::enableEdition() void MainTab::enableEdition()
{ {
if (current_dive == NULL || editMode != NONE) if (current_dive == NULL || editMode)
return; return;
ui.editDiveSiteButton->setEnabled(false); ui.editDiveSiteButton->setEnabled(false);
@ -219,7 +219,7 @@ void MainTab::enableEdition()
ui.dateEdit->setEnabled(true); ui.dateEdit->setEnabled(true);
displayMessage(tr("This dive is being edited.")); displayMessage(tr("This dive is being edited."));
editMode = MANUALLY_ADDED_DIVE; editMode = true;
} }
// 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.
@ -284,7 +284,7 @@ void MainTab::nextInputField(QKeyEvent *event)
bool MainTab::isEditing() bool MainTab::isEditing()
{ {
return editMode != NONE; return editMode;
} }
static bool isHtml(const QString &s) static bool isHtml(const QString &s)
@ -343,7 +343,7 @@ void MainTab::updateDiveInfo()
{ {
ui.location->refreshDiveSiteCache(); ui.location->refreshDiveSiteCache();
// don't execute this while adding / planning a dive // don't execute this while adding / planning a dive
if (editMode == MANUALLY_ADDED_DIVE || MainWindow::instance()->graphics->isPlanner()) if (editMode || MainWindow::instance()->graphics->isPlanner())
return; return;
// If there is no current dive, disable all widgets except the last, which is the dive site tab. // If there is no current dive, disable all widgets except the last, which is the dive site tab.
@ -503,13 +503,13 @@ void MainTab::acceptChanges()
ui.dateEdit->setEnabled(true); ui.dateEdit->setEnabled(true);
hideMessage(); hideMessage();
if (editMode == MANUALLY_ADDED_DIVE) { if (editMode) {
MainWindow::instance()->showProfile(); MainWindow::instance()->showProfile();
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
Command::editProfile(&displayed_dive); Command::editProfile(&displayed_dive);
} }
int scrolledBy = MainWindow::instance()->diveList->verticalScrollBar()->sliderPosition(); int scrolledBy = MainWindow::instance()->diveList->verticalScrollBar()->sliderPosition();
if (editMode == MANUALLY_ADDED_DIVE) { if (editMode) {
MainWindow::instance()->diveList->reload(); MainWindow::instance()->diveList->reload();
MainWindow::instance()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
MainWindow::instance()->graphics->replot(); MainWindow::instance()->graphics->replot();
@ -522,12 +522,12 @@ void MainTab::acceptChanges()
MainWindow::instance()->setEnabledToolbar(true); MainWindow::instance()->setEnabledToolbar(true);
ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty()); ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty());
ignoreInput = false; ignoreInput = false;
editMode = NONE; editMode = false;
} }
void MainTab::rejectChanges() void MainTab::rejectChanges()
{ {
if (editMode != NONE && current_dive) { if (editMode && current_dive) {
if (QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(tr("Discard the changes?"), if (QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(tr("Discard the changes?"),
tr("You are about to discard your changes.")), tr("You are about to discard your changes.")),
QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard) != QMessageBox::Discard) { QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard) != QMessageBox::Discard) {
@ -535,7 +535,7 @@ void MainTab::rejectChanges()
} }
} }
ui.dateEdit->setEnabled(true); ui.dateEdit->setEnabled(true);
editMode = NONE; editMode = false;
hideMessage(); hideMessage();
// no harm done to call cancelPlan even if we were not PLAN mode... // no harm done to call cancelPlan even if we were not PLAN mode...
DivePlannerPointsModel::instance()->cancelPlan(); DivePlannerPointsModel::instance()->cancelPlan();
@ -693,7 +693,7 @@ void MainTab::escDetected()
{ {
// In edit mode, pressing escape cancels the current changes. // In edit mode, pressing escape cancels the current changes.
// In standard mode, remove focus of any active widget to // In standard mode, remove focus of any active widget to
if (editMode != NONE) if (editMode)
rejectChanges(); rejectChanges();
else else
stealFocus(); stealFocus();

View file

@ -26,11 +26,6 @@ class TabBase;
class MainTab : public QTabWidget { class MainTab : public QTabWidget {
Q_OBJECT Q_OBJECT
public: public:
enum EditMode {
NONE,
MANUALLY_ADDED_DIVE
};
MainTab(QWidget *parent = 0); MainTab(QWidget *parent = 0);
~MainTab(); ~MainTab();
void clearTabs(); void clearTabs();
@ -74,7 +69,7 @@ slots:
void escDetected(void); void escDetected(void);
private: private:
Ui::MainTab ui; Ui::MainTab ui;
EditMode editMode; 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;
DiveMasterCompletionModel diveMasterModel; DiveMasterCompletionModel diveMasterModel;