Skip to content

Commit d830821

Browse files
committed
Remove QgsInterruptionChecker and replace with QgsFeedback use
There's little need for two classes with similar goals here.
1 parent 1014e5c commit d830821

11 files changed

+41
-38
lines changed

doc/api_break.dox

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinat
287287
- HalfEdge.
288288
- QgsHtmlAnnotationItem. Use QgsHtmlAnnotation instead.
289289
- QgsHttpTransaction. This class was outdated and code should be ported to native Qt or Python implementations.
290+
- QgsInterruptionChecker. Use QgsFeedback instead.
290291
- QgsGenericProjectionSelector. Use QgsProjectionSelectionTreeWidget instead.
291292
- QgsGeometryCache. It got redundant after removal of old snapping classes (QgsSnapper + friends).
292293
- QgsLabel and QgsLabelAttributes. Replaced by labeling based on PAL library, see QgsLabelingEngine.
@@ -1031,6 +1032,13 @@ None will need to be modified, as the method will return an empty geometry if th
10311032
- fields() no longer returns a pointer, but instead a QgsFields value.
10321033
- The duplicate method setFeatureId() was removed. Use setId() instead.
10331034

1035+
1036+
QgsFeatureIterator {#qgis_api_break_3_0_QgsFeatureIterator}
1037+
------------------
1038+
1039+
- setInterruptionChecker now accepts a QgsFeedback object instead of a QgsInterruptionChecker.
1040+
1041+
10341042
QgsFeatureListViewDelegate {#qgis_api_break_3_0_QgsFeatureListViewDelegate}
10351043
--------------------------
10361044

python/core/qgsfeatureiterator.sip.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99

1010

11-
12-
1311
class QgsAbstractFeatureIterator
1412
{
1513
%Docstring

src/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ SET(QGIS_CORE_MOC_HDRS
637637
qgsvectorlayerexporter.h
638638
qgsvectorlayerfeaturecounter.h
639639
qgsvectorlayerjoinbuffer.h
640+
qgsvectorlayerrenderer.h
640641
qgsvectorlayertools.h
641642
qgsmapthemecollection.h
642643
qgswebpage.h
@@ -920,7 +921,6 @@ SET(QGIS_CORE_HDRS
920921
qgsvectorlayerjoininfo.h
921922
qgsvectorlayerlabelprovider.h
922923
qgsvectorlayerlabeling.h
923-
qgsvectorlayerrenderer.h
924924
qgsvectorlayerundocommand.h
925925
qgsvectorlayerundopassthroughcommand.h
926926
qgsvectorlayerutils.h

src/core/qgsfeatureiterator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ bool QgsAbstractFeatureIterator::prepareOrderBy( const QList<QgsFeatureRequest::
211211
return false;
212212
}
213213

214-
void QgsAbstractFeatureIterator::setInterruptionChecker( QgsInterruptionChecker * )
214+
void QgsAbstractFeatureIterator::setInterruptionChecker( QgsFeedback * )
215215
{
216216
}
217217

src/core/qgsfeatureiterator.h

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,7 @@
1919
#include "qgsfeaturerequest.h"
2020
#include "qgsindexedfeature.h"
2121

22-
23-
24-
/**
25-
* \ingroup core
26-
* Interface that can be optionally attached to an iterator so its
27-
* nextFeature() implementaton can check if it must stop as soon as possible.
28-
* \since QGIS 2.16
29-
* \note not available in Python bindings
30-
*/
31-
class CORE_EXPORT QgsInterruptionChecker SIP_SKIP
32-
{
33-
public:
34-
//! return true if the iterator must stop as soon as possible
35-
virtual bool mustStop() const = 0;
36-
};
22+
class QgsFeedback;
3723

3824
/**
3925
* \ingroup core
@@ -74,7 +60,7 @@ class CORE_EXPORT QgsAbstractFeatureIterator
7460
* \since QGIS 2.16
7561
* \note not available in Python bindings
7662
*/
77-
virtual void setInterruptionChecker( QgsInterruptionChecker *interruptionChecker ) SIP_SKIP;
63+
virtual void setInterruptionChecker( QgsFeedback *interruptionChecker ) SIP_SKIP;
7864

7965
/**
8066
* Returns the status of expression compilation for filter expression requests.
@@ -329,7 +315,7 @@ class CORE_EXPORT QgsFeatureIterator
329315
* \since QGIS 2.16
330316
* \note not available in Python bindings
331317
*/
332-
void setInterruptionChecker( QgsInterruptionChecker *interruptionChecker ) SIP_SKIP;
318+
void setInterruptionChecker( QgsFeedback *interruptionChecker ) SIP_SKIP;
333319

334320
/**
335321
* Returns the status of expression compilation for filter expression requests.
@@ -404,7 +390,7 @@ inline bool operator!= ( const QgsFeatureIterator &fi1, const QgsFeatureIterator
404390
return !( fi1 == fi2 );
405391
}
406392

407-
inline void QgsFeatureIterator::setInterruptionChecker( QgsInterruptionChecker *interruptionChecker )
393+
inline void QgsFeatureIterator::setInterruptionChecker( QgsFeedback *interruptionChecker )
408394
{
409395
if ( mIter )
410396
mIter->setInterruptionChecker( interruptionChecker );

src/core/qgsvectorlayerfeatureiterator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ bool QgsVectorLayerFeatureIterator::close()
402402
return true;
403403
}
404404

405-
void QgsVectorLayerFeatureIterator::setInterruptionChecker( QgsInterruptionChecker *interruptionChecker )
405+
void QgsVectorLayerFeatureIterator::setInterruptionChecker( QgsFeedback *interruptionChecker )
406406
{
407407
mProviderIterator.setInterruptionChecker( interruptionChecker );
408408
mInterruptionChecker = interruptionChecker;

src/core/qgsvectorlayerfeatureiterator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureItera
119119
//! end of iterating: free the resources / lock
120120
bool close() override;
121121

122-
void setInterruptionChecker( QgsInterruptionChecker *interruptionChecker ) override SIP_SKIP;
122+
void setInterruptionChecker( QgsFeedback *interruptionChecker ) override SIP_SKIP;
123123

124124
/**
125125
* Join information prepared for fast attribute id mapping in QgsVectorLayerJoinBuffer::updateFeatureAttributes().
@@ -247,7 +247,7 @@ class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureItera
247247

248248
std::unique_ptr<QgsExpressionContext> mExpressionContext;
249249

250-
QgsInterruptionChecker *mInterruptionChecker = nullptr;
250+
QgsFeedback *mInterruptionChecker = nullptr;
251251

252252
QList< int > mPreparedFields;
253253
QList< int > mFieldsToPrepare;

src/core/qgsvectorlayerrenderer.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,16 @@ void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer *layer, QSet<QStrin
549549
QgsVectorLayerRendererInterruptionChecker::QgsVectorLayerRendererInterruptionChecker
550550
( const QgsRenderContext &context )
551551
: mContext( context )
552+
, mTimer( new QTimer( this ) )
552553
{
553-
}
554+
connect( mTimer, &QTimer::timeout, this, [ = ]
555+
{
556+
if ( mContext.renderingStopped() )
557+
{
558+
mTimer->stop();
559+
cancel();
560+
}
561+
} );
562+
mTimer->start( 50 );
554563

555-
bool QgsVectorLayerRendererInterruptionChecker::mustStop() const
556-
{
557-
return mContext.renderingStopped();
558564
}

src/core/qgsvectorlayerrenderer.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ typedef QList<int> QgsAttributeList;
3939
#include "qgsfeature.h" // QgsFeatureIds
4040
#include "qgsfeatureiterator.h"
4141
#include "qgsvectorsimplifymethod.h"
42+
#include "qgsfeedback.h"
4243

4344
#include "qgsmaplayerrenderer.h"
4445

@@ -50,14 +51,17 @@ class QgsVectorLayerDiagramProvider;
5051
* Interruption checker used by QgsVectorLayerRenderer::render()
5152
* \note not available in Python bindings
5253
*/
53-
class QgsVectorLayerRendererInterruptionChecker: public QgsInterruptionChecker
54+
class QgsVectorLayerRendererInterruptionChecker: public QgsFeedback
5455
{
56+
Q_OBJECT
57+
5558
public:
5659
//! Constructor
5760
explicit QgsVectorLayerRendererInterruptionChecker( const QgsRenderContext &context );
58-
bool mustStop() const override;
61+
5962
private:
6063
const QgsRenderContext &mContext;
64+
QTimer *mTimer = nullptr;
6165
};
6266

6367
/**

src/providers/wfs/qgswfsfeatureiterator.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "qgslogger.h"
2828
#include "qgssettings.h"
2929
#include "qgsexception.h"
30+
#include "qgsfeedback.h"
3031

3132
#include <QDir>
3233
#include <QProgressDialog>
@@ -965,7 +966,7 @@ void QgsWFSFeatureIterator::endOfDownload( bool )
965966
mLoop->quit();
966967
}
967968

968-
void QgsWFSFeatureIterator::setInterruptionChecker( QgsInterruptionChecker *interruptionChecker )
969+
void QgsWFSFeatureIterator::setInterruptionChecker( QgsFeedback *interruptionChecker )
969970
{
970971
mInterruptionChecker = interruptionChecker;
971972
}
@@ -1018,7 +1019,7 @@ void QgsWFSFeatureIterator::checkInterruption()
10181019
{
10191020
//QgsDebugMsg("QgsWFSFeatureIterator::checkInterruption()");
10201021

1021-
if ( mInterruptionChecker && mInterruptionChecker->mustStop() )
1022+
if ( mInterruptionChecker && mInterruptionChecker->isCanceled() )
10221023
{
10231024
mDownloadFinished = true;
10241025
if ( mLoop )
@@ -1037,7 +1038,7 @@ bool QgsWFSFeatureIterator::fetchFeature( QgsFeature &f )
10371038
QgsFeature cachedFeature;
10381039
while ( mCacheIterator.nextFeature( cachedFeature ) )
10391040
{
1040-
if ( mInterruptionChecker && mInterruptionChecker->mustStop() )
1041+
if ( mInterruptionChecker && mInterruptionChecker->isCanceled() )
10411042
return false;
10421043

10431044
//QgsDebugMsg(QString("QgsWFSSharedData::fetchFeature() : mCacheIterator.nextFeature(cachedFeature)") );
@@ -1134,7 +1135,7 @@ bool QgsWFSFeatureIterator::fetchFeature( QgsFeature &f )
11341135
{
11351136
while ( !mReaderStream->atEnd() )
11361137
{
1137-
if ( mInterruptionChecker && mInterruptionChecker->mustStop() )
1138+
if ( mInterruptionChecker && mInterruptionChecker->isCanceled() )
11381139
return false;
11391140

11401141
QgsFeature feat;
@@ -1186,7 +1187,7 @@ bool QgsWFSFeatureIterator::fetchFeature( QgsFeature &f )
11861187

11871188
if ( mDownloadFinished )
11881189
return false;
1189-
if ( mInterruptionChecker && mInterruptionChecker->mustStop() )
1190+
if ( mInterruptionChecker && mInterruptionChecker->isCanceled() )
11901191
return false;
11911192

11921193
//QgsDebugMsg("fetchFeature before loop");

src/providers/wfs/qgswfsfeatureiterator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class QgsWFSFeatureIterator : public QObject,
206206

207207
bool close() override;
208208

209-
void setInterruptionChecker( QgsInterruptionChecker *interruptionChecker ) override;
209+
void setInterruptionChecker( QgsFeedback *interruptionChecker ) override;
210210

211211
//! Used by QgsWFSSharedData::registerToCache()
212212
void connectSignals( QgsWFSFeatureDownloader *downloader );
@@ -232,7 +232,7 @@ class QgsWFSFeatureIterator : public QObject,
232232
bool mDownloadFinished;
233233
QEventLoop *mLoop = nullptr;
234234
QgsFeatureIterator mCacheIterator;
235-
QgsInterruptionChecker *mInterruptionChecker = nullptr;
235+
QgsFeedback *mInterruptionChecker = nullptr;
236236

237237
//! this mutex synchronizes the mWriterXXXX variables between featureReceivedSynchronous() and fetchFeature()
238238
QMutex mMutex;

0 commit comments

Comments
 (0)