summaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-07-29 17:40:53 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-30 12:21:17 -0700
commit4bdd811f06096c2420a05dd3cc78fffbd7f3a663 (patch)
treec263a6b92a517d21c160d7c43439d2804423db88 /desktop-widgets
parent5e1e6110ce50b33e24667ce83ab5d2417a2a466e (diff)
downloadsubsurface-4bdd811f06096c2420a05dd3cc78fffbd7f3a663.tar.gz
Cleanup: remove DiveListView::fixMessyQtModelBehaviour()
The function DiveListView::fixMessyQtModelBehaviour() was used to expand the first columns of dive-trips in the dive-list view. This function was called everytime that the dive-list was modified. It is kind of ludicrous that external callers would have to tell the DiveListView, when it has to update its column headers. Instead, place this functionality in the overriden reset() and rowsInserted() functions, as these are the only ways that rows can be added. Change the DiveTripModel to use the proper beginResetModel()/endResetModel() pair instead of the previous full deletion and full repopulation using the beginRemoveRows()/ endRemoveRows() and beginInsertRows()/endInsertRows(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/divelistview.cpp36
-rw-r--r--desktop-widgets/divelistview.h3
-rw-r--r--desktop-widgets/simplewidgets.cpp1
3 files changed, 26 insertions, 14 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp
index 8e6885ee1..a6268413f 100644
--- a/desktop-widgets/divelistview.cpp
+++ b/desktop-widgets/divelistview.cpp
@@ -39,7 +39,6 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
DiveTripModel *tripModel = new DiveTripModel(this);
model->setSourceModel(tripModel);
setModel(model);
- connect(model, SIGNAL(layoutChanged()), this, SLOT(fixMessyQtModelBehaviour()));
setSortingEnabled(false);
setContextMenuPolicy(Qt::DefaultContextMenu);
@@ -160,12 +159,34 @@ void DiveListView::restoreExpandedRows()
setExpanded(model()->index(i, 0), true);
setAnimated(true);
}
-void DiveListView::fixMessyQtModelBehaviour()
+
+// If the model is reset, check which items are trip-items and expand the first column
+void DiveListView::reset()
{
+ // First, let the QTreeView do its thing.
+ QTreeView::reset();
+
QAbstractItemModel *m = model();
- for (int i = 0; i < model()->rowCount(); i++)
+ for (int i = 0; i < m->rowCount(); ++i) {
if (m->rowCount(m->index(i, 0)) != 0)
setFirstColumnSpanned(i, QModelIndex(), true);
+ }
+}
+
+// If rows are added, check which of these rows is a trip and expand the first column
+void DiveListView::rowsInserted(const QModelIndex &parent, int start, int end)
+{
+ // First, let the QTreeView do its thing.
+ QTreeView::rowsInserted(parent, start, end);
+
+ // Now check for each inserted row whether this is a trip and expand the first column
+ if (parent.isValid()) // Trips don't have a parent
+ return;
+ QAbstractItemModel *m = model();
+ for (int i = start; i <= end; ++i) {
+ if (m->rowCount(m->index(i, 0)) != 0)
+ setFirstColumnSpanned(i, QModelIndex(), true);
+ }
}
// this only remembers dives that were selected, not trips
@@ -435,9 +456,6 @@ void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
setAnimated(true);
}
}
- if (currentLayout == DiveTripModel::TREE) {
- fixMessyQtModelBehaviour();
- }
}
void DiveListView::reloadHeaderActions()
@@ -627,7 +645,6 @@ void DiveListView::merge_trip(const QModelIndex &a, int offset)
combine_trips(trip_a, trip_b);
rememberSelection();
reload(currentLayout, false);
- fixMessyQtModelBehaviour();
restoreSelection();
mark_divelist_changed(true);
//TODO: emit a signal to signalize that the divelist changed?
@@ -658,7 +675,6 @@ void DiveListView::removeFromTrip()
rememberSelection();
reload(currentLayout, false);
- fixMessyQtModelBehaviour();
restoreSelection();
mark_divelist_changed(true);
}
@@ -679,7 +695,6 @@ void DiveListView::newTripAbove()
}
trip->expanded = 1;
reload(currentLayout, false);
- fixMessyQtModelBehaviour();
mark_divelist_changed(true);
restoreSelection();
}
@@ -730,7 +745,6 @@ void DiveListView::addToTrip(int delta)
reload(currentLayout, false);
restoreSelection();
- fixMessyQtModelBehaviour();
}
void DiveListView::markDiveInvalid()
@@ -756,7 +770,6 @@ void DiveListView::markDiveInvalid()
// select top dive that isn't marked invalid
rememberSelection();
}
- fixMessyQtModelBehaviour();
}
void DiveListView::deleteDive()
@@ -787,7 +800,6 @@ void DiveListView::deleteDive()
selectDive(lastDiveNr);
rememberSelection();
}
- fixMessyQtModelBehaviour();
}
void DiveListView::contextMenuEvent(QContextMenuEvent *event)
diff --git a/desktop-widgets/divelistview.h b/desktop-widgets/divelistview.h
index e70f96a72..69db31a9a 100644
--- a/desktop-widgets/divelistview.h
+++ b/desktop-widgets/divelistview.h
@@ -45,7 +45,8 @@ slots:
void removeFromTrip();
void deleteDive();
void markDiveInvalid();
- void fixMessyQtModelBehaviour();
+ void rowsInserted(const QModelIndex &parent, int start, int end) override;
+ void reset() override;
void mergeTripAbove();
void mergeTripBelow();
void newTripAbove();
diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp
index f6b7a3fa1..4bc36daa7 100644
--- a/desktop-widgets/simplewidgets.cpp
+++ b/desktop-widgets/simplewidgets.cpp
@@ -174,7 +174,6 @@ void RenumberDialog::buttonClicked(QAbstractButton *button)
UndoRenumberDives *undoCommand = new UndoRenumberDives(renumberedDives);
MainWindow::instance()->undoStack->push(undoCommand);
- MainWindow::instance()->dive_list()->fixMessyQtModelBehaviour();
mark_divelist_changed(true);
MainWindow::instance()->dive_list()->restoreSelection();
}