18#include <QInputDialog>
44 mModel =
new QStandardItemModel(
this );
45 mStyleList =
new QListView(
this );
46 mStyleList->setModel( mModel );
47 mStyleList->setViewMode( QListView::ListMode );
48 mStyleList->setResizeMode( QListView::Adjust );
50 QToolBar *toolbar =
new QToolBar(
this );
51 QAction *addAction = toolbar->addAction( tr(
"Add" ) );
53 connect( addAction, &QAction::triggered,
this, &QgsMapLayerStyleManagerWidget::addStyle );
54 QAction *removeAction = toolbar->addAction( tr(
"Remove Current" ) );
56 connect( removeAction, &QAction::triggered,
this, &QgsMapLayerStyleManagerWidget::removeStyle );
57 QAction *loadFromFileAction = toolbar->addAction( tr(
"Load Style" ) );
59 connect( loadFromFileAction, &QAction::triggered,
this, &QgsMapLayerStyleManagerWidget::loadStyle );
60 QAction *saveAction = toolbar->addAction( tr(
"Save Style" ) );
62 connect( saveAction, &QAction::triggered,
this, &QgsMapLayerStyleManagerWidget::saveStyle );
63 QAction *saveAsDefaultAction = toolbar->addAction( tr(
"Save as Default" ) );
64 connect( saveAsDefaultAction, &QAction::triggered,
this, &QgsMapLayerStyleManagerWidget::saveAsDefault );
65 QAction *loadDefaultAction = toolbar->addAction( tr(
"Restore Default" ) );
66 connect( loadDefaultAction, &QAction::triggered,
this, &QgsMapLayerStyleManagerWidget::loadDefault );
71 connect( mStyleList, &QAbstractItemView::clicked,
this, &QgsMapLayerStyleManagerWidget::styleClicked );
73 setLayout(
new QVBoxLayout() );
74 layout()->setContentsMargins( 0, 0, 0, 0 );
75 layout()->addWidget( toolbar );
76 layout()->addWidget( mStyleList );
86 for (
const QString &styleName : styles )
88 QStandardItem *item =
new QStandardItem( styleName );
89 item->setData( styleName );
90 mModel->appendRow( item );
94 currentStyleChanged( active );
96 connect( mModel, &QStandardItemModel::itemChanged,
this, &QgsMapLayerStyleManagerWidget::renameStyle );
99void QgsMapLayerStyleManagerWidget::styleClicked(
const QModelIndex &index )
104 const QString name = index.data().toString();
108void QgsMapLayerStyleManagerWidget::currentStyleChanged(
const QString &name )
110 const QList<QStandardItem *> items = mModel->findItems( name );
111 if ( items.isEmpty() )
114 QStandardItem *item = items.at( 0 );
116 mStyleList->setCurrentIndex( item->index() );
119void QgsMapLayerStyleManagerWidget::styleAdded(
const QString &name )
122 QStandardItem *item =
new QStandardItem( name );
123 item->setData( name );
124 mModel->appendRow( item );
127void QgsMapLayerStyleManagerWidget::styleRemoved(
const QString &name )
129 const QList<QStandardItem *> items = mModel->findItems( name );
130 if ( items.isEmpty() )
133 QStandardItem *item = items.at( 0 );
134 mModel->removeRow( item->row() );
137void QgsMapLayerStyleManagerWidget::styleRenamed(
const QString &oldname,
const QString &newname )
139 const QList<QStandardItem *> items = mModel->findItems( oldname );
140 if ( items.isEmpty() )
143 QStandardItem *item = items.at( 0 );
144 item->setText( newname );
145 item->setData( newname );
148void QgsMapLayerStyleManagerWidget::addStyle()
151 const QString text = QInputDialog::getText(
nullptr, tr(
"New Style" ),
152 tr(
"Style name:" ), QLineEdit::Normal,
153 QStringLiteral(
"new style" ), &ok );
154 if ( !ok || text.isEmpty() )
168void QgsMapLayerStyleManagerWidget::removeStyle()
173 QgsDebugError( QStringLiteral(
"Failed to remove current style" ) );
176void QgsMapLayerStyleManagerWidget::renameStyle( QStandardItem *item )
178 const QString oldName = item->data().toString();
179 const QString newName = item->text();
180 item->setData( newName );
181 whileBlocking(
this )->mLayer->styleManager()->renameStyle( oldName, newName );
184void QgsMapLayerStyleManagerWidget::saveAsDefault()
192 case Qgis::LayerType::Vector:
198 case Qgis::LayerType::Raster:
202 case Qgis::LayerType::Mesh:
206 case Qgis::LayerType::VectorTile:
213 case Qgis::LayerType::PointCloud:
214 case Qgis::LayerType::Annotation:
215 case Qgis::LayerType::Plugin:
216 case Qgis::LayerType::Group:
222void QgsMapLayerStyleManagerWidget::loadDefault()
230 case Qgis::LayerType::Vector:
236 case Qgis::LayerType::Raster:
240 case Qgis::LayerType::Mesh:
244 case Qgis::LayerType::VectorTile:
251 case Qgis::LayerType::PointCloud:
252 case Qgis::LayerType::Annotation:
253 case Qgis::LayerType::Plugin:
254 case Qgis::LayerType::Group:
260void QgsMapLayerStyleManagerWidget::saveStyle()
268 case Qgis::LayerType::Vector:
274 case Qgis::LayerType::Raster:
278 case Qgis::LayerType::Mesh:
282 case Qgis::LayerType::VectorTile:
289 case Qgis::LayerType::PointCloud:
290 case Qgis::LayerType::Annotation:
291 case Qgis::LayerType::Plugin:
292 case Qgis::LayerType::Group:
298void QgsMapLayerStyleManagerWidget::loadStyle()
306 case Qgis::LayerType::Vector:
312 case Qgis::LayerType::Raster:
316 case Qgis::LayerType::Mesh:
320 case Qgis::LayerType::VectorTile:
327 case Qgis::LayerType::PointCloud:
328 case Qgis::LayerType::Annotation:
329 case Qgis::LayerType::Plugin:
330 case Qgis::LayerType::Group:
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Map canvas is a class for displaying all GIS data types on a canvas.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
QString currentStyle() const
Returns name of the current style.
bool removeStyle(const QString &name)
Remove a stored style.
QStringList styles() const
Returns list of all defined style names.
bool setCurrentStyle(const QString &name)
Set a different style as the current style - will apply it to the layer.
void styleAdded(const QString &name)
Emitted when a new style has been added.
void styleRenamed(const QString &oldName, const QString &newName)
Emitted when a style has been renamed.
bool addStyleFromLayer(const QString &name)
Add style by cloning the current one.
void currentStyleChanged(const QString ¤tName)
Emitted when the current style has been changed.
void styleRemoved(const QString &name)
Emitted when a style has been removed.
Base class for all map layer types.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
Property sheet for a mesh map layer.
void loadStyle()
Loads a saved style when appropriate button is pressed.
void loadDefaultStyle()
Loads the default style when appropriate button is pressed.
void saveDefaultStyle()
Saves the default style when appropriate button is pressed.
void saveStyleAs()
Saves a style when appriate button is pressed.
Property sheet for a raster map layer.
void saveDefaultStyle()
Saves the default style when appropriate button is pressed.
void loadDefaultStyle()
Loads the default style when appropriate button is pressed.
void saveStyleAs()
Saves a style when appriate button is pressed.
void loadStyle()
Loads a saved style when appropriate button is pressed.
void loadDefaultStyle()
Loads the default style when appropriate button is pressed.
void saveStyleAs()
Saves a style when appriate button is pressed.
void loadStyle()
Loads a saved style when appropriate button is pressed.
void saveDefaultStyle()
Saves the default style when appropriate button is pressed.
Vectortile layer properties dialog.
void saveDefaultStyle()
Saves the default style when appropriate button is pressed.
void saveStyleAs()
Saves a style when appriate button is pressed.
void loadDefaultStyle()
Loads the default style when appropriate button is pressed.
void loadStyle()
Loads a saved style when appropriate button is pressed.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)