Skip to content

Commit

Permalink
Add QgsProject::dirtySet signal (#43595)
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Jun 10, 2021
1 parent bb0dfb6 commit 6aa0cbe
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions python/core/auto_generated/project/qgsproject.sip.in
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/core/project/qgsproject.cpp
Expand Up @@ -520,6 +520,9 @@ void QgsProject::setDirty( const bool dirty )
if ( dirty && mDirtyBlockCount > 0 )
return;

if ( dirty )
emit dirtySet();

if ( mDirty == dirty )
return;

Expand Down
9 changes: 9 additions & 0 deletions src/core/project/qgsproject.h
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions tests/src/core/testqgsproject.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6aa0cbe

Please sign in to comment.