Skip to content
Permalink
Browse files

Generalise QgsMapLayerStyleCategoriesModel to also handle vector tile…

… layers
  • Loading branch information
nyalldawson committed Sep 7, 2020
1 parent c4b344d commit 0ea5f57c7c1c751a791b868d454420aad450e313
@@ -431,7 +431,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
{
QMenu *copyStyleMenu = menuStyleManager->addMenu( tr( "Copy Style" ) );
copyStyleMenu->setToolTipsVisible( true );
QgsMapLayerStyleCategoriesModel *model = new QgsMapLayerStyleCategoriesModel( copyStyleMenu );
QgsMapLayerStyleCategoriesModel *model = new QgsMapLayerStyleCategoriesModel( layer->type(), copyStyleMenu );
model->setShowAllCategories( true );
for ( int row = 0; row < model->rowCount(); ++row )
{
@@ -470,7 +470,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()

QgsMapLayer::StyleCategories sourceCategories = QgsXmlUtils::readFlagAttribute( myRoot, QStringLiteral( "styleCategories" ), QgsMapLayer::AllStyleCategories );

QgsMapLayerStyleCategoriesModel *model = new QgsMapLayerStyleCategoriesModel( pasteStyleMenu );
QgsMapLayerStyleCategoriesModel *model = new QgsMapLayerStyleCategoriesModel( layer->type(), pasteStyleMenu );
model->setShowAllCategories( true );
for ( int row = 0; row < model->rowCount(); ++row )
{
@@ -16,10 +16,27 @@
#include "qgsmaplayerstylecategoriesmodel.h"
#include "qgsapplication.h"

QgsMapLayerStyleCategoriesModel::QgsMapLayerStyleCategoriesModel( QObject *parent )
QgsMapLayerStyleCategoriesModel::QgsMapLayerStyleCategoriesModel( QgsMapLayerType type, QObject *parent )
: QAbstractListModel( parent )
{
mCategoryList = qgsEnumMap<QgsMapLayer::StyleCategory>().keys();
switch ( type )
{
case QgsMapLayerType::VectorLayer:
mCategoryList = qgsEnumMap<QgsMapLayer::StyleCategory>().keys();
break;

case QgsMapLayerType::VectorTileLayer:
mCategoryList << QgsMapLayer::StyleCategory::Symbology << QgsMapLayer::StyleCategory::Labeling;
break;

case QgsMapLayerType::RasterLayer:
case QgsMapLayerType::AnnotationLayer:
case QgsMapLayerType::PluginLayer:
case QgsMapLayerType::MeshLayer:
// not yet handled by the model
break;
}

// move All categories to top
mCategoryList.move( mCategoryList.indexOf( QgsMapLayer::AllStyleCategories ), 0 );
}
@@ -36,8 +36,11 @@ class GUI_EXPORT QgsMapLayerStyleCategoriesModel : public QAbstractListModel
Q_OBJECT

public:
//! constructor
explicit QgsMapLayerStyleCategoriesModel( QObject *parent = nullptr );

/**
* Constructor for QgsMapLayerStyleCategoriesModel, for the specified layer \a type.
*/
explicit QgsMapLayerStyleCategoriesModel( QgsMapLayerType type, QObject *parent = nullptr );

//! Reset the model data
void setCategories( QgsMapLayer::StyleCategories categories );
@@ -74,7 +74,7 @@ QgsVectorLayerLoadStyleDialog::QgsVectorLayerLoadStyleDialog( QgsVectorLayer *la
}

// fill style categories
mModel = new QgsMapLayerStyleCategoriesModel( this );
mModel = new QgsMapLayerStyleCategoriesModel( mLayer->type(), this );
QgsMapLayer::StyleCategories lastStyleCategories = settings.flagValue( QStringLiteral( "style/lastStyleCategories" ), QgsMapLayer::AllStyleCategories );
mModel->setCategories( lastStyleCategories );
mStyleCategoriesListView->setModel( mModel );
@@ -79,7 +79,7 @@ QgsVectorLayerSaveStyleDialog::QgsVectorLayerSaveStyleDialog( QgsVectorLayer *la
} );

// fill style categories
mModel = new QgsMapLayerStyleCategoriesModel( this );
mModel = new QgsMapLayerStyleCategoriesModel( mLayer->type(), this );
QgsMapLayer::StyleCategories lastStyleCategories = settings.flagValue( QStringLiteral( "style/lastStyleCategories" ), QgsMapLayer::AllStyleCategories );
mModel->setCategories( lastStyleCategories );
mStyleCategoriesListView->setModel( mModel );

0 comments on commit 0ea5f57

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