From 30d289e4a8a0caadcf30f06872ce69f44cf0bc0d Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 23 Feb 2020 12:44:09 +0100 Subject: CylinderModel: make dive dynamic The CylinderModel always accessed the global "displayed_dive" and in some special cases also "current_dive". To implement cylinder undo, the model should work on an arbitrary dive. Therefore, in analogy to the weight model, make the dive dynamic. Signed-off-by: Berthold Stoeger --- desktop-widgets/mainwindow.cpp | 2 +- desktop-widgets/tab-widgets/TabDiveEquipment.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 8474eee71..78877d1a5 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -918,7 +918,7 @@ void MainWindow::on_actionReplanDive_triggered() divePlannerWidget->setSalinity(current_dive->salinity); DivePlannerPointsModel::instance()->loadFromDive(current_dive); reset_cylinders(&displayed_dive, true); - DivePlannerPointsModel::instance()->cylindersModel()->updateDive(); + DivePlannerPointsModel::instance()->cylindersModel()->updateDive(&displayed_dive); } void MainWindow::on_actionDivePlanner_triggered() diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp index 33a8e5a3c..d34b44c74 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp @@ -129,7 +129,7 @@ void TabDiveEquipment::toggleTriggeredColumn() void TabDiveEquipment::updateData() { - cylindersModel->updateDive(); + cylindersModel->updateDive(current_dive); weightModel->updateDive(current_dive); suitModel.updateModel(); @@ -262,7 +262,7 @@ void TabDiveEquipment::acceptChanges() void TabDiveEquipment::rejectChanges() { cylindersModel->model()->changed = false; - cylindersModel->updateDive(); + cylindersModel->updateDive(current_dive); weightModel->updateDive(current_dive); } -- cgit v1.2.3-70-g09d2 From 1f8a45db44d12ced038d72c84d663885043e8663 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 24 Feb 2020 11:14:55 +0100 Subject: undo: call removeCylinder undo command in equipment tab Instead of connecting to the remove() function of the model, call the removeCylinder undo command. Take care to translate the index into the source index, should cylinders be hidden! Apart from the map-to-source call, this copies the weightsystem code. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/TabDiveEquipment.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp index d34b44c74..ea2d910ef 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp @@ -33,7 +33,6 @@ TabDiveEquipment::TabDiveEquipment(QWidget *parent) : TabBase(parent), ui.weights->setModel(weightModel); connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &TabDiveEquipment::divesChanged); - connect(ui.cylinders, &TableView::itemClicked, cylindersModel, &CylindersModelFiltered::remove); connect(ui.cylinders, &TableView::itemClicked, this, &TabDiveEquipment::editCylinderWidget); connect(ui.weights, &TableView::itemClicked, this, &TabDiveEquipment::editWeightWidget); @@ -164,14 +163,13 @@ void TabDiveEquipment::addWeight_clicked() void TabDiveEquipment::editCylinderWidget(const QModelIndex &index) { - if (cylindersModel->model()->changed && !MainWindow::instance()->mainTab->isEditing()) { - MainWindow::instance()->mainTab->enableEdition(); + if (!index.isValid()) return; - } - if (index.isValid() && index.column() != CylindersModel::REMOVE) { - MainWindow::instance()->mainTab->enableEdition(); + + if (index.column() == CylindersModel::REMOVE) + divesEdited(Command::removeCylinder(cylindersModel->mapToSource(index).row(), false)); + else ui.cylinders->edit(index); - } } void TabDiveEquipment::editWeightWidget(const QModelIndex &index) -- cgit v1.2.3-70-g09d2 From 0732bb2302418fe07064ea04df3435ab527fbd00 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 27 Feb 2020 18:40:32 +0100 Subject: undo: remove TabDiveWidget::acceptChanges and rejectChanges Since cylinders are now edited using the undo system, these functions are not needed anymore. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/TabDiveEquipment.cpp | 81 ------------------------ desktop-widgets/tab-widgets/TabDiveEquipment.h | 2 - desktop-widgets/tab-widgets/maintab.cpp | 8 --- 3 files changed, 91 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp index ea2d910ef..c5601f1ce 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp @@ -183,87 +183,6 @@ void TabDiveEquipment::editWeightWidget(const QModelIndex &index) ui.weights->edit(index); } -// tricky little macro to edit all the selected dives -// loop ove all DIVES and do WHAT. -#define MODIFY_DIVES(DIVES, WHAT) \ - do { \ - for (dive *mydive: DIVES) { \ - invalidate_dive_cache(mydive); \ - WHAT; \ - } \ - mark_divelist_changed(true); \ - } while (0) - -// Get the list of selected dives, but put the current dive at the last position of the vector -static QVector getSelectedDivesCurrentLast() -{ - QVector res; - struct dive *d; - int i; - for_each_dive (i, d) { - if (d->selected && d != current_dive) - res.append(d); - } - res.append(current_dive); - return res; -} - -// TODO: This is a temporary functions until undo of cylinders is implemented. -// Therefore it is not worth putting it in a header. -extern bool cylinders_equal(const dive *d1, const dive *d2); - -void TabDiveEquipment::acceptChanges() -{ - bool do_replot = false; - - // now check if something has changed and if yes, edit the selected dives that - // were identical with the master dive shown (and mark the divelist as changed) - struct dive *cd = current_dive; - - // Get list of selected dives, but put the current dive last; - // this is required in case the invocation wants to compare things - // to the original value in current_dive like it should - QVector selectedDives = getSelectedDivesCurrentLast(); - - if (cylindersModel->model()->changed) { - mark_divelist_changed(true); - MODIFY_DIVES(selectedDives, - // if we started out with the same cylinder description (for multi-edit) or if we do copt & paste - // make sure that we have the same cylinder type and copy the gasmix, but DON'T copy the start - // and end pressures (those are per dive after all) - if (cylinders_equal(mydive, cd) && mydive != cd) - copy_cylinder_types(&displayed_dive, cd); - copy_cylinders(&displayed_dive.cylinders, &cd->cylinders); - ); - /* if cylinders changed we may have changed gas change events - * and sensor idx in samples as well - * - so far this is ONLY supported for a single selected dive */ - struct divecomputer *tdc = ¤t_dive->dc; - struct divecomputer *sdc = &displayed_dive.dc; - while(tdc && sdc) { - free_events(tdc->events); - copy_events(sdc, tdc); - free(tdc->sample); - copy_samples(sdc, tdc); - tdc = tdc->next; - sdc = sdc->next; - } - do_replot = true; - } - - if (do_replot) - MainWindow::instance()->graphics->replot(); - - cylindersModel->model()->changed = false; -} - -void TabDiveEquipment::rejectChanges() -{ - cylindersModel->model()->changed = false; - cylindersModel->updateDive(current_dive); - weightModel->updateDive(current_dive); -} - void TabDiveEquipment::divesEdited(int i) { // No warning if only one dive was edited diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.h b/desktop-widgets/tab-widgets/TabDiveEquipment.h index 28e6235d1..3576b449e 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.h +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.h @@ -21,8 +21,6 @@ public: ~TabDiveEquipment(); void updateData() override; void clear() override; - void acceptChanges(); - void rejectChanges(); void divesEdited(int i); void closeWarning(); diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 252e135a6..ea20219ce 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -534,10 +534,6 @@ void MainTab::acceptChanges() ui.dateEdit->setEnabled(true); hideMessage(); - // TODO: This is a temporary hack until the equipment tab is included in the undo system: - // The equipment tab is hardcoded at the first place of the "extra widgets". - ((TabDiveEquipment *)extraWidgets[0])->acceptChanges(); - if (lastMode == MANUALLY_ADDED_DIVE) { MainWindow::instance()->showProfile(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); @@ -606,10 +602,6 @@ void MainTab::rejectChanges() clear_dive(&displayed_dive); updateDiveInfo(); - // TODO: This is a temporary hack until the equipment tab is included in the undo system: - // The equipment tab is hardcoded at the first place of the "extra widgets". - ((TabDiveEquipment *)extraWidgets[0])->rejectChanges(); - // the user could have edited the location and then canceled the edit // let's get the correct location back in view MapWidget::instance()->centerOnDiveSite(current_dive ? current_dive->dive_site : nullptr); -- cgit v1.2.3-70-g09d2 From ff38c03e0069e57a5dae7907441c53eb776c65f0 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 27 Feb 2020 20:42:13 +0100 Subject: undo: add cylinders via undo Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/TabDiveEquipment.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp index c5601f1ce..13cfe77c4 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp @@ -152,8 +152,7 @@ void TabDiveEquipment::clear() void TabDiveEquipment::addCylinder_clicked() { - MainWindow::instance()->mainTab->enableEdition(); - cylindersModel->add(); + divesEdited(Command::addCylinder(false)); } void TabDiveEquipment::addWeight_clicked() -- cgit v1.2.3-70-g09d2 From ee64a85d2e97c7f3d20de364ac908ac16fbfbc7a Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 27 Feb 2020 20:55:56 +0100 Subject: cleanup: remove cylinders_equal check in MainTab::rejectChanges() This check make no more sense since cylinder editing is now treated by undo commands. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/maintab.cpp | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index ea20219ce..bd3919b24 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -556,33 +556,11 @@ void MainTab::acceptChanges() editMode = NONE; } -bool weightsystems_equal(const dive *d1, const dive *d2) -{ - if (d1->weightsystems.nr != d2->weightsystems.nr) - return false; - for (int i = 0; i < d1->weightsystems.nr; ++i) { - if (!same_weightsystem(d1->weightsystems.weightsystems[i], d2->weightsystems.weightsystems[i])) - return false; - } - return true; -} - -bool cylinders_equal(const dive *d1, const dive *d2) -{ - if (d1->cylinders.nr != d2->cylinders.nr) - return false; - for (int i = 0; i < d1->cylinders.nr; ++i) { - if (!same_cylinder(*get_cylinder(d1, i), *get_cylinder(d2, i))) - return false; - } - return true; -} - void MainTab::rejectChanges() { EditMode lastMode = editMode; - if (lastMode != NONE && current_dive && !cylinders_equal(current_dive, &displayed_dive)) { + if (lastMode != NONE && current_dive) { 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) { -- cgit v1.2.3-70-g09d2 From 6288b2a61915b36563f2415e8abadd2f5cc57424 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 27 Feb 2020 22:08:20 +0100 Subject: cleanup: remove strange recursive code in MainTab::enableEdition When enableEdition() was called with mode == NONE and the dive was a manually added dive, it would call into MainWindow:: editCurrentDive(), which would in turn call enableEdition(), however with another mode. Since the only caller of enableEdition() is now editCurrentDive() anyway, we can remove that weird code. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/maintab.cpp | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index bd3919b24..7bc04e7a7 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -210,21 +210,6 @@ void MainTab::enableEdition(EditMode newEditMode) { if (((newEditMode == DIVE || newEditMode == NONE) && current_dive == NULL) || editMode != NONE) return; - if ((newEditMode == DIVE || newEditMode == NONE) && - current_dive->dc.model && - 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 - - - - // FIXME : can we get rid of this recursive crap? - - - - MainWindow::instance()->editCurrentDive(); - return; - } ui.editDiveSiteButton->setEnabled(false); MainWindow::instance()->diveList->setEnabled(false); -- cgit v1.2.3-70-g09d2 From 5f858e137d37e7fd2f6325b22651bf1842e872a0 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 27 Feb 2020 22:10:43 +0100 Subject: edit: remove multi-dive version of edit information The "dive is currently" edited is only shown when the profile is edited. This affects only the current dive and therefore a message saying that multiple dives are edited makes no sense. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/maintab.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 7bc04e7a7..3aed133cd 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -220,11 +220,8 @@ void MainTab::enableEdition(EditMode newEditMode) ui.tabWidget->setTabEnabled(5, false); ui.dateEdit->setEnabled(true); - if (amount_selected > 1) { - displayMessage(tr("Multiple dives are being edited.")); - } else { - displayMessage(tr("This dive is being edited.")); - } + displayMessage(tr("This dive is being edited.")); + editMode = newEditMode != NONE ? newEditMode : DIVE; } -- cgit v1.2.3-70-g09d2 From 150bd9763e7f95c589f2118f15bc2401bd3d3350 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 28 Feb 2020 00:29:56 +0100 Subject: cleanup: remove lastMode variable in MainTab::rejectChanges() This stored the old editMode. However, it was not read after editMode was changed, so there is no point to it. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/maintab.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 3aed133cd..2c64833da 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -540,9 +540,7 @@ void MainTab::acceptChanges() void MainTab::rejectChanges() { - EditMode lastMode = editMode; - - if (lastMode != NONE && current_dive) { + if (editMode != NONE && current_dive) { 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) { -- cgit v1.2.3-70-g09d2 From 42b423f02c0b26eedd563be6f75df1e1952f6e72 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 28 Feb 2020 00:34:34 +0100 Subject: cleanup: don't center map on rejecting edit The editing of the dive site is controlled via an undo command. No point in centering the map when cancelling a profile-edit. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/maintab.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 2c64833da..3ae954c05 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -560,9 +560,6 @@ void MainTab::rejectChanges() clear_dive(&displayed_dive); updateDiveInfo(); - // the user could have edited the location and then canceled the edit - // let's get the correct location back in view - MapWidget::instance()->centerOnDiveSite(current_dive ? current_dive->dive_site : nullptr); // show the profile and dive info MainWindow::instance()->graphics->replot(); MainWindow::instance()->setEnabledToolbar(true); -- cgit v1.2.3-70-g09d2 From 1aa25aad6dd553b80dbc8db18e513847121bea58 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 28 Feb 2020 00:43:05 +0100 Subject: desktop: don't disable tabs in edit state The edit state is now only used to edit the profile. There is no reason to disable random tabs. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/maintab.cpp | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 3ae954c05..311887169 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -215,9 +215,6 @@ void MainTab::enableEdition(EditMode newEditMode) MainWindow::instance()->diveList->setEnabled(false); MainWindow::instance()->setEnabledToolbar(false); MainWindow::instance()->enterEditState(); - ui.tabWidget->setTabEnabled(2, false); - ui.tabWidget->setTabEnabled(3, false); - ui.tabWidget->setTabEnabled(5, false); ui.dateEdit->setEnabled(true); displayMessage(tr("This dive is being edited.")); @@ -375,9 +372,6 @@ void MainTab::updateDiveInfo() if (lastSelectedDive && !onDiveSiteTab) lastTabSelectedDive = ui.tabWidget->currentIndex(); ui.tabWidget->setTabText(0, tr("Trip notes")); - ui.tabWidget->setTabEnabled(1, false); - ui.tabWidget->setTabEnabled(2, false); - ui.tabWidget->setTabEnabled(5, false); // Recover the tab selected for last dive trip but only if we're not on the dive site tab if (lastSelectedDive && !onDiveSiteTab) ui.tabWidget->setCurrentIndex(lastTabSelectedDiveTrip); @@ -416,11 +410,6 @@ void MainTab::updateDiveInfo() if (!lastSelectedDive && !onDiveSiteTab) lastTabSelectedDiveTrip = ui.tabWidget->currentIndex(); ui.tabWidget->setTabText(0, tr("Notes")); - ui.tabWidget->setTabEnabled(1, true); - ui.tabWidget->setTabEnabled(2, true); - ui.tabWidget->setTabEnabled(3, true); - ui.tabWidget->setTabEnabled(4, true); - ui.tabWidget->setTabEnabled(5, true); // Recover the tab selected for last dive but only if we're not on the dive site tab if (!lastSelectedDive && !onDiveSiteTab) ui.tabWidget->setCurrentIndex(lastTabSelectedDive); -- cgit v1.2.3-70-g09d2 From 1aa06e680230351024c05152aeca9a189c5a8d4f Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 28 Feb 2020 08:36:13 +0100 Subject: cleanup: remove default-code for editCurrentDive The profile can only be edited for manually added or planned dives. No point in keeping code for other kinds of dives. Signed-off-by: Berthold Stoeger --- desktop-widgets/mainwindow.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 78877d1a5..e1d87b7e6 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -1793,21 +1793,19 @@ void MainWindow::editCurrentDive() struct dive *d = current_dive; QString defaultDC(d->dc.model); DivePlannerPointsModel::instance()->clear(); - disableShortcuts(); if (defaultDC == "manually added dive") { + disableShortcuts(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); graphics->setAddState(); setApplicationState(ApplicationState::EditDive); DivePlannerPointsModel::instance()->loadFromDive(d); mainTab->enableEdition(MainTab::MANUALLY_ADDED_DIVE); } else if (defaultDC == "planned dive") { + disableShortcuts(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); setApplicationState(ApplicationState::EditPlannedDive); DivePlannerPointsModel::instance()->loadFromDive(d); mainTab->enableEdition(MainTab::MANUALLY_ADDED_DIVE); - } else { - setApplicationState(ApplicationState::EditDive); - mainTab->enableEdition(); } } -- cgit v1.2.3-70-g09d2 From 1dcc885bb257d6c8c64074f8788b468397c34aaa Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 28 Feb 2020 20:38:04 +0100 Subject: undo/cylinders: Implement editing of the type This one is tricky, as when browsing through the types-combobox, the user is presented with presets without actually changing the dive. We do not want an undo-command for every change-event in the combo-box. Therefore, implement a scheme analoguous to the weight-editing: A temporary row can be set / committed or reset. Sadly, the code is more complex because we have to consider the planner, which is not included in the undo system. Firstly, the planner uses a different model, therefore all interactions are channeled through setData() with special roles. Secondly, in the planner we shouldn't place an undo command, but simply overwrite the dive. Signed-off-by: Berthold Stoeger --- desktop-widgets/modeldelegates.cpp | 34 +++++--------- qt-models/cylindermodel.cpp | 95 ++++++++++++++++++++++++++++++++++---- qt-models/cylindermodel.h | 11 ++++- 3 files changed, 106 insertions(+), 34 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp index ed7278b4c..65e8f377e 100644 --- a/desktop-widgets/modeldelegates.cpp +++ b/desktop-widgets/modeldelegates.cpp @@ -230,12 +230,6 @@ void ComboBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionV editor->setGeometry(defaultRect); } -static struct RevertCylinderData { - QString type; - int pressure; - int size; -} currCylinderData; - void TankInfoDelegate::setModelData(QWidget*, QAbstractItemModel*, const QModelIndex&) const { QAbstractItemModel *mymodel = currCombo.model; @@ -254,9 +248,9 @@ void TankInfoDelegate::setModelData(QWidget*, QAbstractItemModel*, const QModelI int tankSize = tanks->data(tanks->index(row, TankInfoModel::ML)).toInt(); int tankPressure = tanks->data(tanks->index(row, TankInfoModel::BAR)).toInt(); - mymodel->setData(IDX(CylindersModel::TYPE), cylinderName, Qt::EditRole); - mymodel->setData(IDX(CylindersModel::WORKINGPRESS), tankPressure, CylindersModel::PASS_IN_ROLE); - mymodel->setData(IDX(CylindersModel::SIZE), tankSize, CylindersModel::PASS_IN_ROLE); + mymodel->setData(IDX(CylindersModel::TYPE), cylinderName, CylindersModel::TEMP_ROLE); + mymodel->setData(IDX(CylindersModel::WORKINGPRESS), tankPressure, CylindersModel::TEMP_ROLE); + mymodel->setData(IDX(CylindersModel::SIZE), tankSize, CylindersModel::TEMP_ROLE); } TankInfoDelegate::TankInfoDelegate(QObject *parent) : ComboBoxDelegate(TankInfoModel::instance(), parent, true) @@ -275,25 +269,19 @@ void TankInfoDelegate::reenableReplot(QWidget*, QAbstractItemDelegate::EndEditHi void TankInfoDelegate::editorClosed(QWidget*, QAbstractItemDelegate::EndEditHint hint) { - if (hint == QAbstractItemDelegate::NoHint || - hint == QAbstractItemDelegate::RevertModelCache) { - QAbstractItemModel *mymodel = currCombo.model; - mymodel->setData(IDX(CylindersModel::TYPE), currCylinderData.type, Qt::EditRole); - mymodel->setData(IDX(CylindersModel::WORKINGPRESS), currCylinderData.pressure, CylindersModel::PASS_IN_ROLE); - mymodel->setData(IDX(CylindersModel::SIZE), currCylinderData.size, CylindersModel::PASS_IN_ROLE); - } + QAbstractItemModel *mymodel = currCombo.model; + // Ugly hack: We misuse setData() with COMMIT_ROLE or REVERT_ROLE to commit or + // revert the current row. We send in the type, because we may get multiple + // end events and thus can prevent multiple commits. + if (hint == QAbstractItemDelegate::RevertModelCache) + mymodel->setData(IDX(CylindersModel::TYPE), currCombo.activeText, CylindersModel::REVERT_ROLE); + else + mymodel->setData(IDX(CylindersModel::TYPE), currCombo.activeText, CylindersModel::COMMIT_ROLE); } QWidget *TankInfoDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { - // ncreate editor needs to be called before because it will populate a few - // things in the currCombo global var. QWidget *delegate = ComboBoxDelegate::createEditor(parent, option, index); - QAbstractItemModel *model = currCombo.model; - int row = index.row(); - currCylinderData.type = model->data(model->index(row, CylindersModel::TYPE)).value(); - currCylinderData.pressure = model->data(model->index(row, CylindersModel::WORKINGPRESS_INT)).value(); - currCylinderData.size = model->data(model->index(row, CylindersModel::SIZE_INT)).value(); MainWindow::instance()->graphics->setReplot(false); return delegate; } diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp index d76cdb344..f2ee0c12e 100644 --- a/qt-models/cylindermodel.cpp +++ b/qt-models/cylindermodel.cpp @@ -2,6 +2,7 @@ #include "cylindermodel.h" #include "tankinfomodel.h" #include "models.h" +#include "commands/command.h" #include "core/qthelper.h" #include "core/color.h" #include "qt-models/diveplannermodel.h" @@ -10,7 +11,9 @@ #include "core/subsurface-string.h" CylindersModel::CylindersModel(QObject *parent) : CleanerTableModel(parent), - d(nullptr) + d(nullptr), + tempRow(-1), + tempCyl(empty_cylinder) { // enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH, MOD, MND, USE, IS_USED}; setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("Work press.") << tr("Start press.") << tr("End press.") << tr("O₂%") << tr("He%") @@ -155,7 +158,7 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const return QVariant(); } - const cylinder_t *cyl = get_cylinder(d, index.row()); + const cylinder_t *cyl = index.row() == tempRow ? &tempCyl : get_cylinder(d, index.row()); switch (role) { case Qt::BackgroundRole: { @@ -299,25 +302,49 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in if (!cyl) return false; - if (role == PASS_IN_ROLE) { - // this is our magic 'pass data in' function that allows the delegate to get - // the data here without silly unit conversions; - // so we only implement the two columns we care about + // Here we handle a few cases that allow us to set / commit / revert + // a temporary row. This is a horribly misuse of the model/view system. + // The reason it is done this way is that the planner and the equipment + // tab use different model-classes which are not in a superclass / subclass + // relationship. + switch (role) { + case TEMP_ROLE: + // TEMP_ROLE means that we are not supposed to write through to the + // actual dive, but a temporary cylinder that is displayed while the + // user browses throught the cylinder types. + initTempCyl(index.row()); + switch (index.column()) { + case TYPE: { + QString type = value.toString(); + if (!same_string(qPrintable(type), tempCyl.type.description)) { + free((void *)tempCyl.type.description); + tempCyl.type.description = strdup(qPrintable(type)); + dataChanged(index, index); + } + } case SIZE: - if (cyl->type.size.mliter != value.toInt()) { - cyl->type.size.mliter = value.toInt(); + if (tempCyl.type.size.mliter != value.toInt()) { + tempCyl.type.size.mliter = value.toInt(); dataChanged(index, index); } return true; case WORKINGPRESS: - if (cyl->type.workingpressure.mbar != value.toInt()) { - cyl->type.workingpressure.mbar = value.toInt(); + if (tempCyl.type.workingpressure.mbar != value.toInt()) { + tempCyl.type.workingpressure.mbar = value.toInt(); dataChanged(index, index); } return true; } return false; + case COMMIT_ROLE: + commitTempCyl(index.row()); + return true; + case REVERT_ROLE: + clearTempCyl(); + return true; + default: + break; } QString vString = value.toString(); @@ -621,6 +648,54 @@ void CylindersModel::cylindersReset(const QVector &dives) endResetModel(); } +// Save the cylinder in the given row so that we can revert if the user cancels a type-editing action. +void CylindersModel::initTempCyl(int row) +{ + if (!d || tempRow == row) + return; + clearTempCyl(); + const cylinder_t *cyl = get_cylinder(d, row); + if (!cyl) + return; + + tempRow = row; + tempCyl = clone_cylinder(*cyl); + + dataChanged(index(row, TYPE), index(row, USE)); +} + +void CylindersModel::clearTempCyl() +{ + if (tempRow < 0) + return; + int oldRow = tempRow; + tempRow = -1; + free_cylinder(tempCyl); + dataChanged(index(oldRow, TYPE), index(oldRow, USE)); +} + +void CylindersModel::commitTempCyl(int row) +{ +#ifndef SUBSURFACE_MOBILE + if (tempRow < 0) + return; + if (row != tempRow) + return clearTempCyl(); // Huh? We are supposed to commit a different row than the one we stored? + cylinder_t *cyl = get_cylinder(d, tempRow); + if (!cyl) + return; + // Only submit a command if the type changed + if (!same_string(cyl->type.description, tempCyl.type.description) || gettextFromC::tr(cyl->type.description) != QString(tempCyl.type.description)) { + if (in_planner()) + std::swap(*cyl, tempCyl); + else + Command::editCylinder(tempRow, tempCyl, false); + } + free_cylinder(tempCyl); + tempRow = -1; +#endif +} + CylindersModelFiltered::CylindersModelFiltered(QObject *parent) : QSortFilterProxyModel(parent) { setSourceModel(&source); diff --git a/qt-models/cylindermodel.h b/qt-models/cylindermodel.h index d3d87b900..e4585b0ac 100644 --- a/qt-models/cylindermodel.h +++ b/qt-models/cylindermodel.h @@ -31,7 +31,9 @@ public: }; enum Roles { - PASS_IN_ROLE = Qt::UserRole + 1 // For setting data: don't do any conversions + TEMP_ROLE = Qt::UserRole + 1, // Temporarily set data, but don't store in dive + COMMIT_ROLE, // Save the temporary data to the dive. Must be set with Column == TYPE. + REVERT_ROLE // Revert to original data from dive. Must be set with Column == TYPE. }; explicit CylindersModel(QObject *parent = 0); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; @@ -59,7 +61,14 @@ slots: private: dive *d; + // Used if we temporarily change a line because the user is selecting a weight type + int tempRow; + cylinder_t tempCyl; + cylinder_t *cylinderAt(const QModelIndex &index); + void initTempCyl(int row); + void clearTempCyl(); + void commitTempCyl(int row); }; // Cylinder model that hides unused cylinders if the pref.show_unused_cylinders flag is not set -- cgit v1.2.3-70-g09d2 From 3965ae2c89d30e424e52cb17cd6ecaf9e46ec0f0 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 2 Mar 2020 10:50:24 +0100 Subject: desktop: move undo-disabling from enterEditState to disableShortcuts When entering the edit state, we don't want the user to be able to undo/redo lest things become inconsistent. Since the only way to enter edit state is to edit the profile, we can simply use the disableShortcuts() function that is used by the profile when it goes into edit state. This has one desirable side-effect: Undo is now also disabled in the planner. Undo during planning likewise can lead to inconsistent state. Signed-off-by: Berthold Stoeger --- desktop-widgets/mainwindow.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index e1d87b7e6..bbeb61f70 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -710,6 +710,8 @@ void MainWindow::on_actionPrint_triggered() void MainWindow::disableShortcuts(bool disablePaste) { + undoAction->setEnabled(false); + redoAction->setEnabled(false); ui.actionPreviousDC->setShortcut(QKeySequence()); ui.actionNextDC->setShortcut(QKeySequence()); ui.copy->setShortcut(QKeySequence()); @@ -719,6 +721,8 @@ void MainWindow::disableShortcuts(bool disablePaste) void MainWindow::enableShortcuts() { + undoAction->setEnabled(true); + redoAction->setEnabled(true); ui.actionPreviousDC->setShortcut(Qt::Key_Left); ui.actionNextDC->setShortcut(Qt::Key_Right); ui.copy->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C)); @@ -1090,8 +1094,6 @@ void MainWindow::on_actionViewAll_triggered() void MainWindow::enterEditState() { - undoAction->setEnabled(false); - redoAction->setEnabled(false); stateBeforeEdit = state; if (state == VIEWALL || state == INFO_MAXIMIZED) return; @@ -1115,8 +1117,6 @@ void MainWindow::enterEditState() void MainWindow::exitEditState() { - undoAction->setEnabled(true); - redoAction->setEnabled(true); if (stateBeforeEdit == state) return; enterState(stateBeforeEdit); -- cgit v1.2.3-70-g09d2 From accf1fcc8f6ad84a662aeba71d582abedbcedfd8 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 2 Mar 2020 10:57:18 +0100 Subject: desktop: remove EDIT mode The only way to enter edit mode is to edit the profile. However, that means that the profile is already visible, so there is no need to change the mode. Simply remove the EDIT mode. Signed-off-by: Berthold Stoeger --- desktop-widgets/mainwindow.cpp | 32 -------------------------------- desktop-widgets/mainwindow.h | 3 --- desktop-widgets/tab-widgets/maintab.cpp | 3 --- 3 files changed, 38 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index bbeb61f70..7796ddf04 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -1092,36 +1092,6 @@ void MainWindow::on_actionViewAll_triggered() ui.bottomSplitter->setCollapsible(1,false); } -void MainWindow::enterEditState() -{ - stateBeforeEdit = state; - if (state == VIEWALL || state == INFO_MAXIMIZED) - return; - toggleCollapsible(true); - beginChangeState(EDIT); - ui.topSplitter->setSizes({ EXPANDED, EXPANDED }); - ui.mainSplitter->setSizes({ EXPANDED, COLLAPSED }); - int appW = qApp->desktop()->size().width(); - QList infoProfileSizes { round_int(appW * 0.3), round_int(appW * 0.7) }; - - QSettings settings; - settings.beginGroup("MainWindow"); - if (settings.value("mainSplitter").isValid()) { - ui.topSplitter->restoreState(settings.value("topSplitter").toByteArray()); - if (ui.topSplitter->sizes().first() == 0 || ui.topSplitter->sizes().last() == 0) - ui.topSplitter->setSizes(infoProfileSizes); - } else { - ui.topSplitter->setSizes(infoProfileSizes); - } -} - -void MainWindow::exitEditState() -{ - if (stateBeforeEdit == state) - return; - enterState(stateBeforeEdit); -} - void MainWindow::enterState(CurrentState newState) { state = newState; @@ -1141,8 +1111,6 @@ void MainWindow::enterState(CurrentState newState) case PROFILE_MAXIMIZED: on_actionViewProfile_triggered(); break; - case EDIT: - break; } } diff --git a/desktop-widgets/mainwindow.h b/desktop-widgets/mainwindow.h index 247bddaf3..1fb20a7ce 100644 --- a/desktop-widgets/mainwindow.h +++ b/desktop-widgets/mainwindow.h @@ -58,7 +58,6 @@ public: INFO_MAXIMIZED, PROFILE_MAXIMIZED, LIST_MAXIMIZED, - EDIT, }; MainWindow(); @@ -81,8 +80,6 @@ public: NotificationWidget *getNotificationWidget(); void enableDisableCloudActions(); void enableDisableOtherDCsActions(); - void enterEditState(); - void exitEditState(); void editDiveSite(dive_site *ds); std::unique_ptr mainTab; diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 311887169..14db8ae28 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -214,7 +214,6 @@ void MainTab::enableEdition(EditMode newEditMode) ui.editDiveSiteButton->setEnabled(false); MainWindow::instance()->diveList->setEnabled(false); MainWindow::instance()->setEnabledToolbar(false); - MainWindow::instance()->enterEditState(); ui.dateEdit->setEnabled(true); displayMessage(tr("This dive is being edited.")); @@ -521,7 +520,6 @@ void MainTab::acceptChanges() DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); MainWindow::instance()->diveList->verticalScrollBar()->setSliderPosition(scrolledBy); MainWindow::instance()->diveList->setFocus(); - MainWindow::instance()->exitEditState(); MainWindow::instance()->setEnabledToolbar(true); ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty()); editMode = NONE; @@ -552,7 +550,6 @@ void MainTab::rejectChanges() // show the profile and dive info MainWindow::instance()->graphics->replot(); MainWindow::instance()->setEnabledToolbar(true); - MainWindow::instance()->exitEditState(); ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty()); } -- cgit v1.2.3-70-g09d2 From 13d339451ed9aa13588a452e19bdd59134107155 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 2 Mar 2020 16:03:32 +0100 Subject: cleanup: remove parameter to MainTab::enableEdition All remaining callers were passing MANUALLY_ADDED_DIVE as a new mode, so we may just as well remove the parameter and thus simplify the logic. Signed-off-by: Berthold Stoeger --- desktop-widgets/mainwindow.cpp | 4 ++-- desktop-widgets/tab-widgets/maintab.cpp | 6 +++--- desktop-widgets/tab-widgets/maintab.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 7796ddf04..1c122a4fd 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -1767,13 +1767,13 @@ void MainWindow::editCurrentDive() graphics->setAddState(); setApplicationState(ApplicationState::EditDive); DivePlannerPointsModel::instance()->loadFromDive(d); - mainTab->enableEdition(MainTab::MANUALLY_ADDED_DIVE); + mainTab->enableEdition(); } else if (defaultDC == "planned dive") { disableShortcuts(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); setApplicationState(ApplicationState::EditPlannedDive); DivePlannerPointsModel::instance()->loadFromDive(d); - mainTab->enableEdition(MainTab::MANUALLY_ADDED_DIVE); + mainTab->enableEdition(); } } diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 14db8ae28..eaf19b7db 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -206,9 +206,9 @@ void MainTab::displayMessage(QString str) ui.diveNotesMessage->animatedShow(); } -void MainTab::enableEdition(EditMode newEditMode) +void MainTab::enableEdition() { - if (((newEditMode == DIVE || newEditMode == NONE) && current_dive == NULL) || editMode != NONE) + if (current_dive == NULL || editMode != NONE) return; ui.editDiveSiteButton->setEnabled(false); @@ -218,7 +218,7 @@ void MainTab::enableEdition(EditMode newEditMode) ui.dateEdit->setEnabled(true); displayMessage(tr("This dive is being edited.")); - editMode = newEditMode != NONE ? newEditMode : DIVE; + editMode = MANUALLY_ADDED_DIVE; } // This function gets called if a field gets updated by an undo command. diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index 6411f6b3a..2524ed2a7 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -72,7 +72,7 @@ slots: void closeMessage(); void closeWarning(); void displayMessage(QString str); - void enableEdition(EditMode newEditMode = NONE); + void enableEdition(); void escDetected(void); private: Ui::MainTab ui; -- cgit v1.2.3-70-g09d2 From dcc1d3ed6389b983982063b3829633e2e8d180b6 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 2 Mar 2020 16:05:58 +0100 Subject: cleanup: remove DIVE EditMode in MainTab That mode is not used anymore, since only the editing of profiles of manually added dives enters editing mode. For that case we have the MANUALLY_ADDED_DIVE edit mode. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/maintab.h | 1 - 1 file changed, 1 deletion(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index 2524ed2a7..d6a5af593 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -28,7 +28,6 @@ class MainTab : public QTabWidget { public: enum EditMode { NONE, - DIVE, MANUALLY_ADDED_DIVE, IGNORE_MODE }; -- cgit v1.2.3-70-g09d2 From 806cfcee212fa89ecfccad0f78225b83159d131e Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 3 Mar 2020 23:09:25 +0100 Subject: cleanup: un-singletonify SetpointDialog We have too many global objects. There is no reason why this dialog should be a persistent global object. Signed-off-by: Berthold Stoeger --- desktop-widgets/simplewidgets.cpp | 18 +++--------------- desktop-widgets/simplewidgets.h | 4 +--- profile-widget/profilewidget2.cpp | 4 ++-- 3 files changed, 6 insertions(+), 20 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp index fb4d3750b..cbf37c398 100644 --- a/desktop-widgets/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -174,18 +174,6 @@ RenumberDialog::RenumberDialog(QWidget *parent) : QDialog(parent), selectedOnly( connect(quit, SIGNAL(activated()), parent, SLOT(close())); } -SetpointDialog *SetpointDialog::instance() -{ - static SetpointDialog *self = new SetpointDialog(MainWindow::instance()); - return self; -} - -void SetpointDialog::setpointData(struct divecomputer *divecomputer, int second) -{ - dc = divecomputer; - time = second < 0 ? 0 : second; -} - void SetpointDialog::buttonClicked(QAbstractButton *button) { if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole && dc) { @@ -197,15 +185,15 @@ void SetpointDialog::buttonClicked(QAbstractButton *button) MainWindow::instance()->graphics->replot(); } -SetpointDialog::SetpointDialog(QWidget *parent) : QDialog(parent), - dc(0), time(0) +SetpointDialog::SetpointDialog(struct divecomputer *dcIn, int seconds) : QDialog(MainWindow::instance()), + dc(dcIn), time(seconds < 0 ? 0 : seconds) { ui.setupUi(this); connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); connect(close, SIGNAL(activated()), this, SLOT(close())); QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); - connect(quit, SIGNAL(activated()), parent, SLOT(close())); + connect(quit, SIGNAL(activated()), parent(), SLOT(close())); } ShiftTimesDialog *ShiftTimesDialog::instance() diff --git a/desktop-widgets/simplewidgets.h b/desktop-widgets/simplewidgets.h index 99cfc0fa2..e293f352c 100644 --- a/desktop-widgets/simplewidgets.h +++ b/desktop-widgets/simplewidgets.h @@ -65,14 +65,12 @@ private: class SetpointDialog : public QDialog { Q_OBJECT public: - static SetpointDialog *instance(); - void setpointData(struct divecomputer *divecomputer, int time); + SetpointDialog(struct divecomputer *divecomputer, int time); private slots: void buttonClicked(QAbstractButton *button); private: - explicit SetpointDialog(QWidget *parent); Ui::SetpointDialog ui; struct divecomputer *dc; int time; diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 76822c196..555305817 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -1611,8 +1611,8 @@ void ProfileWidget2::addDivemodeSwitch(int seconds, int divemode) void ProfileWidget2::addSetpointChange(int seconds) { - SetpointDialog::instance()->setpointData(current_dc, seconds); - SetpointDialog::instance()->show(); + SetpointDialog dialog(current_dc, seconds); + dialog.exec(); } void ProfileWidget2::splitDive(int seconds) -- cgit v1.2.3-70-g09d2 From adb53f9c18070e524a2635c5a1d983556f21d5ea Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 3 Mar 2020 23:13:07 +0100 Subject: cleanup: use pointer-to-member version of connect in SetpointDialog While touching this dialog, might as well change away from the MOC version of the connect() statements. Signed-off-by: Berthold Stoeger --- desktop-widgets/simplewidgets.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp index cbf37c398..4b85a8b50 100644 --- a/desktop-widgets/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -189,11 +189,11 @@ SetpointDialog::SetpointDialog(struct divecomputer *dcIn, int seconds) : QDialog dc(dcIn), time(seconds < 0 ? 0 : seconds) { ui.setupUi(this); - connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); + connect(ui.buttonBox, &QDialogButtonBox::clicked, this, &SetpointDialog::buttonClicked); QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); - connect(close, SIGNAL(activated()), this, SLOT(close())); + connect(close, &QShortcut::activated, this, &QDialog::close); QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); - connect(quit, SIGNAL(activated()), parent(), SLOT(close())); + connect(quit, &QShortcut::activated, MainWindow::instance(), &QWidget::close); } ShiftTimesDialog *ShiftTimesDialog::instance() -- cgit v1.2.3-70-g09d2 From 9a4718b46f5fa74c7c67a92d0c09ab805f364e12 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 3 Mar 2020 23:17:08 +0100 Subject: undo: switch SetpointDialog from divecomputer to dive + dc-number Since pointers to divecomputers may not be stable, the undo commands take a dive + a divecomputer number. Update the SetpointDialog accordingly. Signed-off-by: Berthold Stoeger --- desktop-widgets/simplewidgets.cpp | 8 ++++---- desktop-widgets/simplewidgets.h | 5 +++-- profile-widget/profilewidget2.cpp | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp index 4b85a8b50..c31c93676 100644 --- a/desktop-widgets/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -176,8 +176,8 @@ RenumberDialog::RenumberDialog(QWidget *parent) : QDialog(parent), selectedOnly( void SetpointDialog::buttonClicked(QAbstractButton *button) { - if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole && dc) { - add_event(dc, time, SAMPLE_EVENT_PO2, 0, (int)(1000.0 * ui.spinbox->value()), + if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { + add_event(get_dive_dc(d, dcNr), time, SAMPLE_EVENT_PO2, 0, (int)(1000.0 * ui.spinbox->value()), QT_TRANSLATE_NOOP("gettextFromC", "SP change")); invalidate_dive_cache(current_dive); } @@ -185,8 +185,8 @@ void SetpointDialog::buttonClicked(QAbstractButton *button) MainWindow::instance()->graphics->replot(); } -SetpointDialog::SetpointDialog(struct divecomputer *dcIn, int seconds) : QDialog(MainWindow::instance()), - dc(dcIn), time(seconds < 0 ? 0 : seconds) +SetpointDialog::SetpointDialog(struct dive *dIn, int dcNrIn, int seconds) : QDialog(MainWindow::instance()), + d(dIn), dcNr(dcNrIn), time(seconds < 0 ? 0 : seconds) { ui.setupUi(this); connect(ui.buttonBox, &QDialogButtonBox::clicked, this, &SetpointDialog::buttonClicked); diff --git a/desktop-widgets/simplewidgets.h b/desktop-widgets/simplewidgets.h index e293f352c..421695815 100644 --- a/desktop-widgets/simplewidgets.h +++ b/desktop-widgets/simplewidgets.h @@ -65,14 +65,15 @@ private: class SetpointDialog : public QDialog { Q_OBJECT public: - SetpointDialog(struct divecomputer *divecomputer, int time); + SetpointDialog(struct dive *d, int dcNr, int time); private slots: void buttonClicked(QAbstractButton *button); private: Ui::SetpointDialog ui; - struct divecomputer *dc; + struct dive *d; + int dcNr; int time; }; diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 555305817..76b3c9afb 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -1611,7 +1611,7 @@ void ProfileWidget2::addDivemodeSwitch(int seconds, int divemode) void ProfileWidget2::addSetpointChange(int seconds) { - SetpointDialog dialog(current_dc, seconds); + SetpointDialog dialog(current_dive, dc_number, seconds); dialog.exec(); } -- cgit v1.2.3-70-g09d2 From 1971cfad547792ba961f804605ccb12780e17de0 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 3 Mar 2020 23:31:46 +0100 Subject: undo: implement set point change undo command This is a simple copy of the other add-event commands. It could be made more friendly by stating the pO2 value in the text. Signed-off-by: Berthold Stoeger --- commands/command.cpp | 5 +++++ commands/command.h | 1 + commands/command_event.cpp | 6 ++++++ commands/command_event.h | 5 +++++ desktop-widgets/simplewidgets.cpp | 10 ++-------- 5 files changed, 19 insertions(+), 8 deletions(-) (limited to 'desktop-widgets') diff --git a/commands/command.cpp b/commands/command.cpp index 4f92038b9..44eb4b8f0 100644 --- a/commands/command.cpp +++ b/commands/command.cpp @@ -339,4 +339,9 @@ void addEventDivemodeSwitch(struct dive *d, int dcNr, int seconds, int divemode) execute(new AddEventDivemodeSwitch(d, dcNr, seconds, divemode)); } +void addEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2) +{ + execute(new AddEventSetpointChange(d, dcNr, seconds, pO2)); +} + } // namespace Command diff --git a/commands/command.h b/commands/command.h index 1644063a7..aa7c75ab3 100644 --- a/commands/command.h +++ b/commands/command.h @@ -108,6 +108,7 @@ void editTripNotes(dive_trip *trip, const QString &s); void addEventBookmark(struct dive *d, int dcNr, int seconds); void addEventDivemodeSwitch(struct dive *d, int dcNr, int seconds, int divemode); +void addEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2); } // namespace Command diff --git a/commands/command_event.cpp b/commands/command_event.cpp index ddef502bc..a1e13f252 100644 --- a/commands/command_event.cpp +++ b/commands/command_event.cpp @@ -49,4 +49,10 @@ AddEventDivemodeSwitch::AddEventDivemodeSwitch(struct dive *d, int dcNr, int sec setText(tr("Add dive mode switch to %1").arg(gettextFromC::tr(divemode_text_ui[divemode]))); } +AddEventSetpointChange::AddEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2) : + AddEventBase(d, dcNr, create_event(seconds, SAMPLE_EVENT_PO2, 0, pO2.mbar, QT_TRANSLATE_NOOP("gettextFromC", "SP change"))) +{ + setText(tr("Add set point change")); // TODO: format pO2 value in bar or psi. +} + } // namespace Command diff --git a/commands/command_event.h b/commands/command_event.h index 3130a128f..8cceaeb25 100644 --- a/commands/command_event.h +++ b/commands/command_event.h @@ -44,6 +44,11 @@ public: AddEventDivemodeSwitch(struct dive *d, int dcNr, int seconds, int divemode); }; +class AddEventSetpointChange : public AddEventBase { +public: + AddEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2); +}; + } // namespace Command #endif // COMMAND_EVENT_H diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp index c31c93676..423f4b68f 100644 --- a/desktop-widgets/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -23,7 +23,6 @@ #include "commands/command.h" #include "core/metadata.h" #include "core/tag.h" -#include "core/divelist.h" // for mark_divelist_changed double MinMaxAvgWidget::average() const { @@ -176,13 +175,8 @@ RenumberDialog::RenumberDialog(QWidget *parent) : QDialog(parent), selectedOnly( void SetpointDialog::buttonClicked(QAbstractButton *button) { - if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { - add_event(get_dive_dc(d, dcNr), time, SAMPLE_EVENT_PO2, 0, (int)(1000.0 * ui.spinbox->value()), - QT_TRANSLATE_NOOP("gettextFromC", "SP change")); - invalidate_dive_cache(current_dive); - } - mark_divelist_changed(true); - MainWindow::instance()->graphics->replot(); + if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) + Command::addEventSetpointChange(d, dcNr, time, pressure_t { (int)(1000.0 * ui.spinbox->value()) }); } SetpointDialog::SetpointDialog(struct dive *dIn, int dcNrIn, int seconds) : QDialog(MainWindow::instance()), -- cgit v1.2.3-70-g09d2 From e8beeb6767b387204fcaae4a066f226ca37f8a82 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 15 Mar 2020 21:51:27 +0100 Subject: desktop: properly initialize activeText of model-delegates For reasons that I don't understand, we keep track of the current combo-box text for our model-delegates. However, that text was not initialized when the editor was generated, leading to a UI bug in the cylinder and weight widgets: Activate a field, click somewhere else -> either the empty string or the previous string was set. Reported-by: Robert C. Helling Signed-off-by: Berthold Stoeger --- desktop-widgets/modeldelegates.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'desktop-widgets') diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp index 65e8f377e..d7dd28b0e 100644 --- a/desktop-widgets/modeldelegates.cpp +++ b/desktop-widgets/modeldelegates.cpp @@ -129,6 +129,7 @@ QWidget *ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewI currCombo.comboEditor = comboDelegate; currCombo.currRow = index.row(); currCombo.model = const_cast(index.model()); + currCombo.activeText = currCombo.model->data(index).toString(); keyboardFinished = false; // Current display of things on Gnome3 looks like shit, so -- cgit v1.2.3-70-g09d2 From 3b9913d82893ca023eaea2e25cdbc86765aeb40a Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 18 Mar 2020 22:37:18 +0100 Subject: desktop/tabwidgets: replace IGNORE_MODE by flag The editMode was set to IGNORE_MODE when programatically setting fields so that we can ignore changed-signals. That seems to be orthogonal to whether we are in edit mode and indeed when setting IGNORE_MODE the edit mode was saved and restored. Therefore, replace the IGNORE_MODE by an independent ignoreInput flag. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/maintab.cpp | 32 ++++++++++++++++---------------- desktop-widgets/tab-widgets/maintab.h | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index eaf19b7db..87e9854d5 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -50,6 +50,7 @@ struct Completers { MainTab::MainTab(QWidget *parent) : QTabWidget(parent), editMode(NONE), + ignoreInput(false), lastSelectedDive(true), lastTabSelectedDive(0), lastTabSelectedDiveTrip(0), @@ -341,7 +342,6 @@ void MainTab::updateDiveSite(struct dive *d) void MainTab::updateDiveInfo() { ui.location->refreshDiveSiteCache(); - EditMode rememberEM = editMode; // don't execute this while adding / planning a dive if (editMode == MANUALLY_ADDED_DIVE || MainWindow::instance()->graphics->isPlanner()) return; @@ -353,7 +353,7 @@ void MainTab::updateDiveInfo() for (int i = 0; i < extraWidgets.size() - 1; ++i) extraWidgets[i]->setEnabled(enabled); - editMode = IGNORE_MODE; // don't trigger on changes to the widgets + ignoreInput = true; // don't trigger on changes to the widgets for (TabBase *widget: extraWidgets) widget->updateData(); @@ -476,7 +476,7 @@ void MainTab::updateDiveInfo() ui.timeEdit->setTime(QTime(0, 0, 0, 0)); ui.tagWidget->clear(); } - editMode = rememberEM; + ignoreInput = false; if (verbose && current_dive && current_dive->dive_site) qDebug() << "Set the current dive site:" << current_dive->dive_site->uuid; @@ -499,18 +499,17 @@ void MainTab::acceptChanges() if (ui.location->hasFocus()) stealFocus(); - EditMode lastMode = editMode; - editMode = IGNORE_MODE; + ignoreInput = true; ui.dateEdit->setEnabled(true); hideMessage(); - if (lastMode == MANUALLY_ADDED_DIVE) { + if (editMode == MANUALLY_ADDED_DIVE) { MainWindow::instance()->showProfile(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); Command::editProfile(&displayed_dive); } int scrolledBy = MainWindow::instance()->diveList->verticalScrollBar()->sliderPosition(); - if (lastMode == MANUALLY_ADDED_DIVE) { + if (editMode == MANUALLY_ADDED_DIVE) { MainWindow::instance()->diveList->reload(); MainWindow::instance()->refreshDisplay(); MainWindow::instance()->graphics->replot(); @@ -522,6 +521,7 @@ void MainTab::acceptChanges() MainWindow::instance()->diveList->setFocus(); MainWindow::instance()->setEnabledToolbar(true); ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty()); + ignoreInput = false; editMode = NONE; } @@ -565,7 +565,7 @@ void MainTab::divesEdited(int i) void MainTab::on_buddy_editingFinished() { - if (editMode == IGNORE_MODE || !current_dive) + if (ignoreInput || !current_dive) return; divesEdited(Command::editBuddies(stringToList(ui.buddy->toPlainText()), false)); @@ -573,7 +573,7 @@ void MainTab::on_buddy_editingFinished() void MainTab::on_divemaster_editingFinished() { - if (editMode == IGNORE_MODE || !current_dive) + if (ignoreInput || !current_dive) return; divesEdited(Command::editDiveMaster(stringToList(ui.divemaster->toPlainText()), false)); @@ -581,7 +581,7 @@ void MainTab::on_divemaster_editingFinished() void MainTab::on_duration_editingFinished() { - if (editMode == IGNORE_MODE || !current_dive) + if (ignoreInput || !current_dive) return; // Duration editing is special: we only edit the current dive. @@ -590,7 +590,7 @@ void MainTab::on_duration_editingFinished() void MainTab::on_depth_editingFinished() { - if (editMode == IGNORE_MODE || !current_dive) + if (ignoreInput || !current_dive) return; // Depth editing is special: we only edit the current dive. @@ -610,7 +610,7 @@ static void shiftTime(QDateTime &dateTime) void MainTab::on_dateEdit_dateChanged(const QDate &date) { - if (editMode == IGNORE_MODE || !current_dive) + if (ignoreInput || !current_dive) return; QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(1000*current_dive->when, Qt::UTC); dateTime.setTimeSpec(Qt::UTC); @@ -620,7 +620,7 @@ void MainTab::on_dateEdit_dateChanged(const QDate &date) void MainTab::on_timeEdit_timeChanged(const QTime &time) { - if (editMode == IGNORE_MODE || !current_dive) + if (ignoreInput || !current_dive) return; QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(1000*current_dive->when, Qt::UTC); dateTime.setTimeSpec(Qt::UTC); @@ -630,7 +630,7 @@ void MainTab::on_timeEdit_timeChanged(const QTime &time) void MainTab::on_tagWidget_editingFinished() { - if (editMode == IGNORE_MODE || !current_dive) + if (ignoreInput || !current_dive) return; divesEdited(Command::editTags(ui.tagWidget->getBlockStringList(), false)); @@ -638,7 +638,7 @@ void MainTab::on_tagWidget_editingFinished() void MainTab::on_location_diveSiteSelected() { - if (editMode == IGNORE_MODE || !current_dive) + if (ignoreInput || !current_dive) return; struct dive_site *newDs = ui.location->currDiveSite(); @@ -676,7 +676,7 @@ void MainTab::on_notes_editingFinished() void MainTab::on_rating_valueChanged(int value) { - if (editMode == IGNORE_MODE || !current_dive) + if (ignoreInput || !current_dive) return; divesEdited(Command::editRating(value, false)); diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index d6a5af593..bf071619b 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -28,8 +28,7 @@ class MainTab : public QTabWidget { public: enum EditMode { NONE, - MANUALLY_ADDED_DIVE, - IGNORE_MODE + MANUALLY_ADDED_DIVE }; MainTab(QWidget *parent = 0); @@ -76,6 +75,7 @@ slots: private: Ui::MainTab ui; EditMode editMode; + bool ignoreInput; // When computionally editing fields, we have to ignore changed-signals BuddyCompletionModel buddyModel; DiveMasterCompletionModel diveMasterModel; TagCompletionModel tagModel; -- cgit v1.2.3-70-g09d2 From 20e70646584e71f03e5983660c21e7a7e097cf39 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 18 Mar 2020 22:42:47 +0100 Subject: 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 --- desktop-widgets/tab-widgets/maintab.cpp | 22 +++++++++++----------- desktop-widgets/tab-widgets/maintab.h | 7 +------ 2 files changed, 12 insertions(+), 17 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 87e9854d5..7fde2e1b6 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -49,7 +49,7 @@ struct Completers { }; MainTab::MainTab(QWidget *parent) : QTabWidget(parent), - editMode(NONE), + editMode(false), ignoreInput(false), lastSelectedDive(true), lastTabSelectedDive(0), @@ -209,7 +209,7 @@ void MainTab::displayMessage(QString str) void MainTab::enableEdition() { - if (current_dive == NULL || editMode != NONE) + if (current_dive == NULL || editMode) return; ui.editDiveSiteButton->setEnabled(false); @@ -219,7 +219,7 @@ void MainTab::enableEdition() ui.dateEdit->setEnabled(true); 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. @@ -284,7 +284,7 @@ void MainTab::nextInputField(QKeyEvent *event) bool MainTab::isEditing() { - return editMode != NONE; + return editMode; } static bool isHtml(const QString &s) @@ -343,7 +343,7 @@ void MainTab::updateDiveInfo() { ui.location->refreshDiveSiteCache(); // 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; // 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); hideMessage(); - if (editMode == MANUALLY_ADDED_DIVE) { + if (editMode) { MainWindow::instance()->showProfile(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); Command::editProfile(&displayed_dive); } int scrolledBy = MainWindow::instance()->diveList->verticalScrollBar()->sliderPosition(); - if (editMode == MANUALLY_ADDED_DIVE) { + if (editMode) { MainWindow::instance()->diveList->reload(); MainWindow::instance()->refreshDisplay(); MainWindow::instance()->graphics->replot(); @@ -522,12 +522,12 @@ void MainTab::acceptChanges() MainWindow::instance()->setEnabledToolbar(true); ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty()); ignoreInput = false; - editMode = NONE; + editMode = false; } void MainTab::rejectChanges() { - if (editMode != NONE && current_dive) { + if (editMode && current_dive) { 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) { @@ -535,7 +535,7 @@ void MainTab::rejectChanges() } } ui.dateEdit->setEnabled(true); - editMode = NONE; + editMode = false; hideMessage(); // no harm done to call cancelPlan even if we were not PLAN mode... DivePlannerPointsModel::instance()->cancelPlan(); @@ -693,7 +693,7 @@ void MainTab::escDetected() { // In edit mode, pressing escape cancels the current changes. // In standard mode, remove focus of any active widget to - if (editMode != NONE) + if (editMode) rejectChanges(); else stealFocus(); diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index bf071619b..49003be4e 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -26,11 +26,6 @@ class TabBase; class MainTab : public QTabWidget { Q_OBJECT public: - enum EditMode { - NONE, - MANUALLY_ADDED_DIVE - }; - MainTab(QWidget *parent = 0); ~MainTab(); void clearTabs(); @@ -74,7 +69,7 @@ slots: void escDetected(void); private: Ui::MainTab ui; - EditMode editMode; + bool editMode; bool ignoreInput; // When computionally editing fields, we have to ignore changed-signals BuddyCompletionModel buddyModel; DiveMasterCompletionModel diveMasterModel; -- cgit v1.2.3-70-g09d2 From 63414fc82394031a9ce9c25d635430107fde19e0 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 27 Mar 2020 21:49:19 +0100 Subject: undo: show multiple dive warning when editing equipment When editing cylinders or weights directly in the table widgets, no warning was shown if multiple dives were affected. To solve this, emit signals from the respective models and catch them in dive equipment tab. Not very nice, but it works for now. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/TabDiveEquipment.cpp | 2 ++ desktop-widgets/tab-widgets/TabDiveEquipment.h | 2 +- qt-models/cylindermodel.cpp | 11 +++++++---- qt-models/cylindermodel.h | 3 +++ qt-models/weightmodel.cpp | 9 ++++++--- qt-models/weightmodel.h | 3 +++ 6 files changed, 22 insertions(+), 8 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp index 13cfe77c4..78973b6c1 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp @@ -35,6 +35,8 @@ TabDiveEquipment::TabDiveEquipment(QWidget *parent) : TabBase(parent), connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &TabDiveEquipment::divesChanged); connect(ui.cylinders, &TableView::itemClicked, this, &TabDiveEquipment::editCylinderWidget); connect(ui.weights, &TableView::itemClicked, this, &TabDiveEquipment::editWeightWidget); + connect(cylindersModel->model(), &CylindersModel::divesEdited, this, &TabDiveEquipment::divesEdited); + connect(weightModel, &WeightModel::divesEdited, this, &TabDiveEquipment::divesEdited); // Current display of things on Gnome3 looks like shit, so // let's fix that. diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.h b/desktop-widgets/tab-widgets/TabDiveEquipment.h index 3576b449e..55eb21d1e 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.h +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.h @@ -21,7 +21,6 @@ public: ~TabDiveEquipment(); void updateData() override; void clear() override; - void divesEdited(int i); void closeWarning(); private slots: @@ -32,6 +31,7 @@ private slots: void editCylinderWidget(const QModelIndex &index); void editWeightWidget(const QModelIndex &index); void on_suit_editingFinished(); + void divesEdited(int count); private: Ui::TabDiveEquipment ui; diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp index c7e1b186d..e519d347b 100644 --- a/qt-models/cylindermodel.cpp +++ b/qt-models/cylindermodel.cpp @@ -473,7 +473,8 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in } else { #ifndef SUBSURFACE_MOBILE // On the EquipmentTab - place an editCylinder command. - Command::editCylinder(index.row(), cyl, type, false); + int count = Command::editCylinder(index.row(), cyl, type, false); + emit divesEdited(count); #endif } return true; @@ -718,10 +719,12 @@ void CylindersModel::commitTempCyl(int row) return; // Only submit a command if the type changed if (!same_string(cyl->type.description, tempCyl.type.description) || gettextFromC::tr(cyl->type.description) != QString(tempCyl.type.description)) { - if (inPlanner) + if (inPlanner) { std::swap(*cyl, tempCyl); - else - Command::editCylinder(tempRow, tempCyl, Command::EditCylinderType::TYPE, false); + } else { + int count = Command::editCylinder(tempRow, tempCyl, Command::EditCylinderType::TYPE, false); + emit divesEdited(count); + } } free_cylinder(tempCyl); tempRow = -1; diff --git a/qt-models/cylindermodel.h b/qt-models/cylindermodel.h index 7b868b5b2..099a3beb2 100644 --- a/qt-models/cylindermodel.h +++ b/qt-models/cylindermodel.h @@ -51,6 +51,9 @@ public: bool updateBestMixes(); bool cylinderUsed(int i) const; +signals: + void divesEdited(int num); + public slots: void remove(QModelIndex index); diff --git a/qt-models/weightmodel.cpp b/qt-models/weightmodel.cpp index 6e56071e2..6b5f9e70d 100644 --- a/qt-models/weightmodel.cpp +++ b/qt-models/weightmodel.cpp @@ -112,8 +112,10 @@ void WeightModel::commitTempWS() return; // Only submit a command if the type changed weightsystem_t ws = d->weightsystems.weightsystems[tempRow]; - if (!same_string(ws.description, tempWS.description) || gettextFromC::tr(ws.description) != QString(tempWS.description)) - Command::editWeight(tempRow, tempWS, false); + if (!same_string(ws.description, tempWS.description) || gettextFromC::tr(ws.description) != QString(tempWS.description)) { + int count = Command::editWeight(tempRow, tempWS, false); + emit divesEdited(count); + } tempRow = -1; #endif } @@ -126,7 +128,8 @@ bool WeightModel::setData(const QModelIndex &index, const QVariant &value, int r switch (index.column()) { case WEIGHT: ws.weight = string_to_weight(qPrintable(vString)); - Command::editWeight(index.row(), ws, false); + int count = Command::editWeight(index.row(), ws, false); + emit divesEdited(count); return true; } return false; diff --git a/qt-models/weightmodel.h b/qt-models/weightmodel.h index 950e96d2b..b1df4fc8e 100644 --- a/qt-models/weightmodel.h +++ b/qt-models/weightmodel.h @@ -29,6 +29,9 @@ public: void updateDive(dive *d); weightsystem_t weightSystemAt(const QModelIndex &index) const; +signals: + void divesEdited(int num); + public slots: void weightsystemsReset(const QVector &dives); -- cgit v1.2.3-70-g09d2 From 39bc6e3bddbb45bec8933723b4e9fc64a865236b Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 27 Mar 2020 21:53:32 +0100 Subject: cleanup: remove unneeded includes from TabDiveEquipment.cpp Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/TabDiveEquipment.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp index 78973b6c1..9399d3871 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp @@ -1,18 +1,13 @@ // SPDX-License-Identifier: GPL-2.0 #include "TabDiveEquipment.h" #include "maintab.h" -#include "desktop-widgets/mainwindow.h" // TODO: Only used temporarilly for edit mode changes #include "desktop-widgets/simplewidgets.h" // For isGnome3Session() #include "desktop-widgets/modeldelegates.h" #include "commands/command.h" -#include "profile-widget/profilewidget2.h" #include "qt-models/cylindermodel.h" #include "qt-models/weightmodel.h" -#include "core/subsurface-string.h" -#include "core/divelist.h" - #include #include -- cgit v1.2.3-70-g09d2 From be7365755e8d194d839afbde55e3040489bf38b9 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 27 Mar 2020 22:19:50 +0100 Subject: cleanup: remove TankInfoDelegate::reenableReplot Update of the profile is now done by the undo-commands. If the planner needs this, it is probably better to connect directly to the model, not the delegate. Signed-off-by: Berthold Stoeger --- desktop-widgets/modeldelegates.cpp | 10 ---------- desktop-widgets/modeldelegates.h | 1 - 2 files changed, 11 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp index d7dd28b0e..f03008324 100644 --- a/desktop-widgets/modeldelegates.cpp +++ b/desktop-widgets/modeldelegates.cpp @@ -256,16 +256,6 @@ void TankInfoDelegate::setModelData(QWidget*, QAbstractItemModel*, const QModelI TankInfoDelegate::TankInfoDelegate(QObject *parent) : ComboBoxDelegate(TankInfoModel::instance(), parent, true) { - connect(this, SIGNAL(closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint)), - this, SLOT(reenableReplot(QWidget *, QAbstractItemDelegate::EndEditHint))); -} - -void TankInfoDelegate::reenableReplot(QWidget*, QAbstractItemDelegate::EndEditHint) -{ - MainWindow::instance()->graphics->setReplot(true); - // FIXME: We need to replot after a cylinder is selected but the replot below overwrites - // the newly selected cylinder. - // MainWindow::instance()->graphics->replot(); } void TankInfoDelegate::editorClosed(QWidget*, QAbstractItemDelegate::EndEditHint hint) diff --git a/desktop-widgets/modeldelegates.h b/desktop-widgets/modeldelegates.h index 277bf994e..d539c0384 100644 --- a/desktop-widgets/modeldelegates.h +++ b/desktop-widgets/modeldelegates.h @@ -61,7 +61,6 @@ public: public slots: void editorClosed(QWidget *widget, QAbstractItemDelegate::EndEditHint hint); - void reenableReplot(QWidget *widget, QAbstractItemDelegate::EndEditHint hint); }; class TankUseDelegate : public QStyledItemDelegate { -- cgit v1.2.3-70-g09d2 From f9e246fed2433d137e6d30c95608440eadf18770 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 27 Mar 2020 22:33:17 +0100 Subject: cleanup: make static fields local to ComboBoxDelegate All combobox-delegates shared a number of static status fields. In a quest to make the code more reentrant, move that to the actual object. The fields have to be defined as mutable, since they are set in const member functions. Signed-off-by: Berthold Stoeger --- desktop-widgets/modeldelegates.cpp | 9 --------- desktop-widgets/modeldelegates.h | 8 ++++++++ 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp index f03008324..417ae2cdb 100644 --- a/desktop-widgets/modeldelegates.cpp +++ b/desktop-widgets/modeldelegates.cpp @@ -38,7 +38,6 @@ QSize DiveListDelegate::sizeHint(const QStyleOptionViewItem&, const QModelIndex& // Gets the index of the model in the currentRow and column. // currCombo is defined below. #define IDX(_XX) mymodel->index(currCombo.currRow, (_XX)) -static bool keyboardFinished = false; StarWidgetsDelegate::StarWidgetsDelegate(QWidget *parent) : QStyledItemDelegate(parent), parentWidget(parent) @@ -101,14 +100,6 @@ void ComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) c->lineEdit()->setSelection(0, c->lineEdit()->text().length()); } -static struct CurrSelected { - QComboBox *comboEditor; - int currRow; - QString activeText; - QAbstractItemModel *model; - bool ignoreSelection; -} currCombo; - QWidget *ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem&, const QModelIndex &index) const { QComboBox *comboDelegate = new QComboBox(parent); diff --git a/desktop-widgets/modeldelegates.h b/desktop-widgets/modeldelegates.h index d539c0384..1b4c525d0 100644 --- a/desktop-widgets/modeldelegates.h +++ b/desktop-widgets/modeldelegates.h @@ -48,8 +48,16 @@ slots: virtual void editorClosed(QWidget *widget, QAbstractItemDelegate::EndEditHint hint) = 0; private: bool editable; + mutable bool keyboardFinished; protected: QAbstractItemModel *model; + mutable struct CurrSelected { + QComboBox *comboEditor; + int currRow; + QString activeText; + QAbstractItemModel *model; + bool ignoreSelection; + } currCombo; }; class TankInfoDelegate : public ComboBoxDelegate { -- cgit v1.2.3-70-g09d2 From e5c4dee7f65e8f603ad5207ee6fd8a4de28321fe Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 4 Apr 2020 19:05:25 +0200 Subject: delegates: call fixTabBehavior *before* closing the editor fixTabBehavior() set the editor text *after* closing the editor. This left us in an inconsistent state where we thought that the editor is active. By reversing two connects, this problem is resolved. Signed-off-by: Berthold Stoeger --- desktop-widgets/modeldelegates.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp index 417ae2cdb..1908cc543 100644 --- a/desktop-widgets/modeldelegates.cpp +++ b/desktop-widgets/modeldelegates.cpp @@ -84,8 +84,8 @@ const QSize& StarWidgetsDelegate::starSize() const ComboBoxDelegate::ComboBoxDelegate(QAbstractItemModel *model, QObject *parent, bool allowEdit) : QStyledItemDelegate(parent), model(model) { editable = allowEdit; - connect(this, &ComboBoxDelegate::closeEditor, this, &ComboBoxDelegate::editorClosed); connect(this, &ComboBoxDelegate::closeEditor, this, &ComboBoxDelegate::fixTabBehavior); + connect(this, &ComboBoxDelegate::closeEditor, this, &ComboBoxDelegate::editorClosed); } void ComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const -- cgit v1.2.3-70-g09d2 From 7dc04b4437c7aa1788f7d85a513a246ce502dea4 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 4 Apr 2020 23:02:32 +0200 Subject: delegates: remove ComboBoxTemplate::fixTabBehavior The comment states that Qt treats TAB as cancel when in the combobox. However, testing shows that this use-case works without this hack. Since it caused weird behavior (the data was set *after* the editor was closed, leading to inconsistent state), remove it. Note: this overrides the previous commit, which is therefore redundant from a history point of view. However, I'll leave the previous commit in so that if something turns out to break, we can figure out which of the two changes it was. Signed-off-by: Berthold Stoeger --- desktop-widgets/modeldelegates.cpp | 16 +--------------- desktop-widgets/modeldelegates.h | 2 -- 2 files changed, 1 insertion(+), 17 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp index 1908cc543..5480a41db 100644 --- a/desktop-widgets/modeldelegates.cpp +++ b/desktop-widgets/modeldelegates.cpp @@ -84,7 +84,6 @@ const QSize& StarWidgetsDelegate::starSize() const ComboBoxDelegate::ComboBoxDelegate(QAbstractItemModel *model, QObject *parent, bool allowEdit) : QStyledItemDelegate(parent), model(model) { editable = allowEdit; - connect(this, &ComboBoxDelegate::closeEditor, this, &ComboBoxDelegate::fixTabBehavior); connect(this, &ComboBoxDelegate::closeEditor, this, &ComboBoxDelegate::editorClosed); } @@ -121,7 +120,6 @@ QWidget *ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewI currCombo.currRow = index.row(); currCombo.model = const_cast(index.model()); currCombo.activeText = currCombo.model->data(index).toString(); - keyboardFinished = false; // Current display of things on Gnome3 looks like shit, so // let`s fix that. @@ -169,16 +167,6 @@ void ComboBoxDelegate::fakeActivation() QStyledItemDelegate::eventFilter(currCombo.comboEditor, &ev); } -// This 'reverts' the model data to what we actually choosed, -// becaus e a TAB is being understood by Qt as 'cancel' while -// we are on a QComboBox ( but not on a QLineEdit. -void ComboBoxDelegate::fixTabBehavior() -{ - if (keyboardFinished) { - setModelData(0, 0, QModelIndex()); - } -} - bool ComboBoxDelegate::eventFilter(QObject *object, QEvent *event) { // Reacts on Key_UP and Key_DOWN to show the QComboBox - list of choices. @@ -192,10 +180,8 @@ bool ComboBoxDelegate::eventFilter(QObject *object, QEvent *event) return true; } } - if (ev->key() == Qt::Key_Tab || ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return) { + if (ev->key() == Qt::Key_Tab || ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return) currCombo.activeText = currCombo.comboEditor->currentText(); - keyboardFinished = true; - } } else { // the 'Drop Down Menu' part. QKeyEvent *ev = static_cast(event); if (ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return || diff --git a/desktop-widgets/modeldelegates.h b/desktop-widgets/modeldelegates.h index 1b4c525d0..95e9c5fef 100644 --- a/desktop-widgets/modeldelegates.h +++ b/desktop-widgets/modeldelegates.h @@ -44,11 +44,9 @@ slots: void testActivation(const QModelIndex &currIndex); //HACK: try to get rid of this in the future. void fakeActivation(); - void fixTabBehavior(); virtual void editorClosed(QWidget *widget, QAbstractItemDelegate::EndEditHint hint) = 0; private: bool editable; - mutable bool keyboardFinished; protected: QAbstractItemModel *model; mutable struct CurrSelected { -- cgit v1.2.3-70-g09d2