QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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)
29 #include "qgscombinedstylemodel.h"
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 
135  emit styleDatabasesChanged();
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 
168 bool 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 
261  emit styleDatabasesChanged();
262 
263  return true;
264 }
265 
266 QDomElement 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 
325 QList<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 
364  emit styleDatabasesChanged();
365 }
366 
367 void QgsProjectStyleSettings::setStyleDatabasePaths( const QStringList &paths )
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  }
381  emit styleDatabasesChanged();
382 }
383 
384 void 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
410  connect( mProject, &QgsProject::projectColorsChanged, style, &QgsStyle::triggerIconRebuild );
411  }
412 }
413 
414 void QgsProjectStyleSettings::clearStyles()
415 {
416  const QStringList pathsToRemove = mStyleDatabases;
417  for ( const QString &path : pathsToRemove )
418  {
419  emit styleDatabaseAboutToBeRemoved( path );
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 
473 int 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 
479 QVariant 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 )
521  return QgsStyle::defaultStyle()->fileName();
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 
532 QgsStyle *QgsProjectStyleDatabaseModel::styleFromIndex( const QModelIndex &index ) const
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 
589 void 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 
614 void QgsProjectStyleDatabaseModel::styleDatabaseAboutToBeAdded( const QString & )
615 {
616  int row = mSettings->styles().count() + ( mShowDefault ? 1 : 0 ) + ( mProjectStyle ? 1 : 0 );
617  beginInsertRows( QModelIndex(), row, row );
618 }
619 
620 void 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 
628 void QgsProjectStyleDatabaseModel::styleDatabaseAdded( const QString & )
629 {
630  endInsertRows();
631 }
632 
633 void QgsProjectStyleDatabaseModel::styleDatabaseRemoved( const QString & )
634 {
635  endRemoveRows();
636 }
637 
638 void QgsProjectStyleDatabaseModel::projectStyleAboutToBeDestroyed()
639 {
640  beginRemoveRows( QModelIndex(), 0, 0 );
641 }
642 
643 void QgsProjectStyleDatabaseModel::projectStyleDestroyed()
644 {
645  endRemoveRows();
646 }
647 
648 void 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 
664 bool 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 
678 QgsProjectStyleDatabaseProxyModel::Filters QgsProjectStyleDatabaseProxyModel::filters() const
679 {
680  return mFilters;
681 }
682 
683 void QgsProjectStyleDatabaseProxyModel::setFilters( QgsProjectStyleDatabaseProxyModel::Filters filters )
684 {
685  mFilters = filters;
686  invalidateFilter();
687 }
QgsColorRamp
Abstract base class for color ramps.
Definition: qgscolorramp.h:29
QgsProjectStyleDatabaseModel::indexFromStyle
QModelIndex indexFromStyle(QgsStyle *style) const
Returns the model index corresponding to a style.
Definition: qgsprojectstylesettings.cpp:544
QgsStyle::name
QString name() const
Returns the name of the style.
Definition: qgsstyle.cpp:106
qgsprojectstylesettings.h
Qgis::SymbolType::Fill
@ Fill
Fill symbol.
QgsCombinedStyleModel
A model which contains entities from multiple QgsStyle databases.
Definition: qgscombinedstylemodel.h:42
Qgis::SymbolType::Line
@ Line
Line symbol.
QgsProjectStyleSettings::styleDatabasePaths
QStringList styleDatabasePaths() const
Returns a list of all style databases (file paths) associated with the project.
Definition: qgsprojectstylesettings.h:161
QgsCombinedStyleModel::removeStyle
void removeStyle(QgsStyle *style)
Removes a style from the model.
Definition: qgscombinedstylemodel.cpp:86
QgsProjectStyleDatabaseProxyModel::filterAcceptsRow
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Definition: qgsprojectstylesettings.cpp:664
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsProjectStyleSettings::projectStyle
QgsStyle * projectStyle()
Returns the style database to use for project specific styles.
Definition: qgsprojectstylesettings.cpp:163
QgsProjectStyleDatabaseModel
List model representing the style databases associated with a QgsProject.
Definition: qgsprojectstylesettings.h:297
QgsStyle::createDatabase
bool createDatabase(const QString &filename)
Creates an on-disk database.
Definition: qgsstyle.cpp:516
QgsProjectStyleSettings::setDefaultSymbol
void setDefaultSymbol(Qgis::SymbolType symbolType, QgsSymbol *symbol)
Sets the project default symbol for a given type.
Definition: qgsprojectstylesettings.cpp:72
QgsStyle::createMemoryDatabase
bool createMemoryDatabase()
Creates a temporary memory database.
Definition: qgsstyle.cpp:531
QgsProjectStyleDatabaseModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: qgsprojectstylesettings.cpp:479
QgsStyle::fileName
QString fileName() const
Returns the current file name of the style database.
Definition: qgsstyle.h:888
QgsProjectStyleDatabaseModel::rowCount
int rowCount(const QModelIndex &parent) const override
Definition: qgsprojectstylesettings.cpp:473
QgsProjectStyleSettings
Contains settings and properties relating to how a QgsProject should handle styling.
Definition: qgsprojectstylesettings.h:43
qgssymbollayerutils.h
QgsProjectStyleSettings::readXml
bool readXml(const QDomElement &element, const QgsReadWriteContext &context, Qgis::ProjectReadFlags flags=Qgis::ProjectReadFlags())
Reads the settings's state from a DOM element.
Definition: qgsprojectstylesettings.cpp:168
QgsProjectStyleSettings::projectStyleChanged
void projectStyleChanged()
Emitted when the style returned by projectStyle() is changed.
QgsProjectStyleSettings::styles
QList< QgsStyle * > styles() const
Returns a list of all the styles associated with the project.
Definition: qgsprojectstylesettings.cpp:325
qgis.h
QgsProjectStyleSettings::defaultSymbol
QgsSymbol * defaultSymbol(Qgis::SymbolType symbolType) const SIP_FACTORY
Returns the project default symbol for a given type.
Definition: qgsprojectstylesettings.cpp:52
QgsProjectStyleSettings::defaultColorRamp
QgsColorRamp * defaultColorRamp() const SIP_FACTORY
Returns the project default color ramp.
Definition: qgsprojectstylesettings.cpp:93
QgsStyle::setFileName
void setFileName(const QString &filename)
Sets the current file name of the style database.
Definition: qgsstyle.cpp:861
QgsStyle::load
bool load(const QString &filename)
Loads a file into the style.
Definition: qgsstyle.cpp:606
QgsProjectStyleDatabaseProxyModel::Filter::FilterHideReadOnly
@ FilterHideReadOnly
Hide read-only style databases.
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
QgsProjectStyleSettings::setProjectStyle
void setProjectStyle(QgsStyle *style SIP_TRANSFER)
Sets the style database to use for the project style.
Definition: qgsprojectstylesettings.cpp:138
QgsProjectStyleDatabaseModel::PathRole
@ PathRole
Style path.
Definition: qgsprojectstylesettings.h:307
QgsProjectStyleDatabaseProxyModel::filters
QgsProjectStyleDatabaseProxyModel::Filters filters() const
Returns the current filters used for filtering available style.
Definition: qgsprojectstylesettings.cpp:678
QgsStyle::setName
void setName(const QString &name)
Sets the name of the style.
Definition: qgsstyle.cpp:101
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsProjectStyleSettings::setDefaultTextFormat
void setDefaultTextFormat(const QgsTextFormat &textFormat)
Sets the project default text format.
Definition: qgsprojectstylesettings.cpp:108
QgsProjectStyleSettings::combinedStyleModel
QgsCombinedStyleModel * combinedStyleModel()
Returns the combined style model which includes all style databases associated with the project.
Definition: qgsprojectstylesettings.cpp:444
QgsStyle::defaultStyle
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:145
QgsProjectStyleSettings::writeXml
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Returns a DOM element representing the settings.
Definition: qgsprojectstylesettings.cpp:266
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
qgscombinedstylemodel.h
QgsPathResolver::writePath
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
Definition: qgspathresolver.cpp:225
QgsProject::createAttachedFile
QString createAttachedFile(const QString &nameTemplate)
Attaches a file to the project.
Definition: qgsproject.cpp:4055
QgsProjectStyleDatabaseModel::styleFromIndex
QgsStyle * styleFromIndex(const QModelIndex &index) const
Returns the style at the corresponding index.
Definition: qgsprojectstylesettings.cpp:532
Qgis::SymbolType
SymbolType
Symbol types.
Definition: qgis.h:205
QgsProjectStyleSettings::addStyleDatabasePath
void addStyleDatabasePath(const QString &path)
Adds a style database path to the project.
Definition: qgsprojectstylesettings.cpp:354
QgsProjectStyleSettings::styleDatabaseAboutToBeRemoved
void styleDatabaseAboutToBeRemoved(const QString &path)
Emitted when a style database path is about to be removed.
qgscolorramp.h
QgsCombinedStyleModel::addStyle
void addStyle(QgsStyle *style)
Adds a style to the model.
Definition: qgscombinedstylemodel.cpp:36
QgsStyle::importXml
bool importXml(const QString &filename)
Imports the symbols and colorramps into the default style database from the given XML file.
Definition: qgsstyle.cpp:2697
QgsSymbolLayerUtils::saveColorRamp
static QDomElement saveColorRamp(const QString &name, QgsColorRamp *ramp, QDomDocument &doc)
Encodes a color ramp's settings to an XML element.
Definition: qgssymbollayerutils.cpp:3355
QgsProjectStyleSettings::styleDatabasesChanged
void styleDatabasesChanged()
Emitted whenever the set of style databases associated with the project is changed.
QgsProject::projectColorsChanged
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
QgsProject::capabilities
Qgis::ProjectCapabilities capabilities() const
Returns the project's capabilities, which dictate optional functionality which can be selectively ena...
Definition: qgsproject.h:189
QgsProjectStyleSettings::defaultTextFormat
QgsTextFormat defaultTextFormat() const
Returns the project default text format.
Definition: qgsprojectstylesettings.cpp:103
QgsTextFormat::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
Definition: qgstextformat.cpp:488
QgsTextFormat::isValid
bool isValid() const
Returns true if the format is valid.
Definition: qgstextformat.cpp:102
QgsProjectStyleSettings::setDefaultColorRamp
void setDefaultColorRamp(QgsColorRamp *colorRamp)
Sets the project default color ramp.
Definition: qgsprojectstylesettings.cpp:98
QgsColorRamp::clone
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
qgsstyle.h
QgsSymbolLayerUtils::loadColorRamp
static QgsColorRamp * loadColorRamp(QDomElement &element)
Creates a color ramp from the settings encoded in an XML element.
Definition: qgssymbollayerutils.cpp:3330
Qgis::SymbolType::Hybrid
@ Hybrid
Hybrid symbol.
QgsPathResolver::readPath
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
Definition: qgspathresolver.cpp:37
QgsSymbol::clone
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
QgsStyle::aboutToBeDestroyed
void aboutToBeDestroyed()
Emitted just before the style object is destroyed.
QgsProjectStyleSettings::styleDatabaseAdded
void styleDatabaseAdded(const QString &path)
Emitted when a style database path is added.
QgsProjectStyleSettings::setStyleDatabasePaths
void setStyleDatabasePaths(const QStringList &paths)
Sets the paths to all style databases associated with the project.
Definition: qgsprojectstylesettings.cpp:367
QgsProjectStyleSettings::~QgsProjectStyleSettings
~QgsProjectStyleSettings() override
Definition: qgsprojectstylesettings.cpp:43
QgsProjectStyleDatabaseProxyModel::setFilters
void setFilters(QgsProjectStyleDatabaseProxyModel::Filters filters)
Sets the current filters used for filtering available styles.
Definition: qgsprojectstylesettings.cpp:683
QgsStyle
Definition: qgsstyle.h:159
QgsStyle::isReadOnly
bool isReadOnly() const
Returns true if the style is considered a read-only library.
Definition: qgsstyle.cpp:3059
QgsStyle::triggerIconRebuild
void triggerIconRebuild()
Triggers emission of the rebuildIconPreviews() signal.
Definition: qgsstyle.cpp:3054
qgsmarkersymbol.h
QgsProjectStyleSettings::reset
void reset()
Resets the settings to a default state.
Definition: qgsprojectstylesettings.cpp:113
QgsProjectStyleDatabaseModel::StyleRole
@ StyleRole
Style object.
Definition: qgsprojectstylesettings.h:306
QgsProjectStyleSettings::styleDatabaseAboutToBeAdded
void styleDatabaseAboutToBeAdded(const QString &path)
Emitted when a style database path is about to be added.
QgsProject::attachmentIdentifier
QString attachmentIdentifier(const QString &attachedFile) const
Returns an identifier for an attachment file path An attachment identifier is a string which does not...
Definition: qgsproject.cpp:4086
QgsProjectStyleDatabaseProxyModel::QgsProjectStyleDatabaseProxyModel
QgsProjectStyleDatabaseProxyModel(QgsProjectStyleDatabaseModel *model, QObject *parent SIP_TRANSFERTHIS=nullptr)
Available filter flags for filtering the model.
Definition: qgsprojectstylesettings.cpp:657
QgsProjectStyleSettings::styleDatabaseRemoved
void styleDatabaseRemoved(const QString &path)
Emitted when a style database path is removed.
QgsProjectStyleSettings::styleAtPath
QgsStyle * styleAtPath(const QString &path)
Returns a reference to the style database associated with the project with matching file path.
Definition: qgsprojectstylesettings.cpp:337
qgstextformat.h
QgsProjectStyleDatabaseModel::setShowDefaultStyle
void setShowDefaultStyle(bool show)
Sets whether the default style should also be included in the model.
Definition: qgsprojectstylesettings.cpp:569
QgsProjectStyleDatabaseModel::QgsProjectStyleDatabaseModel
QgsProjectStyleDatabaseModel(QgsProjectStyleSettings *settings, QObject *parent SIP_TRANSFERTHIS=nullptr)
Constructor for QgsProjectStyleDatabaseModel, showing the styles from the specified settings.
Definition: qgsprojectstylesettings.cpp:457
Qgis::ProjectCapability::ProjectStyles
@ ProjectStyles
Enable the project embedded style library. Enabling this flag can increase the time required to clear...
qgsfillsymbol.h
QgsTextFormat::writeXml
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
Definition: qgstextformat.cpp:671
QgsProject::resolveAttachmentIdentifier
QString resolveAttachmentIdentifier(const QString &identifier) const
Resolves an attachment identifier to a attachment file path.
Definition: qgsproject.cpp:4091
qgssymbol.h
QgsSymbolLayerUtils::saveSymbol
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
Definition: qgssymbollayerutils.cpp:1397
qgsproject.h
Qgis::SymbolType::Marker
@ Marker
Marker symbol.
QgsReadWriteContext::pathResolver
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
Definition: qgsreadwritecontext.cpp:47
qgslinesymbol.h
QgsProjectStyleSettings::QgsProjectStyleSettings
QgsProjectStyleSettings(QgsProject *project=nullptr)
Constructor for QgsProjectStyleSettings for the specified project.
Definition: qgsprojectstylesettings.cpp:34
QgsStyle::setReadOnly
void setReadOnly(bool readOnly)
Sets whether the style is considered a read-only library.
Definition: qgsstyle.cpp:3064