From 04e8119049c57f4d6839e00eddcd2aca1e16f3c7 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Sun, 22 Oct 2017 18:34:33 +0200 Subject: [PATCH] Add basic function for cancelling queries This doesn't do all the work yet and isn't called anywhere. So don't expect this to do anything useful. --- src/sqlitetablemodel.cpp | 15 +++++++++++++++ src/sqlitetablemodel.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/src/sqlitetablemodel.cpp b/src/sqlitetablemodel.cpp index 03a705df..f24962d8 100644 --- a/src/sqlitetablemodel.cpp +++ b/src/sqlitetablemodel.cpp @@ -920,3 +920,18 @@ void SqliteTableModel::waitForFetchingFinished() if(m_futureFetch.isRunning()) m_futureFetch.waitForFinished(); } + +void SqliteTableModel::cancelQuery() +{ + if(m_rowCount.isRunning()) + { + m_rowCount.cancel(); + m_rowCount = QtConcurrent::run([=]() { + // Make sure we report 0 rows if anybody asks + return 0; + }); + } + + if(m_futureFetch.isRunning()) + m_futureFetch.cancel(); +} diff --git a/src/sqlitetablemodel.h b/src/sqlitetablemodel.h index 0f259f8a..ea957d70 100644 --- a/src/sqlitetablemodel.h +++ b/src/sqlitetablemodel.h @@ -75,6 +75,10 @@ public: public slots: void updateFilter(int column, const QString& value); + // This cancels the execution of the current query. It can't guarantee that the query is stopped immediately or after returning but it should + // stop soon afterwards. If some data has already been loaded into the model, that data is not deleted + void cancelQuery(); + signals: void finishedFetch();