QGIS API Documentation 3.41.0-Master (3440c17df1d)
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 );
111
115 double defaultSymbolOpacity() const { return mDefaultSymbolOpacity; }
116
120 void setDefaultSymbolOpacity( double 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
358 void makeDirty();
359
360 friend class TestQgsProjectProperties;
361};
362
371class CORE_EXPORT QgsProjectStyleDatabaseModel : public QAbstractListModel
372{
373 Q_OBJECT
374
375 public:
376
377 // *INDENT-OFF*
378
386 {
387 Style SIP_MONKEYPATCH_COMPAT_NAME( StyleRole ) = Qt::UserRole + 1,
388 Path SIP_MONKEYPATCH_COMPAT_NAME(PathRole)
389 };
390 Q_ENUM( CustomRole )
391 // *INDENT-ON*
392
393
396 explicit QgsProjectStyleDatabaseModel( QgsProjectStyleSettings *settings, QObject *parent SIP_TRANSFERTHIS = nullptr );
397
398 int rowCount( const QModelIndex &parent ) const override;
399 QVariant data( const QModelIndex &index, int role ) const override;
400
405 QgsStyle *styleFromIndex( const QModelIndex &index ) const;
406
411 QModelIndex indexFromStyle( QgsStyle *style ) const;
412
418 void setShowDefaultStyle( bool show );
419
425 bool showDefaultStyle() const { return mShowDefault; }
426
427 private slots:
428 void styleDatabaseAboutToBeAdded( const QString &path );
429 void styleDatabaseAboutToBeRemoved( const QString &path );
430 void styleDatabaseAdded( const QString &path );
431 void styleDatabaseRemoved( const QString &path );
432
433 void setProjectStyle( QgsStyle *style );
434 void projectStyleAboutToBeDestroyed();
435 void projectStyleDestroyed();
436 void projectStyleChanged();
437
438 private:
439 QgsProjectStyleSettings *mSettings = nullptr;
440 bool mShowDefault = false;
441 QPointer< QgsStyle > mProjectStyle;
442};
443
452class CORE_EXPORT QgsProjectStyleDatabaseProxyModel : public QSortFilterProxyModel
453{
454 Q_OBJECT
455
456 public:
457
459 enum class Filter : int SIP_ENUM_BASETYPE( IntFlag )
460 {
461 FilterHideReadOnly = 1 << 0,
462 };
463 Q_ENUM( Filter )
465 Q_DECLARE_FLAGS( Filters, Filter )
466 Q_FLAG( Filters )
467
472
473 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
474
481
487 void setFilters( QgsProjectStyleDatabaseProxyModel::Filters filters );
488
489 private:
490
492
493};
495
496
497#endif // QGSPROJECTSTYLESETTINGS_H
QFlags< ProjectReadFlag > ProjectReadFlags
Project load flags.
Definition qgis.h:4025
SymbolType
Symbol types.
Definition qgis.h:574
ColorModel
Color model types.
Definition qgis.h:5584
@ 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 styleDatabaseRemoved(const QString &path)
Emitted when a style database path is removed.
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:231
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)