summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2019-11-07 00:29:36 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-11-08 20:50:05 +0100
commit2c11544d9321398f67469085257db6b6114fb992 (patch)
treeaa87aea99253712098c7187c4030fb348fa0e4a6 /qt-models
parent15674f1a71be4fe74cf554e10f19e8570b90cb4f (diff)
downloadsubsurface-2c11544d9321398f67469085257db6b6114fb992.tar.gz
Mobile: correctly update filter text and update all three models
This is even harder because setActiveTrip is called from an action slot from QML. If the C++ code called from that slot causes the object to which this slot belongs to be destroyed, we get very strange crashes. The only workaround I could come up with was to update the filter asynchronously. This all seems very ugly and fragile. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/divelistmodel.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp
index 37e48b023..7d97359f0 100644
--- a/qt-models/divelistmodel.cpp
+++ b/qt-models/divelistmodel.cpp
@@ -7,6 +7,7 @@
#include "core/ssrf.h" // for LOG_STP
#include "core/errorhelper.h" // for verbose
#include <QDateTime>
+#include <QtConcurrent>
#include <QDebug>
// the DiveListSortModel creates the sorted, filtered list of dives that the user
@@ -101,8 +102,14 @@ QString CollapsedDiveListSortModel::tripShortDate(const QString &section)
void CollapsedDiveListSortModel::setActiveTrip(const QString &trip)
{
m_activeTrip = trip;
- updateFilterState();
- invalidateFilter();
+ // we can't update the filter state from the this function as that is called from
+ // a slot in the QML code which could cause the object that is executing the slot
+ // to be destroyed before this function returns.
+ // Instead do this asynchronously
+ QtConcurrent::run(QThreadPool::globalInstance(),
+ [=]{
+ CollapsedDiveListSortModel::instance()->updateFilterState();
+ });
}
QString CollapsedDiveListSortModel::activeTrip() const
@@ -153,8 +160,8 @@ void CollapsedDiveListSortModel::updateFilterState()
}
// everything up to here can be done even if we don't have a source model
if (sourceModel() != nullptr) {
- QVector<int> changedRoles = { DiveListModel::CollapsedRole };
- dataChanged(index(0,0), index(rowCount() - 1, 0), changedRoles);
+ DiveListModel *dlm = DiveListModel::instance();
+ dlm->dataChanged(dlm->index(0,0), dlm->index(dlm->rowCount() - 1, 0));
}
}
@@ -220,7 +227,7 @@ void DiveListSortModel::setSourceModel(QAbstractItemModel *sourceModel)
void DiveListSortModel::setFilter(QString f)
{
filterString = f;
- updateFilterState();
+ CollapsedDiveListSortModel::instance()->updateFilterState();
invalidateFilter();
}