summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-11-07 13:20:46 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-11-07 11:37:51 -0800
commit396598430ba19416795edc5e1b960efdcafed5c6 (patch)
tree4723443d88743004d4c70f8c5efce4d16699ebc6 /qt-models
parent291768b63cd3443372d47ccc67858c398287d867 (diff)
downloadsubsurface-396598430ba19416795edc5e1b960efdcafed5c6.tar.gz
desktop: fix saving of column-widths of device and site tables
Qt's memory management scheme is completely broken and messes with common expectations. QObjects are organized as a tree. The children are destroyed in the destructor of QObject. This means that they are destructed after the destructor of the parent object has run and its sub-object were destructed. Obviously, this makes no sense as the child objects should be able to access their parent at any time. To restore the commonly expected deterministic order of construction and destruction, one might simply do away with Qt's silly object tree and organise things using classical subobjects. However, that breaks with the Qt-generated UI classes: The objects generated by these classes are *not* destructed with the UI class. Instead, they are attached to the widget's QObject tree. Thus these are again destructed *after* the widget! Who comes up with such a scheme? In our case this means that we cannot have models used for TableViews as subobjects, because the TableView needs the model to save the column widths in the destructor. Which, as detailed above is called *after* the desctructor of the widget! Thus, turn these models into heap-allocated objects and add them to the QObject tree. Funilly, this exposes another insanity of Qt's QObject tree: Children are destructed in order of construction! One would expect that if objects are constructed in the sequence A, B, C one can expect that C can, at any time, access B and A. Not so in Qt: The destruction order is likewise A, B, C! Thus, take care to init the widgets before the model. Jeez. Finally, print a warning in the column-saving code of TableWidget, so that these kind of subtleties are caught in the future. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/divelocationmodel.cpp2
-rw-r--r--qt-models/divelocationmodel.h2
2 files changed, 2 insertions, 2 deletions
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp
index f8bad01a7..f353e7832 100644
--- a/qt-models/divelocationmodel.cpp
+++ b/qt-models/divelocationmodel.cpp
@@ -215,7 +215,7 @@ bool DiveSiteSortedModel::lessThan(const QModelIndex &i1, const QModelIndex &i2)
}
}
-DiveSiteSortedModel::DiveSiteSortedModel()
+DiveSiteSortedModel::DiveSiteSortedModel(QObject *parent) : QSortFilterProxyModel(parent)
{
setSourceModel(LocationInformationModel::instance());
}
diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h
index 623296de2..57471dee6 100644
--- a/qt-models/divelocationmodel.h
+++ b/qt-models/divelocationmodel.h
@@ -49,7 +49,7 @@ private:
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
#endif // SUBSURFACE_MOBILE
public:
- DiveSiteSortedModel();
+ DiveSiteSortedModel(QObject *parent = nullptr);
QStringList allSiteNames() const;
void setFilter(const QString &text);
struct dive_site *getDiveSite(const QModelIndex &idx);