QGIS API Documentation 4.1.0-Master (60fea48833c)
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:
56 QgsProjectStyleSettings( QgsProject *project = nullptr );
57
58 ~QgsProjectStyleSettings() override;
59
67
74 void setDefaultSymbol( Qgis::SymbolType symbolType, QgsSymbol *symbol );
75
82
88 void setDefaultColorRamp( QgsColorRamp *colorRamp );
89
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 QgsProject *mProject = nullptr;
334
335 std::unique_ptr< QgsSymbol > mDefaultMarkerSymbol;
336 std::unique_ptr< QgsSymbol > mDefaultLineSymbol;
337 std::unique_ptr< QgsSymbol > mDefaultFillSymbol;
338 std::unique_ptr< QgsColorRamp > mDefaultColorRamp;
339 QgsTextFormat mDefaultTextFormat;
340
341 bool mRandomizeDefaultSymbolColor = true;
342 double mDefaultSymbolOpacity = 1.0;
343
344 QgsStyle *mProjectStyle = nullptr;
345 QStringList mStyleDatabases;
346 QList< QPointer< QgsStyle > > mStyles;
347
348 QgsCombinedStyleModel *mCombinedStyleModel = nullptr;
350 QColorSpace mColorSpace;
351 QString mIccProfileFilePath;
352
353 void loadStyleAtPath( const QString &path );
354 void clearStyles();
355
357 void makeDirty();
358
360};
361
370class CORE_EXPORT QgsProjectStyleDatabaseModel : public QAbstractListModel
371{
372 Q_OBJECT
373
374 public:
375 // *INDENT-OFF*
376
384 {
385 Style SIP_MONKEYPATCH_COMPAT_NAME( StyleRole ) = Qt::UserRole + 1,
387 };
388 Q_ENUM( CustomRole )
389 // *INDENT-ON*
390
391
394 explicit QgsProjectStyleDatabaseModel( QgsProjectStyleSettings *settings, QObject *parent SIP_TRANSFERTHIS = nullptr );
395
396 int rowCount( const QModelIndex &parent ) const override;
397 QVariant data( const QModelIndex &index, int role ) const override;
398
403 QgsStyle *styleFromIndex( const QModelIndex &index ) const;
404
409 QModelIndex indexFromStyle( QgsStyle *style ) const;
410
416 void setShowDefaultStyle( bool show );
417
423 bool showDefaultStyle() const { return mShowDefault; }
424
425 private slots:
426 void styleDatabaseAboutToBeAdded( const QString &path );
427 void styleDatabaseAboutToBeRemoved( const QString &path );
428 void styleDatabaseAdded( const QString &path );
429 void styleDatabaseRemoved( const QString &path );
430
431 void setProjectStyle( QgsStyle *style );
432 void projectStyleAboutToBeDestroyed();
433 void projectStyleDestroyed();
434 void projectStyleChanged();
435
436 private:
437 QgsProjectStyleSettings *mSettings = nullptr;
438 bool mShowDefault = false;
439 QPointer< QgsStyle > mProjectStyle;
440};
441
450class CORE_EXPORT QgsProjectStyleDatabaseProxyModel : public QSortFilterProxyModel
451{
452 Q_OBJECT
453
454 public:
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
485
486 private:
488};
490
491
492#endif // QGSPROJECTSTYLESETTINGS_H
QFlags< ProjectReadFlag > ProjectReadFlags
Project load flags.
Definition qgis.h:4465
SymbolType
Symbol types.
Definition qgis.h:636
ColorModel
Color model types.
Definition qgis.h:6344
@ Rgb
RGB color model.
Definition qgis.h:6345
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:113
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:89
Abstract base class for all rendered symbols.
Definition qgssymbol.h:227
Container for all settings relating to text rendering.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:274
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:267
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:269
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)