Skip to content
Permalink
Browse files

Make QgsMapThemeCollection QML compatible

Sponsored by OPENGIS.ch/QField
  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent 9ac668b commit e6f84dea738aed24866e0695530d4681a3582bea
Showing with 40 additions and 3 deletions.
  1. +17 −2 src/core/qgsmapthemecollection.cpp
  2. +23 −1 src/core/qgsmapthemecollection.h
@@ -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 )
@@ -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
{
@@ -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:

@@ -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.
@@ -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:

/**
@@ -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:

/**

0 comments on commit e6f84de

Please sign in to comment.
You can’t perform that action at this time.