aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--desktop-widgets/divelistview.cpp36
-rw-r--r--desktop-widgets/divelistview.h3
-rw-r--r--desktop-widgets/simplewidgets.cpp1
-rw-r--r--qt-models/divetripmodel.cpp10
-rw-r--r--qt-models/filtermodels.cpp1
5 files changed, 28 insertions, 23 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();
}
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index fd8a2f08a..384da6b89 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -584,10 +584,7 @@ void DiveTripModel::setupModelData()
{
int i = dive_table.nr;
- if (rowCount()) {
- beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
- endRemoveRows();
- }
+ beginResetModel();
if (autogroup)
autogroup_dives();
@@ -621,10 +618,7 @@ void DiveTripModel::setupModelData()
tripItem->children.push_back(diveItem);
}
- if (rowCount()) {
- beginInsertRows(QModelIndex(), 0, rowCount() - 1);
- endInsertRows();
- }
+ endResetModel();
}
DiveTripModel::Layout DiveTripModel::layout() const
diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp
index 34345f381..12d755dc1 100644
--- a/qt-models/filtermodels.cpp
+++ b/qt-models/filtermodels.cpp
@@ -430,7 +430,6 @@ void MultiFilterSortModel::myInvalidate()
divesDisplayed = 0;
invalidateFilter();
- MainWindow::instance()->dive_list()->fixMessyQtModelBehaviour();
// first make sure the trips are no longer shown as selected
// (but without updating the selection state of the dives... this just cleans