Cleanup: unify selection signals

For historic reasons, there where three distinct signals concerning
dive-selection from the undo-machinery:
1) divesSelected: sent newly selected dives
2) currentDiveChanged: sent if the current dive changed
3) selectionChanged: sent at the end of a command if either the selection
   or the current dive changed

Since now the undo-commands do a full reset of the selection, merge these
three signals into a single signal.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-06-23 12:46:42 +02:00 committed by bstoeger
parent 4716c82032
commit 2e230da361
7 changed files with 59 additions and 93 deletions

View file

@ -53,7 +53,6 @@ void setSelection(const std::vector<dive *> &selection, dive *currentDive)
int i;
dive *d;
amount_selected = 0; // We recalculate amount_selected
bool selectionChanged = false;
for_each_dive(i, d) {
// We only modify dives that are currently visible.
if (d->hidden_by_filter) {
@ -75,36 +74,19 @@ void setSelection(const std::vector<dive *> &selection, dive *currentDive)
// don't want, as we set it later anyway.
// There is other parts of the C++ code that touches the innards directly, but
// ultimately this should be pushed down to C.
selectionChanged |= d->selected != newState;
d->selected = newState;
}
// Send the select and deselect signals
emit diveListNotifier.divesSelected(divesToSelect);
bool currentDiveChanged = false;
if (!currentDive) {
// If currentDive is null, we have no current dive. In such a case always
// notify the frontend.
currentDiveChanged = true;
emit diveListNotifier.currentDiveChanged();
} else if (current_dive != currentDive) {
currentDiveChanged = true;
// We cannot simply change the currentd dive to the given dive.
// It might be hidden by a filter and thus not be selected.
if (currentDive->selected)
// Current dive is visible and selected. Excellent.
current_dive = currentDive;
else
// Current not visible -> find a different dive.
setClosestCurrentDive(currentDive->when, selection);
emit diveListNotifier.currentDiveChanged();
// We cannot simply change the current dive to the given dive.
// It might be hidden by a filter and thus not be selected.
current_dive = currentDive;
if (current_dive && !currentDive->selected) {
// Current not visible -> find a different dive.
setClosestCurrentDive(currentDive->when, selection);
}
// If the selection changed -> tell the frontend
if (selectionChanged || currentDiveChanged)
emit diveListNotifier.selectionChanged();
// Send the new selection
emit diveListNotifier.divesSelected(divesToSelect, current_dive);
}
// Turn current selection into a vector.

View file

@ -448,7 +448,7 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection)
scrollTo(idx);
}
// now that everything is up to date, update the widgets
emit diveListNotifier.selectionChanged();
emit divesSelected();
dontEmitDiveChangedSignal = false;
return;
}
@ -663,7 +663,7 @@ void DiveListView::selectionChanged(const QItemSelection &selected, const QItemS
}
}
if (!dontEmitDiveChangedSignal)
emit diveListNotifier.selectionChanged();
emit divesSelected();
// Display the new, processed, selection
QTreeView::selectionChanged(selectionModel()->selection(), newDeselected);
@ -1063,7 +1063,7 @@ void DiveListView::filterFinished()
// If there are no more selected dives, select the first visible dive
if (!selectionModel()->hasSelection())
selectFirstDive();
emit diveListNotifier.selectionChanged();
emit divesSelected();
}
QString DiveListView::lastUsedImageDir()

View file

@ -42,6 +42,8 @@ public:
QList<dive_trip *> selectedTrips();
static QString lastUsedImageDir();
static void updateLastUsedImageDir(const QString &s);
signals:
void divesSelected();
public
slots:
void toggleColumnVisibilityByIndex();

View file

@ -191,7 +191,8 @@ MainWindow::MainWindow() : QMainWindow(),
if (!QIcon::hasThemeIcon("window-close")) {
QIcon::setThemeName("subsurface");
}
connect(&diveListNotifier, &DiveListNotifier::selectionChanged, this, &MainWindow::selectionChanged);
connect(&diveListNotifier, &DiveListNotifier::divesSelected, this, &MainWindow::selectionChanged);
connect(diveList, &DiveListView::divesSelected, this, &MainWindow::selectionChanged);
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(readSettings()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), diveList, SLOT(update()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), diveList, SLOT(reloadHeaderActions()));