40 #include <QDomDocument>
41 #include <QDomElement>
43 #include <QDomNodeList>
45 #include <QTextStream>
52 #define STYLE_CURRENT_VERSION "2"
77 QgsStyle *QgsStyle::sDefaultStyle =
nullptr;
81 std::unique_ptr< QgsSimpleMarkerSymbolLayer > simpleMarker = std::make_unique< QgsSimpleMarkerSymbolLayer >(
Qgis::MarkerShape::Circle,
83 simpleMarker->setStrokeWidth( 0.4 );
84 mPatchMarkerSymbol = std::make_unique< QgsMarkerSymbol >(
QgsSymbolLayerList() << simpleMarker.release() );
86 std::unique_ptr< QgsSimpleLineSymbolLayer > simpleLine = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 84, 176, 74 ), 0.6 );
87 mPatchLineSymbol = std::make_unique< QgsLineSymbol >(
QgsSymbolLayerList() << simpleLine.release() );
89 std::unique_ptr< QgsGradientFillSymbolLayer > gradientFill = std::make_unique< QgsGradientFillSymbolLayer >( QColor( 66, 150, 63 ), QColor( 84, 176, 74 ) );
90 std::unique_ptr< QgsSimpleLineSymbolLayer > simpleOutline = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 56, 128, 54 ), 0.26 );
91 mPatchFillSymbol = std::make_unique< QgsFillSymbol >(
QgsSymbolLayerList() << gradientFill.release() << simpleOutline.release() );
111 switch ( entity->
type() )
145 if ( !sDefaultStyle )
151 if ( !QFile::exists( styleFilename ) )
159 sDefaultStyle->createStyleMetadataTableIfNeeded();
166 if ( sDefaultStyle->
load( styleFilename ) )
168 sDefaultStyle->upgradeIfRequired();
171 sDefaultStyle->
setName( QObject::tr(
"Default" ) );
173 return sDefaultStyle;
178 delete sDefaultStyle;
179 sDefaultStyle =
nullptr;
184 qDeleteAll( mSymbols );
185 qDeleteAll( mColorRamps );
186 qDeleteAll( m3dSymbols );
190 mTextFormats.clear();
194 mCachedFavorites.clear();
203 if ( mSymbols.contains(
name ) )
206 delete mSymbols.value(
name );
224 QDomDocument doc( QStringLiteral(
"dummy" ) );
226 if ( symEl.isNull() )
228 QgsDebugMsg( QStringLiteral(
"Couldn't convert symbol to valid XML!" ) );
233 QTextStream stream( &xmlArray );
234 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
235 stream.setCodec(
"UTF-8" );
237 symEl.save( stream, 4 );
239 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
241 if ( !runEmptyQuery( query ) )
243 QgsDebugMsg( QStringLiteral(
"Couldn't insert symbol into the database!" ) );
299 return mSymbols.value(
name );
304 return mSymbols.count();
309 return mSymbols.keys();
319 if ( mColorRamps.contains(
name ) )
322 delete mColorRamps.value(
name );
340 if ( mTextFormats.contains(
name ) )
343 mTextFormats.remove(
name );
344 mTextFormats.insert(
name, format );
350 mTextFormats.insert(
name, format );
361 if ( mLabelSettings.contains(
name ) )
364 mLabelSettings.remove(
name );
365 mLabelSettings.insert(
name, settings );
371 mLabelSettings.insert(
name, settings );
382 if ( mLegendPatchShapes.contains(
name ) )
385 mLegendPatchShapes.remove(
name );
386 mLegendPatchShapes.insert(
name, shape );
392 mLegendPatchShapes.insert(
name, shape );
403 if ( m3dSymbols.contains(
name ) )
406 delete m3dSymbols.take(
name );
424 QDomDocument doc( QStringLiteral(
"dummy" ) );
427 if ( rampEl.isNull() )
429 QgsDebugMsg( QStringLiteral(
"Couldn't convert color ramp to valid XML!" ) );
434 QTextStream stream( &xmlArray );
435 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
436 stream.setCodec(
"UTF-8" );
438 rampEl.save( stream, 4 );
439 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
440 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
441 if ( !runEmptyQuery( query ) )
443 QgsDebugMsg( QStringLiteral(
"Couldn't insert colorramp into the database!" ) );
465 return ramp ? ramp->
clone() :
nullptr;
470 return mColorRamps.value(
name );
475 return mColorRamps.count();
480 return mColorRamps.keys();
483 void QgsStyle::handleDeferred3DSymbolCreation()
485 for (
auto it = mDeferred3DsymbolElements.constBegin(); it != mDeferred3DsymbolElements.constEnd(); ++it )
487 const QString symbolType = it.value().attribute( QStringLiteral(
"type" ) );
497 QgsDebugMsg(
"Cannot open 3d symbol " + it.key() );
501 mDeferred3DsymbolElements.clear();
504 bool QgsStyle::openDatabase(
const QString &filename )
506 int rc = mCurrentDB.
open( filename );
509 mErrorString = QStringLiteral(
"Couldn't open the style database: %1" ).arg( mCurrentDB.
errorMessage() );
518 mErrorString.clear();
519 if ( !openDatabase( filename ) )
521 mErrorString = QStringLiteral(
"Unable to create database" );
533 mErrorString.clear();
534 if ( !openDatabase( QStringLiteral(
":memory:" ) ) )
536 mErrorString = QStringLiteral(
"Unable to create temporary memory database" );
549 "id INTEGER PRIMARY KEY,"\
552 "favorite INTEGER);"\
553 "CREATE TABLE colorramp("\
554 "id INTEGER PRIMARY KEY,"\
557 "favorite INTEGER);"\
558 "CREATE TABLE textformat("\
559 "id INTEGER PRIMARY KEY,"\
562 "favorite INTEGER);"\
563 "CREATE TABLE labelsettings("\
564 "id INTEGER PRIMARY KEY,"\
567 "favorite INTEGER);"\
568 "CREATE TABLE legendpatchshapes("\
569 "id INTEGER PRIMARY KEY,"\
572 "favorite INTEGER);"\
573 "CREATE TABLE symbol3d("\
574 "id INTEGER PRIMARY KEY,"\
577 "favorite INTEGER);"\
579 "id INTEGER PRIMARY KEY,"\
581 "CREATE TABLE tagmap("\
582 "tag_id INTEGER NOT NULL,"\
583 "symbol_id INTEGER);"\
584 "CREATE TABLE ctagmap("\
585 "tag_id INTEGER NOT NULL,"\
586 "colorramp_id INTEGER);"\
587 "CREATE TABLE tftagmap("\
588 "tag_id INTEGER NOT NULL,"\
589 "textformat_id INTEGER);"\
590 "CREATE TABLE lstagmap("\
591 "tag_id INTEGER NOT NULL,"\
592 "labelsettings_id INTEGER);"\
593 "CREATE TABLE lpstagmap("\
594 "tag_id INTEGER NOT NULL,"\
595 "legendpatchshape_id INTEGER);"\
596 "CREATE TABLE symbol3dtagmap("\
597 "tag_id INTEGER NOT NULL,"\
598 "symbol3d_id INTEGER);"\
599 "CREATE TABLE smartgroup("\
600 "id INTEGER PRIMARY KEY,"\
603 runEmptyQuery( query );
608 mErrorString.clear();
611 if ( !openDatabase( filename ) )
613 mErrorString = QStringLiteral(
"Unable to open database file specified" );
619 QString query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='textformat'" );
622 statement = mCurrentDB.
prepare( query, rc );
623 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
626 "id INTEGER PRIMARY KEY,"\
629 "favorite INTEGER);"\
630 "CREATE TABLE tftagmap("\
631 "tag_id INTEGER NOT NULL,"\
632 "textformat_id INTEGER);" );
633 runEmptyQuery( query );
636 query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='labelsettings'" );
637 statement = mCurrentDB.
prepare( query, rc );
638 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
641 "id INTEGER PRIMARY KEY,"\
644 "favorite INTEGER);"\
645 "CREATE TABLE lstagmap("\
646 "tag_id INTEGER NOT NULL,"\
647 "labelsettings_id INTEGER);" );
648 runEmptyQuery( query );
651 query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='legendpatchshapes'" );
652 statement = mCurrentDB.
prepare( query, rc );
653 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
656 "id INTEGER PRIMARY KEY,"\
659 "favorite INTEGER);"\
660 "CREATE TABLE lpstagmap("\
661 "tag_id INTEGER NOT NULL,"\
662 "legendpatchshape_id INTEGER);" );
663 runEmptyQuery( query );
667 statement = mCurrentDB.
prepare( query, rc );
668 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
671 "id INTEGER PRIMARY KEY,"\
674 "favorite INTEGER);"\
675 "CREATE TABLE symbol3dtagmap("\
676 "tag_id INTEGER NOT NULL,"\
677 "symbol3d_id INTEGER);" );
678 runEmptyQuery( query );
683 "UPDATE colorramp SET favorite=0 WHERE favorite IS NULL;"
684 "UPDATE textformat SET favorite=0 WHERE favorite IS NULL;"
685 "UPDATE labelsettings SET favorite=0 WHERE favorite IS NULL;"
686 "UPDATE legendpatchshapes SET favorite=0 WHERE favorite IS NULL;"
687 "UPDATE symbol3d SET favorite=0 WHERE favorite IS NULL;"
689 runEmptyQuery( query );
695 statement = mCurrentDB.
prepare( query, rc );
697 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
703 if ( !doc.setContent( xmlstring ) )
709 QDomElement symElement = doc.documentElement();
712 mSymbols.insert( symbolName,
symbol );
719 statement = mCurrentDB.
prepare( query, rc );
720 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
726 if ( !doc.setContent( xmlstring ) )
731 QDomElement rampElement = doc.documentElement();
734 mColorRamps.insert( rampName, ramp );
741 statement = mCurrentDB.
prepare( query, rc );
742 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
748 if ( !doc.setContent( xmlstring ) )
750 QgsDebugMsg(
"Cannot open text format " + formatName );
753 QDomElement formatElement = doc.documentElement();
756 mTextFormats.insert( formatName, format );
763 statement = mCurrentDB.
prepare( query, rc );
764 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
770 if ( !doc.setContent( xmlstring ) )
772 QgsDebugMsg(
"Cannot open label settings " + settingsName );
775 QDomElement settingsElement = doc.documentElement();
778 mLabelSettings.insert( settingsName, settings );
785 statement = mCurrentDB.
prepare( query, rc );
786 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
792 if ( !doc.setContent( xmlstring ) )
794 QgsDebugMsg(
"Cannot open legend patch shape " + settingsName );
797 QDomElement settingsElement = doc.documentElement();
800 mLegendPatchShapes.insert( settingsName, shape );
807 statement = mCurrentDB.
prepare( query, rc );
811 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
817 if ( !doc.setContent( xmlstring ) )
819 QgsDebugMsg(
"Cannot open 3d symbol " + settingsName );
822 QDomElement settingsElement = doc.documentElement();
824 if ( !registry3dPopulated )
826 mDeferred3DsymbolElements.insert( settingsName, settingsElement );
830 const QString symbolType = settingsElement.attribute( QStringLiteral(
"type" ) );
835 m3dSymbols.insert( settingsName,
symbol.release() );
839 QgsDebugMsg(
"Cannot open 3d symbol " + settingsName );
846 mFileName = filename;
854 mErrorString.clear();
856 if ( filename.isEmpty() )
857 filename = mFileName;
862 QDomDocument doc(
"qgis_style" );
863 QDomElement root = doc.createElement(
"qgis_style" );
865 doc.appendChild( root );
869 QDomElement rampsElem = doc.createElement(
"colorramps" );
872 for ( QMap<QString, QgsColorRamp *>::iterator itr = mColorRamps.begin(); itr != mColorRamps.end(); ++itr )
875 rampsElem.appendChild( rampEl );
878 root.appendChild( symbolsElem );
879 root.appendChild( rampsElem );
883 if ( !f.open( QFile::WriteOnly ) )
885 mErrorString =
"Couldn't open file for writing: " + filename;
888 QTextStream ts( &f );
889 ts.setCodec(
"UTF-8" );
894 mFileName = filename;
900 if ( mSymbols.contains( newName ) )
902 QgsDebugMsg( QStringLiteral(
"Symbol of new name already exists" ) );
910 mSymbols.insert( newName,
symbol );
914 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database to tag." ) );
921 QgsDebugMsg( QStringLiteral(
"No such symbol for tagging in database: " ) + oldName );
940 if ( mColorRamps.contains( newName ) )
942 QgsDebugMsg( 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 QgsDebugMsg( 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 QgsDebugMsg( QStringLiteral(
"Couldn't insert text format into the database!" ) );
1016 if ( mTextFormats.contains( newName ) )
1018 QgsDebugMsg( 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 QgsDebugMsg( 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 QgsDebugMsg( QStringLiteral(
"Couldn't insert label settings into the database!" ) );
1092 if ( mLabelSettings.contains( newName ) )
1094 QgsDebugMsg( 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 QgsDebugMsg( QStringLiteral(
"Couldn't insert legend patch shape into the database!" ) );
1157 if ( mLegendPatchShapes.contains( newName ) )
1159 QgsDebugMsg( 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;
1252 return textFormat( QStringLiteral(
"Default" ) );
1258 QDomDocument doc( QStringLiteral(
"dummy" ) );
1259 QDomElement elem = doc.createElement( QStringLiteral(
"symbol" ) );
1260 elem.setAttribute( QStringLiteral(
"type" ),
symbol->
type() );
1263 QByteArray xmlArray;
1264 QTextStream stream( &xmlArray );
1265 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1266 stream.setCodec(
"UTF-8" );
1268 elem.save( stream, 4 );
1269 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO symbol3d VALUES (NULL, '%q', '%q', %d);",
1270 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
1271 if ( !runEmptyQuery( query ) )
1273 QgsDebugMsg( QStringLiteral(
"Couldn't insert 3d symbol into the database!" ) );
1288 if ( m3dSymbols.contains( newName ) )
1290 QgsDebugMsg( QStringLiteral(
"3d symbol of new name already exists." ) );
1294 if ( !m3dSymbols.contains( oldName ) )
1298 m3dSymbols.insert( newName,
symbol );
1304 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM symbol3d WHERE name='%q'", oldName.toUtf8().constData() );
1306 statement = mCurrentDB.
prepare( query, nErr );
1307 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1322 return m3dSymbols.keys();
1329 QgsDebugMsg( QStringLiteral(
"Cannot Open database for getting favorite symbols" ) );
1330 return QStringList();
1338 QgsDebugMsg( QStringLiteral(
"No such style entity" ) );
1339 return QStringList();
1342 query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT name FROM %1 WHERE favorite=1" ).arg( entityTableName( type ) ).toLocal8Bit().data() );
1348 statement = mCurrentDB.
prepare( query, nErr );
1350 QStringList symbols;
1351 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1363 QgsDebugMsg( QStringLiteral(
"Cannot open database to get symbols of tagid %1" ).arg( tagid ) );
1364 return QStringList();
1372 QgsDebugMsg( QStringLiteral(
"Unknown Entity" ) );
1373 return QStringList();
1376 subquery =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT %1 FROM %2 WHERE tag_id=%d" ).arg( tagmapEntityIdFieldName( type ),
1377 tagmapTableName( type ) ).toLocal8Bit().data(), tagid );
1383 statement = mCurrentDB.
prepare( subquery, nErr );
1386 QStringList symbols;
1387 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1389 int id = sqlite3_column_int( statement.get(), 0 );
1391 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT name FROM %1 WHERE id=%d" ).arg( entityTableName( type ) ).toLocal8Bit().data(),
id );
1395 statement2 = mCurrentDB.
prepare( query, rc );
1396 while ( rc == SQLITE_OK && sqlite3_step( statement2.get() ) == SQLITE_ROW )
1411 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO tag VALUES (NULL, '%q')", tagname.toUtf8().constData() );
1413 statement = mCurrentDB.
prepare( query, nErr );
1414 if ( nErr == SQLITE_OK )
1415 ( void )sqlite3_step( statement.get() );
1418 settings.
setValue( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 );
1422 return static_cast< int >( sqlite3_last_insert_rowid( mCurrentDB.get() ) );
1428 return QStringList();
1434 statement = mCurrentDB.
prepare( query, nError );
1436 QStringList tagList;
1437 while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1447 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"UPDATE %1 SET name='%q' WHERE id=%d" ).arg( entityTableName( type ) ).toLocal8Bit().data(), newName.toUtf8().constData(),
id );
1449 const bool result = runEmptyQuery( query );
1452 mErrorString = QStringLiteral(
"Could not rename!" );
1456 mCachedTags.clear();
1457 mCachedFavorites.clear();
1482 bool groupRemoved =
false;
1487 query =
qgs_sqlite3_mprintf(
"DELETE FROM tag WHERE id=%d; DELETE FROM tagmap WHERE tag_id=%d",
id,
id );
1488 groupRemoved =
true;
1492 groupRemoved =
true;
1496 query =
qgs_sqlite3_mprintf( QStringLiteral(
"DELETE FROM %1 WHERE id=%d; DELETE FROM %2 WHERE %3=%d" ).arg(
1497 entityTableName( type ),
1498 tagmapTableName( type ),
1499 tagmapEntityIdFieldName( type )
1500 ).toLocal8Bit().data(),
id,
id );
1504 bool result =
false;
1505 if ( !runEmptyQuery( query ) )
1507 QgsDebugMsg( QStringLiteral(
"Could not delete entity!" ) );
1511 mCachedTags.clear();
1512 mCachedFavorites.clear();
1517 settings.
setValue( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 );
1536 std::unique_ptr< QgsSymbol >
symbol( mSymbols.take(
name ) );
1545 std::unique_ptr< QgsAbstract3DSymbol >
symbol( m3dSymbols.take(
name ) );
1554 std::unique_ptr< QgsColorRamp > ramp( mColorRamps.take(
name ) );
1562 if ( !mTextFormats.contains(
name ) )
1565 mTextFormats.remove(
name );
1571 if ( !mLabelSettings.contains(
name ) )
1574 mLabelSettings.remove(
name );
1580 if ( !mLegendPatchShapes.contains(
name ) )
1583 mLegendPatchShapes.remove(
name );
1590 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database to modify." ) );
1597 QgsDebugMsg(
"No matching entity for deleting in database: " +
name );
1600 const bool result =
remove( type,
id );
1603 mCachedTags[ type ].remove(
name );
1604 mCachedFavorites[ type ].remove(
name );
1633 bool QgsStyle::runEmptyQuery(
const QString &query )
1638 char *zErr =
nullptr;
1639 int nErr = sqlite3_exec( mCurrentDB.get(), query.toUtf8().constData(),
nullptr,
nullptr, &zErr );
1641 if ( nErr != SQLITE_OK )
1644 sqlite3_free( zErr );
1647 return nErr == SQLITE_OK;
1658 QgsDebugMsg( QStringLiteral(
"Wrong entity value. cannot apply group" ) );
1662 query =
qgs_sqlite3_mprintf( QStringLiteral(
"UPDATE %1 SET favorite=1 WHERE name='%q'" ).arg( entityTableName( type ) ).toLocal8Bit().data(),
1663 name.toUtf8().constData() );
1667 const bool res = runEmptyQuery( query );
1677 mCachedFavorites[ type ].insert(
name,
true );
1694 QgsDebugMsg( QStringLiteral(
"Wrong entity value. cannot apply group" ) );
1698 query =
qgs_sqlite3_mprintf( QStringLiteral(
"UPDATE %1 SET favorite=0 WHERE name='%q'" ).arg( entityTableName( type ) ).toLocal8Bit().data(),
name.toUtf8().constData() );
1702 const bool res = runEmptyQuery( query );
1705 mCachedFavorites[ type ].insert(
name,
false );
1716 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database to search" ) );
1717 return QStringList();
1726 return QStringList();
1729 item = entityTableName( type );
1734 item.toUtf8().constData(), qword.toUtf8().constData() );
1737 int nErr; statement = mCurrentDB.
prepare( query, nErr );
1739 QSet< QString > symbols;
1740 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1746 query =
qgs_sqlite3_mprintf(
"SELECT id FROM tag WHERE name LIKE '%%%q%%'", qword.toUtf8().constData() );
1747 statement = mCurrentDB.
prepare( query, nErr );
1750 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1755 QString dummy = tagids.join( QLatin1String(
", " ) );
1756 query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT %1 FROM %2 WHERE tag_id IN (%q)" ).arg( tagmapEntityIdFieldName( type ),
1757 tagmapTableName( type ) ).toLocal8Bit().data(), dummy.toUtf8().constData() );
1759 statement = mCurrentDB.
prepare( query, nErr );
1761 QStringList symbolids;
1762 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1767 dummy = symbolids.join( QLatin1String(
", " ) );
1769 item.toUtf8().constData(), dummy.toUtf8().constData() );
1770 statement = mCurrentDB.
prepare( query, nErr );
1771 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1776 return qgis::setToList( symbols );
1783 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database to tag." ) );
1801 QgsDebugMsg( QStringLiteral(
"No such symbol for tagging in database: " ) +
symbol );
1806 const auto constTags =
tags;
1807 for (
const QString &t : constTags )
1810 if ( !
tag.isEmpty() )
1822 QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"INSERT INTO %1 VALUES (%d,%d)" ).arg( tagmapTableName( type ) ).toLocal8Bit().data(), tagid, symbolid );
1824 char *zErr =
nullptr;
1826 nErr = sqlite3_exec( mCurrentDB.get(), query.toUtf8().constData(),
nullptr,
nullptr, &zErr );
1830 sqlite3_free( zErr );
1836 clearCachedTags( type,
symbol );
1846 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database for detagging." ) );
1861 if ( symbolid == 0 )
1866 const auto constTags =
tags;
1867 for (
const QString &
tag : constTags )
1872 statement2 = mCurrentDB.
prepare( query, nErr );
1875 if ( nErr == SQLITE_OK && sqlite3_step( statement2.get() ) == SQLITE_ROW )
1877 tagid = sqlite3_column_int( statement2.get(), 0 );
1883 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 );
1884 runEmptyQuery( query );
1888 clearCachedTags( type,
symbol );
1901 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database for detagging." ) );
1916 if ( symbolid == 0 )
1922 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"DELETE FROM %1 WHERE %2=%d" ).arg( tagmapTableName( type ),
1923 tagmapEntityIdFieldName( type ) ).toLocal8Bit().data(), symbolid );
1924 runEmptyQuery( query );
1926 clearCachedTags( type,
symbol );
1941 return QStringList();
1944 if ( mCachedTags[ type ].contains(
symbol ) )
1945 return mCachedTags[ type ].value(
symbol );
1951 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database for getting the tags." ) );
1952 return QStringList();
1957 return QStringList();
1960 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT tag_id FROM %1 WHERE %2=%d" ).arg( tagmapTableName( type ),
1961 tagmapEntityIdFieldName( type ) ).toLocal8Bit().data(), symbolid );
1964 int nErr; statement = mCurrentDB.
prepare( query, nErr );
1966 QStringList tagList;
1967 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1969 QString subquery =
qgs_sqlite3_mprintf(
"SELECT name FROM tag WHERE id=%d", sqlite3_column_int( statement.get(), 0 ) );
1973 statement2 = mCurrentDB.
prepare( subquery, pErr );
1974 if ( pErr == SQLITE_OK && sqlite3_step( statement2.get() ) == SQLITE_ROW )
1981 mCachedTags[ type ].insert(
symbol, tagList );
1990 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database for getting the tags." ) );
2001 if ( mCachedFavorites[ type ].contains(
name ) )
2002 return mCachedFavorites[ type ].value(
name );
2006 const QStringList names =
allNames( type );
2007 if ( !names.contains(
name ) )
2013 for (
const QString &n : names )
2015 const bool isFav = favorites.contains( n );
2019 mCachedFavorites[ type ].insert( n, isFav );
2028 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database for getting the tags." ) );
2055 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT tag_id FROM %1 WHERE tag_id=%d AND %2=%d" ).arg( tagmapTableName( type ),
2056 tagmapEntityIdFieldName( type ) ).toLocal8Bit().data(), tagid, symbolid );
2059 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2061 return ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW );
2073 statement = mCurrentDB.
prepare( query, nError );
2076 if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2084 int QgsStyle::getId(
const QString &table,
const QString &name )
2086 QString lowerName(
name.toLower() );
2087 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM %q WHERE LOWER(name)='%q'", table.toUtf8().constData(), lowerName.toUtf8().constData() );
2090 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2093 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2095 id = sqlite3_column_int( statement.get(), 0 );
2100 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM %q WHERE name='%q'", table.toUtf8().constData(),
name.toUtf8().constData() );
2103 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2104 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2106 id = sqlite3_column_int( statement.get(), 0 );
2113 QString QgsStyle::getName(
const QString &table,
int id )
const
2115 QString query =
qgs_sqlite3_mprintf(
"SELECT name FROM %q WHERE id='%q'", table.toUtf8().constData(), QString::number(
id ).toUtf8().constData() );
2118 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2121 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2131 return getId( QStringLiteral(
"symbol" ),
name );
2136 return getId( entityTableName( type ),
name );
2141 return getId( QStringLiteral(
"colorramp" ),
name );
2146 return mTextFormats.value(
name );
2151 return mTextFormats.count();
2156 return mTextFormats.keys();
2161 return getId( QStringLiteral(
"textformat" ),
name );
2166 return mLabelSettings.value(
name );
2171 return mLegendPatchShapes.value(
name );
2176 return mLegendPatchShapes.count();
2181 if ( !mLegendPatchShapes.contains(
name ) )
2184 return mLegendPatchShapes.value(
name ).symbolType();
2189 return m3dSymbols.contains(
name ) ? m3dSymbols.value(
name )->clone() :
nullptr;
2194 return m3dSymbols.count();
2199 if ( !m3dSymbols.contains(
name ) )
2200 return QList<QgsWkbTypes::GeometryType>();
2202 return m3dSymbols.value(
name )->compatibleGeometryTypes();
2207 if ( !mLabelSettings.contains(
name ) )
2210 return mLabelSettings.value(
name ).layerType;
2215 return mLabelSettings.count();
2220 return mLabelSettings.keys();
2225 return getId( QStringLiteral(
"labelsettings" ),
name );
2230 return mLegendPatchShapes.keys();
2238 return mPatchMarkerSymbol.get();
2241 return mPatchLineSymbol.get();
2244 return mPatchFillSymbol.get();
2254 return getId( QStringLiteral(
"tag" ),
name );
2259 return getId( QStringLiteral(
"smartgroup" ),
name );
2290 return QStringList();
2296 conditions.values( QStringLiteral(
"!tag" ) ),
2297 conditions.values( QStringLiteral(
"name" ) ),
2298 conditions.values( QStringLiteral(
"!name" ) ) );
2301 int QgsStyle::addSmartgroup(
const QString &name,
const QString &op,
const QStringList &matchTag,
const QStringList &noMatchTag,
const QStringList &matchName,
const QStringList &noMatchName )
2303 QDomDocument doc( QStringLiteral(
"dummy" ) );
2304 QDomElement smartEl = doc.createElement( QStringLiteral(
"smartgroup" ) );
2305 smartEl.setAttribute( QStringLiteral(
"name" ),
name );
2306 smartEl.setAttribute( QStringLiteral(
"operator" ), op );
2308 auto addCondition = [&doc, &smartEl](
const QString & constraint,
const QStringList & parameters )
2310 for (
const QString ¶m : parameters )
2312 QDomElement condEl = doc.createElement( QStringLiteral(
"condition" ) );
2313 condEl.setAttribute( QStringLiteral(
"constraint" ), constraint );
2314 condEl.setAttribute( QStringLiteral(
"param" ), param );
2315 smartEl.appendChild( condEl );
2318 addCondition( QStringLiteral(
"tag" ), matchTag );
2319 addCondition( QStringLiteral(
"!tag" ), noMatchTag );
2320 addCondition( QStringLiteral(
"name" ), matchName );
2321 addCondition( QStringLiteral(
"!name" ), noMatchName );
2323 QByteArray xmlArray;
2324 QTextStream stream( &xmlArray );
2325 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
2326 stream.setCodec(
"UTF-8" );
2328 smartEl.save( stream, 4 );
2330 name.toUtf8().constData(), xmlArray.constData() );
2332 if ( runEmptyQuery( query ) )
2335 settings.
setValue( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 );
2338 return static_cast< int >( sqlite3_last_insert_rowid( mCurrentDB.get() ) );
2342 QgsDebugMsg( QStringLiteral(
"Couldn't add the smart group into the database!" ) );
2351 QgsDebugMsg( QStringLiteral(
"Cannot open database for listing groups" ) );
2360 statement = mCurrentDB.
prepare( query, nError );
2363 while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2366 groupNames.insert( sqlite3_column_int( statement.get(),
SmartgroupId ), group );
2376 QgsDebugMsg( QStringLiteral(
"Cannot open database for listing groups" ) );
2377 return QStringList();
2385 statement = mCurrentDB.
prepare( query, nError );
2388 while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2398 QStringList symbols;
2403 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2404 if ( !( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW ) )
2406 return QStringList();
2412 if ( !doc.setContent( xmlstr ) )
2414 QgsDebugMsg( QStringLiteral(
"Cannot open smartgroup id: %1" ).arg(
id ) );
2416 QDomElement smartEl = doc.documentElement();
2417 QString op = smartEl.attribute( QStringLiteral(
"operator" ) );
2418 QDomNodeList conditionNodes = smartEl.childNodes();
2420 bool firstSet =
true;
2421 for (
int i = 0; i < conditionNodes.count(); i++ )
2423 QDomElement condEl = conditionNodes.at( i ).toElement();
2424 QString constraint = condEl.attribute( QStringLiteral(
"constraint" ) );
2425 QString param = condEl.attribute( QStringLiteral(
"param" ) );
2427 QStringList resultNames;
2429 if ( constraint == QLatin1String(
"tag" ) )
2433 else if ( constraint == QLatin1String(
"name" ) )
2435 resultNames =
allNames( type ).filter( param, Qt::CaseInsensitive );
2437 else if ( constraint == QLatin1String(
"!tag" ) )
2441 for (
const QString &
name : unwanted )
2443 resultNames.removeAll(
name );
2446 else if ( constraint == QLatin1String(
"!name" ) )
2448 const QStringList all =
allNames( type );
2449 for (
const QString &
str : all )
2451 if ( !
str.contains( param, Qt::CaseInsensitive ) )
2459 symbols = resultNames;
2464 if ( op == QLatin1String(
"OR" ) )
2466 symbols << resultNames;
2468 else if ( op == QLatin1String(
"AND" ) )
2470 QStringList dummy = symbols;
2472 for (
const QString &result : std::as_const( resultNames ) )
2474 if ( dummy.contains( result ) )
2483 QStringList unique = qgis::setToList( qgis::listToSet( symbols ) );
2484 std::sort( unique.begin(), unique.end() );
2492 QgsDebugMsg( QStringLiteral(
"Cannot open database for listing groups" ) );
2502 statement = mCurrentDB.
prepare( query, nError );
2503 if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2507 if ( !doc.setContent( xmlstr ) )
2509 QgsDebugMsg( QStringLiteral(
"Cannot open smartgroup id: %1" ).arg(
id ) );
2512 QDomElement smartEl = doc.documentElement();
2513 QDomNodeList conditionNodes = smartEl.childNodes();
2515 for (
int i = 0; i < conditionNodes.count(); i++ )
2517 QDomElement condEl = conditionNodes.at( i ).toElement();
2518 QString constraint = condEl.attribute( QStringLiteral(
"constraint" ) );
2519 QString param = condEl.attribute( QStringLiteral(
"param" ) );
2521 condition.insert( constraint, param );
2532 QgsDebugMsg( QStringLiteral(
"Cannot open database for listing groups" ) );
2542 statement = mCurrentDB.
prepare( query, nError );
2543 if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2547 if ( !doc.setContent( xmlstr ) )
2549 QgsDebugMsg( QStringLiteral(
"Cannot open smartgroup id: %1" ).arg(
id ) );
2551 QDomElement smartEl = doc.documentElement();
2552 op = smartEl.attribute( QStringLiteral(
"operator" ) );
2560 if ( filename.isEmpty() )
2562 QgsDebugMsg( QStringLiteral(
"Invalid filename for style export." ) );
2566 QDomDocument doc( QStringLiteral(
"qgis_style" ) );
2567 QDomElement root = doc.createElement( QStringLiteral(
"qgis_style" ) );
2569 doc.appendChild( root );
2579 QDomNodeList symbolsList = symbolsElem.elementsByTagName( QStringLiteral(
"symbol" ) );
2580 int nbSymbols = symbolsList.count();
2581 for (
int i = 0; i < nbSymbols; ++i )
2583 QDomElement
symbol = symbolsList.at( i ).toElement();
2584 QString
name =
symbol.attribute( QStringLiteral(
"name" ) );
2586 if (
tags.count() > 0 )
2588 symbol.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2590 if ( favoriteSymbols.contains(
name ) )
2592 symbol.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2597 QDomElement rampsElem = doc.createElement( QStringLiteral(
"colorramps" ) );
2598 for ( QMap<QString, QgsColorRamp *>::const_iterator itr = mColorRamps.constBegin(); itr != mColorRamps.constEnd(); ++itr )
2602 if (
tags.count() > 0 )
2604 rampEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2606 if ( favoriteColorramps.contains( itr.key() ) )
2608 rampEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2610 rampsElem.appendChild( rampEl );
2614 QDomElement textFormatsElem = doc.createElement( QStringLiteral(
"textformats" ) );
2615 for (
auto it = mTextFormats.constBegin(); it != mTextFormats.constEnd(); ++it )
2617 QDomElement textFormatEl = doc.createElement( QStringLiteral(
"textformat" ) );
2618 textFormatEl.setAttribute( QStringLiteral(
"name" ), it.key() );
2620 textFormatEl.appendChild( textStyleEl );
2622 if (
tags.count() > 0 )
2624 textFormatEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2626 if ( favoriteTextFormats.contains( it.key() ) )
2628 textFormatEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2630 textFormatsElem.appendChild( textFormatEl );
2634 QDomElement labelSettingsElem = doc.createElement( QStringLiteral(
"labelsettings" ) );
2635 for (
auto it = mLabelSettings.constBegin(); it != mLabelSettings.constEnd(); ++it )
2637 QDomElement labelSettingsEl = doc.createElement( QStringLiteral(
"labelsetting" ) );
2638 labelSettingsEl.setAttribute( QStringLiteral(
"name" ), it.key() );
2640 labelSettingsEl.appendChild( defEl );
2642 if (
tags.count() > 0 )
2644 labelSettingsEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2646 if ( favoriteTextFormats.contains( it.key() ) )
2648 labelSettingsEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2650 labelSettingsElem.appendChild( labelSettingsEl );
2654 QDomElement legendPatchShapesElem = doc.createElement( QStringLiteral(
"legendpatchshapes" ) );
2655 for (
auto it = mLegendPatchShapes.constBegin(); it != mLegendPatchShapes.constEnd(); ++it )
2657 QDomElement legendPatchShapeEl = doc.createElement( QStringLiteral(
"legendpatchshape" ) );
2658 legendPatchShapeEl.setAttribute( QStringLiteral(
"name" ), it.key() );
2659 QDomElement defEl = doc.createElement( QStringLiteral(
"definition" ) );
2661 legendPatchShapeEl.appendChild( defEl );
2663 if (
tags.count() > 0 )
2665 legendPatchShapeEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2667 if ( favoriteLegendShapes.contains( it.key() ) )
2669 legendPatchShapeEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2671 legendPatchShapesElem.appendChild( legendPatchShapeEl );
2675 QDomElement symbols3DElem = doc.createElement( QStringLiteral(
"symbols3d" ) );
2676 for (
auto it = m3dSymbols.constBegin(); it != m3dSymbols.constEnd(); ++it )
2678 QDomElement symbolEl = doc.createElement( QStringLiteral(
"symbol3d" ) );
2679 symbolEl.setAttribute( QStringLiteral(
"name" ), it.key() );
2680 QDomElement defEl = doc.createElement( QStringLiteral(
"definition" ) );
2681 defEl.setAttribute( QStringLiteral(
"type" ), it.value()->type() );
2683 symbolEl.appendChild( defEl );
2685 if (
tags.count() > 0 )
2687 symbolEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2689 if ( favorite3DSymbols.contains( it.key() ) )
2691 symbolEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2693 symbols3DElem.appendChild( symbolEl );
2696 root.appendChild( symbolsElem );
2697 root.appendChild( rampsElem );
2698 root.appendChild( textFormatsElem );
2699 root.appendChild( labelSettingsElem );
2700 root.appendChild( legendPatchShapesElem );
2701 root.appendChild( symbols3DElem );
2704 QFile f( filename );
2705 if ( !f.open( QFile::WriteOnly | QIODevice::Truncate ) )
2707 mErrorString =
"Couldn't open file for writing: " + filename;
2711 QTextStream ts( &f );
2712 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
2713 ts.setCodec(
"UTF-8" );
2718 mFileName = filename;
2729 mErrorString = QString();
2730 QDomDocument doc( QStringLiteral(
"style" ) );
2731 QFile f( filename );
2732 if ( !f.open( QFile::ReadOnly ) )
2734 mErrorString = QStringLiteral(
"Unable to open the specified file" );
2735 QgsDebugMsg( QStringLiteral(
"Error opening the style XML file." ) );
2739 if ( !doc.setContent( &f ) )
2741 mErrorString = QStringLiteral(
"Unable to understand the style file: %1" ).arg( filename );
2742 QgsDebugMsg( QStringLiteral(
"XML Parsing error" ) );
2748 QDomElement docEl = doc.documentElement();
2749 if ( docEl.tagName() != QLatin1String(
"qgis_style" ) )
2751 mErrorString =
"Incorrect root tag in style: " + docEl.tagName();
2755 const QString version = docEl.attribute( QStringLiteral(
"version" ) );
2756 if ( version != QLatin1String(
STYLE_CURRENT_VERSION ) && version != QLatin1String(
"0" ) && version != QLatin1String(
"1" ) )
2758 mErrorString =
"Unknown style file version: " + version;
2764 QDomElement symbolsElement = docEl.firstChildElement( QStringLiteral(
"symbols" ) );
2765 QDomElement e = symbolsElement.firstChildElement();
2769 runEmptyQuery( query );
2774 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2776 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2777 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2783 if ( e.tagName() == QLatin1String(
"symbol" ) )
2785 QString
name = e.attribute( QStringLiteral(
"name" ) );
2787 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2789 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2791 bool favorite =
false;
2792 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2819 for ( QMap<QString, QgsSymbol *>::iterator it = symbols.begin(); it != symbols.end(); ++it )
2826 QDomElement rampsElement = docEl.firstChildElement( QStringLiteral(
"colorramps" ) );
2827 e = rampsElement.firstChildElement();
2828 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2830 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2831 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2837 if ( e.tagName() == QLatin1String(
"colorramp" ) )
2839 QString
name = e.attribute( QStringLiteral(
"name" ) );
2841 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2843 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2845 bool favorite =
false;
2846 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2870 if ( qobject_cast< QGuiApplication * >( QCoreApplication::instance() ) )
2874 const QDomElement textFormatElement = docEl.firstChildElement( QStringLiteral(
"textformats" ) );
2875 e = textFormatElement.firstChildElement();
2876 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2878 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2879 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2885 if ( e.tagName() == QLatin1String(
"textformat" ) )
2887 QString
name = e.attribute( QStringLiteral(
"name" ) );
2889 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2891 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2893 bool favorite =
false;
2894 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2900 const QDomElement styleElem = e.firstChildElement();
2918 const QDomElement labelSettingsElement = docEl.firstChildElement( QStringLiteral(
"labelsettings" ) );
2919 e = labelSettingsElement.firstChildElement();
2920 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2922 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2923 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2929 if ( e.tagName() == QLatin1String(
"labelsetting" ) )
2931 QString
name = e.attribute( QStringLiteral(
"name" ) );
2933 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2935 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2937 bool favorite =
false;
2938 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2944 const QDomElement styleElem = e.firstChildElement();
2963 const QDomElement legendPatchShapesElement = docEl.firstChildElement( QStringLiteral(
"legendpatchshapes" ) );
2964 e = legendPatchShapesElement.firstChildElement();
2965 for ( ; !e.isNull(); e = e.nextSiblingElement() )
2967 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2968 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2974 if ( e.tagName() == QLatin1String(
"legendpatchshape" ) )
2976 QString
name = e.attribute( QStringLiteral(
"name" ) );
2978 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2980 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2982 bool favorite =
false;
2983 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2989 const QDomElement shapeElem = e.firstChildElement();
3007 const QDomElement symbols3DElement = docEl.firstChildElement( QStringLiteral(
"symbols3d" ) );
3008 e = symbols3DElement.firstChildElement();
3009 for ( ; !e.isNull(); e = e.nextSiblingElement() )
3011 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
3012 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
3018 if ( e.tagName() == QLatin1String(
"symbol3d" ) )
3020 QString
name = e.attribute( QStringLiteral(
"name" ) );
3022 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
3024 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
3026 bool favorite =
false;
3027 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
3032 const QDomElement symbolElem = e.firstChildElement();
3033 const QString type = symbolElem.attribute( QStringLiteral(
"type" ) );
3054 runEmptyQuery( query );
3056 mFileName = filename;
3062 QFileInfo fileInfo( path );
3064 if ( fileInfo.suffix().compare( QLatin1String(
"xml" ), Qt::CaseInsensitive ) != 0 )
3068 if ( !QFile::exists( path ) )
3071 QFile inputFile( path );
3072 if ( !inputFile.open( QIODevice::ReadOnly ) )
3075 QTextStream stream( &inputFile );
3076 const QString line = stream.readLine();
3077 return line == QLatin1String(
"<!DOCTYPE qgis_style>" );
3080 bool QgsStyle::updateSymbol( StyleEntity type,
const QString &name )
3082 QDomDocument doc( QStringLiteral(
"dummy" ) );
3084 QByteArray xmlArray;
3085 QTextStream stream( &xmlArray );
3086 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
3087 stream.setCodec(
"UTF-8" );
3099 QgsDebugMsg( QStringLiteral(
"Update request received for unavailable symbol" ) );
3104 if ( symEl.isNull() )
3106 QgsDebugMsg( QStringLiteral(
"Couldn't convert symbol to valid XML!" ) );
3109 symEl.save( stream, 4 );
3111 xmlArray.constData(),
name.toUtf8().constData() );
3120 QgsDebugMsg( QStringLiteral(
"Update request received for unavailable symbol" ) );
3124 symEl = doc.createElement( QStringLiteral(
"symbol" ) );
3125 symEl.setAttribute( QStringLiteral(
"type" ), m3dSymbols.value(
name )->type() );
3127 if ( symEl.isNull() )
3129 QgsDebugMsg( QStringLiteral(
"Couldn't convert symbol to valid XML!" ) );
3132 symEl.save( stream, 4 );
3134 xmlArray.constData(),
name.toUtf8().constData() );
3142 QgsDebugMsg( QStringLiteral(
"Update requested for unavailable color ramp." ) );
3148 if ( symEl.isNull() )
3150 QgsDebugMsg( QStringLiteral(
"Couldn't convert color ramp to valid XML!" ) );
3153 symEl.save( stream, 4 );
3155 xmlArray.constData(),
name.toUtf8().constData() );
3163 QgsDebugMsg( QStringLiteral(
"Update requested for unavailable text format." ) );
3169 if ( symEl.isNull() )
3171 QgsDebugMsg( QStringLiteral(
"Couldn't convert text format to valid XML!" ) );
3174 symEl.save( stream, 4 );
3176 xmlArray.constData(),
name.toUtf8().constData() );
3184 QgsDebugMsg( QStringLiteral(
"Update requested for unavailable label settings." ) );
3190 if ( symEl.isNull() )
3192 QgsDebugMsg( QStringLiteral(
"Couldn't convert label settings to valid XML!" ) );
3195 symEl.save( stream, 4 );
3197 xmlArray.constData(),
name.toUtf8().constData() );
3205 QgsDebugMsg( QStringLiteral(
"Update requested for unavailable legend patch shape." ) );
3210 symEl = doc.createElement( QStringLiteral(
"shape" ) );
3212 symEl.save( stream, 4 );
3214 xmlArray.constData(),
name.toUtf8().constData() );
3221 QgsDebugMsg( QStringLiteral(
"Updating the unsupported StyleEntity" ) );
3227 if ( !runEmptyQuery( query ) )
3229 QgsDebugMsg( QStringLiteral(
"Couldn't update symbol into the database!" ) );
3265 mCachedTags[ type ].remove(
name );
3268 bool QgsStyle::createStyleMetadataTableIfNeeded()
3271 QString query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='stylemetadata'" );
3274 statement = mCurrentDB.
prepare( query, rc );
3276 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
3280 "id INTEGER PRIMARY KEY,"\
3283 runEmptyQuery( query );
3285 runEmptyQuery( query );
3294 void QgsStyle::upgradeIfRequired()
3298 if ( !createStyleMetadataTableIfNeeded() )
3300 const QString query =
qgs_sqlite3_mprintf(
"SELECT value FROM stylemetadata WHERE key='version'" );
3303 if ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
3315 runEmptyQuery( query );
3325 return QStringLiteral(
"symbol" );
3328 return QStringLiteral(
"colorramp" );
3331 return QStringLiteral(
"textformat" );
3334 return QStringLiteral(
"labelsettings" );
3337 return QStringLiteral(
"legendpatchshapes" );
3340 return QStringLiteral(
"symbol3d" );
3343 return QStringLiteral(
"tag" );
3346 return QStringLiteral(
"smartgroup" );
3356 return QStringLiteral(
"tagmap" );
3359 return QStringLiteral(
"ctagmap" );
3362 return QStringLiteral(
"tftagmap" );
3365 return QStringLiteral(
"lstagmap" );
3368 return QStringLiteral(
"lpstagmap" );
3371 return QStringLiteral(
"symbol3dtagmap" );
3385 return QStringLiteral(
"symbol_id" );
3388 return QStringLiteral(
"colorramp_id" );
3391 return QStringLiteral(
"textformat_id" );
3394 return QStringLiteral(
"labelsettings_id" );
3397 return QStringLiteral(
"legendpatchshape_id" );
3400 return QStringLiteral(
"symbol3d_id" );
@ ScaleArea
Calculate scale by the area.
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.
static QgsProject * instance()
Returns the QgsProject singleton instance.
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 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.
bool saveLabelSettings(const QString &name, const QgsPalLayerSettings &settings, bool favorite, const QStringList &tags)
Adds label settings to the database.
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.
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.
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.
QList< QgsWkbTypes::GeometryType > symbol3DCompatibleGeometryTypes(const QString &name) const
Returns the list of the vector layer geometry types which are compatible with the 3D symbol with the ...
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 (since QGIS 3.14)
@ ColorrampEntity
Color ramps.
@ LegendPatchShapeEntity
Legend patch shape (since QGIS 3.14)
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.
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()
QgsStyle()
Constructor for QgsStyle.
static QgsStyle * defaultStyle()
Returns default application-wide style.
void textFormatRenamed(const QString &oldName, const QString &newName)
Emitted whenever a text format has been renamed from oldName to newName.
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.
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.
QgsWkbTypes::GeometryType labelSettingsLayerType(const QString &name) const
Returns the layer geometry type corresponding to the label settings with the specified name,...
void createTables()
Creates tables structure for new database.
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 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.
bool save(QString filename=QString())
Saves style into a file (will use current filename if empty string is passed)
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.
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.
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...
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 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.
Qgis::SymbolType type() const
Returns the symbol's type.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
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.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
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.
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
@ TextFormatName
Text format name.
@ TextFormatXML
Text format definition (as XML)
@ SymbolXML
Symbol definition (as XML)
@ SmartgroupName
Smart group name.
@ SmartgroupId
Smart group ID.
QMap< int, QString > QgsSymbolGroupMap
@ LabelSettingsName
Label settings name.
@ LabelSettingsXML
Label settings definition (as XML)
@ ColorrampName
Color ramp name.
@ ColorrampXML
Color ramp definition (as XML)
QList< QgsSymbolLayer * > QgsSymbolLayerList