QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 <memory.h>
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
22#include "qgstextformat.h"
23#include "qgswkbtypes.h"
24
25#include <QAbstractListModel>
26#include <QColorSpace>
27#include <QPointer>
28#include <QSortFilterProxyModel>
29
30class QDomElement;
32class QDomDocument;
33class QgsProject;
34class QgsSymbol;
35class QgsColorRamp;
36class QgsStyle;
38
46class CORE_EXPORT QgsProjectStyleSettings : public QObject
47{
48 Q_OBJECT
49
50 public:
51
57 QgsProjectStyleSettings( QgsProject *project = nullptr );
58
59 ~QgsProjectStyleSettings() override;
60
68
75 void setDefaultSymbol( Qgis::SymbolType symbolType, QgsSymbol *symbol );
76
83
89 void setDefaultColorRamp( QgsColorRamp *colorRamp );
90
96
101 void setDefaultTextFormat( const QgsTextFormat &textFormat );
102
106 bool randomizeDefaultSymbolColor() const { return mRandomizeDefaultSymbolColor; }
107
111 void setRandomizeDefaultSymbolColor( bool randomized );
112
116 double defaultSymbolOpacity() const { return mDefaultSymbolOpacity; }
117
121 void setDefaultSymbolOpacity( double opacity );
122
126 void reset();
127
133 void removeProjectStyle();
134
140 void setProjectStyle( QgsStyle *style SIP_TRANSFER );
141
147 QgsStyle *projectStyle();
148
165 void setColorModel( Qgis::ColorModel colorModel );
166
179 Qgis::ColorModel colorModel() const;
180
197 void setColorSpace( const QColorSpace &colorSpace );
198
210 QColorSpace colorSpace() const;
211
216 bool readXml( const QDomElement &element, const QgsReadWriteContext &context, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
217
222 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
223
234 QStringList styleDatabasePaths() const { return mStyleDatabases; }
235
241 QList< QgsStyle * > styles() const;
242
246 QgsStyle *styleAtPath( const QString &path );
247
260 void addStyleDatabasePath( const QString &path );
261
274 void setStyleDatabasePaths( const QStringList &paths );
275
286 QgsCombinedStyleModel *combinedStyleModel();
287
288 signals:
289
294
295#ifndef SIP_RUN
296
302 void styleDatabaseAboutToBeAdded( const QString &path );
303
309 void styleDatabaseAdded( const QString &path );
310
316 void styleDatabaseAboutToBeRemoved( const QString &path );
317
323 void styleDatabaseRemoved( const QString &path );
324
331
332#endif
333 private:
334
335 QgsProject *mProject = nullptr;
336
337 std::unique_ptr< QgsSymbol > mDefaultMarkerSymbol;
338 std::unique_ptr< QgsSymbol > mDefaultLineSymbol;
339 std::unique_ptr< QgsSymbol > mDefaultFillSymbol;
340 std::unique_ptr< QgsColorRamp > mDefaultColorRamp;
341 QgsTextFormat mDefaultTextFormat;
342
343 bool mRandomizeDefaultSymbolColor = true;
344 double mDefaultSymbolOpacity = 1.0;
345
346 QgsStyle *mProjectStyle = nullptr;
347 QStringList mStyleDatabases;
348 QList< QPointer< QgsStyle > > mStyles;
349
350 QgsCombinedStyleModel *mCombinedStyleModel = nullptr;
352 QColorSpace mColorSpace;
353 QString mIccProfileFilePath;
354
355 void loadStyleAtPath( const QString &path );
356 void clearStyles();
357
359 void makeDirty();
360
362};
363
372class CORE_EXPORT QgsProjectStyleDatabaseModel : public QAbstractListModel
373{
374 Q_OBJECT
375
376 public:
377
378 // *INDENT-OFF*
379
387 {
388 Style SIP_MONKEYPATCH_COMPAT_NAME( StyleRole ) = Qt::UserRole + 1,
390 };
391 Q_ENUM( CustomRole )
392 // *INDENT-ON*
393
394
397 explicit QgsProjectStyleDatabaseModel( QgsProjectStyleSettings *settings, QObject *parent SIP_TRANSFERTHIS = nullptr );
398
399 int rowCount( const QModelIndex &parent ) const override;
400 QVariant data( const QModelIndex &index, int role ) const override;
401
406 QgsStyle *styleFromIndex( const QModelIndex &index ) const;
407
412 QModelIndex indexFromStyle( QgsStyle *style ) const;
413
419 void setShowDefaultStyle( bool show );
420
426 bool showDefaultStyle() const { return mShowDefault; }
427
428 private slots:
429 void styleDatabaseAboutToBeAdded( const QString &path );
430 void styleDatabaseAboutToBeRemoved( const QString &path );
431 void styleDatabaseAdded( const QString &path );
432 void styleDatabaseRemoved( const QString &path );
433
434 void setProjectStyle( QgsStyle *style );
435 void projectStyleAboutToBeDestroyed();
436 void projectStyleDestroyed();
437 void projectStyleChanged();
438
439 private:
440 QgsProjectStyleSettings *mSettings = nullptr;
441 bool mShowDefault = false;
442 QPointer< QgsStyle > mProjectStyle;
443};
444
453class CORE_EXPORT QgsProjectStyleDatabaseProxyModel : public QSortFilterProxyModel
454{
455 Q_OBJECT
456
457 public:
458
460 enum class Filter : int SIP_ENUM_BASETYPE( IntFlag )
461 {
462 FilterHideReadOnly = 1 << 0,
463 };
464 Q_ENUM( Filter )
466 Q_DECLARE_FLAGS( Filters, Filter )
467 Q_FLAG( Filters )
468
473
474 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
475
482
489
490 private:
491
493
494};
496
497
498#endif // QGSPROJECTSTYLESETTINGS_H
QFlags< ProjectReadFlag > ProjectReadFlags
Project load flags.
Definition qgis.h:4321
SymbolType
Symbol types.
Definition qgis.h:610
ColorModel
Color model types.
Definition qgis.h:5986
@ Rgb
RGB color model.
Definition qgis.h:5987
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.
QgsProjectStyleDatabaseModel(QgsProjectStyleSettings *settings, QObject *parent=nullptr)
Constructor for QgsProjectStyleDatabaseModel, showing the styles from the specified settings.
Filter
Available filter flags for filtering the model.
QgsProjectStyleDatabaseProxyModel::Filters filters() const
Returns the current filters used for filtering available style.
QFlags< Filter > Filters
Available filter flags for filtering the model.
void setFilters(QgsProjectStyleDatabaseProxyModel::Filters filters)
Sets the current filters used for filtering available styles.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
QgsProjectStyleDatabaseProxyModel(QgsProjectStyleDatabaseModel *model, QObject *parent=nullptr)
Constructor for QgsProjectStyleDatabaseProxyModel, for the specified style database model.
Contains settings and properties relating to how a QgsProject should handle styling.
void setDefaultTextFormat(const QgsTextFormat &textFormat)
Sets the project default text format.
QgsTextFormat defaultTextFormat() const
Returns the project default text format.
double defaultSymbolOpacity() const
Returns the default symbol opacity.
void projectStyleChanged()
Emitted when the style returned by projectStyle() is changed.
QgsColorRamp * defaultColorRamp() const
Returns the project default color ramp.
QgsSymbol * defaultSymbol(Qgis::SymbolType symbolType) const
Returns the project default symbol for a given type.
void setDefaultSymbol(Qgis::SymbolType symbolType, QgsSymbol *symbol)
Sets the project default symbol for a given type.
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.
QgsProjectStyleSettings(QgsProject *project=nullptr)
Constructor for QgsProjectStyleSettings for the specified 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 setDefaultColorRamp(QgsColorRamp *colorRamp)
Sets the project default color ramp.
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:109
A container for the context for various read/write operations on objects.
A database of saved style entities, including symbols, color ramps, text formats and others.
Definition qgsstyle.h:88
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:275
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:268
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:270
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)