QGIS API Documentation 3.39.0-Master (d85f3c2a281)
Loading...
Searching...
No Matches
qgsmaplayerstylecategoriesmodel.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayerstylecategoriesmodel.cpp
3 --------------------------------------
4 Date : September 2018
5 Copyright : (C) 2018 by Denis Rouzaud
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "qgsapplication.h"
18
20 : QAbstractListModel( parent )
21{
22 switch ( type )
23 {
25 mCategoryList = qgsEnumList<QgsMapLayer::StyleCategory>();
26 break;
27
30 break;
31
43 break;
50 // not yet handled by the model
51 break;
52 }
53
54 // move All categories to top
55 int idxAllStyleCategories = mCategoryList.indexOf( QgsMapLayer::AllStyleCategories );
56 if ( idxAllStyleCategories > 0 )
57 {
58 mCategoryList.move( idxAllStyleCategories, 0 );
59 }
60}
61
63{
64 if ( mCategories == categories )
65 return;
66
67 beginResetModel();
68 mCategories = categories;
69 endResetModel();
70}
71
76
78{
79 beginResetModel();
80 mShowAllCategories = showAll;
81 endResetModel();
82}
83
84int QgsMapLayerStyleCategoriesModel::rowCount( const QModelIndex & ) const
85{
86 int count = mCategoryList.count();
87 if ( count > 0 && !mShowAllCategories )
88 count--;
89 return count;
90}
91
92int QgsMapLayerStyleCategoriesModel::columnCount( const QModelIndex & ) const
93{
94 return 1;
95}
96
97QVariant QgsMapLayerStyleCategoriesModel::data( const QModelIndex &index, int role ) const
98{
99 if ( !index.isValid() || index.row() >= rowCount() )
100 return QVariant();
101
102 const QgsMapLayer::StyleCategory category = mCategoryList.at( index.row() + ( mShowAllCategories ? 0 : 1 ) );
103
104 if ( role == Qt::UserRole )
105 {
106 return category;
107 }
108 if ( role == Qt::CheckStateRole )
109 {
110 return mCategories.testFlag( category ) ? Qt::Checked : Qt::Unchecked;
111 }
112
113 switch ( category )
114 {
116 switch ( role )
117 {
118 case Qt::DisplayRole:
119 return tr( "Layer Configuration" );
120 case Qt::ToolTipRole:
121 return tr( "Identifiable, removable, searchable, display expression, read-only, hidden" );
122 case Qt::DecorationRole:
123 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/system.svg" ) );
124 }
125 break;
127 switch ( role )
128 {
129 case Qt::DisplayRole:
130 case Qt::ToolTipRole:
131 return tr( "Symbology" );
132 case Qt::DecorationRole:
133 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/symbology.svg" ) );
134 }
135 break;
137 switch ( role )
138 {
139 case Qt::DisplayRole:
140 return tr( "3D Symbology" );
141 case Qt::ToolTipRole:
142 return tr( "3D symbology" );
143 case Qt::DecorationRole:
144 return QgsApplication::getThemeIcon( QStringLiteral( "/3d.svg" ) );
145 }
146 break;
148 switch ( role )
149 {
150 case Qt::DisplayRole:
151 case Qt::ToolTipRole:
152 return tr( "Labels" );
153 case Qt::DecorationRole:
154 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/labels.svg" ) );
155 }
156 break;
158 switch ( role )
159 {
160 case Qt::DisplayRole:
161 return tr( "Fields" );
162 case Qt::ToolTipRole:
163 return tr( "Aliases, widgets, WMS/WFS, expressions, constraints, virtual fields" );
164 case Qt::DecorationRole:
165 return QgsApplication::getThemeIcon( QStringLiteral( "/mSourceFields.svg" ) );
166 }
167 break;
169 switch ( role )
170 {
171 case Qt::DisplayRole:
172 return tr( "Attribute Form" );
173 case Qt::ToolTipRole:
174 return tr( "Attribute form settings, widget configuration" );
175 case Qt::DecorationRole:
176 return QgsApplication::getThemeIcon( QStringLiteral( "/mActionFormView.svg" ) );
177 }
178 break;
180 switch ( role )
181 {
182 case Qt::DisplayRole:
183 return tr( "Actions" );
184 case Qt::ToolTipRole:
185 return tr( "Map layer actions" );
186 case Qt::DecorationRole:
187 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/action.svg" ) );
188 }
189 break;
191 switch ( role )
192 {
193 case Qt::DisplayRole:
194 return tr( "Map Tips" );
195 case Qt::ToolTipRole:
196 return tr( "Map tips" );
197 case Qt::DecorationRole:
198 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/display.svg" ) );
199 }
200 break;
202 switch ( role )
203 {
204 case Qt::DisplayRole:
205 case Qt::ToolTipRole:
206 return tr( "Diagrams" );
207 case Qt::DecorationRole:
208 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/diagram.svg" ) );
209 }
210 break;
212 switch ( role )
213 {
214 case Qt::DisplayRole:
215 return tr( "Attribute Table Configuration" );
216 case Qt::ToolTipRole:
217 return tr( "Choice and order of columns, conditional styling" );
218 case Qt::DecorationRole:
219 return QgsApplication::getThemeIcon( QStringLiteral( "/mActionOpenTable.svg" ) );
220 }
221 break;
223 switch ( role )
224 {
225 case Qt::DisplayRole:
226 return tr( "Rendering" );
227 case Qt::ToolTipRole:
228 return tr( "Scale visibility, simplify method, opacity" );
229 case Qt::DecorationRole:
230 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/rendering.svg" ) );
231 }
232 break;
234 switch ( role )
235 {
236 case Qt::DisplayRole:
237 return tr( "Custom Properties" );
238 case Qt::ToolTipRole:
239 return tr( "Variables, custom properties (often used by plugins and custom python code)" );
240 case Qt::DecorationRole:
241 return QgsApplication::getThemeIcon( QStringLiteral( "/mActionOptions.svg" ) );
242 }
243 break;
245 switch ( role )
246 {
247 case Qt::DisplayRole:
248 return tr( "Geometry Options" );
249 case Qt::ToolTipRole:
250 return tr( "Geometry constraints and validity checks" );
251 case Qt::DecorationRole:
252 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/digitizing.svg" ) );
253 }
254 break;
256 switch ( role )
257 {
258 case Qt::DisplayRole:
259 return tr( "Relations" );
260 case Qt::ToolTipRole:
261 return tr( "Relations with other layers" );
262 case Qt::DecorationRole:
263 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/relations.svg" ) );
264 }
265 break;
266
268 switch ( role )
269 {
270 case Qt::DisplayRole:
271 return tr( "Temporal Properties" );
272 case Qt::ToolTipRole:
273 return tr( "Temporal properties" );
274 case Qt::DecorationRole:
275 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/temporal.svg" ) );
276 }
277 break;
278
280 switch ( role )
281 {
282 case Qt::DisplayRole:
283 return tr( "Legend Settings" );
284 case Qt::ToolTipRole:
285 return tr( "Legend settings" );
286 case Qt::DecorationRole:
287 return QgsApplication::getThemeIcon( QStringLiteral( "/legend.svg" ) );
288 }
289 break;
290
292 switch ( role )
293 {
294 case Qt::DisplayRole:
295 return tr( "Elevation Properties" );
296 case Qt::ToolTipRole:
297 return tr( "Elevation properties" );
298 case Qt::DecorationRole:
299 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/elevationscale.svg" ) );
300 }
301 break;
302
304 switch ( role )
305 {
306 case Qt::DisplayRole:
307 case Qt::ToolTipRole:
308 return tr( "Notes" );
309 case Qt::DecorationRole:
310 return QIcon(); // TODO
311 }
312 break;
313
315 switch ( role )
316 {
317 case Qt::DisplayRole:
318 return tr( "All Style Categories" );
319 case Qt::ToolTipRole:
320 return QVariant();
321 case Qt::DecorationRole:
322 return QVariant();
323 }
324 break;
325
326 }
327 return QVariant();
328}
329
330bool QgsMapLayerStyleCategoriesModel::setData( const QModelIndex &index, const QVariant &value, int role )
331{
332 if ( !index.isValid() || index.row() >= rowCount() )
333 return false;
334
335 if ( role == Qt::CheckStateRole )
336 {
337 const QgsMapLayer::StyleCategory category = data( index, Qt::UserRole ).value<QgsMapLayer::StyleCategory>();
338 if ( value.value<Qt::CheckState>() == Qt::Checked )
339 {
340 mCategories |= category;
341 emit dataChanged( index, index );
342 return true;
343 }
344 else if ( value.value<Qt::CheckState>() == Qt::Unchecked )
345 {
346 mCategories &= ~category;
347 emit dataChanged( index, index );
348 return true;
349 }
350 }
351 return false;
352}
353
354
355Qt::ItemFlags QgsMapLayerStyleCategoriesModel::flags( const QModelIndex & ) const
356{
357 return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
358}
LayerType
Types of layers that can be added to a map.
Definition qgis.h:169
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ Vector
Vector layer.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ Raster
Raster layer.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
void setCategories(QgsMapLayer::StyleCategories categories)
Reset the model data.
int columnCount(const QModelIndex &=QModelIndex()) const override
QgsMapLayerStyleCategoriesModel(Qgis::LayerType type, QObject *parent=nullptr)
Constructor for QgsMapLayerStyleCategoriesModel, for the specified layer type.
Qt::ItemFlags flags(const QModelIndex &) const override
QVariant data(const QModelIndex &index, int role) const override
bool setData(const QModelIndex &index, const QVariant &value, int role) override
QgsMapLayer::StyleCategories categories() const
Returns the categories as defined in the model.
void setShowAllCategories(bool showAll)
Defines if the model should list the AllStyleCategories entry.
int rowCount(const QModelIndex &=QModelIndex()) const override
QFlags< StyleCategory > StyleCategories
StyleCategory
Categories of style to distinguish appropriate sections for import/export.
@ GeometryOptions
Geometry validation configuration.
@ AttributeTable
Attribute table settings: choice and order of columns, conditional styling.
@ LayerConfiguration
General configuration: identifiable, removable, searchable, display expression, read-only.
@ Symbology
Symbology.
@ MapTips
Map tips.
@ Notes
Layer user notes.
@ Temporal
Temporal properties.
@ Rendering
Rendering: scale visibility, simplify method, opacity.
@ Relations
Relations.
@ Elevation
Elevation settings.
@ Symbology3D
3D symbology
@ CustomProperties
Custom properties (by plugins for instance)
@ Actions
Actions.
@ Forms
Feature form.
@ Fields
Aliases, widgets, WMS/WFS, expressions, constraints, virtual fields.
@ Legend
Legend settings.
@ Diagrams
Diagrams.
@ Labeling
Labeling.