Skip to content

Commit 9911209

Browse files
authored
Merge pull request #6375 from nyalldawson/interupt
Remove QgsInterruptionChecker and replace with QgsFeedback
2 parents 627a590 + d830821 commit 9911209

12 files changed

+41
-78
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/qgsvectorlayer.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -698,46 +698,6 @@ long QgsVectorLayer::featureCount( const QString &legendKey ) const
698698
return mSymbolFeatureCountMap.value( legendKey );
699699
}
700700

701-
/**
702-
* \ingroup core
703-
* Used by QgsVectorLayer::countSymbolFeatures() to provide an interruption checker
704-
* \note not available in Python bindings
705-
*/
706-
class QgsVectorLayerInterruptionCheckerDuringCountSymbolFeatures: public QgsInterruptionChecker
707-
{
708-
public:
709-
710-
//! Constructor
711-
explicit QgsVectorLayerInterruptionCheckerDuringCountSymbolFeatures( QProgressDialog *dialog )
712-
: mDialog( dialog )
713-
{
714-
}
715-
716-
bool mustStop() const override
717-
{
718-
if ( mDialog->isVisible() )
719-
{
720-
// So that we get a chance of hitting the Abort button
721-
#ifdef Q_OS_LINUX
722-
// For some reason on Windows hasPendingEvents() always return true,
723-
// but one iteration is actually enough on Windows to get good interactivity
724-
// whereas on Linux we must allow for far more iterations.
725-
// For safety limit the number of iterations
726-
int nIters = 0;
727-
while ( QCoreApplication::hasPendingEvents() && ++nIters < 100 )
728-
#endif
729-
{
730-
QCoreApplication::processEvents();
731-
}
732-
return mDialog->wasCanceled();
733-
}
734-
return false;
735-
}
736-
737-
private:
738-
QProgressDialog *mDialog = nullptr;
739-
};
740-
741701
QgsVectorLayerFeatureCounter *QgsVectorLayer::countSymbolFeatures()
742702
{
743703
if ( mSymbolFeatureCounted || mFeatureCounter )

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
/**

0 commit comments

Comments
 (0)