Skip to content

Commit

Permalink
Add processedCount to report the number of processed objects
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Nov 29, 2021
1 parent 8f09f72 commit 7e2eaec
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
39 changes: 39 additions & 0 deletions python/core/auto_generated/qgsfeedback.sip.in
Expand Up @@ -68,6 +68,31 @@ is in percentage and ranges from 0-100.
.. seealso:: :py:func:`progressChanged`

.. versionadded:: 3.0
%End

unsigned long long processedCount() const /HoldGIL/;
%Docstring
Returns the current processed objects count reported by the feedback object. Depending on how the
feedback object is used processed count reporting may not be supported. The returned value
is an unsigned long integer and starts from 0.

.. seealso:: :py:func:`setProcessedCount`

.. seealso:: :py:func:`progressCountChanged`

.. versionadded:: 3.24
%End

void setProcessedCount( unsigned long long processedCount );
%Docstring
Sets the current processed objects count for the feedback object. The ``processedCount``
argument is an unsigned long integer and starts from 0.

.. seealso:: :py:func:`processedCount`

.. seealso:: :py:func:`progressCountChanged`

.. versionadded:: 3.24
%End

public slots:
Expand All @@ -94,10 +119,24 @@ argument is in percentage and ranges from 0-100.
.. seealso:: :py:func:`progress`

.. versionadded:: 3.0
%End

void processedCountChanged( unsigned long long processedCount );
%Docstring
Emitted when the feedback object reports a change in the number of processed objects.
Depending on how the feedback object is used processed count reporting may not be supported. The ``processedCount``
argument is an unsigned long integer and starts from 0.

.. seealso:: :py:func:`setProgress`

.. seealso:: :py:func:`progress`

.. versionadded:: 3.24
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
35 changes: 35 additions & 0 deletions src/core/qgsfeedback.h
Expand Up @@ -79,6 +79,29 @@ class CORE_EXPORT QgsFeedback : public QObject
*/
double progress() const SIP_HOLDGIL { return mProgress; }

/**
* Returns the current processed objects count reported by the feedback object. Depending on how the
* feedback object is used processed count reporting may not be supported. The returned value
* is an unsigned long integer and starts from 0.
* \see setProcessedCount()
* \see progressCountChanged()
* \since QGIS 3.24
*/
unsigned long long processedCount() const SIP_HOLDGIL { return mProcessedCount; }

/**
* Sets the current processed objects count for the feedback object. The \a processedCount
* argument is an unsigned long integer and starts from 0.
* \see processedCount()
* \see progressCountChanged()
* \since QGIS 3.24
*/
void setProcessedCount( unsigned long long processedCount )
{
mProcessedCount = processedCount;
emit processedCountChanged( processedCount );
}

public slots:

//! Tells the internal routines that the current operation should be canceled. This should be run by the main thread
Expand All @@ -104,11 +127,23 @@ class CORE_EXPORT QgsFeedback : public QObject
*/
void progressChanged( double progress );

/**
* Emitted when the feedback object reports a change in the number of processed objects.
* Depending on how the feedback object is used processed count reporting may not be supported. The \a processedCount
* argument is an unsigned long integer and starts from 0.
* \see setProgress()
* \see progress()
* \since QGIS 3.24
*/
void processedCountChanged( unsigned long long processedCount );

private:
//! Whether the operation has been canceled already. False by default.
bool mCanceled = false;

double mProgress = 0.0;
unsigned long long mProcessedCount = 0;
};


#endif // QGSFEEDBACK_H
11 changes: 11 additions & 0 deletions tests/src/python/test_qgsfeedback.py
Expand Up @@ -40,6 +40,17 @@ def testProgress(self):
self.assertEqual(len(progress_spy), 1)
self.assertEqual(progress_spy[0][0], 25.0)

def testProcessedCount(self):
f = QgsFeedback()
self.assertEqual(f.processedCount(), 0)

processed_spy = QSignalSpy(f.processedCountChanged)

f.setProcessedCount(25)
self.assertEqual(f.processedCount(), 25)
self.assertEqual(len(processed_spy), 1)
self.assertEqual(processed_spy[0][0], 25)


if __name__ == '__main__':
unittest.main()

0 comments on commit 7e2eaec

Please sign in to comment.