QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
qgsprojectstylesettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprojectstylesettings.cpp
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
17#include "qgis.h"
18#include "qgsproject.h"
19#include "qgssymbol.h"
20#include "qgssymbollayerutils.h"
21#include "qgsmarkersymbol.h"
22#include "qgslinesymbol.h"
23#include "qgsfillsymbol.h"
24#include "qgscolorramp.h"
25#include "qgstextformat.h"
26#include "qgsstyle.h"
28
29#include <QDomElement>
30
32 : QObject( project )
33 , mProject( project )
34{
35 mCombinedStyleModel = new QgsCombinedStyleModel( this );
36}
37
39{
40 if ( mProjectStyle )
41 {
42 mProjectStyle->deleteLater();
43 mProjectStyle = nullptr;
44 }
45}
46
48{
49 switch ( symbolType )
50 {
52 return mDefaultMarkerSymbol ? mDefaultMarkerSymbol->clone() : nullptr;
53
55 return mDefaultLineSymbol ? mDefaultLineSymbol->clone() : nullptr;
56
58 return mDefaultFillSymbol ? mDefaultFillSymbol->clone() : nullptr;
59
61 break;
62 }
63
64 return nullptr;
65}
66
68{
69 switch ( symbolType )
70 {
72 mDefaultMarkerSymbol.reset( symbol ? symbol->clone() : nullptr );
73 break;
74
76 mDefaultLineSymbol.reset( symbol ? symbol->clone() : nullptr );
77 break;
78
80 mDefaultFillSymbol.reset( symbol ? symbol->clone() : nullptr );
81 break;
82
84 break;
85 }
86}
87
89{
90 return mDefaultColorRamp ? mDefaultColorRamp->clone() : nullptr;
91}
92
94{
95 mDefaultColorRamp.reset( colorRamp ? colorRamp->clone() : nullptr );
96}
97
99{
100 return mDefaultTextFormat;
101}
102
104{
105 mDefaultTextFormat = textFormat;
106}
107
109{
110 mDefaultMarkerSymbol.reset();
111 mDefaultLineSymbol.reset();
112 mDefaultFillSymbol.reset();
113 mDefaultColorRamp.reset();
114 mDefaultTextFormat = QgsTextFormat();
115 mRandomizeDefaultSymbolColor = true;
116 mDefaultSymbolOpacity = 1.0;
117
118 clearStyles();
119
120 if ( mProject && ( mProject->capabilities() & Qgis::ProjectCapability::ProjectStyles ) )
121 {
122 const QString stylePath = mProject->createAttachedFile( QStringLiteral( "styles.db" ) );
123 QgsStyle *style = new QgsStyle();
124 style->createDatabase( stylePath );
125 style->setName( tr( "Project Style" ) );
126 style->setFileName( stylePath );
127 setProjectStyle( style );
128 }
129
131}
132
134{
135 if ( mProjectStyle )
136 {
137 mCombinedStyleModel->removeStyle( mProjectStyle );
138 mProjectStyle->deleteLater();
139 }
140 mProjectStyle = style;
141 mProjectStyle->setName( tr( "Project Styles" ) );
142
143 // if project color scheme changes, we need to redraw symbols - they may use project colors and accordingly
144 // need updating to reflect the new colors
145 if ( mProject )
146 {
147 connect( mProject, &QgsProject::projectColorsChanged, mProjectStyle, &QgsStyle::triggerIconRebuild );
148 }
149 mCombinedStyleModel->addStyle( mProjectStyle );
150
151 emit projectStyleChanged();
152}
153
155{
156 return mProjectStyle;
157}
158
159bool QgsProjectStyleSettings::readXml( const QDomElement &element, const QgsReadWriteContext &context, Qgis::ProjectReadFlags )
160{
161 mRandomizeDefaultSymbolColor = element.attribute( QStringLiteral( "RandomizeDefaultSymbolColor" ), QStringLiteral( "0" ) ).toInt();
162 mDefaultSymbolOpacity = element.attribute( QStringLiteral( "DefaultSymbolOpacity" ), QStringLiteral( "1.0" ) ).toDouble();
163
164 QDomElement elem = element.firstChildElement( QStringLiteral( "markerSymbol" ) );
165 if ( !elem.isNull() )
166 {
167 QDomElement symbolElem = elem.firstChildElement( QStringLiteral( "symbol" ) );
168 mDefaultMarkerSymbol.reset( !symbolElem.isNull() ? QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( symbolElem, context ) : nullptr );
169 }
170 else
171 {
172 mDefaultMarkerSymbol.reset();
173 }
174
175 elem = element.firstChildElement( QStringLiteral( "lineSymbol" ) );
176 if ( !elem.isNull() )
177 {
178 QDomElement symbolElem = elem.firstChildElement( QStringLiteral( "symbol" ) );
179 mDefaultLineSymbol.reset( !symbolElem.isNull() ? QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) : nullptr );
180 }
181 else
182 {
183 mDefaultLineSymbol.reset();
184 }
185
186 elem = element.firstChildElement( QStringLiteral( "fillSymbol" ) );
187 if ( !elem.isNull() )
188 {
189 QDomElement symbolElem = elem.firstChildElement( QStringLiteral( "symbol" ) );
190 mDefaultFillSymbol.reset( !symbolElem.isNull() ? QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem, context ) : nullptr );
191 }
192 else
193 {
194 mDefaultFillSymbol.reset();
195 }
196
197 elem = element.firstChildElement( QStringLiteral( "colorramp" ) );
198 mDefaultColorRamp.reset( !elem.isNull() ? QgsSymbolLayerUtils::loadColorRamp( elem ) : nullptr );
199
200 elem = element.firstChildElement( QStringLiteral( "text-style" ) );
201 if ( !elem.isNull() )
202 {
203 mDefaultTextFormat.readXml( elem, context );
204 }
205 else
206 {
207 mDefaultTextFormat = QgsTextFormat();
208 }
209
210 {
211 clearStyles();
212 if ( !mProject || ( mProject->capabilities() & Qgis::ProjectCapability::ProjectStyles ) )
213 {
214 const QDomElement styleDatabases = element.firstChildElement( QStringLiteral( "databases" ) );
215 if ( !styleDatabases.isNull() )
216 {
217 const QDomNodeList styleEntries = styleDatabases.childNodes();
218 for ( int i = 0; i < styleEntries.count(); ++i )
219 {
220 const QDomElement styleElement = styleEntries.at( i ).toElement();
221 const QString path = styleElement.attribute( QStringLiteral( "path" ) );
222 const QString fullPath = context.pathResolver().readPath( path );
223 emit styleDatabaseAboutToBeAdded( fullPath );
224 mStyleDatabases.append( fullPath );
225 loadStyleAtPath( fullPath );
226 emit styleDatabaseAdded( fullPath );
227 }
228 }
229
230 if ( mProject && ( mProject->capabilities() & Qgis::ProjectCapability::ProjectStyles ) )
231 {
232 const QString projectStyleId = element.attribute( QStringLiteral( "projectStyleId" ) );
233 const QString projectStyleFile = mProject->resolveAttachmentIdentifier( projectStyleId );
234 QgsStyle *style = new QgsStyle();
235 if ( !projectStyleFile.isEmpty() && QFile::exists( projectStyleFile ) )
236 {
237 style->load( projectStyleFile );
238 style->setFileName( projectStyleFile );
239 }
240 else
241 {
242 const QString stylePath = mProject->createAttachedFile( QStringLiteral( "styles.db" ) );
243 style->createDatabase( stylePath );
244 style->setFileName( stylePath );
245 }
246 style->setName( tr( "Project Style" ) );
247 setProjectStyle( style );
248 }
249 }
250 }
251
253
254 return true;
255}
256
257QDomElement QgsProjectStyleSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
258{
259 QDomElement element = doc.createElement( QStringLiteral( "ProjectStyleSettings" ) );
260
261 element.setAttribute( QStringLiteral( "RandomizeDefaultSymbolColor" ), mRandomizeDefaultSymbolColor ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
262 element.setAttribute( QStringLiteral( "DefaultSymbolOpacity" ), QString::number( mDefaultSymbolOpacity ) );
263
264 if ( mDefaultMarkerSymbol )
265 {
266 QDomElement markerSymbolElem = doc.createElement( QStringLiteral( "markerSymbol" ) );
267 markerSymbolElem.appendChild( QgsSymbolLayerUtils::saveSymbol( QString(), mDefaultMarkerSymbol.get(), doc, context ) );
268 element.appendChild( markerSymbolElem );
269 }
270
271 if ( mDefaultLineSymbol )
272 {
273 QDomElement lineSymbolElem = doc.createElement( QStringLiteral( "lineSymbol" ) );
274 lineSymbolElem.appendChild( QgsSymbolLayerUtils::saveSymbol( QString(), mDefaultLineSymbol.get(), doc, context ) );
275 element.appendChild( lineSymbolElem );
276 }
277
278 if ( mDefaultFillSymbol )
279 {
280 QDomElement fillSymbolElem = doc.createElement( QStringLiteral( "fillSymbol" ) );
281 fillSymbolElem.appendChild( QgsSymbolLayerUtils::saveSymbol( QString(), mDefaultFillSymbol.get(), doc, context ) );
282 element.appendChild( fillSymbolElem );
283 }
284
285 if ( mDefaultColorRamp )
286 {
287 QDomElement colorRampElem = QgsSymbolLayerUtils::saveColorRamp( QString(), mDefaultColorRamp.get(), doc );
288 element.appendChild( colorRampElem );
289 }
290
291 if ( mDefaultTextFormat.isValid() )
292 {
293 QDomElement textFormatElem = mDefaultTextFormat.writeXml( doc, context );
294 element.appendChild( textFormatElem );
295 }
296
297 {
298 QDomElement styleDatabases = doc.createElement( QStringLiteral( "databases" ) );
299 for ( const QString &db : mStyleDatabases )
300 {
301 QDomElement dbElement = doc.createElement( QStringLiteral( "db" ) );
302 dbElement.setAttribute( QStringLiteral( "path" ), context.pathResolver().writePath( db ) );
303 styleDatabases.appendChild( dbElement );
304 }
305 element.appendChild( styleDatabases );
306 }
307
308 if ( mProject && mProjectStyle )
309 {
310 element.setAttribute( QStringLiteral( "projectStyleId" ), mProject->attachmentIdentifier( mProjectStyle->fileName() ) );
311 }
312
313 return element;
314}
315
316QList<QgsStyle *> QgsProjectStyleSettings::styles() const
317{
318 QList< QgsStyle * > res;
319 res.reserve( mStyles.size() );
320 for ( QgsStyle *style : mStyles )
321 {
322 if ( style )
323 res.append( style );
324 }
325 return res;
326}
327
329{
330 if ( path == QgsStyle::defaultStyle()->fileName() )
331 return QgsStyle::defaultStyle();
332
333 if ( mProjectStyle && path == mProjectStyle->fileName() )
334 return mProjectStyle;
335
336 for ( QgsStyle *style : std::as_const( mStyles ) )
337 {
338 if ( style->fileName() == path )
339 return style;
340 }
341
342 return nullptr;
343}
344
346{
347 if ( mStyleDatabases.contains( path ) )
348 return;
349
350 emit styleDatabaseAboutToBeAdded( path );
351 mStyleDatabases.append( path );
352 loadStyleAtPath( path );
353 emit styleDatabaseAdded( path );
354
356}
357
359{
360 if ( paths == mStyleDatabases )
361 return;
362
363 clearStyles();
364
365 for ( const QString &path : paths )
366 {
367 emit styleDatabaseAboutToBeAdded( path );
368 mStyleDatabases.append( path );
369 loadStyleAtPath( path );
370 emit styleDatabaseAdded( path );
371 }
373}
374
375void QgsProjectStyleSettings::loadStyleAtPath( const QString &path )
376{
377 QgsStyle *style = new QgsStyle( this );
378
379 const QFileInfo fileInfo( path );
380 if ( fileInfo.suffix().compare( QLatin1String( "xml" ), Qt::CaseInsensitive ) == 0 )
381 {
382 style->createMemoryDatabase();
383 style->importXml( path );
384 style->setFileName( path );
385 style->setReadOnly( true );
386 }
387 else
388 {
389 style->load( path );
390 }
391 style->setName( fileInfo.completeBaseName() );
392 mStyles.append( style );
393 mCombinedStyleModel->addStyle( style );
394
395 if ( mProject )
396 {
397 // if project color scheme changes, we need to redraw symbols - they may use project colors and accordingly
398 // need updating to reflect the new colors
400 }
401}
402
403void QgsProjectStyleSettings::clearStyles()
404{
405 const QStringList pathsToRemove = mStyleDatabases;
406 for ( const QString &path : pathsToRemove )
407 {
409 mStyleDatabases.removeAll( path );
410 if ( QgsStyle *style = styleAtPath( path ) )
411 {
412 mCombinedStyleModel->removeStyle( style );
413 style->deleteLater();
414 mStyles.removeAll( style );
415 }
416 emit styleDatabaseRemoved( path );
417 }
418
419 // should already be empty, but play it safe..!
420 for ( QgsStyle *style : std::as_const( mStyles ) )
421 {
422 mCombinedStyleModel->removeStyle( style );
423 }
424 qDeleteAll( mStyles );
425 mStyles.clear();
426}
427
429{
430 return mCombinedStyleModel;
431}
432
433
434
435
436//
437// QgsProjectStyleDatabaseModel
438//
439
441 : QAbstractListModel( parent )
442 , mSettings( settings )
443{
444 connect( mSettings, &QgsProjectStyleSettings::styleDatabaseAboutToBeAdded, this, &QgsProjectStyleDatabaseModel::styleDatabaseAboutToBeAdded );
445 connect( mSettings, &QgsProjectStyleSettings::styleDatabaseAdded, this, &QgsProjectStyleDatabaseModel::styleDatabaseAdded );
446 connect( mSettings, &QgsProjectStyleSettings::styleDatabaseAboutToBeRemoved, this, &QgsProjectStyleDatabaseModel::styleDatabaseAboutToBeRemoved );
447 connect( mSettings, &QgsProjectStyleSettings::styleDatabaseRemoved, this, &QgsProjectStyleDatabaseModel::styleDatabaseRemoved );
448
449 if ( mSettings->projectStyle() )
450 setProjectStyle( mSettings->projectStyle() );
451 connect( mSettings, &QgsProjectStyleSettings::projectStyleChanged, this, &QgsProjectStyleDatabaseModel::projectStyleChanged );
452}
453
454int QgsProjectStyleDatabaseModel::rowCount( const QModelIndex &parent ) const
455{
456 Q_UNUSED( parent )
457 return ( mSettings ? mSettings->styleDatabasePaths().count() : 0 ) + ( mProjectStyle ? 1 : 0 ) + ( mShowDefault ? 1 : 0 );
458}
459
460QVariant QgsProjectStyleDatabaseModel::data( const QModelIndex &index, int role ) const
461{
462 if ( index.row() < 0 || index.row() >= rowCount( QModelIndex() ) )
463 return QVariant();
464
465 const bool isProjectStyle = index.row() == 0 && mProjectStyle;
466 const bool isDefault = mShowDefault && ( ( index.row() == 0 && !mProjectStyle ) || ( index.row() == 1 && mProjectStyle ) );
467 const int styleRow = index.row() - ( mShowDefault ? 1 : 0 ) - ( mProjectStyle ? 1 : 0 );
468
469 switch ( role )
470 {
471 case Qt::DisplayRole:
472 case Qt::EditRole:
473 if ( isDefault )
474 return QgsStyle::defaultStyle()->name();
475 else if ( isProjectStyle )
476 return mProjectStyle->name();
477 else
478 return mSettings ? mSettings->styles().at( styleRow )->name() : QVariant();
479
480 case Qt::ToolTipRole:
481 if ( isDefault )
482 return QDir::toNativeSeparators( QgsStyle::defaultStyle()->fileName() );
483 else if ( isProjectStyle )
484 return mProjectStyle->name();
485 else
486 return mSettings ? QDir::toNativeSeparators( mSettings->styles().at( styleRow )->fileName() ) : QVariant();
487
488 case StyleRole:
489 {
490 if ( isDefault )
491 return QVariant::fromValue( QgsStyle::defaultStyle() );
492 else if ( isProjectStyle )
493 return QVariant::fromValue( mProjectStyle.data() );
494 else if ( QgsStyle *style = mSettings->styles().value( styleRow ) )
495 return QVariant::fromValue( style );
496 else
497 return QVariant();
498 }
499
500 case PathRole:
501 if ( isDefault )
503 else if ( isProjectStyle )
504 return mProjectStyle->fileName();
505 else
506 return mSettings ? mSettings->styles().at( styleRow )->fileName() : QVariant();
507
508 default:
509 return QVariant();
510 }
511}
512
514{
515 if ( index.row() == 0 && mProjectStyle )
516 return mProjectStyle;
517 else if ( mShowDefault && ( ( index.row() == 0 && !mProjectStyle ) || ( index.row() == 1 && mProjectStyle ) ) )
518 return QgsStyle::defaultStyle();
519 else if ( QgsStyle *style = qobject_cast< QgsStyle * >( qvariant_cast<QObject *>( data( index, StyleRole ) ) ) )
520 return style;
521 else
522 return nullptr;
523}
524
526{
527 if ( style == mProjectStyle )
528 return index( 0, 0, QModelIndex() );
529 else if ( style == QgsStyle::defaultStyle() && mShowDefault )
530 return index( mProjectStyle ? 1 : 0, 0, QModelIndex() );
531
532 if ( !mSettings )
533 {
534 return QModelIndex();
535 }
536
537 const int r = mSettings->styles().indexOf( style );
538 if ( r < 0 )
539 return QModelIndex();
540
541 QModelIndex idx = index( r + ( mShowDefault ? 1 : 0 ) + ( mProjectStyle ? 1 : 0 ), 0, QModelIndex() );
542 if ( idx.isValid() )
543 {
544 return idx;
545 }
546
547 return QModelIndex();
548}
549
551{
552 if ( show == mShowDefault )
553 return;
554
555 const int row = mProjectStyle ? 1 : 0;
556 if ( show )
557 {
558 beginInsertRows( QModelIndex(), row, row );
559 mShowDefault = true;
560 endInsertRows();
561 }
562 else
563 {
564 beginRemoveRows( QModelIndex(), row, row );
565 mShowDefault = false;
566 endRemoveRows();
567 }
568}
569
570void QgsProjectStyleDatabaseModel::setProjectStyle( QgsStyle *style )
571{
572 if ( style == mProjectStyle )
573 return;
574
575 if ( mProjectStyle )
576 {
577 disconnect( mProjectStyle, &QgsStyle::aboutToBeDestroyed, this, &QgsProjectStyleDatabaseModel::projectStyleAboutToBeDestroyed );
578 disconnect( mProjectStyle, &QgsStyle::destroyed, this, &QgsProjectStyleDatabaseModel::projectStyleDestroyed );
579 beginRemoveRows( QModelIndex(), 0, 0 );
580 mProjectStyle = nullptr;
581 endRemoveRows();
582 }
583
584 if ( style )
585 {
586 beginInsertRows( QModelIndex(), 0, 0 );
587 mProjectStyle = style;
588 endInsertRows();
589
590 connect( mProjectStyle, &QgsStyle::aboutToBeDestroyed, this, &QgsProjectStyleDatabaseModel::projectStyleAboutToBeDestroyed );
591 connect( mProjectStyle, &QgsStyle::destroyed, this, &QgsProjectStyleDatabaseModel::projectStyleDestroyed );
592 }
593}
594
595void QgsProjectStyleDatabaseModel::styleDatabaseAboutToBeAdded( const QString & )
596{
597 int row = mSettings->styles().count() + ( mShowDefault ? 1 : 0 ) + ( mProjectStyle ? 1 : 0 );
598 beginInsertRows( QModelIndex(), row, row );
599}
600
601void QgsProjectStyleDatabaseModel::styleDatabaseAboutToBeRemoved( const QString &path )
602{
603 QgsStyle *style = mSettings->styleAtPath( path );
604 int row = mSettings->styles().indexOf( style ) + ( mShowDefault ? 1 : 0 ) + ( mProjectStyle ? 1 : 0 );
605 if ( row >= 0 )
606 beginRemoveRows( QModelIndex(), row, row );
607}
608
609void QgsProjectStyleDatabaseModel::styleDatabaseAdded( const QString & )
610{
611 endInsertRows();
612}
613
614void QgsProjectStyleDatabaseModel::styleDatabaseRemoved( const QString & )
615{
616 endRemoveRows();
617}
618
619void QgsProjectStyleDatabaseModel::projectStyleAboutToBeDestroyed()
620{
621 beginRemoveRows( QModelIndex(), 0, 0 );
622}
623
624void QgsProjectStyleDatabaseModel::projectStyleDestroyed()
625{
626 endRemoveRows();
627}
628
629void QgsProjectStyleDatabaseModel::projectStyleChanged()
630{
631 setProjectStyle( mSettings->projectStyle() );
632}
633
634//
635// QgsProjectStyleDatabaseProxyModel
636//
637
639 : QSortFilterProxyModel( parent )
640{
641 setSourceModel( model );
642 setDynamicSortFilter( true );
643}
644
645bool QgsProjectStyleDatabaseProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
646{
647 if ( mFilters & Filter::FilterHideReadOnly )
648 {
649 if ( const QgsStyle *style = qobject_cast< QgsStyle * >( sourceModel()->data( sourceModel()->index( sourceRow, 0, sourceParent ), QgsProjectStyleDatabaseModel::Role::StyleRole ).value< QObject * >() ) )
650 {
651 if ( style->isReadOnly() )
652 return false;
653 }
654 }
655
656 return true;
657}
658
659QgsProjectStyleDatabaseProxyModel::Filters QgsProjectStyleDatabaseProxyModel::filters() const
660{
661 return mFilters;
662}
663
664void QgsProjectStyleDatabaseProxyModel::setFilters( QgsProjectStyleDatabaseProxyModel::Filters filters )
665{
666 mFilters = filters;
667 invalidateFilter();
668}
@ ProjectStyles
Enable the project embedded style library. Enabling this flag can increase the time required to clear...
SymbolType
Symbol types.
Definition: qgis.h:320
@ Marker
Marker symbol.
@ Line
Line symbol.
@ Fill
Fill symbol.
@ Hybrid
Hybrid symbol.
Abstract base class for color ramps.
Definition: qgscolorramp.h:30
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
A model which contains entities from multiple QgsStyle databases.
void removeStyle(QgsStyle *style)
Removes a style from the model.
void addStyle(QgsStyle *style)
Adds a style to the model.
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
List model representing the style databases associated with a QgsProject.
QVariant data(const QModelIndex &index, int role) const override
void setShowDefaultStyle(bool show)
Sets whether the default style should also be included in the model.
QModelIndex indexFromStyle(QgsStyle *style) const
Returns the model index corresponding to a style.
QgsProjectStyleDatabaseModel(QgsProjectStyleSettings *settings, QObject *parent SIP_TRANSFERTHIS=nullptr)
Constructor for QgsProjectStyleDatabaseModel, showing the styles from the specified settings.
QgsStyle * styleFromIndex(const QModelIndex &index) const
Returns the style at the corresponding index.
int rowCount(const QModelIndex &parent) const override
QgsProjectStyleDatabaseProxyModel(QgsProjectStyleDatabaseModel *model, QObject *parent SIP_TRANSFERTHIS=nullptr)
Available filter flags for filtering the model.
QgsProjectStyleDatabaseProxyModel::Filters filters() const
Returns the current filters used for filtering available style.
void setFilters(QgsProjectStyleDatabaseProxyModel::Filters filters)
Sets the current filters used for filtering available styles.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
@ FilterHideReadOnly
Hide read-only style databases.
Contains settings and properties relating to how a QgsProject should handle styling.
void setDefaultTextFormat(const QgsTextFormat &textFormat)
Sets the project default text format.
QList< QgsStyle * > styles() const
Returns a list of all the styles associated with the project.
void setStyleDatabasePaths(const QStringList &paths)
Sets the paths to all style databases associated with the project.
QgsStyle * styleAtPath(const QString &path)
Returns a reference to the style database associated with the project with matching file path.
QgsTextFormat defaultTextFormat() const
Returns the project default text format.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Returns a DOM element representing the settings.
void projectStyleChanged()
Emitted when the style returned by projectStyle() is changed.
void setDefaultSymbol(Qgis::SymbolType symbolType, QgsSymbol *symbol)
Sets the project default symbol for a given type.
void setProjectStyle(QgsStyle *style SIP_TRANSFER)
Sets the style database to use for the project style.
QStringList styleDatabasePaths() const
Returns a list of all style databases (file paths) associated with the project.
void reset()
Resets the settings to a default state.
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.
QgsSymbol * defaultSymbol(Qgis::SymbolType symbolType) const SIP_FACTORY
Returns the project default symbol for a given type.
void setDefaultColorRamp(QgsColorRamp *colorRamp)
Sets the project default color ramp.
void addStyleDatabasePath(const QString &path)
Adds a style database path to the project.
void styleDatabaseRemoved(const QString &path)
Emitted when a style database path is removed.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context, Qgis::ProjectReadFlags flags=Qgis::ProjectReadFlags())
Reads the settings's state from a DOM element.
QgsStyle * projectStyle()
Returns the style database to use for project specific styles.
QgsCombinedStyleModel * combinedStyleModel()
Returns the combined style model which includes all style databases associated with the project.
QgsColorRamp * defaultColorRamp() const SIP_FACTORY
Returns the project default color ramp.
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:105
QString createAttachedFile(const QString &nameTemplate)
Attaches a file to the project.
QString attachmentIdentifier(const QString &attachedFile) const
Returns an identifier for an attachment file path An attachment identifier is a string which does not...
QString resolveAttachmentIdentifier(const QString &identifier) const
Resolves an attachment identifier to a attachment file path.
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
Qgis::ProjectCapabilities capabilities() const
Returns the project's capabilities, which dictate optional functionality which can be selectively ena...
Definition: qgsproject.h:193
The class is used as a container of context for various read/write operations on other objects.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
void setFileName(const QString &filename)
Sets the current file name of the style database.
Definition: qgsstyle.cpp:867
void aboutToBeDestroyed()
Emitted just before the style object is destroyed.
bool createDatabase(const QString &filename)
Creates an on-disk database.
Definition: qgsstyle.cpp:522
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:145
void triggerIconRebuild()
Triggers emission of the rebuildIconPreviews() signal.
Definition: qgsstyle.cpp:3061
void setName(const QString &name)
Sets the name of the style.
Definition: qgsstyle.cpp:101
QString fileName() const
Returns the current file name of the style database.
Definition: qgsstyle.h:887
bool isReadOnly() const
Returns true if the style is considered a read-only library.
Definition: qgsstyle.cpp:3066
bool createMemoryDatabase()
Creates a temporary memory database.
Definition: qgsstyle.cpp:537
bool load(const QString &filename)
Loads a file into the style.
Definition: qgsstyle.cpp:612
QString name() const
Returns the name of the style.
Definition: qgsstyle.cpp:106
void setReadOnly(bool readOnly)
Sets whether the style is considered a read-only library.
Definition: qgsstyle.cpp:3071
bool importXml(const QString &filename)
Imports the symbols and colorramps into the default style database from the given XML file.
Definition: qgsstyle.cpp:2704
static QgsColorRamp * loadColorRamp(QDomElement &element)
Creates a color ramp from the settings encoded in an XML element.
static QDomElement saveColorRamp(const QString &name, QgsColorRamp *ramp, QDomDocument &doc)
Encodes a color ramp's settings to an XML element.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:93
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
Container for all settings relating to text rendering.
Definition: qgstextformat.h:41
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
bool isValid() const
Returns true if the format is valid.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.