QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
34 break;
41 // not yet handled by the model
42 break;
43 }
44
45 // move All categories to top
46 int idxAllStyleCategories = mCategoryList.indexOf( QgsMapLayer::AllStyleCategories );
47 if ( idxAllStyleCategories > 0 )
48 {
49 mCategoryList.move( idxAllStyleCategories, 0 );
50 }
51}
52
53void QgsMapLayerStyleCategoriesModel::setCategories( QgsMapLayer::StyleCategories categories )
54{
55 if ( mCategories == categories )
56 return;
57
58 beginResetModel();
59 mCategories = categories;
60 endResetModel();
61}
62
63QgsMapLayer::StyleCategories QgsMapLayerStyleCategoriesModel::categories() const
64{
65 return mCategories;
66}
67
69{
70 beginResetModel();
71 mShowAllCategories = showAll;
72 endResetModel();
73}
74
75int QgsMapLayerStyleCategoriesModel::rowCount( const QModelIndex & ) const
76{
77 int count = mCategoryList.count();
78 if ( count > 0 && !mShowAllCategories )
79 count--;
80 return count;
81}
82
83int QgsMapLayerStyleCategoriesModel::columnCount( const QModelIndex & ) const
84{
85 return 1;
86}
87
88QVariant QgsMapLayerStyleCategoriesModel::data( const QModelIndex &index, int role ) const
89{
90 if ( !index.isValid() || index.row() >= rowCount() )
91 return QVariant();
92
93 const QgsMapLayer::StyleCategory category = mCategoryList.at( index.row() + ( mShowAllCategories ? 0 : 1 ) );
94
95 if ( role == Qt::UserRole )
96 {
97 return category;
98 }
99 if ( role == Qt::CheckStateRole )
100 {
101 return mCategories.testFlag( category ) ? Qt::Checked : Qt::Unchecked;
102 }
103
104 switch ( category )
105 {
107 switch ( role )
108 {
109 case Qt::DisplayRole:
110 return tr( "Layer Configuration" );
111 case Qt::ToolTipRole:
112 return tr( "Identifiable, removable, searchable, display expression, read-only, hidden" );
113 case Qt::DecorationRole:
114 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/system.svg" ) );
115 }
116 break;
118 switch ( role )
119 {
120 case Qt::DisplayRole:
121 return tr( "Symbology" );
122 case Qt::ToolTipRole:
123 return QVariant();
124 case Qt::DecorationRole:
125 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/symbology.svg" ) );
126 }
127 break;
129 switch ( role )
130 {
131 case Qt::DisplayRole:
132 return tr( "3D Symbology" );
133 case Qt::ToolTipRole:
134 return QVariant();
135 case Qt::DecorationRole:
136 return QgsApplication::getThemeIcon( QStringLiteral( "/3d.svg" ) );
137 }
138 break;
140 switch ( role )
141 {
142 case Qt::DisplayRole:
143 return tr( "Labels" );
144 case Qt::ToolTipRole:
145 return QVariant();
146 case Qt::DecorationRole:
147 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/labels.svg" ) );
148 }
149 break;
151 switch ( role )
152 {
153 case Qt::DisplayRole:
154 return tr( "Fields" );
155 case Qt::ToolTipRole:
156 return tr( "Aliases, widgets, WMS/WFS, expressions, constraints, virtual fields" );
157 case Qt::DecorationRole:
158 return QgsApplication::getThemeIcon( QStringLiteral( "/mSourceFields.svg" ) );
159 }
160 break;
162 switch ( role )
163 {
164 case Qt::DisplayRole:
165 return tr( "Forms" );
166 case Qt::ToolTipRole:
167 return QVariant();
168 case Qt::DecorationRole:
169 return QgsApplication::getThemeIcon( QStringLiteral( "/mActionFormView.svg" ) );
170 }
171 break;
173 switch ( role )
174 {
175 case Qt::DisplayRole:
176 return tr( "Actions" );
177 case Qt::ToolTipRole:
178 return QVariant();
179 case Qt::DecorationRole:
180 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/action.svg" ) );
181 }
182 break;
184 switch ( role )
185 {
186 case Qt::DisplayRole:
187 return tr( "Map Tips" );
188 case Qt::ToolTipRole:
189 return QVariant();
190 case Qt::DecorationRole:
191 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/display.svg" ) );
192 }
193 break;
195 switch ( role )
196 {
197 case Qt::DisplayRole:
198 return tr( "Diagrams" );
199 case Qt::ToolTipRole:
200 return QVariant();
201 case Qt::DecorationRole:
202 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/diagram.svg" ) );
203 }
204 break;
206 switch ( role )
207 {
208 case Qt::DisplayRole:
209 return tr( "Attribute Table Settings" );
210 case Qt::ToolTipRole:
211 return tr( "Choice and order of columns, conditional styling" );
212 case Qt::DecorationRole:
213 return QgsApplication::getThemeIcon( QStringLiteral( "/mActionOpenTable.svg" ) );
214 }
215 break;
217 switch ( role )
218 {
219 case Qt::DisplayRole:
220 return tr( "Rendering" );
221 case Qt::ToolTipRole:
222 return tr( "Scale visibility, simplify method, opacity" );
223 case Qt::DecorationRole:
224 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/rendering.svg" ) );
225 }
226 break;
228 switch ( role )
229 {
230 case Qt::DisplayRole:
231 return tr( "Custom Properties" );
232 case Qt::ToolTipRole:
233 return QVariant();
234 case Qt::DecorationRole:
235 return QgsApplication::getThemeIcon( QStringLiteral( "/mActionOptions.svg" ) );
236 }
237 break;
239 switch ( role )
240 {
241 case Qt::DisplayRole:
242 return tr( "Geometry Options" );
243 case Qt::ToolTipRole:
244 return tr( "Geometry constraints and validity checks" );
245 case Qt::DecorationRole:
246 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/digitizing.svg" ) );
247 }
248 break;
250 switch ( role )
251 {
252 case Qt::DisplayRole:
253 return tr( "Relations" );
254 case Qt::ToolTipRole:
255 return tr( "Relations with other layers" );
256 case Qt::DecorationRole:
257 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/relations.svg" ) );
258 }
259 break;
260
262 switch ( role )
263 {
264 case Qt::DisplayRole:
265 return tr( "Temporal Properties" );
266 case Qt::ToolTipRole:
267 return tr( "Temporal properties" );
268 case Qt::DecorationRole:
269 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/temporal.svg" ) );
270 }
271 break;
272
274 switch ( role )
275 {
276 case Qt::DisplayRole:
277 return tr( "Legend Settings" );
278 case Qt::ToolTipRole:
279 return tr( "Legend settings" );
280 case Qt::DecorationRole:
281 return QgsApplication::getThemeIcon( QStringLiteral( "/legend.svg" ) );
282 }
283 break;
284
286 switch ( role )
287 {
288 case Qt::DisplayRole:
289 return tr( "Elevation Properties" );
290 case Qt::ToolTipRole:
291 return tr( "Elevation properties" );
292 case Qt::DecorationRole:
293 return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/elevationscale.svg" ) );
294 }
295 break;
296
298 switch ( role )
299 {
300 case Qt::DisplayRole:
301 case Qt::ToolTipRole:
302 return tr( "Notes" );
303 case Qt::DecorationRole:
304 return QIcon(); // TODO
305 }
306 break;
307
309 switch ( role )
310 {
311 case Qt::DisplayRole:
312 return tr( "All Style Categories" );
313 case Qt::ToolTipRole:
314 return QVariant();
315 case Qt::DecorationRole:
316 return QVariant();
317 }
318 break;
319
320 }
321 return QVariant();
322}
323
324bool QgsMapLayerStyleCategoriesModel::setData( const QModelIndex &index, const QVariant &value, int role )
325{
326 if ( !index.isValid() || index.row() >= rowCount() )
327 return false;
328
329 if ( role == Qt::CheckStateRole )
330 {
331 const QgsMapLayer::StyleCategory category = data( index, Qt::UserRole ).value<QgsMapLayer::StyleCategory>();
332 if ( value.value<Qt::CheckState>() == Qt::Checked )
333 {
334 mCategories |= category;
335 emit dataChanged( index, index );
336 return true;
337 }
338 else if ( value.value<Qt::CheckState>() == Qt::Unchecked )
339 {
340 mCategories &= ~category;
341 emit dataChanged( index, index );
342 return true;
343 }
344 }
345 return false;
346}
347
348
349Qt::ItemFlags QgsMapLayerStyleCategoriesModel::flags( const QModelIndex & ) const
350{
351 return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
352}
LayerType
Types of layers that can be added to a map.
Definition qgis.h:114
@ 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
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 (since QGIS 3.20)
@ Temporal
Temporal properties (since QGIS 3.14)
@ Rendering
Rendering: scale visibility, simplify method, opacity.
@ Relations
Relations.
@ Elevation
Elevation settings (since QGIS 3.18)
@ 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 (since QGIS 3.16)
@ Diagrams
Diagrams.
@ Labeling
Labeling.