mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
selection: move test for programmatical selection changes to widget
The DiveListView widget has to differentiate between programmatical und user-initiated selection changes. It did so by using the DiveListNotifier::inCommand() flag. However, 1) There is only one point of entry for such selection changes, viz. the MultiFilterSortModel::selectionChanged() signal 2) This signal is not only emitted in command-context. Another source is for example dive-map selection changes. Therefore, move the programmatical-selection-change status down to the widget and set/reset it in the diveSelectionChanged() slot. This makes "select all visible dive sites" somewhat faster. Sadly, not as much as expected. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
aaecc6e98e
commit
5d49da5d6b
2 changed files with 10 additions and 2 deletions
|
@ -32,7 +32,8 @@
|
||||||
|
|
||||||
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent),
|
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent),
|
||||||
currentLayout(DiveTripModelBase::TREE),
|
currentLayout(DiveTripModelBase::TREE),
|
||||||
initialColumnWidths(DiveTripModelBase::COLUMNS, 50) // Set up with default length 50
|
initialColumnWidths(DiveTripModelBase::COLUMNS, 50), // Set up with default length 50
|
||||||
|
programmaticalSelectionChange(false)
|
||||||
{
|
{
|
||||||
setItemDelegate(new DiveListDelegate(this));
|
setItemDelegate(new DiveListDelegate(this));
|
||||||
setUniformRowHeights(true);
|
setUniformRowHeights(true);
|
||||||
|
@ -201,6 +202,11 @@ void DiveListView::reset()
|
||||||
// If items were selected, inform the selection model
|
// If items were selected, inform the selection model
|
||||||
void DiveListView::diveSelectionChanged(const QVector<QModelIndex> &indices)
|
void DiveListView::diveSelectionChanged(const QVector<QModelIndex> &indices)
|
||||||
{
|
{
|
||||||
|
// This is the entry point for programmatical selection changes.
|
||||||
|
// Set a flag so that selection changes are not further processed,
|
||||||
|
// since the core structures were already set.
|
||||||
|
programmaticalSelectionChange = true;
|
||||||
|
|
||||||
clearSelection();
|
clearSelection();
|
||||||
QItemSelectionModel *s = selectionModel();
|
QItemSelectionModel *s = selectionModel();
|
||||||
for (const QModelIndex &index: indices) {
|
for (const QModelIndex &index: indices) {
|
||||||
|
@ -215,6 +221,7 @@ void DiveListView::diveSelectionChanged(const QVector<QModelIndex> &indices)
|
||||||
}
|
}
|
||||||
|
|
||||||
selectionChangeDone();
|
selectionChangeDone();
|
||||||
|
programmaticalSelectionChange = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::currentDiveChanged(QModelIndex index)
|
void DiveListView::currentDiveChanged(QModelIndex index)
|
||||||
|
@ -522,7 +529,7 @@ void DiveListView::selectionChangeDone()
|
||||||
|
|
||||||
void DiveListView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
void DiveListView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
||||||
{
|
{
|
||||||
if (diveListNotifier.inCommand()) {
|
if (programmaticalSelectionChange) {
|
||||||
// This is a programmatical change of the selection.
|
// This is a programmatical change of the selection.
|
||||||
// Call the QTreeView base function to reflect the selection in the display,
|
// Call the QTreeView base function to reflect the selection in the display,
|
||||||
// but don't process it any further.
|
// but don't process it any further.
|
||||||
|
|
|
@ -86,6 +86,7 @@ private:
|
||||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||||
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override;
|
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override;
|
||||||
QNetworkAccessManager manager;
|
QNetworkAccessManager manager;
|
||||||
|
bool programmaticalSelectionChange;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DIVELISTVIEW_H
|
#endif // DIVELISTVIEW_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue