Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make QgsMapThemeCollection QML compatible
Sponsored by OPENGIS.ch/QField
  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent 9ac668b commit e6f84de
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/core/qgsmapthemecollection.cpp
Expand Up @@ -29,8 +29,7 @@
QgsMapThemeCollection::QgsMapThemeCollection( QgsProject* project )
: mProject( project )
{
connect( project, SIGNAL( layersRemoved( QStringList ) ),
this, SLOT( registryLayersRemoved( QStringList ) ) );
connect( project, &QgsProject::layersRemoved, this, &QgsMapThemeCollection::registryLayersRemoved );
}

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

QgsProject* QgsMapThemeCollection::project()
{
return mProject;
}

void QgsMapThemeCollection::setProject( QgsProject* project )
{
if ( project == mProject )
return;

disconnect( mProject, &QgsProject::layersRemoved, this, &QgsMapThemeCollection::registryLayersRemoved );
mProject = project;
connect( mProject, &QgsProject::layersRemoved, this, &QgsMapThemeCollection::registryLayersRemoved );
emit projectChanged();
}


bool QgsMapThemeCollection::hasMapTheme( const QString& name ) const
{
Expand Down
24 changes: 23 additions & 1 deletion src/core/qgsmapthemecollection.h
Expand Up @@ -44,6 +44,7 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject
Q_OBJECT

Q_PROPERTY( QStringList mapThemes READ mapThemes NOTIFY mapThemesChanged )
Q_PROPERTY( QgsProject* project READ project WRITE setProject NOTIFY projectChanged )

public:

Expand Down Expand Up @@ -124,7 +125,7 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject
/**
* Create map theme collection that handles themes of the given project.
*/
QgsMapThemeCollection( QgsProject* project );
QgsMapThemeCollection( QgsProject* project = nullptr );

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

/**
* The QgsProject on which this map theme collection works.
*
* \note Added in QGIS 3.0
*/
QgsProject* project();

/**
* \copydoc project()
* \note Added in QGIS 3.0
*/
void setProject( QgsProject* project );

signals:

/**
Expand All @@ -226,6 +240,14 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject
*/
void mapThemesChanged();

/**
* Emitted when the project changes
*
* \copydoc project()
* \note Added in QGIS 3.0
*/
void projectChanged();

private slots:

/**
Expand Down

0 comments on commit e6f84de

Please sign in to comment.