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