QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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 delete mProjectStyle;
139 mProjectStyle = nullptr;
140 }
141}
142
144{
145 if ( mProjectStyle )
146 {
147 mCombinedStyleModel->removeStyle( mProjectStyle );
148 mProjectStyle->deleteLater();
149 }
150 mProjectStyle = style;
151 mProjectStyle->setName( tr( "Project Styles" ) );
152
153 // if project color scheme changes, we need to redraw symbols - they may use project colors and accordingly
154 // need updating to reflect the new colors
155 if ( mProject )
156 {
157 connect( mProject, &QgsProject::projectColorsChanged, mProjectStyle, &QgsStyle::triggerIconRebuild );
158 }
159 mCombinedStyleModel->addStyle( mProjectStyle );
160
161 emit projectStyleChanged();
162}
163
165{
166 return mProjectStyle;
167}
168
169bool QgsProjectStyleSettings::readXml( const QDomElement &element, const QgsReadWriteContext &context, Qgis::ProjectReadFlags )
170{
171 mRandomizeDefaultSymbolColor = element.attribute( QStringLiteral( "RandomizeDefaultSymbolColor" ), QStringLiteral( "0" ) ).toInt();
172 mDefaultSymbolOpacity = element.attribute( QStringLiteral( "DefaultSymbolOpacity" ), QStringLiteral( "1.0" ) ).toDouble();
173
174 QDomElement elem = element.firstChildElement( QStringLiteral( "markerSymbol" ) );
175 if ( !elem.isNull() )
176 {
177 QDomElement symbolElem = elem.firstChildElement( QStringLiteral( "symbol" ) );
178 mDefaultMarkerSymbol.reset( !symbolElem.isNull() ? QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( symbolElem, context ) : nullptr );
179 }
180 else
181 {
182 mDefaultMarkerSymbol.reset();
183 }
184
185 elem = element.firstChildElement( QStringLiteral( "lineSymbol" ) );
186 if ( !elem.isNull() )
187 {
188 QDomElement symbolElem = elem.firstChildElement( QStringLiteral( "symbol" ) );
189 mDefaultLineSymbol.reset( !symbolElem.isNull() ? QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) : nullptr );
190 }
191 else
192 {
193 mDefaultLineSymbol.reset();
194 }
195
196 elem = element.firstChildElement( QStringLiteral( "fillSymbol" ) );
197 if ( !elem.isNull() )
198 {
199 QDomElement symbolElem = elem.firstChildElement( QStringLiteral( "symbol" ) );
200 mDefaultFillSymbol.reset( !symbolElem.isNull() ? QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem, context ) : nullptr );
201 }
202 else
203 {
204 mDefaultFillSymbol.reset();
205 }
206
207 elem = element.firstChildElement( QStringLiteral( "colorramp" ) );
208 mDefaultColorRamp.reset( !elem.isNull() ? QgsSymbolLayerUtils::loadColorRamp( elem ) : nullptr );
209
210 elem = element.firstChildElement( QStringLiteral( "text-style" ) );
211 if ( !elem.isNull() )
212 {
213 mDefaultTextFormat.readXml( elem, context );
214 }
215 else
216 {
217 mDefaultTextFormat = QgsTextFormat();
218 }
219
220 {
221 clearStyles();
222 if ( !mProject || ( mProject->capabilities() & Qgis::ProjectCapability::ProjectStyles ) )
223 {
224 const QDomElement styleDatabases = element.firstChildElement( QStringLiteral( "databases" ) );
225 if ( !styleDatabases.isNull() )
226 {
227 const QDomNodeList styleEntries = styleDatabases.childNodes();
228 for ( int i = 0; i < styleEntries.count(); ++i )
229 {
230 const QDomElement styleElement = styleEntries.at( i ).toElement();
231 const QString path = styleElement.attribute( QStringLiteral( "path" ) );
232 const QString fullPath = context.pathResolver().readPath( path );
233 emit styleDatabaseAboutToBeAdded( fullPath );
234 mStyleDatabases.append( fullPath );
235 loadStyleAtPath( fullPath );
236 emit styleDatabaseAdded( fullPath );
237 }
238 }
239
240 if ( mProject && ( mProject->capabilities() & Qgis::ProjectCapability::ProjectStyles ) )
241 {
242 const QString projectStyleId = element.attribute( QStringLiteral( "projectStyleId" ) );
243 const QString projectStyleFile = mProject->resolveAttachmentIdentifier( projectStyleId );
244 QgsStyle *style = new QgsStyle();
245 if ( !projectStyleFile.isEmpty() && QFile::exists( projectStyleFile ) )
246 {
247 style->load( projectStyleFile );
248 style->setFileName( projectStyleFile );
249 }
250 else
251 {
252 const QString stylePath = mProject->createAttachedFile( QStringLiteral( "styles.db" ) );
253 style->createDatabase( stylePath );
254 style->setFileName( stylePath );
255 }
256 style->setName( tr( "Project Style" ) );
257 setProjectStyle( style );
258 }
259 }
260 }
261
263
264 return true;
265}
266
267QDomElement QgsProjectStyleSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
268{
269 QDomElement element = doc.createElement( QStringLiteral( "ProjectStyleSettings" ) );
270
271 element.setAttribute( QStringLiteral( "RandomizeDefaultSymbolColor" ), mRandomizeDefaultSymbolColor ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
272 element.setAttribute( QStringLiteral( "DefaultSymbolOpacity" ), QString::number( mDefaultSymbolOpacity ) );
273
274 if ( mDefaultMarkerSymbol )
275 {
276 QDomElement markerSymbolElem = doc.createElement( QStringLiteral( "markerSymbol" ) );
277 markerSymbolElem.appendChild( QgsSymbolLayerUtils::saveSymbol( QString(), mDefaultMarkerSymbol.get(), doc, context ) );
278 element.appendChild( markerSymbolElem );
279 }
280
281 if ( mDefaultLineSymbol )
282 {
283 QDomElement lineSymbolElem = doc.createElement( QStringLiteral( "lineSymbol" ) );
284 lineSymbolElem.appendChild( QgsSymbolLayerUtils::saveSymbol( QString(), mDefaultLineSymbol.get(), doc, context ) );
285 element.appendChild( lineSymbolElem );
286 }
287
288 if ( mDefaultFillSymbol )
289 {
290 QDomElement fillSymbolElem = doc.createElement( QStringLiteral( "fillSymbol" ) );
291 fillSymbolElem.appendChild( QgsSymbolLayerUtils::saveSymbol( QString(), mDefaultFillSymbol.get(), doc, context ) );
292 element.appendChild( fillSymbolElem );
293 }
294
295 if ( mDefaultColorRamp )
296 {
297 QDomElement colorRampElem = QgsSymbolLayerUtils::saveColorRamp( QString(), mDefaultColorRamp.get(), doc );
298 element.appendChild( colorRampElem );
299 }
300
301 if ( mDefaultTextFormat.isValid() )
302 {
303 QDomElement textFormatElem = mDefaultTextFormat.writeXml( doc, context );
304 element.appendChild( textFormatElem );
305 }
306
307 {
308 QDomElement styleDatabases = doc.createElement( QStringLiteral( "databases" ) );
309 for ( const QString &db : mStyleDatabases )
310 {
311 QDomElement dbElement = doc.createElement( QStringLiteral( "db" ) );
312 dbElement.setAttribute( QStringLiteral( "path" ), context.pathResolver().writePath( db ) );
313 styleDatabases.appendChild( dbElement );
314 }
315 element.appendChild( styleDatabases );
316 }
317
318 if ( mProject && mProjectStyle )
319 {
320 element.setAttribute( QStringLiteral( "projectStyleId" ), mProject->attachmentIdentifier( mProjectStyle->fileName() ) );
321 }
322
323 return element;
324}
325
326QList<QgsStyle *> QgsProjectStyleSettings::styles() const
327{
328 QList< QgsStyle * > res;
329 res.reserve( mStyles.size() );
330 for ( QgsStyle *style : mStyles )
331 {
332 if ( style )
333 res.append( style );
334 }
335 return res;
336}
337
339{
340 if ( path == QgsStyle::defaultStyle()->fileName() )
341 return QgsStyle::defaultStyle();
342
343 if ( mProjectStyle && path == mProjectStyle->fileName() )
344 return mProjectStyle;
345
346 for ( QgsStyle *style : std::as_const( mStyles ) )
347 {
348 if ( style->fileName() == path )
349 return style;
350 }
351
352 return nullptr;
353}
354
356{
357 if ( mStyleDatabases.contains( path ) )
358 return;
359
360 emit styleDatabaseAboutToBeAdded( path );
361 mStyleDatabases.append( path );
362 loadStyleAtPath( path );
363 emit styleDatabaseAdded( path );
364
366}
367
369{
370 if ( paths == mStyleDatabases )
371 return;
372
373 clearStyles();
374
375 for ( const QString &path : paths )
376 {
377 emit styleDatabaseAboutToBeAdded( path );
378 mStyleDatabases.append( path );
379 loadStyleAtPath( path );
380 emit styleDatabaseAdded( path );
381 }
383}
384
385void QgsProjectStyleSettings::loadStyleAtPath( const QString &path )
386{
387 QgsStyle *style = new QgsStyle( this );
388
389 const QFileInfo fileInfo( path );
390 if ( fileInfo.suffix().compare( QLatin1String( "xml" ), Qt::CaseInsensitive ) == 0 )
391 {
392 style->createMemoryDatabase();
393 style->importXml( path );
394 style->setFileName( path );
395 style->setReadOnly( true );
396 }
397 else
398 {
399 style->load( path );
400 }
401 style->setName( fileInfo.completeBaseName() );
402 mStyles.append( style );
403 mCombinedStyleModel->addStyle( style );
404
405 if ( mProject )
406 {
407 // if project color scheme changes, we need to redraw symbols - they may use project colors and accordingly
408 // need updating to reflect the new colors
410 }
411}
412
413void QgsProjectStyleSettings::clearStyles()
414{
415 const QStringList pathsToRemove = mStyleDatabases;
416 for ( const QString &path : pathsToRemove )
417 {
419 mStyleDatabases.removeAll( path );
420 if ( QgsStyle *style = styleAtPath( path ) )
421 {
422 mCombinedStyleModel->removeStyle( style );
423 style->deleteLater();
424 mStyles.removeAll( style );
425 }
426 emit styleDatabaseRemoved( path );
427 }
428
429 // should already be empty, but play it safe..!
430 for ( QgsStyle *style : std::as_const( mStyles ) )
431 {
432 mCombinedStyleModel->removeStyle( style );
433 }
434 qDeleteAll( mStyles );
435 mStyles.clear();
436}
437
439{
440 return mCombinedStyleModel;
441}
442
443
444
445
446//
447// QgsProjectStyleDatabaseModel
448//
449
451 : QAbstractListModel( parent )
452 , mSettings( settings )
453{
454 connect( mSettings, &QgsProjectStyleSettings::styleDatabaseAboutToBeAdded, this, &QgsProjectStyleDatabaseModel::styleDatabaseAboutToBeAdded );
455 connect( mSettings, &QgsProjectStyleSettings::styleDatabaseAdded, this, &QgsProjectStyleDatabaseModel::styleDatabaseAdded );
456 connect( mSettings, &QgsProjectStyleSettings::styleDatabaseAboutToBeRemoved, this, &QgsProjectStyleDatabaseModel::styleDatabaseAboutToBeRemoved );
457 connect( mSettings, &QgsProjectStyleSettings::styleDatabaseRemoved, this, &QgsProjectStyleDatabaseModel::styleDatabaseRemoved );
458
459 if ( mSettings->projectStyle() )
460 setProjectStyle( mSettings->projectStyle() );
461 connect( mSettings, &QgsProjectStyleSettings::projectStyleChanged, this, &QgsProjectStyleDatabaseModel::projectStyleChanged );
462}
463
464int QgsProjectStyleDatabaseModel::rowCount( const QModelIndex &parent ) const
465{
466 Q_UNUSED( parent )
467 return ( mSettings ? mSettings->styleDatabasePaths().count() : 0 ) + ( mProjectStyle ? 1 : 0 ) + ( mShowDefault ? 1 : 0 );
468}
469
470QVariant QgsProjectStyleDatabaseModel::data( const QModelIndex &index, int role ) const
471{
472 if ( index.row() < 0 || index.row() >= rowCount( QModelIndex() ) )
473 return QVariant();
474
475 const bool isProjectStyle = index.row() == 0 && mProjectStyle;
476 const bool isDefault = mShowDefault && ( ( index.row() == 0 && !mProjectStyle ) || ( index.row() == 1 && mProjectStyle ) );
477 const int styleRow = index.row() - ( mShowDefault ? 1 : 0 ) - ( mProjectStyle ? 1 : 0 );
478
479 switch ( role )
480 {
481 case Qt::DisplayRole:
482 case Qt::EditRole:
483 if ( isDefault )
484 return QgsStyle::defaultStyle()->name();
485 else if ( isProjectStyle )
486 return mProjectStyle->name();
487 else
488 return mSettings ? mSettings->styles().at( styleRow )->name() : QVariant();
489
490 case Qt::ToolTipRole:
491 if ( isDefault )
492 return QDir::toNativeSeparators( QgsStyle::defaultStyle()->fileName() );
493 else if ( isProjectStyle )
494 return mProjectStyle->name();
495 else
496 return mSettings ? QDir::toNativeSeparators( mSettings->styles().at( styleRow )->fileName() ) : QVariant();
497
498 case static_cast< int >( CustomRole::Style ):
499 {
500 if ( isDefault )
501 return QVariant::fromValue( QgsStyle::defaultStyle() );
502 else if ( isProjectStyle )
503 return QVariant::fromValue( mProjectStyle.data() );
504 else if ( QgsStyle *style = mSettings->styles().value( styleRow ) )
505 return QVariant::fromValue( style );
506 else
507 return QVariant();
508 }
509
510 case static_cast< int >( CustomRole::Path ):
511 if ( isDefault )
513 else if ( isProjectStyle )
514 return mProjectStyle->fileName();
515 else
516 return mSettings ? mSettings->styles().at( styleRow )->fileName() : QVariant();
517
518 default:
519 return QVariant();
520 }
521}
522
524{
525 if ( index.row() == 0 && mProjectStyle )
526 return mProjectStyle;
527 else if ( mShowDefault && ( ( index.row() == 0 && !mProjectStyle ) || ( index.row() == 1 && mProjectStyle ) ) )
528 return QgsStyle::defaultStyle();
529 else if ( QgsStyle *style = qobject_cast< QgsStyle * >( qvariant_cast<QObject *>( data( index, static_cast< int >( CustomRole::Style ) ) ) ) )
530 return style;
531 else
532 return nullptr;
533}
534
536{
537 if ( style == mProjectStyle )
538 return index( 0, 0, QModelIndex() );
539 else if ( style == QgsStyle::defaultStyle() && mShowDefault )
540 return index( mProjectStyle ? 1 : 0, 0, QModelIndex() );
541
542 if ( !mSettings )
543 {
544 return QModelIndex();
545 }
546
547 const int r = mSettings->styles().indexOf( style );
548 if ( r < 0 )
549 return QModelIndex();
550
551 QModelIndex idx = index( r + ( mShowDefault ? 1 : 0 ) + ( mProjectStyle ? 1 : 0 ), 0, QModelIndex() );
552 if ( idx.isValid() )
553 {
554 return idx;
555 }
556
557 return QModelIndex();
558}
559
561{
562 if ( show == mShowDefault )
563 return;
564
565 const int row = mProjectStyle ? 1 : 0;
566 if ( show )
567 {
568 beginInsertRows( QModelIndex(), row, row );
569 mShowDefault = true;
570 endInsertRows();
571 }
572 else
573 {
574 beginRemoveRows( QModelIndex(), row, row );
575 mShowDefault = false;
576 endRemoveRows();
577 }
578}
579
580void QgsProjectStyleDatabaseModel::setProjectStyle( QgsStyle *style )
581{
582 if ( style == mProjectStyle )
583 return;
584
585 if ( mProjectStyle )
586 {
587 disconnect( mProjectStyle, &QgsStyle::aboutToBeDestroyed, this, &QgsProjectStyleDatabaseModel::projectStyleAboutToBeDestroyed );
588 disconnect( mProjectStyle, &QgsStyle::destroyed, this, &QgsProjectStyleDatabaseModel::projectStyleDestroyed );
589 beginRemoveRows( QModelIndex(), 0, 0 );
590 mProjectStyle = nullptr;
591 endRemoveRows();
592 }
593
594 if ( style )
595 {
596 beginInsertRows( QModelIndex(), 0, 0 );
597 mProjectStyle = style;
598 endInsertRows();
599
600 connect( mProjectStyle, &QgsStyle::aboutToBeDestroyed, this, &QgsProjectStyleDatabaseModel::projectStyleAboutToBeDestroyed );
601 connect( mProjectStyle, &QgsStyle::destroyed, this, &QgsProjectStyleDatabaseModel::projectStyleDestroyed );
602 }
603}
604
605void QgsProjectStyleDatabaseModel::styleDatabaseAboutToBeAdded( const QString & )
606{
607 int row = mSettings->styles().count() + ( mShowDefault ? 1 : 0 ) + ( mProjectStyle ? 1 : 0 );
608 beginInsertRows( QModelIndex(), row, row );
609}
610
611void QgsProjectStyleDatabaseModel::styleDatabaseAboutToBeRemoved( const QString &path )
612{
613 QgsStyle *style = mSettings->styleAtPath( path );
614 int row = mSettings->styles().indexOf( style ) + ( mShowDefault ? 1 : 0 ) + ( mProjectStyle ? 1 : 0 );
615 if ( row >= 0 )
616 beginRemoveRows( QModelIndex(), row, row );
617}
618
619void QgsProjectStyleDatabaseModel::styleDatabaseAdded( const QString & )
620{
621 endInsertRows();
622}
623
624void QgsProjectStyleDatabaseModel::styleDatabaseRemoved( const QString & )
625{
626 endRemoveRows();
627}
628
629void QgsProjectStyleDatabaseModel::projectStyleAboutToBeDestroyed()
630{
631 beginRemoveRows( QModelIndex(), 0, 0 );
632}
633
634void QgsProjectStyleDatabaseModel::projectStyleDestroyed()
635{
636 endRemoveRows();
637}
638
639void QgsProjectStyleDatabaseModel::projectStyleChanged()
640{
641 setProjectStyle( mSettings->projectStyle() );
642}
643
644//
645// QgsProjectStyleDatabaseProxyModel
646//
647
649 : QSortFilterProxyModel( parent )
650{
651 setSourceModel( model );
652 setDynamicSortFilter( true );
653}
654
655bool QgsProjectStyleDatabaseProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
656{
657 if ( mFilters & Filter::FilterHideReadOnly )
658 {
659 if ( const QgsStyle *style = qobject_cast< QgsStyle * >( sourceModel()->data( sourceModel()->index( sourceRow, 0, sourceParent ), static_cast< int >( QgsProjectStyleDatabaseModel::CustomRole::Style ) ).value< QObject * >() ) )
660 {
661 if ( style->isReadOnly() )
662 return false;
663 }
664 }
665
666 return true;
667}
668
670{
671 return mFilters;
672}
673
675{
676 mFilters = filters;
677 invalidateFilter();
678}
QFlags< ProjectReadFlag > ProjectReadFlags
Project load flags.
Definition: qgis.h:3562
@ ProjectStyles
Enable the project embedded style library. Enabling this flag can increase the time required to clear...
SymbolType
Symbol types.
Definition: qgis.h:401
@ Marker
Marker symbol.
@ Line
Line symbol.
@ Fill
Fill symbol.
@ Hybrid
Hybrid symbol.
Abstract base class for color ramps.
Definition: qgscolorramp.h:29
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=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
@ FilterHideReadOnly
Hide read-only style databases.
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.
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 setProjectStyle(QgsStyle *style)
Sets the style database to use for the project style.
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.
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.
void removeProjectStyle()
Removes and deletes the project style database.
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.
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
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:197
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:893
void aboutToBeDestroyed()
Emitted just before the style object is destroyed.
bool createDatabase(const QString &filename)
Creates an on-disk database.
Definition: qgsstyle.cpp:548
void triggerIconRebuild()
Triggers emission of the rebuildIconPreviews() signal.
Definition: qgsstyle.cpp:3087
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:901
bool isReadOnly() const
Returns true if the style is considered a read-only library.
Definition: qgsstyle.cpp:3092
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition: qgsstyle.cpp:145
bool createMemoryDatabase()
Creates a temporary memory database.
Definition: qgsstyle.cpp:563
bool load(const QString &filename)
Loads a file into the style.
Definition: qgsstyle.cpp:638
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:3097
bool importXml(const QString &filename)
Imports the symbols and colorramps into the default style database from the given XML file.
Definition: qgsstyle.cpp:2730
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:94
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.