QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsprojectstylesettings.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsprojectstylesettings.h
3 ---------------------------
4 begin : May 2022
5 copyright : (C) 2022 by Mathieu Pellerin
6 email : nirvn dot asia at gmail dot com
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#ifndef QGSPROJECTSTYLESETTINGS_H
16#define QGSPROJECTSTYLESETTINGS_H
17
18#include "qgis_core.h"
19#include "qgstextformat.h"
20#include "qgswkbtypes.h"
21
22#include <memory.h>
23#include <QAbstractListModel>
24#include <QSortFilterProxyModel>
25#include <QPointer>
26
27class QDomElement;
29class QDomDocument;
30class QgsProject;
31class QgsSymbol;
32class QgsColorRamp;
33class QgsStyle;
35
43class CORE_EXPORT QgsProjectStyleSettings : public QObject
44{
45 Q_OBJECT
46
47 public:
48
54 QgsProjectStyleSettings( QgsProject *project = nullptr );
55
56 ~QgsProjectStyleSettings() override;
57
64 QgsSymbol *defaultSymbol( Qgis::SymbolType symbolType ) const SIP_FACTORY;
65
72 void setDefaultSymbol( Qgis::SymbolType symbolType, QgsSymbol *symbol );
73
79 QgsColorRamp *defaultColorRamp() const SIP_FACTORY;
80
86 void setDefaultColorRamp( QgsColorRamp *colorRamp );
87
92 QgsTextFormat defaultTextFormat() const;
93
98 void setDefaultTextFormat( const QgsTextFormat &textFormat );
99
103 bool randomizeDefaultSymbolColor() const { return mRandomizeDefaultSymbolColor; }
104
108 void setRandomizeDefaultSymbolColor( bool randomized ) { mRandomizeDefaultSymbolColor = randomized; }
109
113 double defaultSymbolOpacity() const { return mDefaultSymbolOpacity; }
114
118 void setDefaultSymbolOpacity( double opacity ) { mDefaultSymbolOpacity = opacity; }
119
123 void reset();
124
130 void removeProjectStyle();
131
137 void setProjectStyle( QgsStyle *style SIP_TRANSFER );
138
144 QgsStyle *projectStyle();
145
150 bool readXml( const QDomElement &element, const QgsReadWriteContext &context, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
151
156 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
157
168 QStringList styleDatabasePaths() const { return mStyleDatabases; }
169
175 QList< QgsStyle * > styles() const;
176
180 QgsStyle *styleAtPath( const QString &path );
181
194 void addStyleDatabasePath( const QString &path );
195
208 void setStyleDatabasePaths( const QStringList &paths );
209
220 QgsCombinedStyleModel *combinedStyleModel();
221
222 signals:
223
228
229#ifndef SIP_RUN
230
236 void styleDatabaseAboutToBeAdded( const QString &path );
237
243 void styleDatabaseAdded( const QString &path );
244
250 void styleDatabaseAboutToBeRemoved( const QString &path );
251
257 void styleDatabaseRemoved( const QString &path );
258
265
266#endif
267 private:
268
269 QgsProject *mProject = nullptr;
270
271 std::unique_ptr< QgsSymbol > mDefaultMarkerSymbol;
272 std::unique_ptr< QgsSymbol > mDefaultLineSymbol;
273 std::unique_ptr< QgsSymbol > mDefaultFillSymbol;
274 std::unique_ptr< QgsColorRamp > mDefaultColorRamp;
275 QgsTextFormat mDefaultTextFormat;
276
277 bool mRandomizeDefaultSymbolColor = true;
278 double mDefaultSymbolOpacity = 1.0;
279
280 QgsStyle *mProjectStyle = nullptr;
281 QStringList mStyleDatabases;
282 QList< QPointer< QgsStyle > > mStyles;
283
284 QgsCombinedStyleModel *mCombinedStyleModel = nullptr;
285
286 void loadStyleAtPath( const QString &path );
287 void clearStyles();
288
289};
290
299class CORE_EXPORT QgsProjectStyleDatabaseModel : public QAbstractListModel
300{
301 Q_OBJECT
302
303 public:
304
306 enum Role
307 {
308 StyleRole = Qt::UserRole + 1,
310 };
311
315 explicit QgsProjectStyleDatabaseModel( QgsProjectStyleSettings *settings, QObject *parent SIP_TRANSFERTHIS = nullptr );
316
317 int rowCount( const QModelIndex &parent ) const override;
318 QVariant data( const QModelIndex &index, int role ) const override;
319
324 QgsStyle *styleFromIndex( const QModelIndex &index ) const;
325
330 QModelIndex indexFromStyle( QgsStyle *style ) const;
331
337 void setShowDefaultStyle( bool show );
338
344 bool showDefaultStyle() const { return mShowDefault; }
345
346 private slots:
347 void styleDatabaseAboutToBeAdded( const QString &path );
348 void styleDatabaseAboutToBeRemoved( const QString &path );
349 void styleDatabaseAdded( const QString &path );
350 void styleDatabaseRemoved( const QString &path );
351
352 void setProjectStyle( QgsStyle *style );
353 void projectStyleAboutToBeDestroyed();
354 void projectStyleDestroyed();
355 void projectStyleChanged();
356
357 private:
358 QgsProjectStyleSettings *mSettings = nullptr;
359 bool mShowDefault = false;
360 QPointer< QgsStyle > mProjectStyle;
361};
362
371class CORE_EXPORT QgsProjectStyleDatabaseProxyModel : public QSortFilterProxyModel
372{
373 Q_OBJECT
374
375 public:
376
378 enum class Filter
379 {
380 FilterHideReadOnly = 1 << 0,
381 };
382 Q_ENUM( Filter )
384 Q_DECLARE_FLAGS( Filters, Filter )
385 Q_FLAG( Filters )
386
387
391
392 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
393
399 QgsProjectStyleDatabaseProxyModel::Filters filters() const;
400
406 void setFilters( QgsProjectStyleDatabaseProxyModel::Filters filters );
407
408 private:
409
410 QgsProjectStyleDatabaseProxyModel::Filters mFilters;
411
412};
413Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProjectStyleDatabaseProxyModel::Filters )
414
415
416#endif // QGSPROJECTSTYLESETTINGS_H
SymbolType
Attribute editing capabilities which may be supported by vector data providers.
Definition qgis.h:368
Abstract base class for color ramps.
A model which contains entities from multiple QgsStyle databases.
List model representing the style databases associated with a QgsProject.
bool showDefaultStyle() const
Returns true if the model includes the default style.
A proxy model for filtering QgsProjectStyleDatabaseModel.
Filter
Available filter flags for filtering the model.
Contains settings and properties relating to how a QgsProject should handle styling.
double defaultSymbolOpacity() const
Returns the default symbol opacity.
void projectStyleChanged()
Emitted when the style returned by projectStyle() is changed.
bool randomizeDefaultSymbolColor() const
Returns whether the default symbol fill color is randomized.
QStringList styleDatabasePaths() const
Returns a list of all style databases (file paths) associated with the project.
void styleDatabaseAdded(const QString &path)
Emitted when a style database path is added.
void styleDatabaseAboutToBeRemoved(const QString &path)
Emitted when a style database path is about to be removed.
void setRandomizeDefaultSymbolColor(bool randomized)
Sets whether the default symbol fill color is randomized.
void styleDatabaseRemoved(const QString &path)
Emitted when a style database path is removed.
void setDefaultSymbolOpacity(double opacity)
Sets the default symbol opacity.
void styleDatabaseAboutToBeAdded(const QString &path)
Emitted when a style database path is about to be added.
void styleDatabasesChanged()
Emitted whenever the set of style databases associated with the project is changed.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
The class is used as a container of context for various read/write operations on other objects.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:94
Container for all settings relating to text rendering.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:76
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)