40#include <QDomDocument>
43#include <QDomNodeList>
52#define STYLE_CURRENT_VERSION "2"
77QgsStyle *QgsStyle::sDefaultStyle =
nullptr;
82 std::unique_ptr< QgsSimpleMarkerSymbolLayer > simpleMarker = std::make_unique< QgsSimpleMarkerSymbolLayer >(
Qgis::MarkerShape::Circle,
84 simpleMarker->setStrokeWidth( 0.4 );
85 mPatchMarkerSymbol = std::make_unique< QgsMarkerSymbol >(
QgsSymbolLayerList() << simpleMarker.release() );
87 std::unique_ptr< QgsSimpleLineSymbolLayer > simpleLine = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 84, 176, 74 ), 0.6 );
88 mPatchLineSymbol = std::make_unique< QgsLineSymbol >(
QgsSymbolLayerList() << simpleLine.release() );
90 std::unique_ptr< QgsGradientFillSymbolLayer > gradientFill = std::make_unique< QgsGradientFillSymbolLayer >( QColor( 66, 150, 63 ), QColor( 84, 176, 74 ) );
91 std::unique_ptr< QgsSimpleLineSymbolLayer > simpleOutline = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 56, 128, 54 ), 0.26 );
92 mPatchFillSymbol = std::make_unique< QgsFillSymbol >(
QgsSymbolLayerList() << gradientFill.release() << simpleOutline.release() );
113 switch ( entity->
type() )
147 static QString sStyleFilename;
148 if ( !sDefaultStyle )
154 if ( !QFile::exists( sStyleFilename ) )
162 sDefaultStyle->createStyleMetadataTableIfNeeded();
169 sDefaultStyle->mInitialized =
false;
172 sDefaultStyle->initializeDefaultStyle( sStyleFilename );
175 sDefaultStyle->
setName( QObject::tr(
"Default" ) );
177 else if ( initialize && !sDefaultStyle->mInitialized )
180 sDefaultStyle->initializeDefaultStyle( sStyleFilename );
182 return sDefaultStyle;
185void QgsStyle::initializeDefaultStyle(
const QString &filename )
187 Q_ASSERT(
this == sDefaultStyle );
188 if (
this != sDefaultStyle )
204 delete sDefaultStyle;
205 sDefaultStyle =
nullptr;
210 qDeleteAll( mSymbols );
211 qDeleteAll( mColorRamps );
212 qDeleteAll( m3dSymbols );
216 mTextFormats.clear();
220 mCachedFavorites.clear();
229 if ( mSymbols.contains(
name ) )
232 delete mSymbols.value(
name );
250 QDomDocument doc( QStringLiteral(
"dummy" ) );
252 if ( symEl.isNull() )
254 QgsDebugError( QStringLiteral(
"Couldn't convert symbol to valid XML!" ) );
259 QTextStream stream( &xmlArray );
260#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
261 stream.setCodec(
"UTF-8" );
263 symEl.save( stream, 4 );
265 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
267 if ( !runEmptyQuery( query ) )
269 QgsDebugError( QStringLiteral(
"Couldn't insert symbol into the database!" ) );
331 return mSymbols.value(
name );
336 return mSymbols.count();
341 return mSymbols.keys();
351 if ( mColorRamps.contains(
name ) )
354 delete mColorRamps.value(
name );
372 if ( mTextFormats.contains(
name ) )
375 mTextFormats.remove(
name );
376 mTextFormats.insert(
name, format );
382 mTextFormats.insert(
name, format );
393 if ( mLabelSettings.contains(
name ) )
396 mLabelSettings.remove(
name );
397 mLabelSettings.insert(
name, settings );
403 mLabelSettings.insert(
name, settings );
414 if ( mLegendPatchShapes.contains(
name ) )
417 mLegendPatchShapes.remove(
name );
418 mLegendPatchShapes.insert(
name, shape );
424 mLegendPatchShapes.insert(
name, shape );
435 if ( m3dSymbols.contains(
name ) )
438 delete m3dSymbols.take(
name );
456 QDomDocument doc( QStringLiteral(
"dummy" ) );
459 if ( rampEl.isNull() )
461 QgsDebugError( QStringLiteral(
"Couldn't convert color ramp to valid XML!" ) );
466 QTextStream stream( &xmlArray );
467#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
468 stream.setCodec(
"UTF-8" );
470 rampEl.save( stream, 4 );
471 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
472 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
473 if ( !runEmptyQuery( query ) )
475 QgsDebugError( QStringLiteral(
"Couldn't insert colorramp into the database!" ) );
497 return ramp ? ramp->
clone() :
nullptr;
502 return mColorRamps.value(
name );
507 return mColorRamps.count();
512 return mColorRamps.keys();
515void QgsStyle::handleDeferred3DSymbolCreation()
517 for (
auto it = mDeferred3DsymbolElements.constBegin(); it != mDeferred3DsymbolElements.constEnd(); ++it )
519 const QString symbolType = it.value().attribute( QStringLiteral(
"type" ) );
533 mDeferred3DsymbolElements.clear();
536bool QgsStyle::openDatabase(
const QString &filename )
538 int rc = mCurrentDB.
open( filename );
541 mErrorString = QStringLiteral(
"Couldn't open the style database: %1" ).arg( mCurrentDB.
errorMessage() );
550 mErrorString.clear();
551 if ( !openDatabase( filename ) )
553 mErrorString = QStringLiteral(
"Unable to create database" );
565 mErrorString.clear();
566 if ( !openDatabase( QStringLiteral(
":memory:" ) ) )
568 mErrorString = QStringLiteral(
"Unable to create temporary memory database" );
581 "id INTEGER PRIMARY KEY,"\
584 "favorite INTEGER);"\
585 "CREATE TABLE colorramp("\
586 "id INTEGER PRIMARY KEY,"\
589 "favorite INTEGER);"\
590 "CREATE TABLE textformat("\
591 "id INTEGER PRIMARY KEY,"\
594 "favorite INTEGER);"\
595 "CREATE TABLE labelsettings("\
596 "id INTEGER PRIMARY KEY,"\
599 "favorite INTEGER);"\
600 "CREATE TABLE legendpatchshapes("\
601 "id INTEGER PRIMARY KEY,"\
604 "favorite INTEGER);"\
605 "CREATE TABLE symbol3d("\
606 "id INTEGER PRIMARY KEY,"\
609 "favorite INTEGER);"\
611 "id INTEGER PRIMARY KEY,"\
613 "CREATE TABLE tagmap("\
614 "tag_id INTEGER NOT NULL,"\
615 "symbol_id INTEGER);"\
616 "CREATE TABLE ctagmap("\
617 "tag_id INTEGER NOT NULL,"\
618 "colorramp_id INTEGER);"\
619 "CREATE TABLE tftagmap("\
620 "tag_id INTEGER NOT NULL,"\
621 "textformat_id INTEGER);"\
622 "CREATE TABLE lstagmap("\
623 "tag_id INTEGER NOT NULL,"\
624 "labelsettings_id INTEGER);"\
625 "CREATE TABLE lpstagmap("\
626 "tag_id INTEGER NOT NULL,"\
627 "legendpatchshape_id INTEGER);"\
628 "CREATE TABLE symbol3dtagmap("\
629 "tag_id INTEGER NOT NULL,"\
630 "symbol3d_id INTEGER);"\
631 "CREATE TABLE smartgroup("\
632 "id INTEGER PRIMARY KEY,"\
635 runEmptyQuery( query );
640 mErrorString.clear();
643 if ( !openDatabase( filename ) )
645 mErrorString = QStringLiteral(
"Unable to open database file specified" );
651 QString query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='textformat'" );
654 statement = mCurrentDB.
prepare( query, rc );
655 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
658 "id INTEGER PRIMARY KEY,"\
661 "favorite INTEGER);"\
662 "CREATE TABLE tftagmap("\
663 "tag_id INTEGER NOT NULL,"\
664 "textformat_id INTEGER);" );
665 runEmptyQuery( query );
668 query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='labelsettings'" );
669 statement = mCurrentDB.
prepare( query, rc );
670 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
673 "id INTEGER PRIMARY KEY,"\
676 "favorite INTEGER);"\
677 "CREATE TABLE lstagmap("\
678 "tag_id INTEGER NOT NULL,"\
679 "labelsettings_id INTEGER);" );
680 runEmptyQuery( query );
683 query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='legendpatchshapes'" );
684 statement = mCurrentDB.
prepare( query, rc );
685 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
688 "id INTEGER PRIMARY KEY,"\
691 "favorite INTEGER);"\
692 "CREATE TABLE lpstagmap("\
693 "tag_id INTEGER NOT NULL,"\
694 "legendpatchshape_id INTEGER);" );
695 runEmptyQuery( query );
699 statement = mCurrentDB.
prepare( query, rc );
700 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
703 "id INTEGER PRIMARY KEY,"\
706 "favorite INTEGER);"\
707 "CREATE TABLE symbol3dtagmap("\
708 "tag_id INTEGER NOT NULL,"\
709 "symbol3d_id INTEGER);" );
710 runEmptyQuery( query );
715 "UPDATE colorramp SET favorite=0 WHERE favorite IS NULL;"
716 "UPDATE textformat SET favorite=0 WHERE favorite IS NULL;"
717 "UPDATE labelsettings SET favorite=0 WHERE favorite IS NULL;"
718 "UPDATE legendpatchshapes SET favorite=0 WHERE favorite IS NULL;"
719 "UPDATE symbol3d SET favorite=0 WHERE favorite IS NULL;"
721 runEmptyQuery( query );
727 statement = mCurrentDB.
prepare( query, rc );
729 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
735 if ( !doc.setContent( xmlstring ) )
741 QDomElement symElement = doc.documentElement();
744 mSymbols.insert( symbolName,
symbol );
751 statement = mCurrentDB.
prepare( query, rc );
752 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
758 if ( !doc.setContent( xmlstring ) )
763 QDomElement rampElement = doc.documentElement();
766 mColorRamps.insert( rampName, ramp );
773 statement = mCurrentDB.
prepare( query, rc );
774 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
780 if ( !doc.setContent( xmlstring ) )
785 QDomElement formatElement = doc.documentElement();
788 mTextFormats.insert( formatName, format );
795 statement = mCurrentDB.
prepare( query, rc );
796 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
802 if ( !doc.setContent( xmlstring ) )
804 QgsDebugError(
"Cannot open label settings " + settingsName );
807 QDomElement settingsElement = doc.documentElement();
810 mLabelSettings.insert( settingsName, settings );
817 statement = mCurrentDB.
prepare( query, rc );
818 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
824 if ( !doc.setContent( xmlstring ) )
826 QgsDebugError(
"Cannot open legend patch shape " + settingsName );
829 QDomElement settingsElement = doc.documentElement();
832 mLegendPatchShapes.insert( settingsName, shape );
839 statement = mCurrentDB.
prepare( query, rc );
843 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
849 if ( !doc.setContent( xmlstring ) )
854 QDomElement settingsElement = doc.documentElement();
856 if ( !registry3dPopulated )
858 mDeferred3DsymbolElements.insert( settingsName, settingsElement );
862 const QString symbolType = settingsElement.attribute( QStringLiteral(
"type" ) );
867 m3dSymbols.insert( settingsName,
symbol.release() );
878 mFileName = filename;
879 createStyleMetadataTableIfNeeded();
885 mErrorString.clear();
887 if ( !filename.isEmpty() )
888 mFileName = filename;
895 mFileName = filename;
900 if ( mSymbols.contains( newName ) )
902 QgsDebugError( QStringLiteral(
"Symbol of new name already exists" ) );
910 mSymbols.insert( newName,
symbol );
914 QgsDebugError( QStringLiteral(
"Sorry! Cannot open database to tag." ) );
921 QgsDebugError( QStringLiteral(
"No such symbol for tagging in database: " ) + oldName );
940 if ( mColorRamps.contains( newName ) )
942 QgsDebugError( QStringLiteral(
"Color ramp of new name already exists." ) );
950 mColorRamps.insert( newName, ramp );
956 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM colorramp WHERE name='%q'", oldName.toUtf8().constData() );
958 statement = mCurrentDB.
prepare( query, nErr );
959 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
961 rampid = sqlite3_column_int( statement.get(), 0 );
976 QDomDocument doc( QStringLiteral(
"dummy" ) );
979 if ( formatElem.isNull() )
981 QgsDebugError( QStringLiteral(
"Couldn't convert text format to valid XML!" ) );
986 QTextStream stream( &xmlArray );
987#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
988 stream.setCodec(
"UTF-8" );
990 formatElem.save( stream, 4 );
991 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO textformat VALUES (NULL, '%q', '%q', %d);",
992 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
993 if ( !runEmptyQuery( query ) )
995 QgsDebugError( QStringLiteral(
"Couldn't insert text format into the database!" ) );
1016 if ( mTextFormats.contains( newName ) )
1018 QgsDebugError( QStringLiteral(
"Text format of new name already exists." ) );
1022 if ( !mTextFormats.contains( oldName ) )
1026 mTextFormats.insert( newName, format );
1032 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM textformat WHERE name='%q'", oldName.toUtf8().constData() );
1034 statement = mCurrentDB.
prepare( query, nErr );
1035 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1037 textFormatId = sqlite3_column_int( statement.get(), 0 );
1052 QDomDocument doc( QStringLiteral(
"dummy" ) );
1055 if ( settingsElem.isNull() )
1057 QgsDebugError( QStringLiteral(
"Couldn't convert label settings to valid XML!" ) );
1061 QByteArray xmlArray;
1062 QTextStream stream( &xmlArray );
1063#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1064 stream.setCodec(
"UTF-8" );
1066 settingsElem.save( stream, 4 );
1067 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO labelsettings VALUES (NULL, '%q', '%q', %d);",
1068 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
1069 if ( !runEmptyQuery( query ) )
1071 QgsDebugError( QStringLiteral(
"Couldn't insert label settings into the database!" ) );
1092 if ( mLabelSettings.contains( newName ) )
1094 QgsDebugError( QStringLiteral(
"Label settings of new name already exists." ) );
1098 if ( !mLabelSettings.contains( oldName ) )
1102 mLabelSettings.insert( newName, settings );
1108 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM labelsettings WHERE name='%q'", oldName.toUtf8().constData() );
1110 statement = mCurrentDB.
prepare( query, nErr );
1111 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1128 QDomDocument doc( QStringLiteral(
"dummy" ) );
1129 QDomElement shapeElem = doc.createElement( QStringLiteral(
"shape" ) );
1132 QByteArray xmlArray;
1133 QTextStream stream( &xmlArray );
1134#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1135 stream.setCodec(
"UTF-8" );
1137 shapeElem.save( stream, 4 );
1138 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO legendpatchshapes VALUES (NULL, '%q', '%q', %d);",
1139 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
1140 if ( !runEmptyQuery( query ) )
1142 QgsDebugError( QStringLiteral(
"Couldn't insert legend patch shape into the database!" ) );
1157 if ( mLegendPatchShapes.contains( newName ) )
1159 QgsDebugError( QStringLiteral(
"Legend patch shape of new name already exists." ) );
1163 if ( !mLegendPatchShapes.contains( oldName ) )
1167 mLegendPatchShapes.insert( newName, shape );
1173 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM legendpatchshapes WHERE name='%q'", oldName.toUtf8().constData() );
1175 statement = mCurrentDB.
prepare( query, nErr );
1176 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1194 if ( mDefaultPatchCache[
static_cast< int >( type ) ].contains( size ) )
1195 return mDefaultPatchCache[
static_cast< int >( type ) ].value( size );
1201 geom =
QgsGeometry( std::make_unique< QgsPoint >(
static_cast< int >( size.width() ) / 2,
static_cast< int >( size.height() ) / 2 ) );
1208 double y =
static_cast< int >( size.height() ) / 2 + 0.5;
1209 geom =
QgsGeometry( std::make_unique< QgsLineString >( ( QVector< double >() << 0 << size.width() ),
1210 ( QVector< double >() << y << y ) ) );
1216 geom =
QgsGeometry( std::make_unique< QgsPolygon >(
1217 new QgsLineString( QVector< double >() << 0 <<
static_cast< int >( size.width() ) <<
static_cast< int >( size.width() ) << 0 << 0,
1218 QVector< double >() <<
static_cast< int >( size.height() ) <<
static_cast< int >( size.height() ) << 0 << 0 <<
static_cast< int >( size.height() ) ) ) );
1227 mDefaultPatchCache[
static_cast< int >( type ) ][size ] = res;
1234 return QList<QList<QPolygonF> >();
1236 if ( mDefaultPatchQPolygonFCache[
static_cast< int >( type ) ].contains( size ) )
1237 return mDefaultPatchQPolygonFCache[
static_cast< int >( type ) ].value( size );
1240 mDefaultPatchQPolygonFCache[
static_cast< int >( type ) ][size ] = res;
1246 return textFormat( QStringLiteral(
"Default" ) );
1266 QDomDocument doc( QStringLiteral(
"dummy" ) );
1267 QDomElement elem = doc.createElement( QStringLiteral(
"symbol" ) );
1268 elem.setAttribute( QStringLiteral(
"type" ),
symbol->
type() );
1271 QByteArray xmlArray;
1272 QTextStream stream( &xmlArray );
1273#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1274 stream.setCodec(
"UTF-8" );
1276 elem.save( stream, 4 );
1277 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO symbol3d VALUES (NULL, '%q', '%q', %d);",
1278 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
1279 if ( !runEmptyQuery( query ) )
1281 QgsDebugError( QStringLiteral(
"Couldn't insert 3d symbol into the database!" ) );
1296 if ( m3dSymbols.contains( newName ) )
1298 QgsDebugError( QStringLiteral(
"3d symbol of new name already exists." ) );
1302 if ( !m3dSymbols.contains( oldName ) )
1306 m3dSymbols.insert( newName,
symbol );
1312 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM symbol3d WHERE name='%q'", oldName.toUtf8().constData() );
1314 statement = mCurrentDB.
prepare( query, nErr );
1315 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1330 return m3dSymbols.keys();
1337 QgsDebugError( QStringLiteral(
"Cannot Open database for getting favorite symbols" ) );
1338 return QStringList();
1347 return QStringList();
1350 query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT name FROM %1 WHERE favorite=1" ).arg( entityTableName( type ) ).toLocal8Bit().data() );
1356 statement = mCurrentDB.
prepare( query, nErr );
1358 QStringList symbols;
1359 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1371 QgsDebugError( QStringLiteral(
"Cannot open database to get symbols of tagid %1" ).arg( tagid ) );
1372 return QStringList();
1381 return QStringList();
1384 subquery =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT %1 FROM %2 WHERE tag_id=%d" ).arg( tagmapEntityIdFieldName( type ),
1385 tagmapTableName( type ) ).toLocal8Bit().data(), tagid );
1391 statement = mCurrentDB.
prepare( subquery, nErr );
1394 QStringList symbols;
1395 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1397 int id = sqlite3_column_int( statement.get(), 0 );
1399 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT name FROM %1 WHERE id=%d" ).arg( entityTableName( type ) ).toLocal8Bit().data(),
id );
1403 statement2 = mCurrentDB.
prepare( query, rc );
1404 while ( rc == SQLITE_OK && sqlite3_step( statement2.get() ) == SQLITE_ROW )
1419 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO tag VALUES (NULL, '%q')", tagname.toUtf8().constData() );
1421 statement = mCurrentDB.
prepare( query, nErr );
1422 if ( nErr == SQLITE_OK )
1423 ( void )sqlite3_step( statement.get() );
1426 settings.
setValue( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 );
1430 return static_cast< int >( sqlite3_last_insert_rowid( mCurrentDB.get() ) );
1436 return QStringList();
1442 statement = mCurrentDB.
prepare( query, nError );
1444 QStringList tagList;
1445 while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1455 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"UPDATE %1 SET name='%q' WHERE id=%d" ).arg( entityTableName( type ) ).toLocal8Bit().data(), newName.toUtf8().constData(),
id );
1457 const bool result = runEmptyQuery( query );
1460 mErrorString = QStringLiteral(
"Could not rename!" );
1464 mCachedTags.clear();
1465 mCachedFavorites.clear();
1490 bool groupRemoved =
false;
1495 query =
qgs_sqlite3_mprintf(
"DELETE FROM tag WHERE id=%d; DELETE FROM tagmap WHERE tag_id=%d",
id,
id );
1496 groupRemoved =
true;
1500 groupRemoved =
true;
1504 query =
qgs_sqlite3_mprintf( QStringLiteral(
"DELETE FROM %1 WHERE id=%d; DELETE FROM %2 WHERE %3=%d" ).arg(
1505 entityTableName( type ),
1506 tagmapTableName( type ),
1507 tagmapEntityIdFieldName( type )
1508 ).toLocal8Bit().data(),
id,
id );
1512 bool result =
false;
1513 if ( !runEmptyQuery( query ) )
1515 QgsDebugError( QStringLiteral(
"Could not delete entity!" ) );
1519 mCachedTags.clear();
1520 mCachedFavorites.clear();
1525 settings.
setValue( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 );
1544 std::unique_ptr< QgsSymbol >
symbol( mSymbols.take(
name ) );
1553 std::unique_ptr< QgsAbstract3DSymbol >
symbol( m3dSymbols.take(
name ) );
1562 std::unique_ptr< QgsColorRamp > ramp( mColorRamps.take(
name ) );
1570 if ( !mTextFormats.contains(
name ) )
1573 mTextFormats.remove(
name );
1579 if ( !mLabelSettings.contains(
name ) )
1582 mLabelSettings.remove(
name );
1588 if ( !mLegendPatchShapes.contains(
name ) )
1591 mLegendPatchShapes.remove(
name );
1598 QgsDebugError( QStringLiteral(
"Sorry! Cannot open database to modify." ) );
1608 const bool result =
remove( type,
id );
1611 mCachedTags[ type ].remove(
name );
1612 mCachedFavorites[ type ].remove(
name );
1641bool QgsStyle::runEmptyQuery(
const QString &query )
1646 char *zErr =
nullptr;
1647 int nErr = sqlite3_exec( mCurrentDB.get(), query.toUtf8().constData(),
nullptr,
nullptr, &zErr );
1649 if ( nErr != SQLITE_OK )
1652 sqlite3_free( zErr );
1655 return nErr == SQLITE_OK;
1666 QgsDebugError( QStringLiteral(
"Wrong entity value. cannot apply group" ) );
1670 query =
qgs_sqlite3_mprintf( QStringLiteral(
"UPDATE %1 SET favorite=1 WHERE name='%q'" ).arg( entityTableName( type ) ).toLocal8Bit().data(),
1671 name.toUtf8().constData() );
1675 const bool res = runEmptyQuery( query );
1685 mCachedFavorites[ type ].insert(
name,
true );
1702 QgsDebugError( QStringLiteral(
"Wrong entity value. cannot apply group" ) );
1706 query =
qgs_sqlite3_mprintf( QStringLiteral(
"UPDATE %1 SET favorite=0 WHERE name='%q'" ).arg( entityTableName( type ) ).toLocal8Bit().data(),
name.toUtf8().constData() );
1710 const bool res = runEmptyQuery( query );
1713 mCachedFavorites[ type ].insert(
name,
false );
1724 QgsDebugError( QStringLiteral(
"Sorry! Cannot open database to search" ) );
1725 return QStringList();
1734 return QStringList();
1737 item = entityTableName( type );
1742 item.toUtf8().constData(), qword.toUtf8().constData() );
1745 int nErr; statement = mCurrentDB.
prepare( query, nErr );
1747 QSet< QString > symbols;
1748 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1754 query =
qgs_sqlite3_mprintf(
"SELECT id FROM tag WHERE name LIKE '%%%q%%'", qword.toUtf8().constData() );
1755 statement = mCurrentDB.
prepare( query, nErr );
1758 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1763 QString dummy = tagids.join( QLatin1String(
", " ) );
1764 query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT %1 FROM %2 WHERE tag_id IN (%q)" ).arg( tagmapEntityIdFieldName( type ),
1765 tagmapTableName( type ) ).toLocal8Bit().data(), dummy.toUtf8().constData() );
1767 statement = mCurrentDB.
prepare( query, nErr );
1769 QStringList symbolids;
1770 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1775 dummy = symbolids.join( QLatin1String(
", " ) );
1777 item.toUtf8().constData(), dummy.toUtf8().constData() );
1778 statement = mCurrentDB.
prepare( query, nErr );
1779 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1784 return QStringList( symbols.constBegin(), symbols.constEnd() );
1791 QgsDebugError( QStringLiteral(
"Sorry! Cannot open database to tag." ) );
1814 const auto constTags =
tags;
1815 for (
const QString &t : constTags )
1818 if ( !
tag.isEmpty() )
1830 QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"INSERT INTO %1 VALUES (%d,%d)" ).arg( tagmapTableName( type ) ).toLocal8Bit().data(), tagid, symbolid );
1832 char *zErr =
nullptr;
1834 nErr = sqlite3_exec( mCurrentDB.get(), query.toUtf8().constData(),
nullptr,
nullptr, &zErr );
1838 sqlite3_free( zErr );
1844 clearCachedTags( type,
symbol );
1854 QgsDebugError( QStringLiteral(
"Sorry! Cannot open database for detagging." ) );
1869 if ( symbolid == 0 )
1874 const auto constTags =
tags;
1875 for (
const QString &
tag : constTags )
1880 statement2 = mCurrentDB.
prepare( query, nErr );
1883 if ( nErr == SQLITE_OK && sqlite3_step( statement2.get() ) == SQLITE_ROW )
1885 tagid = sqlite3_column_int( statement2.get(), 0 );
1891 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"DELETE FROM %1 WHERE tag_id=%d AND %2=%d" ).arg( tagmapTableName( type ), tagmapEntityIdFieldName( type ) ).toLocal8Bit().data(), tagid, symbolid );
1892 runEmptyQuery( query );
1896 clearCachedTags( type,
symbol );
1909 QgsDebugError( QStringLiteral(
"Sorry! Cannot open database for detagging." ) );
1924 if ( symbolid == 0 )
1930 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"DELETE FROM %1 WHERE %2=%d" ).arg( tagmapTableName( type ),
1931 tagmapEntityIdFieldName( type ) ).toLocal8Bit().data(), symbolid );
1932 runEmptyQuery( query );
1934 clearCachedTags( type,
symbol );
1949 return QStringList();
1952 if ( mCachedTags[ type ].contains(
symbol ) )
1953 return mCachedTags[ type ].value(
symbol );
1959 QgsDebugError( QStringLiteral(
"Sorry! Cannot open database for getting the tags." ) );
1960 return QStringList();
1965 return QStringList();
1968 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT tag_id FROM %1 WHERE %2=%d" ).arg( tagmapTableName( type ),
1969 tagmapEntityIdFieldName( type ) ).toLocal8Bit().data(), symbolid );
1972 int nErr; statement = mCurrentDB.
prepare( query, nErr );
1974 QStringList tagList;
1975 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1977 QString subquery =
qgs_sqlite3_mprintf(
"SELECT name FROM tag WHERE id=%d", sqlite3_column_int( statement.get(), 0 ) );
1981 statement2 = mCurrentDB.
prepare( subquery, pErr );
1982 if ( pErr == SQLITE_OK && sqlite3_step( statement2.get() ) == SQLITE_ROW )
1989 mCachedTags[ type ].insert(
symbol, tagList );
1998 QgsDebugError( QStringLiteral(
"Sorry! Cannot open database for getting the tags." ) );
2009 if ( mCachedFavorites[ type ].contains(
name ) )
2010 return mCachedFavorites[ type ].value(
name );
2014 const QStringList names =
allNames( type );
2015 if ( !names.contains(
name ) )
2021 for (
const QString &n : names )
2023 const bool isFav = favorites.contains( n );
2027 mCachedFavorites[ type ].insert( n, isFav );
2036 QgsDebugError( QStringLiteral(
"Sorry! Cannot open database for getting the tags." ) );
2063 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT tag_id FROM %1 WHERE tag_id=%d AND %2=%d" ).arg( tagmapTableName( type ),
2064 tagmapEntityIdFieldName( type ) ).toLocal8Bit().data(), tagid, symbolid );
2067 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2069 return ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW );
2081 statement = mCurrentDB.
prepare( query, nError );
2084 if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2092int QgsStyle::getId(
const QString &table,
const QString &name )
2094 QString lowerName(
name.toLower() );
2095 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM %q WHERE LOWER(name)='%q'", table.toUtf8().constData(), lowerName.toUtf8().constData() );
2098 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2101 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2103 id = sqlite3_column_int( statement.get(), 0 );
2108 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM %q WHERE name='%q'", table.toUtf8().constData(),
name.toUtf8().constData() );
2111 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2112 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2114 id = sqlite3_column_int( statement.get(), 0 );
2121QString QgsStyle::getName(
const QString &table,
int id )
const
2123 QString query =
qgs_sqlite3_mprintf(
"SELECT name FROM %q WHERE id='%q'", table.toUtf8().constData(), QString::number(
id ).toUtf8().constData() );
2126 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2129 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2139 return getId( QStringLiteral(
"symbol" ),
name );
2144 return getId( entityTableName( type ),
name );
2149 return getId( QStringLiteral(
"colorramp" ),
name );
2154 return mTextFormats.value(
name );
2159 return mTextFormats.count();
2164 return mTextFormats.keys();
2169 return getId( QStringLiteral(
"textformat" ),
name );
2174 return mLabelSettings.value(
name );
2179 return mLegendPatchShapes.value(
name );
2184 return mLegendPatchShapes.count();
2189 if ( !mLegendPatchShapes.contains(
name ) )
2192 return mLegendPatchShapes.value(
name ).symbolType();
2197 return m3dSymbols.contains(
name ) ? m3dSymbols.value(
name )->clone() :
nullptr;
2202 return m3dSymbols.count();
2207 if ( !m3dSymbols.contains(
name ) )
2208 return QList<Qgis::GeometryType>();
2210 return m3dSymbols.value(
name )->compatibleGeometryTypes();
2215 if ( !mLabelSettings.contains(
name ) )
2218 return mLabelSettings.value(
name ).layerType;
2223 return mLabelSettings.count();
2228 return mLabelSettings.keys();
2233 return getId( QStringLiteral(
"labelsettings" ),
name );
2238 return mLegendPatchShapes.keys();
2246 return mPatchMarkerSymbol.get();
2249 return mPatchLineSymbol.get();
2252 return mPatchFillSymbol.get();
2262 return getId( QStringLiteral(
"tag" ),
name );
2267 return getId( QStringLiteral(
"smartgroup" ),
name );
2298 return QStringList();
2304 conditions.values( QStringLiteral(
"!tag" ) ),
2305 conditions.values( QStringLiteral(
"name" ) ),
2306 conditions.values( QStringLiteral(
"!name" ) ) );
2309int QgsStyle::addSmartgroup(
const QString &name,
const QString &op,
const QStringList &matchTag,
const QStringList &noMatchTag,
const QStringList &matchName,
const QStringList &noMatchName )
2311 QDomDocument doc( QStringLiteral(
"dummy" ) );
2312 QDomElement smartEl = doc.createElement( QStringLiteral(
"smartgroup" ) );
2313 smartEl.setAttribute( QStringLiteral(
"name" ),
name );
2314 smartEl.setAttribute( QStringLiteral(
"operator" ), op );
2316 auto addCondition = [&doc, &smartEl](
const QString & constraint,
const QStringList & parameters )
2318 for (
const QString ¶m : parameters )
2320 QDomElement condEl = doc.createElement( QStringLiteral(
"condition" ) );
2321 condEl.setAttribute( QStringLiteral(
"constraint" ), constraint );
2322 condEl.setAttribute( QStringLiteral(
"param" ), param );
2323 smartEl.appendChild( condEl );
2326 addCondition( QStringLiteral(
"tag" ), matchTag );
2327 addCondition( QStringLiteral(
"!tag" ), noMatchTag );
2328 addCondition( QStringLiteral(
"name" ), matchName );
2329 addCondition( QStringLiteral(
"!name" ), noMatchName );
2331 QByteArray xmlArray;
2332 QTextStream stream( &xmlArray );
2333#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
2334 stream.setCodec(
"UTF-8" );
2336 smartEl.save( stream, 4 );
2338 name.toUtf8().constData(), xmlArray.constData() );
2340 if ( runEmptyQuery( query ) )
2343 settings.
setValue( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 );
2346 return static_cast< int >( sqlite3_last_insert_rowid( mCurrentDB.get() ) );
2350 QgsDebugError( QStringLiteral(
"Couldn't add the smart group into the database!" ) );
2359 QgsDebugError( QStringLiteral(
"Cannot open database for listing groups" ) );
2368 statement = mCurrentDB.
prepare( query, nError );
2371 while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2384 QgsDebugError( QStringLiteral(
"Cannot open database for listing groups" ) );
2385 return QStringList();
2393 statement = mCurrentDB.
prepare( query, nError );
2396 while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2406 QStringList symbols;
2411 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2412 if ( !( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW ) )
2414 return QStringList();
2420 if ( !doc.setContent( xmlstr ) )
2422 QgsDebugError( QStringLiteral(
"Cannot open smartgroup id: %1" ).arg(
id ) );
2424 QDomElement smartEl = doc.documentElement();
2425 QString op = smartEl.attribute( QStringLiteral(
"operator" ) );
2426 QDomNodeList conditionNodes = smartEl.childNodes();
2428 bool firstSet =
true;
2429 for (
int i = 0; i < conditionNodes.count(); i++ )
2431 QDomElement condEl = conditionNodes.at( i ).toElement();
2432 QString constraint = condEl.attribute( QStringLiteral(
"constraint" ) );
2433 QString param = condEl.attribute( QStringLiteral(
"param" ) );
2435 QStringList resultNames;
2437 if ( constraint == QLatin1String(
"tag" ) )
2441 else if ( constraint == QLatin1String(
"name" ) )
2443 resultNames =
allNames( type ).filter( param, Qt::CaseInsensitive );
2445 else if ( constraint == QLatin1String(
"!tag" ) )
2449 for (
const QString &
name : unwanted )
2451 resultNames.removeAll(
name );
2454 else if ( constraint == QLatin1String(
"!name" ) )
2456 const QStringList all =
allNames( type );
2457 for (
const QString &
str : all )
2459 if ( !
str.contains( param, Qt::CaseInsensitive ) )
2467 symbols = resultNames;
2472 if ( op == QLatin1String(
"OR" ) )
2474 symbols << resultNames;
2476 else if ( op == QLatin1String(
"AND" ) )
2478 QStringList dummy = symbols;
2480 for (
const QString &result : std::as_const( resultNames ) )
2482 if ( dummy.contains( result ) )
2491 const QSet< QString > uniqueSet( symbols.constBegin(), symbols.constEnd() );
2492 QStringList unique( uniqueSet.begin(), uniqueSet.end() );
2493 std::sort( unique.begin(), unique.end() );
2501 QgsDebugError( QStringLiteral(
"Cannot open database for listing groups" ) );
2511 statement = mCurrentDB.
prepare( query, nError );
2512 if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2516 if ( !doc.setContent( xmlstr ) )
2518 QgsDebugError( QStringLiteral(
"Cannot open smartgroup id: %1" ).arg(
id ) );
2521 QDomElement smartEl = doc.documentElement();
2522 QDomNodeList conditionNodes = smartEl.childNodes();
2524 for (
int i = 0; i < conditionNodes.count(); i++ )
2526 QDomElement condEl = conditionNodes.at( i ).toElement();
2527 QString constraint = condEl.attribute( QStringLiteral(
"constraint" ) );
2528 QString param = condEl.attribute( QStringLiteral(
"param" ) );
2530 condition.insert( constraint, param );
2541 QgsDebugError( QStringLiteral(
"Cannot open database for listing groups" ) );
2551 statement = mCurrentDB.
prepare( query, nError );
2552 if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2556 if ( !doc.setContent( xmlstr ) )
2558 QgsDebugError( QStringLiteral(
"Cannot open smartgroup id: %1" ).arg(
id ) );
2560 QDomElement smartEl = doc.documentElement();
2561 op = smartEl.attribute( QStringLiteral(
"operator" ) );
2569 if ( filename.isEmpty() )
2571 QgsDebugError( QStringLiteral(
"Invalid filename for style export." ) );
2575 QDomDocument doc( QStringLiteral(
"qgis_style" ) );
2576 QDomElement root = doc.createElement( QStringLiteral(
"qgis_style" ) );
2578 doc.appendChild( root );
2588 QDomNodeList symbolsList = symbolsElem.elementsByTagName( QStringLiteral(
"symbol" ) );
2589 int nbSymbols = symbolsList.count();
2590 for (
int i = 0; i < nbSymbols; ++i )
2592 QDomElement
symbol = symbolsList.at( i ).toElement();
2593 QString
name =
symbol.attribute( QStringLiteral(
"name" ) );
2595 if (
tags.count() > 0 )
2597 symbol.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2599 if ( favoriteSymbols.contains(
name ) )
2601 symbol.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2606 QDomElement rampsElem = doc.createElement( QStringLiteral(
"colorramps" ) );
2607 for ( QMap<QString, QgsColorRamp *>::const_iterator itr = mColorRamps.constBegin(); itr != mColorRamps.constEnd(); ++itr )
2611 if (
tags.count() > 0 )
2613 rampEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2615 if ( favoriteColorramps.contains( itr.key() ) )
2617 rampEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2619 rampsElem.appendChild( rampEl );
2623 QDomElement textFormatsElem = doc.createElement( QStringLiteral(
"textformats" ) );
2624 for (
auto it = mTextFormats.constBegin(); it != mTextFormats.constEnd(); ++it )
2626 QDomElement textFormatEl = doc.createElement( QStringLiteral(
"textformat" ) );
2627 textFormatEl.setAttribute( QStringLiteral(
"name" ), it.key() );
2629 textFormatEl.appendChild( textStyleEl );
2631 if (
tags.count() > 0 )
2633 textFormatEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2635 if ( favoriteTextFormats.contains( it.key() ) )
2637 textFormatEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2639 textFormatsElem.appendChild( textFormatEl );
2643 QDomElement labelSettingsElem = doc.createElement( QStringLiteral(
"labelsettings" ) );
2644 for (
auto it = mLabelSettings.constBegin(); it != mLabelSettings.constEnd(); ++it )
2646 QDomElement labelSettingsEl = doc.createElement( QStringLiteral(
"labelsetting" ) );
2647 labelSettingsEl.setAttribute( QStringLiteral(
"name" ), it.key() );
2649 labelSettingsEl.appendChild( defEl );
2651 if (
tags.count() > 0 )
2653 labelSettingsEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2655 if ( favoriteTextFormats.contains( it.key() ) )
2657 labelSettingsEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2659 labelSettingsElem.appendChild( labelSettingsEl );
2663 QDomElement legendPatchShapesElem = doc.createElement( QStringLiteral(
"legendpatchshapes" ) );
2664 for (
auto it = mLegendPatchShapes.constBegin(); it != mLegendPatchShapes.constEnd(); ++it )
2666 QDomElement legendPatchShapeEl = doc.createElement( QStringLiteral(
"legendpatchshape" ) );
2667 legendPatchShapeEl.setAttribute( QStringLiteral(
"name" ), it.key() );
2668 QDomElement defEl = doc.createElement( QStringLiteral(
"definition" ) );
2670 legendPatchShapeEl.appendChild( defEl );
2672 if (
tags.count() > 0 )
2674 legendPatchShapeEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2676 if ( favoriteLegendShapes.contains( it.key() ) )
2678 legendPatchShapeEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2680 legendPatchShapesElem.appendChild( legendPatchShapeEl );
2684 QDomElement symbols3DElem = doc.createElement( QStringLiteral(
"symbols3d" ) );
2685 for (
auto it = m3dSymbols.constBegin(); it != m3dSymbols.constEnd(); ++it )
2687 QDomElement symbolEl = doc.createElement( QStringLiteral(
"symbol3d" ) );
2688 symbolEl.setAttribute( QStringLiteral(
"name" ), it.key() );
2689 QDomElement defEl = doc.createElement( QStringLiteral(
"definition" ) );
2690 defEl.setAttribute( QStringLiteral(
"type" ), it.value()->type() );
2692 symbolEl.appendChild( defEl );
2694 if (
tags.count() > 0 )
2696 symbolEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2698 if ( favorite3DSymbols.contains( it.key() ) )
2700 symbolEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2702 symbols3DElem.appendChild( symbolEl );
2705 root.appendChild( symbolsElem );
2706 root.appendChild( rampsElem );
2707 root.appendChild( textFormatsElem );
2708 root.appendChild( labelSettingsElem );
2709 root.appendChild( legendPatchShapesElem );
2710 root.appendChild( symbols3DElem );
2713 QFile f( filename );
2714 if ( !f.open( QFile::WriteOnly | QIODevice::Truncate ) )
2716 mErrorString =
"Couldn't open file for writing: " + filename;
2720 QTextStream ts( &f );
2721#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
2722 ts.setCodec(
"UTF-8" );
2737 mErrorString = QString();
2738 QDomDocument doc( QStringLiteral(
"style" ) );
2739 QFile f( filename );
2740 if ( !f.open( QFile::ReadOnly ) )
2742 mErrorString = QStringLiteral(
"Unable to open the specified file" );
2743 QgsDebugError( QStringLiteral(
"Error opening the style XML file." ) );
2747 if ( !doc.setContent( &f ) )
2749 mErrorString = QStringLiteral(
"Unable to understand the style file: %1" ).arg( filename );
2756 QDomElement docEl = doc.documentElement();
2757 if ( docEl.tagName() != QLatin1String(
"qgis_style" ) )
2759 mErrorString =
"Incorrect root tag in style: " + docEl.tagName();
2763 const QString version = docEl.attribute( QStringLiteral(
"version" ) );
2764 if ( version != QLatin1String(
STYLE_CURRENT_VERSION ) && version != QLatin1String(
"0" ) && version != QLatin1String(
"1" ) )
2766 mErrorString =
"Unknown style file version: " + version;
2772 QDomElement symbolsElement = docEl.firstChildElement( QStringLiteral(
"symbols" ) );
2773 QDomElement e = symbolsElement.firstChildElement();
2777 runEmptyQuery( query );
2782 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2784 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2785 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2791 if ( e.tagName() == QLatin1String(
"symbol" ) )
2793 QString
name = e.attribute( QStringLiteral(
"name" ) );
2795 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2797 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2799 bool favorite =
false;
2800 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2827 for ( QMap<QString, QgsSymbol *>::iterator it = symbols.begin(); it != symbols.end(); ++it )
2834 QDomElement rampsElement = docEl.firstChildElement( QStringLiteral(
"colorramps" ) );
2835 e = rampsElement.firstChildElement();
2836 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2838 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2839 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2845 if ( e.tagName() == QLatin1String(
"colorramp" ) )
2847 QString
name = e.attribute( QStringLiteral(
"name" ) );
2849 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2851 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2853 bool favorite =
false;
2854 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2878 if ( qobject_cast< QGuiApplication * >( QCoreApplication::instance() ) )
2882 const QDomElement textFormatElement = docEl.firstChildElement( QStringLiteral(
"textformats" ) );
2883 e = textFormatElement.firstChildElement();
2884 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2886 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2887 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2893 if ( e.tagName() == QLatin1String(
"textformat" ) )
2895 QString
name = e.attribute( QStringLiteral(
"name" ) );
2897 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2899 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2901 bool favorite =
false;
2902 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2908 const QDomElement styleElem = e.firstChildElement();
2926 const QDomElement labelSettingsElement = docEl.firstChildElement( QStringLiteral(
"labelsettings" ) );
2927 e = labelSettingsElement.firstChildElement();
2928 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2930 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2931 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2937 if ( e.tagName() == QLatin1String(
"labelsetting" ) )
2939 QString
name = e.attribute( QStringLiteral(
"name" ) );
2941 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2943 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2945 bool favorite =
false;
2946 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2952 const QDomElement styleElem = e.firstChildElement();
2971 const QDomElement legendPatchShapesElement = docEl.firstChildElement( QStringLiteral(
"legendpatchshapes" ) );
2972 e = legendPatchShapesElement.firstChildElement();
2973 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2975 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2976 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2982 if ( e.tagName() == QLatin1String(
"legendpatchshape" ) )
2984 QString
name = e.attribute( QStringLiteral(
"name" ) );
2986 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2988 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2990 bool favorite =
false;
2991 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2997 const QDomElement shapeElem = e.firstChildElement();
3015 const QDomElement symbols3DElement = docEl.firstChildElement( QStringLiteral(
"symbols3d" ) );
3016 e = symbols3DElement.firstChildElement();
3017 for ( ; !e.isNull(); e = e.nextSiblingElement() )
3019 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
3020 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
3026 if ( e.tagName() == QLatin1String(
"symbol3d" ) )
3028 QString
name = e.attribute( QStringLiteral(
"name" ) );
3030 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
3032 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
3034 bool favorite =
false;
3035 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
3040 const QDomElement symbolElem = e.firstChildElement();
3041 const QString type = symbolElem.attribute( QStringLiteral(
"type" ) );
3062 runEmptyQuery( query );
3069 QFileInfo fileInfo( path );
3071 if ( fileInfo.suffix().compare( QLatin1String(
"xml" ), Qt::CaseInsensitive ) != 0 )
3075 if ( !QFile::exists( path ) )
3078 QFile inputFile( path );
3079 if ( !inputFile.open( QIODevice::ReadOnly ) )
3082 QTextStream stream( &inputFile );
3083 const QString line = stream.readLine();
3084 return line == QLatin1String(
"<!DOCTYPE qgis_style>" );
3099 mReadOnly = readOnly;
3102bool QgsStyle::updateSymbol( StyleEntity type,
const QString &name )
3104 QDomDocument doc( QStringLiteral(
"dummy" ) );
3106 QByteArray xmlArray;
3107 QTextStream stream( &xmlArray );
3108#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
3109 stream.setCodec(
"UTF-8" );
3121 QgsDebugError( QStringLiteral(
"Update request received for unavailable symbol" ) );
3126 if ( symEl.isNull() )
3128 QgsDebugError( QStringLiteral(
"Couldn't convert symbol to valid XML!" ) );
3131 symEl.save( stream, 4 );
3133 xmlArray.constData(),
name.toUtf8().constData() );
3142 QgsDebugError( QStringLiteral(
"Update request received for unavailable symbol" ) );
3146 symEl = doc.createElement( QStringLiteral(
"symbol" ) );
3147 symEl.setAttribute( QStringLiteral(
"type" ), m3dSymbols.value(
name )->type() );
3149 if ( symEl.isNull() )
3151 QgsDebugError( QStringLiteral(
"Couldn't convert symbol to valid XML!" ) );
3154 symEl.save( stream, 4 );
3156 xmlArray.constData(),
name.toUtf8().constData() );
3164 QgsDebugError( QStringLiteral(
"Update requested for unavailable color ramp." ) );
3170 if ( symEl.isNull() )
3172 QgsDebugError( QStringLiteral(
"Couldn't convert color ramp to valid XML!" ) );
3175 symEl.save( stream, 4 );
3177 xmlArray.constData(),
name.toUtf8().constData() );
3185 QgsDebugError( QStringLiteral(
"Update requested for unavailable text format." ) );
3191 if ( symEl.isNull() )
3193 QgsDebugError( QStringLiteral(
"Couldn't convert text format to valid XML!" ) );
3196 symEl.save( stream, 4 );
3198 xmlArray.constData(),
name.toUtf8().constData() );
3206 QgsDebugError( QStringLiteral(
"Update requested for unavailable label settings." ) );
3212 if ( symEl.isNull() )
3214 QgsDebugError( QStringLiteral(
"Couldn't convert label settings to valid XML!" ) );
3217 symEl.save( stream, 4 );
3219 xmlArray.constData(),
name.toUtf8().constData() );
3227 QgsDebugError( QStringLiteral(
"Update requested for unavailable legend patch shape." ) );
3232 symEl = doc.createElement( QStringLiteral(
"shape" ) );
3234 symEl.save( stream, 4 );
3236 xmlArray.constData(),
name.toUtf8().constData() );
3243 QgsDebugError( QStringLiteral(
"Updating the unsupported StyleEntity" ) );
3249 if ( !runEmptyQuery( query ) )
3251 QgsDebugError( QStringLiteral(
"Couldn't update symbol into the database!" ) );
3287 mCachedTags[ type ].remove(
name );
3290bool QgsStyle::createStyleMetadataTableIfNeeded()
3293 QString query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='stylemetadata'" );
3296 statement = mCurrentDB.
prepare( query, rc );
3298 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
3302 "id INTEGER PRIMARY KEY,"\
3305 runEmptyQuery( query );
3307 runEmptyQuery( query );
3316void QgsStyle::upgradeIfRequired()
3320 if ( !createStyleMetadataTableIfNeeded() )
3322 const QString query =
qgs_sqlite3_mprintf(
"SELECT value FROM stylemetadata WHERE key='version'" );
3325 if ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
3337 runEmptyQuery( query );
3347 return QStringLiteral(
"symbol" );
3350 return QStringLiteral(
"colorramp" );
3353 return QStringLiteral(
"textformat" );
3356 return QStringLiteral(
"labelsettings" );
3359 return QStringLiteral(
"legendpatchshapes" );
3362 return QStringLiteral(
"symbol3d" );
3365 return QStringLiteral(
"tag" );
3368 return QStringLiteral(
"smartgroup" );
3378 return QStringLiteral(
"tagmap" );
3381 return QStringLiteral(
"ctagmap" );
3384 return QStringLiteral(
"tftagmap" );
3387 return QStringLiteral(
"lstagmap" );
3390 return QStringLiteral(
"lpstagmap" );
3393 return QStringLiteral(
"symbol3dtagmap" );
3407 return QStringLiteral(
"symbol_id" );
3410 return QStringLiteral(
"colorramp_id" );
3413 return QStringLiteral(
"textformat_id" );
3416 return QStringLiteral(
"labelsettings_id" );
3419 return QStringLiteral(
"legendpatchshape_id" );
3422 return QStringLiteral(
"symbol3d_id" );
@ 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.
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 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...
The class is used as a container of context for various read/write operations on other objects.
Scoped object for logging of the runtime for a single operation or group of operations.
This class is a composition of two QSettings instances:
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.
bool addEntity(const QString &name, const QgsStyleEntityInterface *entity, bool update=false)
Adds an entity to the style, with the specified name.
bool saveColorRamp(const QString &name, QgsColorRamp *ramp, bool favorite, const QStringList &tags)
Adds the colorramp to the database.
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.
void symbolSaved(const QString &name, QgsSymbol *symbol)
Emitted every time a new symbol has been added to the database.
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 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.
bool saveSymbol(const QString &name, QgsSymbol *symbol, bool favorite, const QStringList &tags)
Adds the symbol to the database with tags.
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.
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.
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 QgsColorRamp * loadColorRamp(QDomElement &element)
Creates a color ramp from the settings encoded in an XML element.
static QDomElement saveColorRamp(const QString &name, QgsColorRamp *ramp, QDomDocument &doc)
Encodes a color ramp's settings to an XML element.
static 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 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.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
Qgis::SymbolType type() const
Returns the symbol's type.
Container for all settings relating to text rendering.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
bool isValid() const
Returns true if the format is valid.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
int open(const QString &path)
Opens the database at the specified file path.
QString errorMessage() const
Returns the most recent error message encountered by the database.
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