mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
use a model for select map layer style categories (#7907)
this avoids cluttering QgsMapLayer and reduces a bit code redundancy
This commit is contained in:
parent
efa72779af
commit
3724f9e9e2
@ -94,31 +94,6 @@ This is the base class for all map layer types (vector, raster).
|
||||
typedef QFlags<QgsMapLayer::StyleCategory> 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`.
|
||||
|
@ -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
|
||||
|
@ -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<QgsMapLayer::StyleCategory> categories = qgsEnumMap<QgsMapLayer::StyleCategory>().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<QIcon>();
|
||||
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<QgsMapLayer::StyleCategory> categories = qgsEnumMap<QgsMapLayer::StyleCategory>().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<QIcon>();
|
||||
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
|
||||
|
237
src/app/qgsmaplayerstylecategoriesmodel.cpp
Normal file
237
src/app/qgsmaplayerstylecategoriesmodel.cpp
Normal file
@ -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<QgsMapLayer::StyleCategory>().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::CheckState>() == Qt::Checked )
|
||||
{
|
||||
mCategories |= category;
|
||||
emit dataChanged( index, index );
|
||||
return true;
|
||||
}
|
||||
else if ( value.value<Qt::CheckState>() == Qt::Unchecked )
|
||||
{
|
||||
mCategories &= category;
|
||||
emit dataChanged( index, index );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Qt::ItemFlags QgsMapLayerStyleCategoriesModel::flags( const QModelIndex & ) const
|
||||
{
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
|
||||
}
|
55
src/app/qgsmaplayerstylecategoriesmodel.h
Normal file
55
src/app/qgsmaplayerstylecategoriesmodel.h
Normal file
@ -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 <QAbstractListModel>
|
||||
|
||||
#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<QgsMapLayer::StyleCategory> mCategoryList;
|
||||
//! display All categories on first line
|
||||
bool mShowAllCategories = false;
|
||||
};
|
||||
|
||||
#endif // QGSMAPLAYERSTYLECATEGORIESMODEL_H
|
@ -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<QgsMapLayer::StyleCategory>().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<QgsMapLayer::StyleCategory>();
|
||||
}
|
||||
return categories;
|
||||
return mModel->categories();
|
||||
}
|
||||
|
||||
QgsVectorLayerProperties::StyleType QgsVectorLayerLoadStyleDialog::currentStyleType() const
|
||||
|
@ -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;
|
||||
|
@ -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<QgsMapLayer::StyleCategory>().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<QgsMapLayer::StyleCategory>();
|
||||
}
|
||||
return categories;
|
||||
return mModel->categories();
|
||||
}
|
||||
|
||||
QgsVectorLayerProperties::StyleType QgsVectorLayerSaveStyleDialog::currentStyleType() const
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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 )
|
||||
|
@ -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;
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>475</width>
|
||||
<height>390</height>
|
||||
<height>546</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -79,16 +79,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QListWidget" name="mStyleCategoriesListWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
@ -199,6 +189,16 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QListView" name="mStyleCategoriesListView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>491</width>
|
||||
<height>527</height>
|
||||
<height>535</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -137,7 +137,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QListWidget" name="mStyleCategoriesListWidget">
|
||||
<widget class="QListView" name="mStyleCategoriesListView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
|
Loading…
x
Reference in New Issue
Block a user