44#include <QDomDocument>
47#include <QDomNodeList>
53#include "moc_qgsstyle.cpp"
55using namespace Qt::StringLiterals;
57#define STYLE_CURRENT_VERSION "2"
82QgsStyle *QgsStyle::sDefaultStyle =
nullptr;
89 simpleMarker->setStrokeWidth( 0.4 );
90 mPatchMarkerSymbol = std::make_unique< QgsMarkerSymbol >(
QgsSymbolLayerList() << simpleMarker.release() );
92 auto simpleLine = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 84, 176, 74 ), 0.6 );
93 mPatchLineSymbol = std::make_unique< QgsLineSymbol >(
QgsSymbolLayerList() << simpleLine.release() );
95 auto gradientFill = std::make_unique< QgsGradientFillSymbolLayer >( QColor( 66, 150, 63 ), QColor( 84, 176, 74 ) );
96 auto simpleOutline = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 56, 128, 54 ), 0.26 );
97 mPatchFillSymbol = std::make_unique< QgsFillSymbol >(
QgsSymbolLayerList() << gradientFill.release() << simpleOutline.release() );
118 switch ( entity->
type() )
152 static QString sStyleFilename;
153 if ( !sDefaultStyle )
159 if ( !QFile::exists( sStyleFilename ) )
162 sDefaultStyle->createDatabase( sStyleFilename );
167 sDefaultStyle->createStyleMetadataTableIfNeeded();
174 sDefaultStyle->mInitialized =
false;
177 sDefaultStyle->initializeDefaultStyle( sStyleFilename );
180 sDefaultStyle->setName( QObject::tr(
"Default" ) );
182 else if ( initialize && !sDefaultStyle->mInitialized )
185 sDefaultStyle->initializeDefaultStyle( sStyleFilename );
187 return sDefaultStyle;
190void QgsStyle::initializeDefaultStyle(
const QString &filename )
192 Q_ASSERT(
this == sDefaultStyle );
193 if (
this != sDefaultStyle )
209 delete sDefaultStyle;
210 sDefaultStyle =
nullptr;
215 qDeleteAll( mSymbols );
216 qDeleteAll( mColorRamps );
217 qDeleteAll( m3dSymbols );
221 mTextFormats.clear();
225 mCachedFavorites.clear();
234 auto it = mSymbols.constFind(
name );
235 if ( it != mSymbols.constEnd() )
256 QDomDocument doc( u
"dummy"_s );
258 if ( symEl.isNull() )
265 QTextStream stream( &xmlArray );
266 symEl.save( stream, 4 );
268 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
270 if ( !runEmptyQuery( query ) )
272 QgsDebugError( u
"Couldn't insert symbol into the database!"_s );
334 return mSymbols.value(
name );
339 return mSymbols.count();
344 return mSymbols.keys();
354 auto it = mColorRamps.constFind(
name );
355 if ( it != mColorRamps.constEnd() )
376 auto it = mTextFormats.find(
name );
377 if ( it != mTextFormats.end() )
380 mTextFormats.erase( it );
381 mTextFormats.insert(
name, format );
387 mTextFormats.insert(
name, format );
398 auto it = mLabelSettings.find(
name );
399 if ( it != mLabelSettings.end() )
402 mLabelSettings.erase( it );
403 mLabelSettings.insert(
name, settings );
409 mLabelSettings.insert(
name, settings );
420 auto it = mLegendPatchShapes.find(
name );
421 if ( it != mLegendPatchShapes.end() )
424 mLegendPatchShapes.erase( it );
425 mLegendPatchShapes.insert(
name, shape );
431 mLegendPatchShapes.insert(
name, shape );
442 auto it = m3dSymbols.constFind(
name );
443 if ( it != m3dSymbols.constEnd() )
464 QDomDocument doc( u
"dummy"_s );
467 if ( rampEl.isNull() )
469 QgsDebugError( u
"Couldn't convert color ramp to valid XML!"_s );
474 QTextStream stream( &xmlArray );
475 rampEl.save( stream, 4 );
476 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
477 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
478 if ( !runEmptyQuery( query ) )
480 QgsDebugError( u
"Couldn't insert colorramp into the database!"_s );
502 return ramp ? ramp->
clone() :
nullptr;
512 return mColorRamps.count();
517 return mColorRamps.keys();
520void QgsStyle::handleDeferred3DSymbolCreation()
522 for (
auto it = mDeferred3DsymbolElements.constBegin(); it != mDeferred3DsymbolElements.constEnd(); ++it )
524 const QString symbolType = it.value().attribute( u
"type"_s );
538 mDeferred3DsymbolElements.clear();
541bool QgsStyle::openDatabase(
const QString &filename )
543 int rc = mCurrentDB.open( filename );
546 mErrorString = u
"Couldn't open the style database: %1"_s.arg( mCurrentDB.errorMessage() );
555 mErrorString.clear();
556 if ( !openDatabase( filename ) )
558 mErrorString = u
"Unable to create database"_s;
570 mErrorString.clear();
571 if ( !openDatabase( u
":memory:"_s ) )
573 mErrorString = u
"Unable to create temporary memory database"_s;
586 "id INTEGER PRIMARY KEY,"\
589 "favorite INTEGER);"\
590 "CREATE TABLE colorramp("\
591 "id INTEGER PRIMARY KEY,"\
594 "favorite INTEGER);"\
595 "CREATE TABLE textformat("\
596 "id INTEGER PRIMARY KEY,"\
599 "favorite INTEGER);"\
600 "CREATE TABLE labelsettings("\
601 "id INTEGER PRIMARY KEY,"\
604 "favorite INTEGER);"\
605 "CREATE TABLE legendpatchshapes("\
606 "id INTEGER PRIMARY KEY,"\
609 "favorite INTEGER);"\
610 "CREATE TABLE symbol3d("\
611 "id INTEGER PRIMARY KEY,"\
614 "favorite INTEGER);"\
616 "id INTEGER PRIMARY KEY,"\
618 "CREATE TABLE tagmap("\
619 "tag_id INTEGER NOT NULL,"\
620 "symbol_id INTEGER);"\
621 "CREATE TABLE ctagmap("\
622 "tag_id INTEGER NOT NULL,"\
623 "colorramp_id INTEGER);"\
624 "CREATE TABLE tftagmap("\
625 "tag_id INTEGER NOT NULL,"\
626 "textformat_id INTEGER);"\
627 "CREATE TABLE lstagmap("\
628 "tag_id INTEGER NOT NULL,"\
629 "labelsettings_id INTEGER);"\
630 "CREATE TABLE lpstagmap("\
631 "tag_id INTEGER NOT NULL,"\
632 "legendpatchshape_id INTEGER);"\
633 "CREATE TABLE symbol3dtagmap("\
634 "tag_id INTEGER NOT NULL,"\
635 "symbol3d_id INTEGER);"\
636 "CREATE TABLE smartgroup("\
637 "id INTEGER PRIMARY KEY,"\
640 runEmptyQuery( query );
645 mErrorString.clear();
648 if ( !openDatabase( filename ) )
650 mErrorString = u
"Unable to open database file specified"_s;
656 QString query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='textformat'" );
659 statement = mCurrentDB.prepare( query, rc );
660 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
663 "id INTEGER PRIMARY KEY,"\
666 "favorite INTEGER);"\
667 "CREATE TABLE tftagmap("\
668 "tag_id INTEGER NOT NULL,"\
669 "textformat_id INTEGER);" );
670 runEmptyQuery( query );
673 query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='labelsettings'" );
674 statement = mCurrentDB.prepare( query, rc );
675 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
678 "id INTEGER PRIMARY KEY,"\
681 "favorite INTEGER);"\
682 "CREATE TABLE lstagmap("\
683 "tag_id INTEGER NOT NULL,"\
684 "labelsettings_id INTEGER);" );
685 runEmptyQuery( query );
688 query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='legendpatchshapes'" );
689 statement = mCurrentDB.prepare( query, rc );
690 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
693 "id INTEGER PRIMARY KEY,"\
696 "favorite INTEGER);"\
697 "CREATE TABLE lpstagmap("\
698 "tag_id INTEGER NOT NULL,"\
699 "legendpatchshape_id INTEGER);" );
700 runEmptyQuery( query );
704 statement = mCurrentDB.prepare( query, rc );
705 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
708 "id INTEGER PRIMARY KEY,"\
711 "favorite INTEGER);"\
712 "CREATE TABLE symbol3dtagmap("\
713 "tag_id INTEGER NOT NULL,"\
714 "symbol3d_id INTEGER);" );
715 runEmptyQuery( query );
720 "UPDATE colorramp SET favorite=0 WHERE favorite IS NULL;"
721 "UPDATE textformat SET favorite=0 WHERE favorite IS NULL;"
722 "UPDATE labelsettings SET favorite=0 WHERE favorite IS NULL;"
723 "UPDATE legendpatchshapes SET favorite=0 WHERE favorite IS NULL;"
724 "UPDATE symbol3d SET favorite=0 WHERE favorite IS NULL;"
726 runEmptyQuery( query );
732 statement = mCurrentDB.prepare( query, rc );
734 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
740 if ( !doc.setContent( xmlstring ) )
746 QDomElement symElement = doc.documentElement();
749 mSymbols.insert( symbolName,
symbol.release() );
756 statement = mCurrentDB.prepare( query, rc );
757 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
763 if ( !doc.setContent( xmlstring ) )
768 QDomElement rampElement = doc.documentElement();
771 mColorRamps.insert( rampName, ramp.release() );
778 statement = mCurrentDB.prepare( query, rc );
779 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
785 if ( !doc.setContent( xmlstring ) )
790 QDomElement formatElement = doc.documentElement();
793 mTextFormats.insert( formatName, format );
800 statement = mCurrentDB.prepare( query, rc );
801 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
807 if ( !doc.setContent( xmlstring ) )
809 QgsDebugError(
"Cannot open label settings " + settingsName );
812 QDomElement settingsElement = doc.documentElement();
815 mLabelSettings.insert( settingsName, settings );
822 statement = mCurrentDB.prepare( query, rc );
823 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
829 if ( !doc.setContent( xmlstring ) )
831 QgsDebugError(
"Cannot open legend patch shape " + settingsName );
834 QDomElement settingsElement = doc.documentElement();
837 mLegendPatchShapes.insert( settingsName, shape );
844 statement = mCurrentDB.prepare( query, rc );
848 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
854 if ( !doc.setContent( xmlstring ) )
859 QDomElement settingsElement = doc.documentElement();
861 if ( !registry3dPopulated )
863 mDeferred3DsymbolElements.insert( settingsName, settingsElement );
867 const QString symbolType = settingsElement.attribute( u
"type"_s );
872 m3dSymbols.insert( settingsName,
symbol.release() );
883 mFileName = filename;
884 createStyleMetadataTableIfNeeded();
890 mErrorString.clear();
892 if ( !filename.isEmpty() )
893 mFileName = filename;
900 mFileName = filename;
905 if ( mSymbols.contains( newName ) )
915 mSymbols.insert( newName,
symbol );
926 QgsDebugError( u
"No such symbol for tagging in database: "_s + oldName );
945 if ( mColorRamps.contains( newName ) )
947 QgsDebugError( u
"Color ramp of new name already exists."_s );
955 mColorRamps.insert( newName, ramp );
961 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM colorramp WHERE name='%q'", oldName.toUtf8().constData() );
963 statement = mCurrentDB.prepare( query, nErr );
964 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
966 rampid = sqlite3_column_int( statement.get(), 0 );
981 QDomDocument doc( u
"dummy"_s );
984 if ( formatElem.isNull() )
986 QgsDebugError( u
"Couldn't convert text format to valid XML!"_s );
991 QTextStream stream( &xmlArray );
992 formatElem.save( stream, 4 );
993 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO textformat VALUES (NULL, '%q', '%q', %d);",
994 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
995 if ( !runEmptyQuery( query ) )
997 QgsDebugError( u
"Couldn't insert text format into the database!"_s );
1018 if ( mTextFormats.contains( newName ) )
1020 QgsDebugError( u
"Text format of new name already exists."_s );
1024 if ( !mTextFormats.contains( oldName ) )
1028 mTextFormats.insert( newName, format );
1034 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM textformat WHERE name='%q'", oldName.toUtf8().constData() );
1036 statement = mCurrentDB.prepare( query, nErr );
1037 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1039 textFormatId = sqlite3_column_int( statement.get(), 0 );
1054 QDomDocument doc( u
"dummy"_s );
1057 if ( settingsElem.isNull() )
1059 QgsDebugError( u
"Couldn't convert label settings to valid XML!"_s );
1063 QByteArray xmlArray;
1064 QTextStream stream( &xmlArray );
1065#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1066 stream.setCodec(
"UTF-8" );
1068 settingsElem.save( stream, 4 );
1069 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO labelsettings VALUES (NULL, '%q', '%q', %d);",
1070 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
1071 if ( !runEmptyQuery( query ) )
1073 QgsDebugError( u
"Couldn't insert label settings into the database!"_s );
1094 if ( mLabelSettings.contains( newName ) )
1096 QgsDebugError( u
"Label settings of new name already exists."_s );
1100 if ( !mLabelSettings.contains( oldName ) )
1104 mLabelSettings.insert( newName, settings );
1110 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM labelsettings WHERE name='%q'", oldName.toUtf8().constData() );
1112 statement = mCurrentDB.prepare( query, nErr );
1113 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1130 QDomDocument doc( u
"dummy"_s );
1131 QDomElement shapeElem = doc.createElement( u
"shape"_s );
1134 QByteArray xmlArray;
1135 QTextStream stream( &xmlArray );
1136#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1137 stream.setCodec(
"UTF-8" );
1139 shapeElem.save( stream, 4 );
1140 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO legendpatchshapes VALUES (NULL, '%q', '%q', %d);",
1141 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
1142 if ( !runEmptyQuery( query ) )
1144 QgsDebugError( u
"Couldn't insert legend patch shape into the database!"_s );
1159 if ( mLegendPatchShapes.contains( newName ) )
1161 QgsDebugError( u
"Legend patch shape of new name already exists."_s );
1165 if ( !mLegendPatchShapes.contains( oldName ) )
1169 mLegendPatchShapes.insert( newName, shape );
1175 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM legendpatchshapes WHERE name='%q'", oldName.toUtf8().constData() );
1177 statement = mCurrentDB.prepare( query, nErr );
1178 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1196 auto it = mDefaultPatchCache[
static_cast< int >( type ) ].constFind( size );
1197 if ( it != mDefaultPatchCache[
static_cast< int >( type ) ].constEnd() )
1204 geom =
QgsGeometry( std::make_unique< QgsPoint >(
static_cast< int >( size.width() ) / 2,
static_cast< int >( size.height() ) / 2 ) );
1211 double y =
static_cast< int >( size.height() ) / 2 + 0.5;
1212 geom =
QgsGeometry( std::make_unique< QgsLineString >( ( QVector< double >() << 0 << size.width() ),
1213 ( QVector< double >() << y << y ) ) );
1219 geom =
QgsGeometry( std::make_unique< QgsPolygon >(
1220 new QgsLineString( QVector< double >() << 0 <<
static_cast< int >( size.width() ) <<
static_cast< int >( size.width() ) << 0 << 0,
1221 QVector< double >() <<
static_cast< int >( size.height() ) <<
static_cast< int >( size.height() ) << 0 << 0 <<
static_cast< int >( size.height() ) ) ) );
1230 mDefaultPatchCache[
static_cast< int >( type ) ][size ] = res;
1237 return QList<QList<QPolygonF> >();
1239 auto it = mDefaultPatchQPolygonFCache[
static_cast< int >( type ) ].constFind( size );
1240 if ( it != mDefaultPatchQPolygonFCache[
static_cast< int >( type ) ].constEnd() )
1244 mDefaultPatchQPolygonFCache[
static_cast< int >( type ) ][size ] = res;
1270 QDomDocument doc( u
"dummy"_s );
1271 QDomElement elem = doc.createElement( u
"symbol"_s );
1272 elem.setAttribute( u
"type"_s,
symbol->type() );
1275 QByteArray xmlArray;
1276 QTextStream stream( &xmlArray );
1277#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1278 stream.setCodec(
"UTF-8" );
1280 elem.save( stream, 4 );
1281 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO symbol3d VALUES (NULL, '%q', '%q', %d);",
1282 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
1283 if ( !runEmptyQuery( query ) )
1285 QgsDebugError( u
"Couldn't insert 3d symbol into the database!"_s );
1300 if ( m3dSymbols.contains( newName ) )
1302 QgsDebugError( u
"3d symbol of new name already exists."_s );
1306 if ( !m3dSymbols.contains( oldName ) )
1310 m3dSymbols.insert( newName,
symbol );
1316 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM symbol3d WHERE name='%q'", oldName.toUtf8().constData() );
1318 statement = mCurrentDB.prepare( query, nErr );
1319 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1334 return m3dSymbols.keys();
1341 QgsDebugError( u
"Cannot Open database for getting favorite symbols"_s );
1342 return QStringList();
1351 return QStringList();
1354 query =
qgs_sqlite3_mprintf( u
"SELECT name FROM %1 WHERE favorite=1"_s.arg( entityTableName( type ) ).toLocal8Bit().data() );
1360 statement = mCurrentDB.prepare( query, nErr );
1362 QStringList symbols;
1363 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1375 QgsDebugError( u
"Cannot open database to get symbols of tagid %1"_s.arg( tagid ) );
1376 return QStringList();
1385 return QStringList();
1388 subquery =
qgs_sqlite3_mprintf( u
"SELECT %1 FROM %2 WHERE tag_id=%d"_s.arg( tagmapEntityIdFieldName( type ),
1389 tagmapTableName( type ) ).toLocal8Bit().data(), tagid );
1395 statement = mCurrentDB.prepare( subquery, nErr );
1398 QStringList symbols;
1399 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1401 int id = sqlite3_column_int( statement.get(), 0 );
1403 const QString query =
qgs_sqlite3_mprintf( u
"SELECT name FROM %1 WHERE id=%d"_s.arg( entityTableName( type ) ).toLocal8Bit().data(),
id );
1407 statement2 = mCurrentDB.prepare( query, rc );
1408 while ( rc == SQLITE_OK && sqlite3_step( statement2.get() ) == SQLITE_ROW )
1423 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO tag VALUES (NULL, '%q')", tagname.toUtf8().constData() );
1425 statement = mCurrentDB.prepare( query, nErr );
1426 if ( nErr == SQLITE_OK )
1427 ( void )sqlite3_step( statement.get() );
1430 settings.
setValue( u
"qgis/symbolsListGroupsIndex"_s, 0 );
1434 return static_cast< int >( sqlite3_last_insert_rowid( mCurrentDB.get() ) );
1440 return QStringList();
1446 statement = mCurrentDB.prepare( query, nError );
1448 QStringList tagList;
1449 while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1459 const QString query =
qgs_sqlite3_mprintf( u
"UPDATE %1 SET name='%q' WHERE id=%d"_s.arg( entityTableName( type ) ).toLocal8Bit().data(), newName.toUtf8().constData(),
id );
1461 const bool result = runEmptyQuery( query );
1464 mErrorString = u
"Could not rename!"_s;
1468 mCachedTags.clear();
1469 mCachedFavorites.clear();
1494 bool groupRemoved =
false;
1499 query =
qgs_sqlite3_mprintf(
"DELETE FROM tag WHERE id=%d; DELETE FROM tagmap WHERE tag_id=%d",
id,
id );
1500 groupRemoved =
true;
1504 groupRemoved =
true;
1508 query =
qgs_sqlite3_mprintf( u
"DELETE FROM %1 WHERE id=%d; DELETE FROM %2 WHERE %3=%d"_s.arg(
1509 entityTableName( type ),
1510 tagmapTableName( type ),
1511 tagmapEntityIdFieldName( type )
1512 ).toLocal8Bit().data(),
id,
id );
1516 bool result =
false;
1517 if ( !runEmptyQuery( query ) )
1523 mCachedTags.clear();
1524 mCachedFavorites.clear();
1529 settings.
setValue( u
"qgis/symbolsListGroupsIndex"_s, 0 );
1548 std::unique_ptr< QgsSymbol >
symbol( mSymbols.take(
name ) );
1557 std::unique_ptr< QgsAbstract3DSymbol >
symbol( m3dSymbols.take(
name ) );
1566 std::unique_ptr< QgsColorRamp > ramp( mColorRamps.take(
name ) );
1574 auto it = mTextFormats.find(
name );
1575 if ( it == mTextFormats.end() )
1578 mTextFormats.erase( it );
1584 auto it = mLabelSettings.find(
name );
1585 if ( it == mLabelSettings.end() )
1588 mLabelSettings.erase( it );
1594 auto it = mLegendPatchShapes.find(
name );
1595 if ( it == mLegendPatchShapes.end() )
1598 mLegendPatchShapes.erase( it );
1605 QgsDebugError( u
"Sorry! Cannot open database to modify."_s );
1615 const bool result =
remove( type,
id );
1618 mCachedTags[ type ].remove(
name );
1619 mCachedFavorites[ type ].remove(
name );
1648bool QgsStyle::runEmptyQuery(
const QString &query )
1653 char *zErr =
nullptr;
1654 int nErr = sqlite3_exec( mCurrentDB.get(), query.toUtf8().constData(),
nullptr,
nullptr, &zErr );
1656 if ( nErr != SQLITE_OK )
1659 sqlite3_free( zErr );
1662 return nErr == SQLITE_OK;
1673 QgsDebugError( u
"Wrong entity value. cannot apply group"_s );
1677 query =
qgs_sqlite3_mprintf( u
"UPDATE %1 SET favorite=1 WHERE name='%q'"_s.arg( entityTableName( type ) ).toLocal8Bit().data(),
1678 name.toUtf8().constData() );
1682 const bool res = runEmptyQuery( query );
1692 mCachedFavorites[ type ].insert(
name,
true );
1709 QgsDebugError( u
"Wrong entity value. cannot apply group"_s );
1713 query =
qgs_sqlite3_mprintf( u
"UPDATE %1 SET favorite=0 WHERE name='%q'"_s.arg( entityTableName( type ) ).toLocal8Bit().data(),
name.toUtf8().constData() );
1717 const bool res = runEmptyQuery( query );
1720 mCachedFavorites[ type ].insert(
name,
false );
1731 QgsDebugError( u
"Sorry! Cannot open database to search"_s );
1732 return QStringList();
1741 return QStringList();
1744 item = entityTableName( type );
1749 item.toUtf8().constData(), qword.toUtf8().constData() );
1752 int nErr; statement = mCurrentDB.prepare( query, nErr );
1754 QSet< QString > symbols;
1755 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1761 query =
qgs_sqlite3_mprintf(
"SELECT id FROM tag WHERE name LIKE '%%%q%%'", qword.toUtf8().constData() );
1762 statement = mCurrentDB.prepare( query, nErr );
1765 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1770 QString dummy = tagids.join(
", "_L1 );
1771 query =
qgs_sqlite3_mprintf( u
"SELECT %1 FROM %2 WHERE tag_id IN (%q)"_s.arg( tagmapEntityIdFieldName( type ),
1772 tagmapTableName( type ) ).toLocal8Bit().data(), dummy.toUtf8().constData() );
1774 statement = mCurrentDB.prepare( query, nErr );
1776 QStringList symbolids;
1777 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1782 dummy = symbolids.join(
", "_L1 );
1784 item.toUtf8().constData(), dummy.toUtf8().constData() );
1785 statement = mCurrentDB.prepare( query, nErr );
1786 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1791 return QStringList( symbols.constBegin(), symbols.constEnd() );
1821 const auto constTags =
tags;
1822 for (
const QString &t : constTags )
1825 if ( !
tag.isEmpty() )
1837 QString query =
qgs_sqlite3_mprintf( u
"INSERT INTO %1 VALUES (%d,%d)"_s.arg( tagmapTableName( type ) ).toLocal8Bit().data(), tagid, symbolid );
1839 char *zErr =
nullptr;
1841 nErr = sqlite3_exec( mCurrentDB.get(), query.toUtf8().constData(),
nullptr,
nullptr, &zErr );
1845 sqlite3_free( zErr );
1851 clearCachedTags( type,
symbol );
1861 QgsDebugError( u
"Sorry! Cannot open database for detagging."_s );
1876 if ( symbolid == 0 )
1881 const auto constTags =
tags;
1882 for (
const QString &
tag : constTags )
1887 statement2 = mCurrentDB.prepare( query, nErr );
1890 if ( nErr == SQLITE_OK && sqlite3_step( statement2.get() ) == SQLITE_ROW )
1892 tagid = sqlite3_column_int( statement2.get(), 0 );
1898 const QString query =
qgs_sqlite3_mprintf( u
"DELETE FROM %1 WHERE tag_id=%d AND %2=%d"_s.arg( tagmapTableName( type ), tagmapEntityIdFieldName( type ) ).toLocal8Bit().data(), tagid, symbolid );
1899 runEmptyQuery( query );
1903 clearCachedTags( type,
symbol );
1916 QgsDebugError( u
"Sorry! Cannot open database for detagging."_s );
1931 if ( symbolid == 0 )
1937 const QString query =
qgs_sqlite3_mprintf( u
"DELETE FROM %1 WHERE %2=%d"_s.arg( tagmapTableName( type ),
1938 tagmapEntityIdFieldName( type ) ).toLocal8Bit().data(), symbolid );
1939 runEmptyQuery( query );
1941 clearCachedTags( type,
symbol );
1956 return QStringList();
1960 auto it = mCachedTags[ type ].constFind(
symbol );
1961 if ( it != mCachedTags[ type ].constEnd() )
1969 QgsDebugError( u
"Sorry! Cannot open database for getting the tags."_s );
1970 return QStringList();
1975 return QStringList();
1978 const QString query =
qgs_sqlite3_mprintf( u
"SELECT tag_id FROM %1 WHERE %2=%d"_s.arg( tagmapTableName( type ),
1979 tagmapEntityIdFieldName( type ) ).toLocal8Bit().data(), symbolid );
1982 int nErr; statement = mCurrentDB.prepare( query, nErr );
1984 QStringList tagList;
1985 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1987 QString subquery =
qgs_sqlite3_mprintf(
"SELECT name FROM tag WHERE id=%d", sqlite3_column_int( statement.get(), 0 ) );
1991 statement2 = mCurrentDB.prepare( subquery, pErr );
1992 if ( pErr == SQLITE_OK && sqlite3_step( statement2.get() ) == SQLITE_ROW )
1999 mCachedTags[ type ].insert(
symbol, tagList );
2008 QgsDebugError( u
"Sorry! Cannot open database for getting the tags."_s );
2020 auto it = mCachedFavorites[ type ].constFind(
name );
2021 if ( it != mCachedFavorites[ type ].constEnd() )
2027 const QStringList names =
allNames( type );
2028 if ( !names.contains(
name ) )
2034 for (
const QString &n : names )
2036 const bool isFav = favorites.contains( n );
2040 mCachedFavorites[ type ].insert( n, isFav );
2049 QgsDebugError( u
"Sorry! Cannot open database for getting the tags."_s );
2076 const QString query =
qgs_sqlite3_mprintf( u
"SELECT tag_id FROM %1 WHERE tag_id=%d AND %2=%d"_s.arg( tagmapTableName( type ),
2077 tagmapEntityIdFieldName( type ) ).toLocal8Bit().data(), tagid, symbolid );
2080 int nErr; statement = mCurrentDB.prepare( query, nErr );
2082 return ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW );
2094 statement = mCurrentDB.prepare( query, nError );
2097 if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2105int QgsStyle::getId(
const QString &table,
const QString &name )
2107 QString lowerName(
name.toLower() );
2108 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM %q WHERE LOWER(name)='%q'", table.toUtf8().constData(), lowerName.toUtf8().constData() );
2111 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2114 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2116 id = sqlite3_column_int( statement.get(), 0 );
2121 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM %q WHERE name='%q'", table.toUtf8().constData(),
name.toUtf8().constData() );
2123 sqlite3_statement_unique_ptr statement;
2124 int nErr; statement = mCurrentDB.prepare( query, nErr );
2125 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2127 id = sqlite3_column_int( statement.get(), 0 );
2134QString QgsStyle::getName(
const QString &table,
int id )
const
2136 QString query =
qgs_sqlite3_mprintf(
"SELECT name FROM %q WHERE id='%q'", table.toUtf8().constData(), QString::number(
id ).toUtf8().constData() );
2138 sqlite3_statement_unique_ptr statement;
2139 int nErr; statement = mCurrentDB.prepare( query, nErr );
2142 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2152 return getId( u
"symbol"_s,
name );
2157 return getId( entityTableName( type ),
name );
2162 return getId( u
"colorramp"_s,
name );
2167 return mTextFormats.value(
name );
2172 return mTextFormats.count();
2177 return mTextFormats.keys();
2182 return getId( u
"textformat"_s,
name );
2187 return mLabelSettings.value(
name );
2192 return mLegendPatchShapes.value(
name );
2197 return mLegendPatchShapes.count();
2202 auto it = mLegendPatchShapes.constFind(
name );
2203 if ( it == mLegendPatchShapes.constEnd() )
2206 return it.value().symbolType();
2211 auto it = m3dSymbols.constFind(
name );
2212 if ( it != m3dSymbols.constEnd( ) )
2213 return it.value()->
clone();
2219 return m3dSymbols.count();
2224 auto it = m3dSymbols.constFind(
name );
2225 if ( it == m3dSymbols.constEnd() )
2226 return QList<Qgis::GeometryType>();
2228 return it.value()->compatibleGeometryTypes();
2233 auto it = mLabelSettings.constFind(
name );
2234 if ( it == mLabelSettings.constEnd() )
2237 return it.value().layerType;
2242 return mLabelSettings.count();
2247 return mLabelSettings.keys();
2252 return getId( u
"labelsettings"_s,
name );
2257 return mLegendPatchShapes.keys();
2265 return mPatchMarkerSymbol.get();
2268 return mPatchLineSymbol.get();
2271 return mPatchFillSymbol.get();
2281 return getId( u
"tag"_s,
name );
2286 return getId( u
"smartgroup"_s,
name );
2317 return QStringList();
2323 conditions.values( u
"!tag"_s ),
2324 conditions.values( u
"name"_s ),
2325 conditions.values( u
"!name"_s ) );
2328int QgsStyle::addSmartgroup(
const QString &
name,
const QString &op,
const QStringList &matchTag,
const QStringList &noMatchTag,
const QStringList &matchName,
const QStringList &noMatchName )
2330 QDomDocument doc( u
"dummy"_s );
2331 QDomElement smartEl = doc.createElement( u
"smartgroup"_s );
2332 smartEl.setAttribute( u
"name"_s,
name );
2333 smartEl.setAttribute( u
"operator"_s, op );
2335 auto addCondition = [&doc, &smartEl](
const QString & constraint,
const QStringList & parameters )
2337 for (
const QString ¶m : parameters )
2339 QDomElement condEl = doc.createElement( u
"condition"_s );
2340 condEl.setAttribute( u
"constraint"_s, constraint );
2341 condEl.setAttribute( u
"param"_s, param );
2342 smartEl.appendChild( condEl );
2345 addCondition( u
"tag"_s, matchTag );
2346 addCondition( u
"!tag"_s, noMatchTag );
2347 addCondition( u
"name"_s, matchName );
2348 addCondition( u
"!name"_s, noMatchName );
2350 QByteArray xmlArray;
2351 QTextStream stream( &xmlArray );
2352#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
2353 stream.setCodec(
"UTF-8" );
2355 smartEl.save( stream, 4 );
2357 name.toUtf8().constData(), xmlArray.constData() );
2359 if ( runEmptyQuery( query ) )
2362 settings.
setValue( u
"qgis/symbolsListGroupsIndex"_s, 0 );
2365 return static_cast< int >( sqlite3_last_insert_rowid( mCurrentDB.get() ) );
2369 QgsDebugError( u
"Couldn't add the smart group into the database!"_s );
2378 QgsDebugError( u
"Cannot open database for listing groups"_s );
2387 statement = mCurrentDB.prepare( query, nError );
2390 while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2403 QgsDebugError( u
"Cannot open database for listing groups"_s );
2404 return QStringList();
2412 statement = mCurrentDB.prepare( query, nError );
2415 while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2425 QStringList symbols;
2430 int nErr; statement = mCurrentDB.prepare( query, nErr );
2431 if ( !( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW ) )
2433 return QStringList();
2439 if ( !doc.setContent( xmlstr ) )
2441 QgsDebugError( u
"Cannot open smartgroup id: %1"_s.arg(
id ) );
2443 QDomElement smartEl = doc.documentElement();
2444 QString op = smartEl.attribute( u
"operator"_s );
2445 QDomNodeList conditionNodes = smartEl.childNodes();
2447 bool firstSet =
true;
2448 for (
int i = 0; i < conditionNodes.count(); i++ )
2450 QDomElement condEl = conditionNodes.at( i ).toElement();
2451 QString constraint = condEl.attribute( u
"constraint"_s );
2452 QString param = condEl.attribute( u
"param"_s );
2454 QStringList resultNames;
2456 if ( constraint ==
"tag"_L1 )
2460 else if ( constraint ==
"name"_L1 )
2462 resultNames =
allNames( type ).filter( param, Qt::CaseInsensitive );
2464 else if ( constraint ==
"!tag"_L1 )
2468 for (
const QString &
name : unwanted )
2470 resultNames.removeAll(
name );
2473 else if ( constraint ==
"!name"_L1 )
2475 const QStringList all =
allNames( type );
2476 for (
const QString &str : all )
2478 if ( !str.contains( param, Qt::CaseInsensitive ) )
2486 symbols = resultNames;
2491 if ( op ==
"OR"_L1 )
2493 symbols << resultNames;
2495 else if ( op ==
"AND"_L1 )
2497 QStringList dummy = symbols;
2499 for (
const QString &result : std::as_const( resultNames ) )
2501 if ( dummy.contains( result ) )
2510 const QSet< QString > uniqueSet( symbols.constBegin(), symbols.constEnd() );
2511 QStringList unique( uniqueSet.begin(), uniqueSet.end() );
2512 std::sort( unique.begin(), unique.end() );
2520 QgsDebugError( u
"Cannot open database for listing groups"_s );
2530 statement = mCurrentDB.prepare( query, nError );
2531 if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2535 if ( !doc.setContent( xmlstr ) )
2537 QgsDebugError( u
"Cannot open smartgroup id: %1"_s.arg(
id ) );
2540 QDomElement smartEl = doc.documentElement();
2541 QDomNodeList conditionNodes = smartEl.childNodes();
2543 for (
int i = 0; i < conditionNodes.count(); i++ )
2545 QDomElement condEl = conditionNodes.at( i ).toElement();
2546 QString constraint = condEl.attribute( u
"constraint"_s );
2547 QString param = condEl.attribute( u
"param"_s );
2549 condition.insert( constraint, param );
2560 QgsDebugError( u
"Cannot open database for listing groups"_s );
2570 statement = mCurrentDB.prepare( query, nError );
2571 if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2575 if ( !doc.setContent( xmlstr ) )
2577 QgsDebugError( u
"Cannot open smartgroup id: %1"_s.arg(
id ) );
2579 QDomElement smartEl = doc.documentElement();
2580 op = smartEl.attribute( u
"operator"_s );
2588 if ( filename.isEmpty() )
2594 QDomDocument doc( u
"qgis_style"_s );
2595 QDomElement root = doc.createElement( u
"qgis_style"_s );
2597 doc.appendChild( root );
2607 QDomNodeList symbolsList = symbolsElem.elementsByTagName( u
"symbol"_s );
2608 int nbSymbols = symbolsList.count();
2609 for (
int i = 0; i < nbSymbols; ++i )
2611 QDomElement
symbol = symbolsList.at( i ).toElement();
2612 QString
name =
symbol.attribute( u
"name"_s );
2614 if (
tags.count() > 0 )
2616 symbol.setAttribute( u
"tags"_s,
tags.join(
',' ) );
2618 if ( favoriteSymbols.contains(
name ) )
2620 symbol.setAttribute( u
"favorite"_s, u
"1"_s );
2625 QDomElement rampsElem = doc.createElement( u
"colorramps"_s );
2626 for ( QMap<QString, QgsColorRamp *>::const_iterator itr = mColorRamps.constBegin(); itr != mColorRamps.constEnd(); ++itr )
2630 if (
tags.count() > 0 )
2632 rampEl.setAttribute( u
"tags"_s,
tags.join(
',' ) );
2634 if ( favoriteColorramps.contains( itr.key() ) )
2636 rampEl.setAttribute( u
"favorite"_s, u
"1"_s );
2638 rampsElem.appendChild( rampEl );
2642 QDomElement textFormatsElem = doc.createElement( u
"textformats"_s );
2643 for (
auto it = mTextFormats.constBegin(); it != mTextFormats.constEnd(); ++it )
2645 QDomElement textFormatEl = doc.createElement( u
"textformat"_s );
2646 textFormatEl.setAttribute( u
"name"_s, it.key() );
2648 textFormatEl.appendChild( textStyleEl );
2650 if (
tags.count() > 0 )
2652 textFormatEl.setAttribute( u
"tags"_s,
tags.join(
',' ) );
2654 if ( favoriteTextFormats.contains( it.key() ) )
2656 textFormatEl.setAttribute( u
"favorite"_s, u
"1"_s );
2658 textFormatsElem.appendChild( textFormatEl );
2662 QDomElement labelSettingsElem = doc.createElement( u
"labelsettings"_s );
2663 for (
auto it = mLabelSettings.constBegin(); it != mLabelSettings.constEnd(); ++it )
2665 QDomElement labelSettingsEl = doc.createElement( u
"labelsetting"_s );
2666 labelSettingsEl.setAttribute( u
"name"_s, it.key() );
2668 labelSettingsEl.appendChild( defEl );
2670 if (
tags.count() > 0 )
2672 labelSettingsEl.setAttribute( u
"tags"_s,
tags.join(
',' ) );
2674 if ( favoriteTextFormats.contains( it.key() ) )
2676 labelSettingsEl.setAttribute( u
"favorite"_s, u
"1"_s );
2678 labelSettingsElem.appendChild( labelSettingsEl );
2682 QDomElement legendPatchShapesElem = doc.createElement( u
"legendpatchshapes"_s );
2683 for (
auto it = mLegendPatchShapes.constBegin(); it != mLegendPatchShapes.constEnd(); ++it )
2685 QDomElement legendPatchShapeEl = doc.createElement( u
"legendpatchshape"_s );
2686 legendPatchShapeEl.setAttribute( u
"name"_s, it.key() );
2687 QDomElement defEl = doc.createElement( u
"definition"_s );
2689 legendPatchShapeEl.appendChild( defEl );
2691 if (
tags.count() > 0 )
2693 legendPatchShapeEl.setAttribute( u
"tags"_s,
tags.join(
',' ) );
2695 if ( favoriteLegendShapes.contains( it.key() ) )
2697 legendPatchShapeEl.setAttribute( u
"favorite"_s, u
"1"_s );
2699 legendPatchShapesElem.appendChild( legendPatchShapeEl );
2703 QDomElement symbols3DElem = doc.createElement( u
"symbols3d"_s );
2704 for (
auto it = m3dSymbols.constBegin(); it != m3dSymbols.constEnd(); ++it )
2706 QDomElement symbolEl = doc.createElement( u
"symbol3d"_s );
2707 symbolEl.setAttribute( u
"name"_s, it.key() );
2708 QDomElement defEl = doc.createElement( u
"definition"_s );
2709 defEl.setAttribute( u
"type"_s, it.value()->type() );
2711 symbolEl.appendChild( defEl );
2713 if (
tags.count() > 0 )
2715 symbolEl.setAttribute( u
"tags"_s,
tags.join(
',' ) );
2717 if ( favorite3DSymbols.contains( it.key() ) )
2719 symbolEl.setAttribute( u
"favorite"_s, u
"1"_s );
2721 symbols3DElem.appendChild( symbolEl );
2724 root.appendChild( symbolsElem );
2725 root.appendChild( rampsElem );
2726 root.appendChild( textFormatsElem );
2727 root.appendChild( labelSettingsElem );
2728 root.appendChild( legendPatchShapesElem );
2729 root.appendChild( symbols3DElem );
2732 QFile f( filename );
2733 if ( !f.open( QFile::WriteOnly | QIODevice::Truncate ) )
2735 mErrorString =
"Couldn't open file for writing: " + filename;
2739 QTextStream ts( &f );
2740#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
2741 ts.setCodec(
"UTF-8" );
2756 mErrorString = QString();
2757 QDomDocument doc( u
"style"_s );
2758 QFile f( filename );
2759 if ( !f.open( QFile::ReadOnly ) )
2761 mErrorString = u
"Unable to open the specified file"_s;
2766 if ( !doc.setContent( &f ) )
2768 mErrorString = u
"Unable to understand the style file: %1"_s.arg( filename );
2775 QDomElement docEl = doc.documentElement();
2776 if ( docEl.tagName() !=
"qgis_style"_L1 )
2778 mErrorString =
"Incorrect root tag in style: " + docEl.tagName();
2782 const QString version = docEl.attribute( u
"version"_s );
2785 mErrorString =
"Unknown style file version: " + version;
2791 QDomElement symbolsElement = docEl.firstChildElement( u
"symbols"_s );
2792 QDomElement e = symbolsElement.firstChildElement();
2796 runEmptyQuery( query );
2801 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2803 const int entityAddedVersion = e.attribute( u
"addedVersion"_s ).toInt();
2804 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2810 if ( e.tagName() ==
"symbol"_L1 )
2812 QString
name = e.attribute( u
"name"_s );
2814 if ( e.hasAttribute( u
"tags"_s ) )
2816 tags = e.attribute( u
"tags"_s ).split(
',' );
2818 bool favorite =
false;
2819 if ( e.hasAttribute( u
"favorite"_s ) && e.attribute( u
"favorite"_s ) ==
"1"_L1 )
2827 QgsSymbol *symbolPtr =
symbol.get();
2847 for ( QMap<QString, QgsSymbol *>::iterator it = symbols.begin(); it != symbols.end(); ++it )
2854 QDomElement rampsElement = docEl.firstChildElement( u
"colorramps"_s );
2855 e = rampsElement.firstChildElement();
2856 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2858 const int entityAddedVersion = e.attribute( u
"addedVersion"_s ).toInt();
2859 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2865 if ( e.tagName() ==
"colorramp"_L1 )
2867 QString
name = e.attribute( u
"name"_s );
2869 if ( e.hasAttribute( u
"tags"_s ) )
2871 tags = e.attribute( u
"tags"_s ).split(
',' );
2873 bool favorite =
false;
2874 if ( e.hasAttribute( u
"favorite"_s ) && e.attribute( u
"favorite"_s ) ==
"1"_L1 )
2882 QgsColorRamp *rampPtr = ramp.get();
2899 if ( qobject_cast< QGuiApplication * >( QCoreApplication::instance() ) )
2903 const QDomElement textFormatElement = docEl.firstChildElement( u
"textformats"_s );
2904 e = textFormatElement.firstChildElement();
2905 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2907 const int entityAddedVersion = e.attribute( u
"addedVersion"_s ).toInt();
2908 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2914 if ( e.tagName() ==
"textformat"_L1 )
2916 QString
name = e.attribute( u
"name"_s );
2918 if ( e.hasAttribute( u
"tags"_s ) )
2920 tags = e.attribute( u
"tags"_s ).split(
',' );
2922 bool favorite =
false;
2923 if ( e.hasAttribute( u
"favorite"_s ) && e.attribute( u
"favorite"_s ) ==
"1"_L1 )
2928 QgsTextFormat format;
2929 const QDomElement styleElem = e.firstChildElement();
2930 format.
readXml( styleElem, QgsReadWriteContext() );
2947 const QDomElement labelSettingsElement = docEl.firstChildElement( u
"labelsettings"_s );
2948 e = labelSettingsElement.firstChildElement();
2949 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2951 const int entityAddedVersion = e.attribute( u
"addedVersion"_s ).toInt();
2952 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2958 if ( e.tagName() ==
"labelsetting"_L1 )
2960 QString
name = e.attribute( u
"name"_s );
2962 if ( e.hasAttribute( u
"tags"_s ) )
2964 tags = e.attribute( u
"tags"_s ).split(
',' );
2966 bool favorite =
false;
2967 if ( e.hasAttribute( u
"favorite"_s ) && e.attribute( u
"favorite"_s ) ==
"1"_L1 )
2972 QgsPalLayerSettings settings;
2973 const QDomElement styleElem = e.firstChildElement();
2974 settings.
readXml( styleElem, QgsReadWriteContext() );
2992 const QDomElement legendPatchShapesElement = docEl.firstChildElement( u
"legendpatchshapes"_s );
2993 e = legendPatchShapesElement.firstChildElement();
2994 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2996 const int entityAddedVersion = e.attribute( u
"addedVersion"_s ).toInt();
2997 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
3003 if ( e.tagName() ==
"legendpatchshape"_L1 )
3005 QString
name = e.attribute( u
"name"_s );
3007 if ( e.hasAttribute( u
"tags"_s ) )
3009 tags = e.attribute( u
"tags"_s ).split(
',' );
3011 bool favorite =
false;
3012 if ( e.hasAttribute( u
"favorite"_s ) && e.attribute( u
"favorite"_s ) ==
"1"_L1 )
3017 QgsLegendPatchShape shape;
3018 const QDomElement shapeElem = e.firstChildElement();
3019 shape.
readXml( shapeElem, QgsReadWriteContext() );
3036 const QDomElement symbols3DElement = docEl.firstChildElement( u
"symbols3d"_s );
3037 e = symbols3DElement.firstChildElement();
3038 for ( ; !e.isNull(); e = e.nextSiblingElement() )
3040 const int entityAddedVersion = e.attribute( u
"addedVersion"_s ).toInt();
3041 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
3047 if ( e.tagName() ==
"symbol3d"_L1 )
3049 QString
name = e.attribute( u
"name"_s );
3051 if ( e.hasAttribute( u
"tags"_s ) )
3053 tags = e.attribute( u
"tags"_s ).split(
',' );
3055 bool favorite =
false;
3056 if ( e.hasAttribute( u
"favorite"_s ) && e.attribute( u
"favorite"_s ) ==
"1"_L1 )
3061 const QDomElement symbolElem = e.firstChildElement();
3062 const QString type = symbolElem.attribute( u
"type"_s );
3066 sym->readXml( symbolElem, QgsReadWriteContext() );
3067 QgsAbstract3DSymbol *newSym = sym.get();
3083 runEmptyQuery( query );
3090 QFileInfo fileInfo( path );
3092 if ( fileInfo.suffix().compare(
"xml"_L1, Qt::CaseInsensitive ) != 0 )
3096 if ( !QFile::exists( path ) )
3099 QFile inputFile( path );
3100 if ( !inputFile.open( QIODevice::ReadOnly ) )
3103 QTextStream stream( &inputFile );
3104 const QString line = stream.readLine();
3105 return line ==
"<!DOCTYPE qgis_style>"_L1;
3120 mReadOnly = readOnly;
3123bool QgsStyle::updateSymbol( StyleEntity type,
const QString &name )
3125 QDomDocument doc( u
"dummy"_s );
3127 QByteArray xmlArray;
3128 QTextStream stream( &xmlArray );
3129#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
3130 stream.setCodec(
"UTF-8" );
3140 auto it = mSymbols.constFind(
name );
3141 if ( it == mSymbols.constEnd() || !it.value() )
3143 QgsDebugError( u
"Update request received for unavailable symbol"_s );
3148 if ( symEl.isNull() )
3150 QgsDebugError( u
"Couldn't convert symbol to valid XML!"_s );
3153 symEl.save( stream, 4 );
3155 xmlArray.constData(),
name.toUtf8().constData() );
3162 auto it = m3dSymbols.constFind(
name );
3163 if ( it == m3dSymbols.constEnd() || !it.value() )
3165 QgsDebugError( u
"Update request received for unavailable symbol"_s );
3169 symEl = doc.createElement( u
"symbol"_s );
3170 symEl.setAttribute( u
"type"_s, it.value()->type() );
3171 it.value()->writeXml( symEl, QgsReadWriteContext() );
3172 if ( symEl.isNull() )
3174 QgsDebugError( u
"Couldn't convert symbol to valid XML!"_s );
3177 symEl.save( stream, 4 );
3179 xmlArray.constData(),
name.toUtf8().constData() );
3185 auto it = mColorRamps.constFind(
name );
3186 if ( it == mColorRamps.constEnd() || !it.value() )
3188 QgsDebugError( u
"Update requested for unavailable color ramp."_s );
3193 if ( symEl.isNull() )
3195 QgsDebugError( u
"Couldn't convert color ramp to valid XML!"_s );
3198 symEl.save( stream, 4 );
3200 xmlArray.constData(),
name.toUtf8().constData() );
3206 auto it = mTextFormats.constFind(
name );
3207 if ( it == mTextFormats.constEnd() )
3209 QgsDebugError( u
"Update requested for unavailable text format."_s );
3213 symEl = it.value().writeXml( doc, QgsReadWriteContext() );
3214 if ( symEl.isNull() )
3216 QgsDebugError( u
"Couldn't convert text format to valid XML!"_s );
3219 symEl.save( stream, 4 );
3221 xmlArray.constData(),
name.toUtf8().constData() );
3227 auto it = mLabelSettings.constFind(
name );
3228 if ( it == mLabelSettings.constEnd() )
3230 QgsDebugError( u
"Update requested for unavailable label settings."_s );
3234 symEl = it.value().writeXml( doc, QgsReadWriteContext() );
3235 if ( symEl.isNull() )
3237 QgsDebugError( u
"Couldn't convert label settings to valid XML!"_s );
3240 symEl.save( stream, 4 );
3242 xmlArray.constData(),
name.toUtf8().constData() );
3248 auto it = mLegendPatchShapes.constFind(
name );
3249 if ( it == mLegendPatchShapes.constEnd() )
3251 QgsDebugError( u
"Update requested for unavailable legend patch shape."_s );
3255 symEl = doc.createElement( u
"shape"_s );
3256 it.value().writeXml( symEl, doc, QgsReadWriteContext() );
3257 symEl.save( stream, 4 );
3259 xmlArray.constData(),
name.toUtf8().constData() );
3272 if ( !runEmptyQuery( query ) )
3274 QgsDebugError( u
"Couldn't update symbol into the database!"_s );
3310 mCachedTags[ type ].remove(
name );
3313bool QgsStyle::createStyleMetadataTableIfNeeded()
3316 QString query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='stylemetadata'" );
3317 sqlite3_statement_unique_ptr statement;
3319 statement = mCurrentDB.prepare( query, rc );
3321 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
3325 "id INTEGER PRIMARY KEY,"\
3328 runEmptyQuery( query );
3330 runEmptyQuery( query );
3339void QgsStyle::upgradeIfRequired()
3343 if ( !createStyleMetadataTableIfNeeded() )
3345 const QString query =
qgs_sqlite3_mprintf(
"SELECT value FROM stylemetadata WHERE key='version'" );
3347 sqlite3_statement_unique_ptr statement = mCurrentDB.prepare( query, rc );
3348 if ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
3360 runEmptyQuery( query );
3373 return u
"colorramp"_s;
3376 return u
"textformat"_s;
3379 return u
"labelsettings"_s;
3382 return u
"legendpatchshapes"_s;
3385 return u
"symbol3d"_s;
3391 return u
"smartgroup"_s;
3404 return u
"ctagmap"_s;
3407 return u
"tftagmap"_s;
3410 return u
"lstagmap"_s;
3413 return u
"lpstagmap"_s;
3416 return u
"symbol3dtagmap"_s;
3430 return u
"symbol_id"_s;
3433 return u
"colorramp_id"_s;
3436 return u
"textformat_id"_s;
3439 return u
"labelsettings_id"_s;
3442 return u
"legendpatchshape_id"_s;
3445 return u
"symbol3d_id"_s;
@ ScaleArea
Calculate scale by the area.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
static int versionInt()
Version number used for comparing versions using the "Check QGIS Version" function.
QStringList symbolTypes() const
Returns a list of all available symbol types.
Abstract base class for 3D symbols that are used by VectorLayer3DRenderer objects.
virtual QgsAbstract3DSymbol * clone() const =0
Returns a new instance of the symbol with the same settings.
static QString userStylePath()
Returns the path to user's style.
static QString defaultStylePath()
Returns the path to default style (works as a starting point).
static Qgs3DSymbolRegistry * symbol3DRegistry()
Returns registry of available 3D symbols.
Abstract base class for color ramps.
virtual double value(int index) const =0
Returns relative value between [0,1] of color at specified index.
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
A geometry is the spatial representation of a feature.
Represents a patch shape for use in map legends.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Read settings from a DOM element.
QList< QList< QPolygonF > > toQPolygonF(Qgis::SymbolType type, QSizeF size) const
Converts the patch shape to a set of QPolygonF objects representing how the patch should be drawn for...
void writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
Qgis::SymbolType symbolType() const
Returns the symbol type associated with this patch.
Line string geometry type, with support for z-dimension and m-values.
Contains settings for how a map layer will be labeled.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
QgsTextFormat defaultTextFormat() const
Returns the project default text format.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
const QgsProjectStyleSettings * styleSettings() const
Returns the project's style settings, which contains settings and properties relating to how a QgsPro...
A container for the context for various read/write operations on objects.
Scoped object for logging of the runtime for a single operation or group of operations.
Stores settings for use within QGIS.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
A color ramp entity for QgsStyle databases.
QgsStyle::StyleEntity type() const override
Returns the type of style entity.
An interface for entities which can be placed in a QgsStyle database.
virtual QgsStyle::StyleEntity type() const =0
Returns the type of style entity.
A label settings entity for QgsStyle databases.
QgsStyle::StyleEntity type() const override
Returns the type of style entity.
A legend patch shape entity for QgsStyle databases.
QgsStyle::StyleEntity type() const override
Returns the type of style entity.
A 3d symbol entity for QgsStyle databases.
QgsStyle::StyleEntity type() const override
Returns the type of style entity.
A symbol entity for QgsStyle databases.
QgsStyle::StyleEntity type() const override
Returns the type of style entity.
A text format entity for QgsStyle databases.
QgsStyle::StyleEntity type() const override
Returns the type of style entity.
A database of saved style entities, including symbols, color ramps, text formats and others.
bool addEntity(const QString &name, const QgsStyleEntityInterface *entity, bool update=false)
Adds an entity to the style, with the specified name.
void setFileName(const QString &filename)
Sets the current file name of the style database.
void labelSettingsChanged(const QString &name)
Emitted whenever a label setting's definition is changed.
int colorRampCount()
Returns count of color ramps.
bool detagSymbol(StyleEntity type, const QString &symbol, const QStringList &tags)
Detags the symbol with the given list.
QgsTextFormat textFormat(const QString &name) const
Returns the text format with the specified name.
QStringList allNames(StyleEntity type) const
Returns a list of the names of all existing entities of the specified type.
QgsLegendPatchShape defaultPatch(Qgis::SymbolType type, QSizeF size) const
Returns the default legend patch shape for the given symbol type.
bool remove(StyleEntity type, int id)
Removes the specified entity from the database.
bool removeSymbol(const QString &name)
Removes symbol from style (and delete it).
void entityChanged(QgsStyle::StyleEntity entity, const QString &name)
Emitted whenever an entity's definition is changed.
bool removeLabelSettings(const QString &name)
Removes label settings from the style.
void labelSettingsAdded(const QString &name)
Emitted whenever label settings have been added to the style and the database has been updated as a r...
QStringList tags() const
Returns a list of all tags in the style database.
QString tag(int id) const
Returns the tag name for the given id.
QgsSmartConditionMap smartgroup(int id)
Returns the QgsSmartConditionMap for the given id.
bool renameColorRamp(const QString &oldName, const QString &newName)
Changes ramp's name.
void rampAdded(const QString &name)
Emitted whenever a color ramp has been added to the style and the database has been updated as a resu...
QStringList symbol3DNames() const
Returns a list of names of 3d symbols in the style.
bool tagSymbol(StyleEntity type, const QString &symbol, const QStringList &tags)
Tags the symbol with the tags in the list.
int entityId(StyleEntity type, const QString &name)
Returns the id in the style database for the given name of the specified entity type.
void rebuildIconPreviews()
Emitted whenever icon previews for entities in the style must be rebuilt.
bool saveLabelSettings(const QString &name, const QgsPalLayerSettings &settings, bool favorite, const QStringList &tags)
Adds label settings to the database.
Q_DECL_DEPRECATED bool save(const QString &filename=QString())
Saves style into a file.
bool symbolHasTag(StyleEntity type, const QString &symbol, const QString &tag)
Returns whether a given tag is associated with the symbol.
void aboutToBeDestroyed()
Emitted just before the style object is destroyed.
QgsTextFormat defaultTextFormat(QgsStyle::TextFormatContext context=QgsStyle::TextFormatContext::Labeling) const
Returns the default text format to use for new text based objects in the specified context.
@ XML
Label settings definition (as XML).
@ Name
Label settings name.
bool createDatabase(const QString &filename)
Creates an on-disk database.
QStringList textFormatNames() const
Returns a list of names of text formats in the style.
const QgsColorRamp * colorRampRef(const QString &name) const
Returns a const pointer to a symbol (doesn't create new instance).
QStringList symbolsWithTag(StyleEntity type, int tagid) const
Returns the symbol names with which have the given tag.
bool addColorRamp(const QString &name, QgsColorRamp *colorRamp, bool update=false)
Adds a color ramp to the style.
bool removeTextFormat(const QString &name)
Removes a text format from the style.
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
void labelSettingsRemoved(const QString &name)
Emitted whenever label settings have been removed from the style and the database has been updated as...
QStringList symbolsOfSmartgroup(StyleEntity type, int id)
Returns the symbols for the smartgroup.
int labelSettingsCount() const
Returns count of label settings in the style.
StyleEntity
Enum for Entities involved in a style.
@ LabelSettingsEntity
Label settings.
@ TextFormatEntity
Text formats.
@ SmartgroupEntity
Smart groups.
@ Symbol3DEntity
3D symbol entity
@ ColorrampEntity
Color ramps.
@ LegendPatchShapeEntity
Legend patch shape.
QStringList tagsOfSymbol(StyleEntity type, const QString &symbol)
Returns the tags associated with the symbol.
void symbolRenamed(const QString &oldName, const QString &newName)
Emitted whenever a symbol has been renamed from oldName to newName.
QList< Qgis::GeometryType > symbol3DCompatibleGeometryTypes(const QString &name) const
Returns the list of the vector layer geometry types which are compatible with the 3D symbol with the ...
@ XML
Color ramp definition (as XML).
void groupsModified()
Emitted every time a tag or smartgroup has been added, removed, or renamed.
void clear()
Removes all contents of the style.
int smartgroupId(const QString &smartgroup)
Returns the database id for the given smartgroup name.
void rampRemoved(const QString &name)
Emitted whenever a color ramp has been removed from the style and the database has been updated as a ...
void entityRenamed(QgsStyle::StyleEntity entity, const QString &oldName, const QString &newName)
Emitted whenever a entity of the specified type has been renamed from oldName to newName.
const QgsSymbol * symbolRef(const QString &name) const
Returns a const pointer to a symbol (doesn't create new instance).
int addSmartgroup(const QString &name, const QString &op, const QgsSmartConditionMap &conditions)
Adds a new smartgroup to the database and returns the id.
QStringList colorRampNames() const
Returns a list of names of color ramps.
void textFormatChanged(const QString &name)
Emitted whenever a text format's definition is changed.
bool addSymbol3D(const QString &name, QgsAbstract3DSymbol *symbol, bool update=false)
Adds a 3d symbol with the specified name to the style.
QStringList legendPatchShapeNames() const
Returns a list of names of legend patch shapes in the style.
bool renameLegendPatchShape(const QString &oldName, const QString &newName)
Changes a legend patch shape's name.
static void cleanDefaultStyle()
Deletes the default style. Only to be used by QgsApplication::exitQgis().
void symbolSaved(const QString &name, const QgsSymbol *symbol)
Emitted every time a new symbol has been added to the database.
void textFormatRenamed(const QString &oldName, const QString &newName)
Emitted whenever a text format has been renamed from oldName to newName.
void triggerIconRebuild()
Triggers emission of the rebuildIconPreviews() signal.
void setName(const QString &name)
Sets the name of the style.
bool removeEntityByName(StyleEntity type, const QString &name)
Removes the entry of the specified type with matching name from the database.
void labelSettingsRenamed(const QString &oldName, const QString &newName)
Emitted whenever label settings have been renamed from oldName to newName.
void initialized()
Emitted when the style database has been fully initialized.
@ XML
Text format definition (as XML).
int textFormatCount() const
Returns count of text formats in the style.
QStringList findSymbols(StyleEntity type, const QString &qword)
Returns the names of the symbols which have a matching 'substring' in its definition.
int tagId(const QString &tag)
Returns the database id for the given tag name.
void rampRenamed(const QString &oldName, const QString &newName)
Emitted whenever a color ramp has been renamed from oldName to newName.
bool exportXml(const QString &filename)
Exports the style as a XML file.
void createTables()
Creates tables structure for new database.
bool isReadOnly() const
Returns true if the style is considered a read-only library.
bool addLegendPatchShape(const QString &name, const QgsLegendPatchShape &shape, bool update=false)
Adds a legend patch shape with the specified name to the style.
int textFormatId(const QString &name)
Returns the ID in the style database for the given text format by name.
QgsColorRamp * colorRamp(const QString &name) const
Returns a new copy of the specified color ramp.
int symbolCount()
Returns count of symbols in style.
bool renameEntity(StyleEntity type, const QString &oldName, const QString &newName)
Renames an entity of the specified type from oldName to newName.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
static bool isXmlStyleFile(const QString &path)
Tests if the file at path is a QGIS style XML file.
int symbol3DCount() const
Returns count of 3D symbols in the style.
bool createMemoryDatabase()
Creates a temporary memory database.
int colorrampId(const QString &name)
Returns the id in the style database for the given colorramp name returns 0 if not found.
bool saveSymbol(const QString &name, const QgsSymbol *symbol, bool favorite, const QStringList &tags)
Adds the symbol to the database with tags.
QStringList labelSettingsNames() const
Returns a list of names of label settings in the style.
bool load(const QString &filename)
Loads a file into the style.
QStringList smartgroupNames() const
Returns the smart groups list.
bool rename(StyleEntity type, int id, const QString &newName)
Renames the given entity with the specified id.
bool renameTextFormat(const QString &oldName, const QString &newName)
Changes a text format's name.
void textFormatAdded(const QString &name)
Emitted whenever a text format has been added to the style and the database has been updated as a res...
bool removeFavorite(StyleEntity type, const QString &name)
Removes the specified symbol from favorites.
static QgsTextFormat defaultTextFormatForProject(QgsProject *project, QgsStyle::TextFormatContext context=QgsStyle::TextFormatContext::Labeling)
Returns the default text format to use for new text based objects for the specified project,...
int legendPatchShapesCount() const
Returns count of legend patch shapes in the style.
QgsSymbolGroupMap smartgroupsListMap()
Returns the smart groups map with id as key and name as value.
bool isFavorite(StyleEntity type, const QString &name)
Returns true if the symbol with matching type and name is marked as a favorite.
int symbolId(const QString &name)
Returns the id in the style database for the given symbol name returns 0 if not found.
bool saveLegendPatchShape(const QString &name, const QgsLegendPatchShape &shape, bool favorite, const QStringList &tags)
Adds a legend patch shape to the database.
QString name() const
Returns the name of the style.
QgsStyle(QObject *parent=nullptr)
Constructor for QgsStyle, with the specified parent object.
Qgis::GeometryType labelSettingsLayerType(const QString &name) const
Returns the layer geometry type corresponding to the label settings with the specified name,...
@ XML
Symbol definition (as XML).
bool renameLabelSettings(const QString &oldName, const QString &newName)
Changes a label setting's name.
bool renameSymbol3D(const QString &oldName, const QString &newName)
Changes a 3d symbol's name.
bool addTextFormat(const QString &name, const QgsTextFormat &format, bool update=false)
Adds a text format with the specified name to the style.
bool saveColorRamp(const QString &name, const QgsColorRamp *ramp, bool favorite, const QStringList &tags)
Adds the colorramp to the database.
void rampChanged(const QString &name)
Emitted whenever a color ramp's definition is changed.
QStringList symbolsOfFavorite(StyleEntity type) const
Returns the symbol names which are flagged as favorite.
void entityTagsChanged(QgsStyle::StyleEntity entity, const QString &name, const QStringList &newTags)
Emitted whenever an entity's tags are changed.
bool renameSymbol(const QString &oldName, const QString &newName)
Renames a symbol from oldName to newName.
bool removeColorRamp(const QString &name)
Removes color ramp from style (and delete it).
bool saveSymbol3D(const QString &name, QgsAbstract3DSymbol *symbol, bool favorite, const QStringList &tags)
Adds a 3d symbol to the database.
void favoritedChanged(QgsStyle::StyleEntity entity, const QString &name, bool isFavorite)
Emitted whenever an entity is either favorited or un-favorited.
QgsPalLayerSettings labelSettings(const QString &name) const
Returns the label settings with the specified name.
void entityRemoved(QgsStyle::StyleEntity entity, const QString &name)
Emitted whenever an entity of the specified type is removed from the style and the database has been ...
int labelSettingsId(const QString &name)
Returns the ID in the style database for the given label settings by name.
Qgis::SymbolType legendPatchShapeSymbolType(const QString &name) const
Returns the symbol type corresponding to the legend patch shape with the specified name,...
QgsAbstract3DSymbol * symbol3D(const QString &name) const
Returns a new copy of the 3D symbol with the specified name.
int addTag(const QString &tagName)
Adds a new tag and returns the tag's id.
const QgsSymbol * previewSymbolForPatchShape(const QgsLegendPatchShape &shape) const
Returns a symbol to use for rendering preview icons for a patch shape.
bool addSymbol(const QString &name, QgsSymbol *symbol, bool update=false)
Adds a symbol to style and takes symbol's ownership.
QgsLegendPatchShape legendPatchShape(const QString &name) const
Returns the legend patch shape with the specified name.
void entityAdded(QgsStyle::StyleEntity entity, const QString &name)
Emitted every time a new entity has been added to the database.
QStringList symbolNames() const
Returns a list of names of symbols.
TextFormatContext
Text format context.
void symbolRemoved(const QString &name)
Emitted whenever a symbol has been removed from the style and the database has been updated as a resu...
void symbolChanged(const QString &name)
Emitted whenever a symbol's definition is changed.
bool addFavorite(StyleEntity type, const QString &name)
Adds the specified symbol to favorites.
QString smartgroupOperator(int id)
Returns the operator for the smartgroup.
bool saveTextFormat(const QString &name, const QgsTextFormat &format, bool favorite, const QStringList &tags)
Adds a text format to the database.
QList< QList< QPolygonF > > defaultPatchAsQPolygonF(Qgis::SymbolType type, QSizeF size) const
Returns the default patch geometry for the given symbol type and size as a set of QPolygonF objects (...
void textFormatRemoved(const QString &name)
Emitted whenever a text format has been removed from the style and the database has been updated as a...
void setReadOnly(bool readOnly)
Sets whether the style is considered a read-only library.
bool importXml(const QString &filename)
Imports the symbols and colorramps into the default style database from the given XML file.
bool addLabelSettings(const QString &name, const QgsPalLayerSettings &settings, bool update=false)
Adds label settings with the specified name to the style.
static std::unique_ptr< QgsColorRamp > loadColorRamp(QDomElement &element)
Creates a color ramp from the settings encoded in an XML element.
static std::unique_ptr< QgsSymbol > loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
static QDomElement saveColorRamp(const QString &name, const QgsColorRamp *ramp, QDomDocument &doc)
Encodes a color ramp's settings to an XML element.
static void resetSymbolLayerIds(QgsSymbol *symbol)
Regenerate recursively unique id from all symbol symbol layers.
static QgsSymbolMap loadSymbols(QDomElement &element, const QgsReadWriteContext &context)
Reads a collection of symbols from XML and returns them in a map. Caller is responsible for deleting ...
static QDomElement saveSymbols(QgsSymbolMap &symbols, const QString &tagName, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a collection of symbols to XML with specified tagName for the top-level element.
Abstract base class for all rendered symbols.
Container for all settings relating to text rendering.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
QString columnAsText(int column) const
Returns the column value from the current statement row as a string.
QMultiMap< QString, QString > QgsSmartConditionMap
A multimap to hold the smart group conditions as constraint and parameter pairs.
#define QgsDebugError(str)
QMap< QString, QgsSymbol * > QgsSymbolMap
QString qgs_sqlite3_mprintf(const char *format,...)
Wraps sqlite3_mprintf() by automatically freeing the memory.
LegendPatchTable
Columns available in the legend patch table.
@ LegendPatchTableId
Legend patch ID.
@ LegendPatchTableName
Legend patch name.
@ LegendPatchTableFavoriteId
Legend patch is favorite flag.
@ LegendPatchTableXML
Legend patch definition (as XML).
#define STYLE_CURRENT_VERSION
Symbol3DTable
Columns available in the 3d symbol table.
@ Symbol3DTableXML
3d symbol definition (as XML)
@ Symbol3DTableName
3d symbol name
@ Symbol3DTableFavoriteId
3d symbol is favorite flag
@ Symbol3DTableId
3d symbol ID
QMap< int, QString > QgsSymbolGroupMap
QList< QgsSymbolLayer * > QgsSymbolLayerList