diff --git a/python/core/auto_generated/qgsmaplayer.sip.in b/python/core/auto_generated/qgsmaplayer.sip.in index 69051dfee9f..ce27379a415 100644 --- a/python/core/auto_generated/qgsmaplayer.sip.in +++ b/python/core/auto_generated/qgsmaplayer.sip.in @@ -94,31 +94,6 @@ This is the base class for all map layer types (vector, raster). typedef QFlags StyleCategories; - struct ReadableStyleCategory - { - public: - ReadableStyleCategory( const QString &name, const QString &toolTip = QString() ); -%Docstring -Create a ReadableStyleCategory -%End - ReadableStyleCategory( const QString &name, const QIcon &icon, const QString &toolTip = QString() ); -%Docstring -Create a ReadableStyleCategory -%End - QString name() const; -%Docstring -Return the translated name of the category -%End - QString toolTip() const; -%Docstring -Return the translated tooltip of the category -%End - QIcon icon() const; -%Docstring -Return the icon of the category -%End - }; - QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, const QString &name = QString(), const QString &source = QString() ); %Docstring Constructor for QgsMapLayer @@ -181,15 +156,6 @@ Returns the extension of a Property. .. versionadded:: 3.0 %End - static ReadableStyleCategory readableStyleCategory( StyleCategory category ); -%Docstring -Readable and Translated category - -.. versionadded:: 3.4 -%End - - - QString id() const; %Docstring Returns the layer's unique ID, which is used to access this layer from :py:class:`QgsProject`. diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 6e3123e4b0f..bf90ef83b7e 100755 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -61,6 +61,7 @@ SET(QGIS_APP_SRCS qgslayertreeviewmemoryindicator.cpp qgslayertreeviewnonremovableindicator.cpp qgsmapcanvasdockwidget.cpp + qgsmaplayerstylecategoriesmodel.cpp qgsmaplayerstyleguiutils.cpp qgsmapsavedialog.cpp qgspuzzlewidget.cpp @@ -285,6 +286,7 @@ SET (QGIS_APP_MOC_HDRS qgslayertreeviewfilterindicator.h qgslayertreeviewnonremovableindicator.h qgsmapcanvasdockwidget.h + qgsmaplayerstylecategoriesmodel.h qgsmaplayerstyleguiutils.h qgsmapsavedialog.h qgspuzzlewidget.h diff --git a/src/app/qgsapplayertreeviewmenuprovider.cpp b/src/app/qgsapplayertreeviewmenuprovider.cpp index d054cb863b5..313fbd06f07 100644 --- a/src/app/qgsapplayertreeviewmenuprovider.cpp +++ b/src/app/qgsapplayertreeviewmenuprovider.cpp @@ -12,6 +12,7 @@ * (at your option) any later version. * * * ***************************************************************************/ + #include "qgsapplayertreeviewmenuprovider.h" @@ -37,6 +38,8 @@ #include "qgslayertreeregistrybridge.h" #include "qgssymbolselectordialog.h" #include "qgssinglesymbolrenderer.h" +#include "qgsmaplayerstylecategoriesmodel.h" + QgsAppLayerTreeViewMenuProvider::QgsAppLayerTreeViewMenuProvider( QgsLayerTreeView *view, QgsMapCanvas *canvas ) : mView( view ) @@ -320,13 +323,17 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu() { QMenu *copyStyleMenu = menuStyleManager->addMenu( tr( "Copy Style" ) ); copyStyleMenu->setToolTipsVisible( true ); - QList categories = qgsEnumMap().keys(); - categories.move( categories.indexOf( QgsMapLayer::AllStyleCategories ), 0 ); // move All categories to top - for ( QgsMapLayer::StyleCategory category : categories ) + QgsMapLayerStyleCategoriesModel *model = new QgsMapLayerStyleCategoriesModel( copyStyleMenu ); + model->setShowAllCategories( true ); + for ( int row = 0; row < model->rowCount(); ++row ) { - QgsMapLayer::ReadableStyleCategory readableCategory = QgsMapLayer::readableStyleCategory( category ); - QAction *copyAction = new QAction( readableCategory.icon(), readableCategory.name(), copyStyleMenu ); - copyAction->setToolTip( readableCategory.toolTip() ); + QModelIndex index = model->index( row, 0 ); + QString name = model->data( index, Qt::DisplayRole ).toString(); + QString tooltip = model->data( index, Qt::ToolTipRole ).toString(); + QIcon icon = model->data( index, Qt::DecorationRole ).value(); + QgsMapLayer::StyleCategory category = model->index2category( index ); + QAction *copyAction = new QAction( icon, name, copyStyleMenu ); + copyAction->setToolTip( tooltip ); connect( copyAction, &QAction::triggered, this, [ = ]() {app->copyStyle( layer, category );} ); copyStyleMenu->addAction( copyAction ); if ( category == QgsMapLayer::AllStyleCategories ) @@ -342,19 +349,24 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu() { if ( layer->type() == QgsMapLayer::VectorLayer ) { - QMenu *copyStyleMenu = menuStyleManager->addMenu( tr( "Paste Style" ) ); - copyStyleMenu->setToolTipsVisible( true ); - QList categories = qgsEnumMap().keys(); - categories.move( categories.indexOf( QgsMapLayer::AllStyleCategories ), 0 ); // move All categories to top - for ( QgsMapLayer::StyleCategory category : categories ) + QMenu *pasteStyleMenu = menuStyleManager->addMenu( tr( "Paste Style" ) ); + pasteStyleMenu->setToolTipsVisible( true ); + + QgsMapLayerStyleCategoriesModel *model = new QgsMapLayerStyleCategoriesModel( pasteStyleMenu ); + model->setShowAllCategories( true ); + for ( int row = 0; row < model->rowCount(); ++row ) { - QgsMapLayer::ReadableStyleCategory readableCategory = QgsMapLayer::readableStyleCategory( category ); - QAction *copyAction = new QAction( readableCategory.icon(), readableCategory.name() ); - copyAction->setToolTip( readableCategory.toolTip() ); - connect( copyAction, &QAction::triggered, this, [ = ]() {app->pasteStyle( layer, category );} ); - copyStyleMenu->addAction( copyAction ); + QModelIndex index = model->index( row, 0 ); + QString name = model->data( index, Qt::DisplayRole ).toString(); + QString tooltip = model->data( index, Qt::ToolTipRole ).toString(); + QIcon icon = model->data( index, Qt::DecorationRole ).value(); + QgsMapLayer::StyleCategory category = model->index2category( index ); + QAction *copyAction = new QAction( icon, name, pasteStyleMenu ); + copyAction->setToolTip( tooltip ); + connect( copyAction, &QAction::triggered, this, [ = ]() {app->copyStyle( layer, category );} ); + pasteStyleMenu->addAction( copyAction ); if ( category == QgsMapLayer::AllStyleCategories ) - copyStyleMenu->addSeparator(); + pasteStyleMenu->addSeparator(); } } else diff --git a/src/app/qgsmaplayerstylecategoriesmodel.cpp b/src/app/qgsmaplayerstylecategoriesmodel.cpp new file mode 100644 index 00000000000..62ce192cee0 --- /dev/null +++ b/src/app/qgsmaplayerstylecategoriesmodel.cpp @@ -0,0 +1,237 @@ +/*************************************************************************** + qgsmaplayerstylecategoriesmodel.cpp + -------------------------------------- + Date : September 2018 + Copyright : (C) 2018 by Denis Rouzaud + Email : denis@opengis.ch + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgsmaplayerstylecategoriesmodel.h" + +QgsMapLayerStyleCategoriesModel::QgsMapLayerStyleCategoriesModel( QObject *parent ) + : QAbstractListModel( parent ) +{ + mCategoryList = qgsEnumMap().keys(); + // move All categories to top + mCategoryList.move( mCategoryList.indexOf( QgsMapLayer::AllStyleCategories ), 0 ); +} + +void QgsMapLayerStyleCategoriesModel::setCategories( QgsMapLayer::StyleCategories categories ) +{ + if ( mCategories == categories ) + return; + + beginResetModel(); + mCategories = categories; + endResetModel(); +} + +QgsMapLayer::StyleCategories QgsMapLayerStyleCategoriesModel::categories() const +{ + return mCategories; +} + +void QgsMapLayerStyleCategoriesModel::setShowAllCategories( bool showAll ) +{ + beginResetModel(); + mShowAllCategories = showAll; + endResetModel(); +} + +QgsMapLayer::StyleCategory QgsMapLayerStyleCategoriesModel::index2category( const QModelIndex &index ) const +{ + return mCategoryList.at( index.row() - ( mShowAllCategories ? 0 : 1 ) ); +} + +int QgsMapLayerStyleCategoriesModel::rowCount( const QModelIndex & ) const +{ + int count = mCategoryList.count(); + if ( !mShowAllCategories ) + count--; + return count; +} + +int QgsMapLayerStyleCategoriesModel::columnCount( const QModelIndex & ) const +{ + return 1; +} + +QVariant QgsMapLayerStyleCategoriesModel::data( const QModelIndex &index, int role ) const +{ + if ( !index.isValid() || index.row() >= rowCount() ) + return QVariant(); + + QgsMapLayer::StyleCategory category = index2category( index ); + + switch ( category ) + { + case QgsMapLayer::LayerConfiguration: + switch ( role ) + { + case Qt::DisplayRole: + return tr( "Layer Configuration" ); + case Qt::ToolTipRole: + return tr( "Identifiable, removable, searchable, display expression, read-only" ); + case Qt::DecorationRole: + return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/system.svg" ) ); + } + case QgsMapLayer::Symbology : + switch ( role ) + { + case Qt::DisplayRole: + return tr( "Symbology" ); + case Qt::ToolTipRole: + return QVariant(); + case Qt::DecorationRole: + return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/symbology.svg" ) ); + } + case QgsMapLayer::Symbology3D: + switch ( role ) + { + case Qt::DisplayRole: + return tr( "3D Symbology" ); + case Qt::ToolTipRole: + return QVariant(); + case Qt::DecorationRole: + return QgsApplication::getThemeIcon( QStringLiteral( "/3d.svg" ) ); + } + case QgsMapLayer::Labeling : + switch ( role ) + { + case Qt::DisplayRole: + return tr( "Labels" ); + case Qt::ToolTipRole: + return QVariant(); + case Qt::DecorationRole: + return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/labels.svg" ) ); + } + case QgsMapLayer::Fields : + switch ( role ) + { + case Qt::DisplayRole: + return tr( "Fields" ); + case Qt::ToolTipRole: + return tr( "Aliases, widgets, WMS/WFS, expressions, constraints, virtual fields" ); + case Qt::DecorationRole: + return QgsApplication::getThemeIcon( QStringLiteral( "/mSourceFields" ) ); + } + case QgsMapLayer::Forms : + switch ( role ) + { + case Qt::DisplayRole: + return tr( "Forms" ); + case Qt::ToolTipRole: + return QVariant(); + case Qt::DecorationRole: + return QgsApplication::getThemeIcon( QStringLiteral( "/mActionFormView" ) ); + } + case QgsMapLayer::Actions : + switch ( role ) + { + case Qt::DisplayRole: + return tr( "Actions" ); + case Qt::ToolTipRole: + return QVariant(); + case Qt::DecorationRole: + return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/action.svg" ) ); + } + case QgsMapLayer::MapTips : + switch ( role ) + { + case Qt::DisplayRole: + return tr( "Map Tips" ); + case Qt::ToolTipRole: + return QVariant(); + case Qt::DecorationRole: + return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/display.svg" ) ); + } + case QgsMapLayer::Diagrams : + switch ( role ) + { + case Qt::DisplayRole: + return tr( "Diagrams" ); + case Qt::ToolTipRole: + return QVariant(); + case Qt::DecorationRole: + return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/diagram.svg" ) ); + } + case QgsMapLayer::AttributeTable : + switch ( role ) + { + case Qt::DisplayRole: + return tr( "Attribute Table Settings" ); + case Qt::ToolTipRole: + return tr( "Choice and order of columns, conditional styling" ); + case Qt::DecorationRole: + return QgsApplication::getThemeIcon( QStringLiteral( "/mActionOpenTable" ) ); + } + case QgsMapLayer::Rendering : + switch ( role ) + { + case Qt::DisplayRole: + return tr( "Rendering" ); + case Qt::ToolTipRole: + return tr( "Scale visibility, simplify method, opacity" ); + case Qt::DecorationRole: + return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/rendering.svg" ) ); + } + case QgsMapLayer::CustomProperties : + switch ( role ) + { + case Qt::DisplayRole: + return tr( "Custom Properties" ); + case Qt::ToolTipRole: + return QVariant(); + case Qt::DecorationRole: + return QgsApplication::getThemeIcon( QStringLiteral( "/mActionOptions.svg" ) ); + } + case QgsMapLayer::AllStyleCategories : + switch ( role ) + { + case Qt::DisplayRole: + return tr( "All Style Categories" ); + case Qt::ToolTipRole: + return QVariant(); + case Qt::DecorationRole: + return QVariant(); + } + } + return QVariant(); +} + +bool QgsMapLayerStyleCategoriesModel::setData( const QModelIndex &index, const QVariant &value, int role ) +{ + if ( !index.isValid() || index.row() >= rowCount() ) + return false; + + if ( role == Qt::CheckStateRole ) + { + QgsMapLayer::StyleCategory category = index2category( index ); + if ( value.value() == Qt::Checked ) + { + mCategories |= category; + emit dataChanged( index, index ); + return true; + } + else if ( value.value() == Qt::Unchecked ) + { + mCategories &= category; + emit dataChanged( index, index ); + return true; + } + } + return false; +} + + +Qt::ItemFlags QgsMapLayerStyleCategoriesModel::flags( const QModelIndex & ) const +{ + return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable; +} diff --git a/src/app/qgsmaplayerstylecategoriesmodel.h b/src/app/qgsmaplayerstylecategoriesmodel.h new file mode 100644 index 00000000000..b7522d0b633 --- /dev/null +++ b/src/app/qgsmaplayerstylecategoriesmodel.h @@ -0,0 +1,55 @@ +/*************************************************************************** + qgsmaplayerstylecategoriesmodel.h + -------------------------------------- + Date : September 2018 + Copyright : (C) 2018 by Denis Rouzaud + Email : denis@opengis.ch + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef QGSMAPLAYERSTYLECATEGORIESMODEL_H +#define QGSMAPLAYERSTYLECATEGORIESMODEL_H + +#include + +#include "qgsmaplayer.h" + +class QgsMapLayerStyleCategoriesModel : public QAbstractListModel +{ + public: + explicit QgsMapLayerStyleCategoriesModel( QObject *parent = nullptr ); + + //! reset the model data + void setCategories( QgsMapLayer::StyleCategories categories ); + + //! return the categories as defined in the model + QgsMapLayer::StyleCategories categories() const; + + //! defines if the model should list the AllStyleCategories entry + void setShowAllCategories( bool showAll ); + + //! return the category for the given index + QgsMapLayer::StyleCategory index2category( const QModelIndex &index ) const; + + int rowCount( const QModelIndex & = QModelIndex() ) const override; + int columnCount( const QModelIndex & = QModelIndex() ) const override; + QVariant data( const QModelIndex &index, int role ) const override; + bool setData( const QModelIndex &index, const QVariant &value, int role ) override; + Qt::ItemFlags flags( const QModelIndex & ) const override; + + private: + //! current data as flags + QgsMapLayer::StyleCategories mCategories; + //! map of existing categories + QList mCategoryList; + //! display All categories on first line + bool mShowAllCategories = false; +}; + +#endif // QGSMAPLAYERSTYLECATEGORIESMODEL_H diff --git a/src/app/qgsvectorlayerloadstyledialog.cpp b/src/app/qgsvectorlayerloadstyledialog.cpp index 1358554f96b..1a2eb2b0ca1 100644 --- a/src/app/qgsvectorlayerloadstyledialog.cpp +++ b/src/app/qgsvectorlayerloadstyledialog.cpp @@ -21,6 +21,7 @@ #include "qgisapp.h" #include "qgssettings.h" #include "qgsvectorlayerproperties.h" +#include "qgsmaplayerstylecategoriesmodel.h" @@ -50,7 +51,7 @@ QgsVectorLayerLoadStyleDialog::QgsVectorLayerLoadStyleDialog( QgsVectorLayer *la mFromFileWidget->setVisible( type != QgsVectorLayerProperties::DB ); mFromDbWidget->setVisible( type == QgsVectorLayerProperties::DB ); mDeleteButton->setVisible( type == QgsVectorLayerProperties::DB && mLayer->dataProvider()->isDeleteStyleFromDatabaseSupported() ); - mStyleCategoriesListWidget->setEnabled( currentStyleType() != QgsVectorLayerProperties::SLD ); + mStyleCategoriesListView->setEnabled( currentStyleType() != QgsVectorLayerProperties::SLD ); updateLoadButtonState(); } ); mStyleTypeComboBox->addItem( tr( "from file" ), QgsVectorLayerProperties::QML ); // QML is used as entry, but works for SLD too, see currentStyleType() @@ -58,19 +59,10 @@ QgsVectorLayerLoadStyleDialog::QgsVectorLayerLoadStyleDialog( QgsVectorLayer *la mStyleTypeComboBox->addItem( tr( "from database (%1)" ).arg( providerName ), QgsVectorLayerProperties::DB ); // fill style categories + mModel = new QgsMapLayerStyleCategoriesModel( this ); QgsMapLayer::StyleCategories lastStyleCategories = settings.flagValue( QStringLiteral( "style/lastStyleCategories" ), QgsMapLayer::AllStyleCategories ); - for ( QgsMapLayer::StyleCategory category : qgsEnumMap().keys() ) - { - if ( category == QgsMapLayer::AllStyleCategories ) - continue; - - QgsMapLayer::ReadableStyleCategory readableCategory = QgsMapLayer::readableStyleCategory( category ); - - QListWidgetItem *item = new QListWidgetItem( readableCategory.icon(), readableCategory.name(), mStyleCategoriesListWidget ); - item->setFlags( ( item->flags() | Qt::ItemIsUserCheckable ) & ~Qt::ItemIsSelectable ); - item->setCheckState( lastStyleCategories.testFlag( category ) ? Qt::Checked : Qt::Unchecked ); - item->setData( Qt::UserRole, category ); - } + mModel->setCategories( lastStyleCategories ); + mStyleCategoriesListView->setModel( mModel ); // load from file setup mFileWidget->setFilter( tr( "QGIS Layer Style File, SLD File" ) + QStringLiteral( " (*.qml *.sld)" ) ); @@ -78,7 +70,7 @@ QgsVectorLayerLoadStyleDialog::QgsVectorLayerLoadStyleDialog( QgsVectorLayer *la mFileWidget->setDefaultRoot( myLastUsedDir ); connect( mFileWidget, &QgsFileWidget::fileChanged, this, [ = ]( const QString & ) { - mStyleCategoriesListWidget->setEnabled( currentStyleType() != QgsVectorLayerProperties::SLD ); + mStyleCategoriesListView->setEnabled( currentStyleType() != QgsVectorLayerProperties::SLD ); updateLoadButtonState(); } ); @@ -103,7 +95,7 @@ QgsVectorLayerLoadStyleDialog::QgsVectorLayerLoadStyleDialog( QgsVectorLayer *la setTabOrder( mRelatedTable, mOthersTable ); restoreGeometry( settings.value( QStringLiteral( "Windows/vectorLayerLoadStyle/geometry" ) ).toByteArray() ); - mStyleCategoriesListWidget->adjustSize(); + mStyleCategoriesListView->adjustSize(); } QgsVectorLayerLoadStyleDialog::~QgsVectorLayerLoadStyleDialog() @@ -114,14 +106,7 @@ QgsVectorLayerLoadStyleDialog::~QgsVectorLayerLoadStyleDialog() QgsMapLayer::StyleCategories QgsVectorLayerLoadStyleDialog::styleCategories() const { - QgsMapLayer::StyleCategories categories; - for ( int row = 0; row < mStyleCategoriesListWidget->count(); ++row ) - { - QListWidgetItem *item = mStyleCategoriesListWidget->item( row ); - if ( item->checkState() == Qt::Checked ) - categories |= item->data( Qt::UserRole ).value(); - } - return categories; + return mModel->categories(); } QgsVectorLayerProperties::StyleType QgsVectorLayerLoadStyleDialog::currentStyleType() const diff --git a/src/app/qgsvectorlayerloadstyledialog.h b/src/app/qgsvectorlayerloadstyledialog.h index 554589b2341..63c38652374 100644 --- a/src/app/qgsvectorlayerloadstyledialog.h +++ b/src/app/qgsvectorlayerloadstyledialog.h @@ -22,6 +22,8 @@ #include "qgsvectorlayerproperties.h" #include "qgsmaplayer.h" +class QgsMapLayerStyleCategoriesModel; + class APP_EXPORT QgsVectorLayerLoadStyleDialog : public QDialog, private Ui::QgsVectorLayerLoadStyleDialog { Q_OBJECT @@ -51,6 +53,7 @@ class APP_EXPORT QgsVectorLayerLoadStyleDialog : public QDialog, private Ui::Qgs private: QgsVectorLayer *mLayer = nullptr; + QgsMapLayerStyleCategoriesModel *mModel; QString mSelectedStyleId; QString mSelectedStyleName; int mSectionLimit = 0; diff --git a/src/app/qgsvectorlayersavestyledialog.cpp b/src/app/qgsvectorlayersavestyledialog.cpp index c738c86f9e4..ef36441f86f 100644 --- a/src/app/qgsvectorlayersavestyledialog.cpp +++ b/src/app/qgsvectorlayersavestyledialog.cpp @@ -20,6 +20,7 @@ #include "qgsvectorlayer.h" #include "qgssettings.h" #include "qgshelp.h" +#include "qgsmaplayerstylecategoriesmodel.h" QgsVectorLayerSaveStyleDialog::QgsVectorLayerSaveStyleDialog( QgsVectorLayer *layer, QWidget *parent ) : QDialog( parent ) @@ -44,7 +45,7 @@ QgsVectorLayerSaveStyleDialog::QgsVectorLayerSaveStyleDialog( QgsVectorLayer *la QgsVectorLayerProperties::StyleType type = currentStyleType(); mSaveToFileWidget->setVisible( type != QgsVectorLayerProperties::DB ); mSaveToDbWidget->setVisible( type == QgsVectorLayerProperties::DB ); - mStyleCategoriesListWidget->setEnabled( type == QgsVectorLayerProperties::QML ); + mStyleCategoriesListView->setEnabled( type == QgsVectorLayerProperties::QML ); mFileWidget->setFilter( type == QgsVectorLayerProperties::QML ? tr( "QGIS Layer Style File (*.qml)" ) : tr( "SLD File (*.sld)" ) ); updateSaveButtonState(); } ); @@ -69,22 +70,13 @@ QgsVectorLayerSaveStyleDialog::QgsVectorLayerSaveStyleDialog( QgsVectorLayer *la mFileWidget->setDefaultRoot( myLastUsedDir ); // fill style categories + mModel = new QgsMapLayerStyleCategoriesModel( this ); QgsMapLayer::StyleCategories lastStyleCategories = settings.flagValue( QStringLiteral( "style/lastStyleCategories" ), QgsMapLayer::AllStyleCategories ); - for ( QgsMapLayer::StyleCategory category : qgsEnumMap().keys() ) - { - if ( category == QgsMapLayer::AllStyleCategories ) - continue; - - QgsMapLayer::ReadableStyleCategory readableCategory = QgsMapLayer::readableStyleCategory( category ); - - QListWidgetItem *item = new QListWidgetItem( readableCategory.icon(), readableCategory.name(), mStyleCategoriesListWidget ); - item->setFlags( ( item->flags() | Qt::ItemIsUserCheckable ) & ~Qt::ItemIsSelectable ); - item->setCheckState( lastStyleCategories.testFlag( category ) ? Qt::Checked : Qt::Unchecked ); - item->setData( Qt::UserRole, category ); - } + mModel->setCategories( lastStyleCategories ); + mStyleCategoriesListView->setModel( mModel ); restoreGeometry( settings.value( QStringLiteral( "Windows/vectorLayerSaveStyle/geometry" ) ).toByteArray() ); - mStyleCategoriesListWidget->adjustSize(); + mStyleCategoriesListView->adjustSize(); } void QgsVectorLayerSaveStyleDialog::accept() @@ -123,14 +115,7 @@ QString QgsVectorLayerSaveStyleDialog::outputFilePath() const QgsMapLayer::StyleCategories QgsVectorLayerSaveStyleDialog::styleCategories() const { - QgsMapLayer::StyleCategories categories; - for ( int row = 0; row < mStyleCategoriesListWidget->count(); ++row ) - { - QListWidgetItem *item = mStyleCategoriesListWidget->item( row ); - if ( item->checkState() == Qt::Checked ) - categories |= item->data( Qt::UserRole ).value(); - } - return categories; + return mModel->categories(); } QgsVectorLayerProperties::StyleType QgsVectorLayerSaveStyleDialog::currentStyleType() const diff --git a/src/app/qgsvectorlayersavestyledialog.h b/src/app/qgsvectorlayersavestyledialog.h index 838fe347b7f..023be5edcdb 100644 --- a/src/app/qgsvectorlayersavestyledialog.h +++ b/src/app/qgsvectorlayersavestyledialog.h @@ -21,6 +21,7 @@ #include "qgsvectorlayerproperties.h" class QgsVectorLayer; +class QgsMapLayerStyleCategoriesModel; class QgsVectorLayerSaveStyleDialog : public QDialog, private Ui::QgsVectorLayerSaveStyleDialog @@ -56,7 +57,8 @@ class QgsVectorLayerSaveStyleDialog : public QDialog, private Ui::QgsVectorLayer void readUiFileContent( const QString &filePath ); private: - QgsVectorLayer *mLayer = nullptr;; + QgsVectorLayer *mLayer = nullptr; + QgsMapLayerStyleCategoriesModel *mModel; QString mUiFileContent; }; diff --git a/src/core/qgsmaplayer.cpp b/src/core/qgsmaplayer.cpp index eeb2035e029..2f4530381b9 100644 --- a/src/core/qgsmaplayer.cpp +++ b/src/core/qgsmaplayer.cpp @@ -67,56 +67,6 @@ QString QgsMapLayer::extensionPropertyType( QgsMapLayer::PropertyType type ) return QString(); } -QgsMapLayer::ReadableStyleCategory QgsMapLayer::readableStyleCategory( QgsMapLayer::StyleCategory category ) -{ - switch ( category ) - { - case LayerConfiguration: - return ReadableStyleCategory( tr( "Layer Configuration" ), - QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/system.svg" ) ), - tr( "Identifiable, removable, searchable, display expression, read-only" ) ); - case Symbology : - return ReadableStyleCategory( tr( "Symbology" ), - QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/symbology.svg" ) ) ); - case Symbology3D: - return ReadableStyleCategory( tr( "3D Symbology" ), - QgsApplication::getThemeIcon( QStringLiteral( "/3d.svg" ) ) ); - case Labeling : - return ReadableStyleCategory( tr( "Labels" ), - QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/labels.svg" ) ) ); - case Fields : - return ReadableStyleCategory( tr( "Fields" ), - QgsApplication::getThemeIcon( QStringLiteral( "/mSourceFields.svg" ) ), - tr( "Aliases, widgets, WMS/WFS, expressions, constraints, virtual fields" ) ); - case Forms : - return ReadableStyleCategory( tr( "Forms" ), - QgsApplication::getThemeIcon( QStringLiteral( "/mActionFormView.svg" ) ) ); - case Actions : - return ReadableStyleCategory( tr( "Actions" ), - QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/action.svg" ) ) ); - case MapTips : - return ReadableStyleCategory( tr( "Map Tips" ), - QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/display.svg" ) ) ); - case Diagrams : - return ReadableStyleCategory( tr( "Diagrams" ), - QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/diagram.svg" ) ) ); - case AttributeTable : - return ReadableStyleCategory( tr( "Attribute Table Settings" ), - QgsApplication::getThemeIcon( QStringLiteral( "/mActionOpenTable.svg" ) ), - tr( "Choice and order of columns, conditional styling" ) ); - case Rendering : - return ReadableStyleCategory( tr( "Rendering" ), - QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/rendering.svg" ) ), - tr( "Scale visibility, simplify method, opacity" ) ); - case CustomProperties : - return ReadableStyleCategory( tr( "Custom Properties" ), - QgsApplication::getThemeIcon( QStringLiteral( "/mActionOptions.svg" ) ) ); - case AllStyleCategories : - return ReadableStyleCategory( tr( "All Categories" ) ); - } - return ReadableStyleCategory( tr( "All Categories" ) ); // no warnings -} - QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type, const QString &lyrname, const QString &source ) diff --git a/src/core/qgsmaplayer.h b/src/core/qgsmaplayer.h index b6197bc94a7..8cdbf353007 100644 --- a/src/core/qgsmaplayer.h +++ b/src/core/qgsmaplayer.h @@ -160,34 +160,6 @@ class CORE_EXPORT QgsMapLayer : public QObject Q_DECLARE_FLAGS( StyleCategories, StyleCategory ) Q_FLAG( StyleCategories ) - /** - * Style category with its name, tooltip and icon. - * Text are translated and readable - * \since QGIS 3.4 - */ - struct ReadableStyleCategory - { - public: - //! Create a ReadableStyleCategory - ReadableStyleCategory( const QString &name, const QString &toolTip = QString() ) - : mName( name ), mToolTip( toolTip ) - {} - //! Create a ReadableStyleCategory - ReadableStyleCategory( const QString &name, const QIcon &icon, const QString &toolTip = QString() ) - : mName( name ), mToolTip( toolTip ), mIcon( icon ) - {} - //! Return the translated name of the category - QString name() const {return mName;} - //! Return the translated tooltip of the category - QString toolTip() const {return mToolTip;} - //! Return the icon of the category - QIcon icon() const {return mIcon;} - private: - QString mName; - QString mToolTip; - QIcon mIcon; - }; - /** * Constructor for QgsMapLayer * \param type layer type @@ -241,14 +213,6 @@ class CORE_EXPORT QgsMapLayer : public QObject */ static QString extensionPropertyType( PropertyType type ); - /** - * Readable and Translated category - * \since QGIS 3.4 - */ - static ReadableStyleCategory readableStyleCategory( StyleCategory category ); - - - //! Returns the layer's unique ID, which is used to access this layer from QgsProject. QString id() const; diff --git a/src/ui/qgsvectorlayerloadstyledialog.ui b/src/ui/qgsvectorlayerloadstyledialog.ui index 04437f7b5cd..0e3d1b79adb 100644 --- a/src/ui/qgsvectorlayerloadstyledialog.ui +++ b/src/ui/qgsvectorlayerloadstyledialog.ui @@ -7,7 +7,7 @@ 0 0 475 - 390 + 546 @@ -79,16 +79,6 @@ - - - - - 0 - 0 - - - - @@ -199,6 +189,16 @@ + + + + + 0 + 0 + + + + diff --git a/src/ui/qgsvectorlayersavestyledialog.ui b/src/ui/qgsvectorlayersavestyledialog.ui index 1eafe626bd3..410ec100c36 100644 --- a/src/ui/qgsvectorlayersavestyledialog.ui +++ b/src/ui/qgsvectorlayersavestyledialog.ui @@ -7,7 +7,7 @@ 0 0 491 - 527 + 535 @@ -137,7 +137,7 @@ - + 0