Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #6375 from nyalldawson/interupt
Remove QgsInterruptionChecker and replace with QgsFeedback
  • Loading branch information
nyalldawson committed Feb 19, 2018
2 parents 627a590 + d830821 commit 9911209
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 78 deletions.
8 changes: 8 additions & 0 deletions doc/api_break.dox
Expand Up @@ -287,6 +287,7 @@ should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinat
- HalfEdge.
- QgsHtmlAnnotationItem. Use QgsHtmlAnnotation instead.
- QgsHttpTransaction. This class was outdated and code should be ported to native Qt or Python implementations.
- QgsInterruptionChecker. Use QgsFeedback instead.
- QgsGenericProjectionSelector. Use QgsProjectionSelectionTreeWidget instead.
- QgsGeometryCache. It got redundant after removal of old snapping classes (QgsSnapper + friends).
- QgsLabel and QgsLabelAttributes. Replaced by labeling based on PAL library, see QgsLabelingEngine.
Expand Down Expand Up @@ -1031,6 +1032,13 @@ None will need to be modified, as the method will return an empty geometry if th
- fields() no longer returns a pointer, but instead a QgsFields value.
- The duplicate method setFeatureId() was removed. Use setId() instead.


QgsFeatureIterator {#qgis_api_break_3_0_QgsFeatureIterator}
------------------

- setInterruptionChecker now accepts a QgsFeedback object instead of a QgsInterruptionChecker.


QgsFeatureListViewDelegate {#qgis_api_break_3_0_QgsFeatureListViewDelegate}
--------------------------

Expand Down
2 changes: 0 additions & 2 deletions python/core/qgsfeatureiterator.sip.in
Expand Up @@ -8,8 +8,6 @@





class QgsAbstractFeatureIterator
{
%Docstring
Expand Down
2 changes: 1 addition & 1 deletion src/core/CMakeLists.txt
Expand Up @@ -637,6 +637,7 @@ SET(QGIS_CORE_MOC_HDRS
qgsvectorlayerexporter.h
qgsvectorlayerfeaturecounter.h
qgsvectorlayerjoinbuffer.h
qgsvectorlayerrenderer.h
qgsvectorlayertools.h
qgsmapthemecollection.h
qgswebpage.h
Expand Down Expand Up @@ -920,7 +921,6 @@ SET(QGIS_CORE_HDRS
qgsvectorlayerjoininfo.h
qgsvectorlayerlabelprovider.h
qgsvectorlayerlabeling.h
qgsvectorlayerrenderer.h
qgsvectorlayerundocommand.h
qgsvectorlayerundopassthroughcommand.h
qgsvectorlayerutils.h
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsfeatureiterator.cpp
Expand Up @@ -211,7 +211,7 @@ bool QgsAbstractFeatureIterator::prepareOrderBy( const QList<QgsFeatureRequest::
return false;
}

void QgsAbstractFeatureIterator::setInterruptionChecker( QgsInterruptionChecker * )
void QgsAbstractFeatureIterator::setInterruptionChecker( QgsFeedback * )
{
}

Expand Down
22 changes: 4 additions & 18 deletions src/core/qgsfeatureiterator.h
Expand Up @@ -19,21 +19,7 @@
#include "qgsfeaturerequest.h"
#include "qgsindexedfeature.h"



/**
* \ingroup core
* Interface that can be optionally attached to an iterator so its
* nextFeature() implementaton can check if it must stop as soon as possible.
* \since QGIS 2.16
* \note not available in Python bindings
*/
class CORE_EXPORT QgsInterruptionChecker SIP_SKIP
{
public:
//! return true if the iterator must stop as soon as possible
virtual bool mustStop() const = 0;
};
class QgsFeedback;

/**
* \ingroup core
Expand Down Expand Up @@ -74,7 +60,7 @@ class CORE_EXPORT QgsAbstractFeatureIterator
* \since QGIS 2.16
* \note not available in Python bindings
*/
virtual void setInterruptionChecker( QgsInterruptionChecker *interruptionChecker ) SIP_SKIP;
virtual void setInterruptionChecker( QgsFeedback *interruptionChecker ) SIP_SKIP;

/**
* Returns the status of expression compilation for filter expression requests.
Expand Down Expand Up @@ -329,7 +315,7 @@ class CORE_EXPORT QgsFeatureIterator
* \since QGIS 2.16
* \note not available in Python bindings
*/
void setInterruptionChecker( QgsInterruptionChecker *interruptionChecker ) SIP_SKIP;
void setInterruptionChecker( QgsFeedback *interruptionChecker ) SIP_SKIP;

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

inline void QgsFeatureIterator::setInterruptionChecker( QgsInterruptionChecker *interruptionChecker )
inline void QgsFeatureIterator::setInterruptionChecker( QgsFeedback *interruptionChecker )
{
if ( mIter )
mIter->setInterruptionChecker( interruptionChecker );
Expand Down
40 changes: 0 additions & 40 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -698,46 +698,6 @@ long QgsVectorLayer::featureCount( const QString &legendKey ) const
return mSymbolFeatureCountMap.value( legendKey );
}

/**
* \ingroup core
* Used by QgsVectorLayer::countSymbolFeatures() to provide an interruption checker
* \note not available in Python bindings
*/
class QgsVectorLayerInterruptionCheckerDuringCountSymbolFeatures: public QgsInterruptionChecker
{
public:

//! Constructor
explicit QgsVectorLayerInterruptionCheckerDuringCountSymbolFeatures( QProgressDialog *dialog )
: mDialog( dialog )
{
}

bool mustStop() const override
{
if ( mDialog->isVisible() )
{
// So that we get a chance of hitting the Abort button
#ifdef Q_OS_LINUX
// For some reason on Windows hasPendingEvents() always return true,
// but one iteration is actually enough on Windows to get good interactivity
// whereas on Linux we must allow for far more iterations.
// For safety limit the number of iterations
int nIters = 0;
while ( QCoreApplication::hasPendingEvents() && ++nIters < 100 )
#endif
{
QCoreApplication::processEvents();
}
return mDialog->wasCanceled();
}
return false;
}

private:
QProgressDialog *mDialog = nullptr;
};

QgsVectorLayerFeatureCounter *QgsVectorLayer::countSymbolFeatures()
{
if ( mSymbolFeatureCounted || mFeatureCounter )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayerfeatureiterator.cpp
Expand Up @@ -402,7 +402,7 @@ bool QgsVectorLayerFeatureIterator::close()
return true;
}

void QgsVectorLayerFeatureIterator::setInterruptionChecker( QgsInterruptionChecker *interruptionChecker )
void QgsVectorLayerFeatureIterator::setInterruptionChecker( QgsFeedback *interruptionChecker )
{
mProviderIterator.setInterruptionChecker( interruptionChecker );
mInterruptionChecker = interruptionChecker;
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayerfeatureiterator.h
Expand Up @@ -119,7 +119,7 @@ class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureItera
//! end of iterating: free the resources / lock
bool close() override;

void setInterruptionChecker( QgsInterruptionChecker *interruptionChecker ) override SIP_SKIP;
void setInterruptionChecker( QgsFeedback *interruptionChecker ) override SIP_SKIP;

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

std::unique_ptr<QgsExpressionContext> mExpressionContext;

QgsInterruptionChecker *mInterruptionChecker = nullptr;
QgsFeedback *mInterruptionChecker = nullptr;

QList< int > mPreparedFields;
QList< int > mFieldsToPrepare;
Expand Down
14 changes: 10 additions & 4 deletions src/core/qgsvectorlayerrenderer.cpp
Expand Up @@ -549,10 +549,16 @@ void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer *layer, QSet<QStrin
QgsVectorLayerRendererInterruptionChecker::QgsVectorLayerRendererInterruptionChecker
( const QgsRenderContext &context )
: mContext( context )
, mTimer( new QTimer( this ) )
{
}
connect( mTimer, &QTimer::timeout, this, [ = ]
{
if ( mContext.renderingStopped() )
{
mTimer->stop();
cancel();
}
} );
mTimer->start( 50 );

bool QgsVectorLayerRendererInterruptionChecker::mustStop() const
{
return mContext.renderingStopped();
}
8 changes: 6 additions & 2 deletions src/core/qgsvectorlayerrenderer.h
Expand Up @@ -39,6 +39,7 @@ typedef QList<int> QgsAttributeList;
#include "qgsfeature.h" // QgsFeatureIds
#include "qgsfeatureiterator.h"
#include "qgsvectorsimplifymethod.h"
#include "qgsfeedback.h"

#include "qgsmaplayerrenderer.h"

Expand All @@ -50,14 +51,17 @@ class QgsVectorLayerDiagramProvider;
* Interruption checker used by QgsVectorLayerRenderer::render()
* \note not available in Python bindings
*/
class QgsVectorLayerRendererInterruptionChecker: public QgsInterruptionChecker
class QgsVectorLayerRendererInterruptionChecker: public QgsFeedback
{
Q_OBJECT

public:
//! Constructor
explicit QgsVectorLayerRendererInterruptionChecker( const QgsRenderContext &context );
bool mustStop() const override;

private:
const QgsRenderContext &mContext;
QTimer *mTimer = nullptr;
};

/**
Expand Down
11 changes: 6 additions & 5 deletions src/providers/wfs/qgswfsfeatureiterator.cpp
Expand Up @@ -27,6 +27,7 @@
#include "qgslogger.h"
#include "qgssettings.h"
#include "qgsexception.h"
#include "qgsfeedback.h"

#include <QDir>
#include <QProgressDialog>
Expand Down Expand Up @@ -965,7 +966,7 @@ void QgsWFSFeatureIterator::endOfDownload( bool )
mLoop->quit();
}

void QgsWFSFeatureIterator::setInterruptionChecker( QgsInterruptionChecker *interruptionChecker )
void QgsWFSFeatureIterator::setInterruptionChecker( QgsFeedback *interruptionChecker )
{
mInterruptionChecker = interruptionChecker;
}
Expand Down Expand Up @@ -1018,7 +1019,7 @@ void QgsWFSFeatureIterator::checkInterruption()
{
//QgsDebugMsg("QgsWFSFeatureIterator::checkInterruption()");

if ( mInterruptionChecker && mInterruptionChecker->mustStop() )
if ( mInterruptionChecker && mInterruptionChecker->isCanceled() )
{
mDownloadFinished = true;
if ( mLoop )
Expand All @@ -1037,7 +1038,7 @@ bool QgsWFSFeatureIterator::fetchFeature( QgsFeature &f )
QgsFeature cachedFeature;
while ( mCacheIterator.nextFeature( cachedFeature ) )
{
if ( mInterruptionChecker && mInterruptionChecker->mustStop() )
if ( mInterruptionChecker && mInterruptionChecker->isCanceled() )
return false;

//QgsDebugMsg(QString("QgsWFSSharedData::fetchFeature() : mCacheIterator.nextFeature(cachedFeature)") );
Expand Down Expand Up @@ -1134,7 +1135,7 @@ bool QgsWFSFeatureIterator::fetchFeature( QgsFeature &f )
{
while ( !mReaderStream->atEnd() )
{
if ( mInterruptionChecker && mInterruptionChecker->mustStop() )
if ( mInterruptionChecker && mInterruptionChecker->isCanceled() )
return false;

QgsFeature feat;
Expand Down Expand Up @@ -1186,7 +1187,7 @@ bool QgsWFSFeatureIterator::fetchFeature( QgsFeature &f )

if ( mDownloadFinished )
return false;
if ( mInterruptionChecker && mInterruptionChecker->mustStop() )
if ( mInterruptionChecker && mInterruptionChecker->isCanceled() )
return false;

//QgsDebugMsg("fetchFeature before loop");
Expand Down
4 changes: 2 additions & 2 deletions src/providers/wfs/qgswfsfeatureiterator.h
Expand Up @@ -206,7 +206,7 @@ class QgsWFSFeatureIterator : public QObject,

bool close() override;

void setInterruptionChecker( QgsInterruptionChecker *interruptionChecker ) override;
void setInterruptionChecker( QgsFeedback *interruptionChecker ) override;

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

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

0 comments on commit 9911209

Please sign in to comment.