Skip to content

Commit e6f84de

Browse files
committed
Make QgsMapThemeCollection QML compatible
Sponsored by OPENGIS.ch/QField
1 parent 9ac668b commit e6f84de

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/core/qgsmapthemecollection.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
QgsMapThemeCollection::QgsMapThemeCollection( QgsProject* project )
3030
: mProject( project )
3131
{
32-
connect( project, SIGNAL( layersRemoved( QStringList ) ),
33-
this, SLOT( registryLayersRemoved( QStringList ) ) );
32+
connect( project, &QgsProject::layersRemoved, this, &QgsMapThemeCollection::registryLayersRemoved );
3433
}
3534

3635
QgsMapThemeCollection::MapThemeLayerRecord QgsMapThemeCollection::createThemeLayerRecord( QgsLayerTreeLayer* nodeLayer, QgsLayerTreeModel* model )
@@ -160,6 +159,22 @@ void QgsMapThemeCollection::applyTheme( const QString& name, QgsLayerTreeGroup*
160159
update( name, createThemeFromCurrentState( root, model ) );
161160
}
162161

162+
QgsProject* QgsMapThemeCollection::project()
163+
{
164+
return mProject;
165+
}
166+
167+
void QgsMapThemeCollection::setProject( QgsProject* project )
168+
{
169+
if ( project == mProject )
170+
return;
171+
172+
disconnect( mProject, &QgsProject::layersRemoved, this, &QgsMapThemeCollection::registryLayersRemoved );
173+
mProject = project;
174+
connect( mProject, &QgsProject::layersRemoved, this, &QgsMapThemeCollection::registryLayersRemoved );
175+
emit projectChanged();
176+
}
177+
163178

164179
bool QgsMapThemeCollection::hasMapTheme( const QString& name ) const
165180
{

src/core/qgsmapthemecollection.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject
4444
Q_OBJECT
4545

4646
Q_PROPERTY( QStringList mapThemes READ mapThemes NOTIFY mapThemesChanged )
47+
Q_PROPERTY( QgsProject* project READ project WRITE setProject NOTIFY projectChanged )
4748

4849
public:
4950

@@ -124,7 +125,7 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject
124125
/**
125126
* Create map theme collection that handles themes of the given project.
126127
*/
127-
QgsMapThemeCollection( QgsProject* project );
128+
QgsMapThemeCollection( QgsProject* project = nullptr );
128129

129130
/**
130131
* Returns whether a map theme with a matching name exists.
@@ -218,6 +219,19 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject
218219
*/
219220
void applyTheme( const QString& name, QgsLayerTreeGroup* root, QgsLayerTreeModel* model );
220221

222+
/**
223+
* The QgsProject on which this map theme collection works.
224+
*
225+
* \note Added in QGIS 3.0
226+
*/
227+
QgsProject* project();
228+
229+
/**
230+
* \copydoc project()
231+
* \note Added in QGIS 3.0
232+
*/
233+
void setProject( QgsProject* project );
234+
221235
signals:
222236

223237
/**
@@ -226,6 +240,14 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject
226240
*/
227241
void mapThemesChanged();
228242

243+
/**
244+
* Emitted when the project changes
245+
*
246+
* \copydoc project()
247+
* \note Added in QGIS 3.0
248+
*/
249+
void projectChanged();
250+
229251
private slots:
230252

231253
/**

0 commit comments

Comments
 (0)