mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Dive list: cache shown flag in model (quick-fix for undo-crash)
We have a very fundamental problem with data-duplication in core and qt-models. In a particular case, this led to an easily reproducible crash: 1) An undo command moved the last dive of a trip to another. 2) When an undo-command removed the last dive of a trip to a different trip, the dive was removed from the trip in the core. Then, the model was updated. 3) That lead at first to a rearrangement of the trips, because the trip with the added dive is moved before the trip with the removed dive. 4) In such a case, the filter-model checks the visibility of the trip. 5) Since the trip with the removed dive has no dives in the core, visibility was determined as false. 6) From this point on the mappings of the QSortFilterProxyModel were messed up. Accesses led to crashes. It is unclear whether this is a Qt bug or only a QOI issue. As a quick-fix, cache the visibility flag of trips directly in the Qt-models. Don't set the visibility directly in the core, but go via the Qt-models. Thus, a more clear layering is achieved. In the long run, we can hopefully get rid of the data-duplication in the models. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
4b0f90ced3
commit
cbcddaa396
3 changed files with 97 additions and 30 deletions
|
|
@ -52,6 +52,7 @@ public:
|
|||
DIVE_ROLE,
|
||||
TRIP_ROLE,
|
||||
DIVE_IDX,
|
||||
SHOWN_ROLE,
|
||||
SELECTED_ROLE
|
||||
};
|
||||
enum Layout {
|
||||
|
|
@ -74,6 +75,7 @@ public:
|
|||
DiveTripModelBase(QObject *parent = 0);
|
||||
int columnCount(const QModelIndex&) const;
|
||||
virtual void filterFinished() = 0;
|
||||
virtual bool setShown(const QModelIndex &idx, bool shown) = 0;
|
||||
|
||||
// Used for sorting. This is a bit of a layering violation, as sorting should be performed
|
||||
// by the higher-up QSortFilterProxyModel, but it makes things so much easier!
|
||||
|
|
@ -126,6 +128,7 @@ private:
|
|||
bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const override;
|
||||
void changeDiveSelection(dive_trip *trip, const QVector<dive *> &dives, bool select) override;
|
||||
dive *diveOrNull(const QModelIndex &index) const override;
|
||||
bool setShown(const QModelIndex &idx, bool shown);
|
||||
|
||||
// The tree model has two levels. At the top level, we have either trips or dives
|
||||
// that do not belong to trips. Such a top-level item is represented by the "Item"
|
||||
|
|
@ -138,6 +141,7 @@ private:
|
|||
struct Item {
|
||||
dive_or_trip d_or_t;
|
||||
std::vector<dive *> dives; // std::vector<> instead of QVector for insert() with three iterators
|
||||
bool shown;
|
||||
Item(dive_trip *t, const QVector<dive *> &dives);
|
||||
Item(dive_trip *t, dive *d); // Initialize a trip with one dive
|
||||
Item(dive *d); // Initialize a top-level dive
|
||||
|
|
@ -187,6 +191,7 @@ private:
|
|||
bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const override;
|
||||
void changeDiveSelection(dive_trip *trip, const QVector<dive *> &dives, bool select) override;
|
||||
dive *diveOrNull(const QModelIndex &index) const override;
|
||||
bool setShown(const QModelIndex &idx, bool shown);
|
||||
|
||||
std::vector<dive *> items; // TODO: access core data directly
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue