Add QgsProject::dirtySet signal (#43595)

This commit is contained in:
Sandro Mani 2021-06-10 12:50:47 +02:00 committed by GitHub
parent bb0dfb6ba3
commit 6aa0cbed91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 0 deletions

View File

@ -1799,6 +1799,18 @@ Emitted when the project dirty status changes.
.. versionadded:: 3.2
%End
void dirtySet();
%Docstring
Emitted when setDirty(true) is called.
.. note::
As opposed to :py:func:`~QgsProject.isDirtyChanged`, this signal is invoked every time setDirty(true)
is called, regardless of whether the project was already dirty.
.. versionadded:: 3.20
%End
void mapScalesChanged() /Deprecated/;
%Docstring

View File

@ -520,6 +520,9 @@ void QgsProject::setDirty( const bool dirty )
if ( dirty && mDirtyBlockCount > 0 )
return;
if ( dirty )
emit dirtySet();
if ( mDirty == dirty )
return;

View File

@ -1824,6 +1824,15 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
void isDirtyChanged( bool dirty );
/**
* Emitted when setDirty(true) is called.
* \note As opposed to isDirtyChanged(), this signal is invoked every time setDirty(true)
* is called, regardless of whether the project was already dirty.
*
* \since QGIS 3.20
*/
void dirtySet();
/**
* Emitted whenever the project is saved to a qgz file.
* This can be used to package additional files into the qgz file by modifying the \a files map.

View File

@ -39,6 +39,7 @@ class TestQgsProject : public QObject
void init();// will be called before each testfunction is executed.
void cleanup();// will be called after every testfunction.
void testDirtySet();
void testReadPath();
void testPathResolver();
void testPathResolverSvg();
@ -85,6 +86,15 @@ void TestQgsProject::cleanupTestCase()
QgsApplication::exitQgis();
}
void TestQgsProject::testDirtySet()
{
QgsProject p;
bool dirtySet = false;
connect( &p, &QgsProject::dirtySet, [&] { dirtySet = true; } );
p.setDirty( true );
QVERIFY( dirtySet );
}
void TestQgsProject::testReadPath()
{
QgsProject *prj = new QgsProject;