QGIS API Documentation 3.39.0-Master (3aed037ce22)
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 "qgis_sip.h"
20#include "qgstextformat.h"
21#include "qgswkbtypes.h"
22
23#include <memory.h>
24#include <QAbstractListModel>
25#include <QColorSpace>
26#include <QSortFilterProxyModel>
27#include <QPointer>
28
29class QDomElement;
31class QDomDocument;
32class QgsProject;
33class QgsSymbol;
34class QgsColorRamp;
35class QgsStyle;
37
45class CORE_EXPORT QgsProjectStyleSettings : public QObject
46{
47 Q_OBJECT
48
49 public:
50
56 QgsProjectStyleSettings( QgsProject *project = nullptr );
57
58 ~QgsProjectStyleSettings() override;
59
66 QgsSymbol *defaultSymbol( Qgis::SymbolType symbolType ) const SIP_FACTORY;
67
74 void setDefaultSymbol( Qgis::SymbolType symbolType, QgsSymbol *symbol );
75
81 QgsColorRamp *defaultColorRamp() const SIP_FACTORY;
82
88 void setDefaultColorRamp( QgsColorRamp *colorRamp );
89
94 QgsTextFormat defaultTextFormat() const;
95
100 void setDefaultTextFormat( const QgsTextFormat &textFormat );
101
105 bool randomizeDefaultSymbolColor() const { return mRandomizeDefaultSymbolColor; }
106
110 void setRandomizeDefaultSymbolColor( bool randomized ) { mRandomizeDefaultSymbolColor = randomized; }
111
115 double defaultSymbolOpacity() const { return mDefaultSymbolOpacity; }
116
120 void setDefaultSymbolOpacity( double opacity ) { mDefaultSymbolOpacity = opacity; }
121
125 void reset();
126
132 void removeProjectStyle();
133
139 void setProjectStyle( QgsStyle *style SIP_TRANSFER );
140
146 QgsStyle *projectStyle();
147
164 void setColorModel( Qgis::ColorModel colorModel );
165
178 Qgis::ColorModel colorModel() const;
179
196 void setColorSpace( const QColorSpace &colorSpace );
197
209 QColorSpace colorSpace() const;
210
215 bool readXml( const QDomElement &element, const QgsReadWriteContext &context, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
216
221 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
222
233 QStringList styleDatabasePaths() const { return mStyleDatabases; }
234
240 QList< QgsStyle * > styles() const;
241
245 QgsStyle *styleAtPath( const QString &path );
246
259 void addStyleDatabasePath( const QString &path );
260
273 void setStyleDatabasePaths( const QStringList &paths );
274
285 QgsCombinedStyleModel *combinedStyleModel();
286
287 signals:
288
293
294#ifndef SIP_RUN
295
301 void styleDatabaseAboutToBeAdded( const QString &path );
302
308 void styleDatabaseAdded( const QString &path );
309
315 void styleDatabaseAboutToBeRemoved( const QString &path );
316
322 void styleDatabaseRemoved( const QString &path );
323
330
331#endif
332 private:
333
334 QgsProject *mProject = nullptr;
335
336 std::unique_ptr< QgsSymbol > mDefaultMarkerSymbol;
337 std::unique_ptr< QgsSymbol > mDefaultLineSymbol;
338 std::unique_ptr< QgsSymbol > mDefaultFillSymbol;
339 std::unique_ptr< QgsColorRamp > mDefaultColorRamp;
340 QgsTextFormat mDefaultTextFormat;
341
342 bool mRandomizeDefaultSymbolColor = true;
343 double mDefaultSymbolOpacity = 1.0;
344
345 QgsStyle *mProjectStyle = nullptr;
346 QStringList mStyleDatabases;
347 QList< QPointer< QgsStyle > > mStyles;
348
349 QgsCombinedStyleModel *mCombinedStyleModel = nullptr;
351 QColorSpace mColorSpace;
352 QString mIccProfileFilePath;
353
354 void loadStyleAtPath( const QString &path );
355 void clearStyles();
356
357 friend class TestQgsProjectProperties;
358};
359
368class CORE_EXPORT QgsProjectStyleDatabaseModel : public QAbstractListModel
369{
370 Q_OBJECT
371
372 public:
373
374 // *INDENT-OFF*
375
383 {
384 Style SIP_MONKEYPATCH_COMPAT_NAME( StyleRole ) = Qt::UserRole + 1,
385 Path SIP_MONKEYPATCH_COMPAT_NAME(PathRole)
386 };
387 Q_ENUM( CustomRole )
388 // *INDENT-ON*
389
390
393 explicit QgsProjectStyleDatabaseModel( QgsProjectStyleSettings *settings, QObject *parent SIP_TRANSFERTHIS = nullptr );
394
395 int rowCount( const QModelIndex &parent ) const override;
396 QVariant data( const QModelIndex &index, int role ) const override;
397
402 QgsStyle *styleFromIndex( const QModelIndex &index ) const;
403
408 QModelIndex indexFromStyle( QgsStyle *style ) const;
409
415 void setShowDefaultStyle( bool show );
416
422 bool showDefaultStyle() const { return mShowDefault; }
423
424 private slots:
425 void styleDatabaseAboutToBeAdded( const QString &path );
426 void styleDatabaseAboutToBeRemoved( const QString &path );
427 void styleDatabaseAdded( const QString &path );
428 void styleDatabaseRemoved( const QString &path );
429
430 void setProjectStyle( QgsStyle *style );
431 void projectStyleAboutToBeDestroyed();
432 void projectStyleDestroyed();
433 void projectStyleChanged();
434
435 private:
436 QgsProjectStyleSettings *mSettings = nullptr;
437 bool mShowDefault = false;
438 QPointer< QgsStyle > mProjectStyle;
439};
440
449class CORE_EXPORT QgsProjectStyleDatabaseProxyModel : public QSortFilterProxyModel
450{
451 Q_OBJECT
452
453 public:
454
456 enum class Filter : int SIP_ENUM_BASETYPE( IntFlag )
457 {
458 FilterHideReadOnly = 1 << 0,
459 };
460 Q_ENUM( Filter )
462 Q_DECLARE_FLAGS( Filters, Filter )
463 Q_FLAG( Filters )
464
469
470 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
471
478
484 void setFilters( QgsProjectStyleDatabaseProxyModel::Filters filters );
485
486 private:
487
489
490};
492
493
494#endif // QGSPROJECTSTYLESETTINGS_H
QFlags< ProjectReadFlag > ProjectReadFlags
Project load flags.
Definition qgis.h:3833
SymbolType
Symbol types.
Definition qgis.h:500
ColorModel
Color model types.
Definition qgis.h:5311
@ Rgb
RGB color model.
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.
QFlags< Filter > Filters
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_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)