mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
QgsFeedback can handle report progress reports
This commit is contained in:
parent
4b3d4017d0
commit
8182ec2d3d
@ -36,8 +36,15 @@ class QgsFeedback : QObject
|
||||
//! Tells whether the operation has been canceled already
|
||||
bool isCanceled() const;
|
||||
|
||||
void setProgress( double progress );
|
||||
|
||||
double progress() const;
|
||||
|
||||
signals:
|
||||
//! Internal routines can connect to this signal if they use event loop
|
||||
void canceled();
|
||||
|
||||
void progressChanged( double progress );
|
||||
|
||||
|
||||
};
|
||||
|
@ -61,13 +61,44 @@ class CORE_EXPORT QgsFeedback : public QObject
|
||||
//! Tells whether the operation has been canceled already
|
||||
bool isCanceled() const { return mCanceled; }
|
||||
|
||||
/**
|
||||
* Sets the current progress for the feedback object. The \a progress
|
||||
* argument is in percentage and valid values range from 0-100.
|
||||
* @see progress()
|
||||
* @see progressChanged()
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
void setProgress( double progress ) { mProgress = progress; emit progressChanged( mProgress ); }
|
||||
|
||||
/**
|
||||
* Returns the current progress reported by the feedback object. Depending on how the
|
||||
* feedback object is used progress reporting may not be supported. The returned value
|
||||
* is in percentage and ranges from 0-100.
|
||||
* @see setProgress()
|
||||
* @see progressChanged()
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
double progress() const { return mProgress; }
|
||||
|
||||
signals:
|
||||
//! Internal routines can connect to this signal if they use event loop
|
||||
void canceled();
|
||||
|
||||
/**
|
||||
* Emitted when the feedback object reports a progress change. Depending on how the
|
||||
* feedback object is used progress reporting may not be supported. The \a progress
|
||||
* argument is in percentage and ranges from 0-100.
|
||||
* @note added in QGIS 3.0
|
||||
* @see setProgress()
|
||||
* @see progress()
|
||||
*/
|
||||
void progressChanged( double progress );
|
||||
|
||||
private:
|
||||
//! Whether the operation has been canceled already. False by default.
|
||||
bool mCanceled;
|
||||
|
||||
double mProgress = 0.0;
|
||||
};
|
||||
|
||||
#endif // QGSFEEDBACK_H
|
||||
|
@ -50,6 +50,7 @@ ADD_PYTHON_TEST(PyQgsFieldFormattersTest test_qgsfieldformatters.py)
|
||||
ADD_PYTHON_TEST(PyQgsFillSymbolLayers test_qgsfillsymbollayers.py)
|
||||
ADD_PYTHON_TEST(PyQgsProject test_qgsproject.py)
|
||||
ADD_PYTHON_TEST(PyQgsFeatureIterator test_qgsfeatureiterator.py)
|
||||
ADD_PYTHON_TEST(PyQgsFeedback test_qgsfeedback.py)
|
||||
ADD_PYTHON_TEST(PyQgsField test_qgsfield.py)
|
||||
ADD_PYTHON_TEST(PyQgsFieldModel test_qgsfieldmodel.py)
|
||||
ADD_PYTHON_TEST(PyQgsFilterLineEdit test_qgsfilterlineedit.py)
|
||||
|
48
tests/src/python/test_qgsfeedback.py
Normal file
48
tests/src/python/test_qgsfeedback.py
Normal file
@ -0,0 +1,48 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""QGIS Unit tests for QgsFeedback.
|
||||
|
||||
.. note:: This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
"""
|
||||
__author__ = 'Nyall Dawson'
|
||||
__date__ = '12/02/2017'
|
||||
__copyright__ = 'Copyright 2017, The QGIS Project'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import qgis # NOQA
|
||||
import os
|
||||
|
||||
from qgis.core import (QgsFeedback)
|
||||
from qgis.PyQt.QtTest import QSignalSpy
|
||||
from qgis.testing import unittest
|
||||
|
||||
|
||||
class TestQgsFeedback(unittest.TestCase):
|
||||
|
||||
def testCancel(self):
|
||||
f = QgsFeedback()
|
||||
self.assertFalse(f.isCanceled())
|
||||
|
||||
cancel_spy = QSignalSpy(f.canceled)
|
||||
|
||||
f.cancel()
|
||||
self.assertTrue(f.isCanceled())
|
||||
self.assertEqual(len(cancel_spy), 1)
|
||||
|
||||
def testProgress(self):
|
||||
f = QgsFeedback()
|
||||
self.assertEqual(f.progress(), 0.0)
|
||||
|
||||
progress_spy = QSignalSpy(f.progressChanged)
|
||||
|
||||
f.setProgress(25)
|
||||
self.assertEqual(f.progress(), 25.0)
|
||||
self.assertEqual(len(progress_spy), 1)
|
||||
self.assertEqual(progress_spy[0][0], 25.0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user