35 #include <QDomDocument>
36 #include <QDomElement>
38 #include <QDomNodeList>
40 #include <QTextStream>
47 #define STYLE_CURRENT_VERSION "2"
72 QgsStyle *QgsStyle::sDefaultStyle =
nullptr;
78 simpleMarker->setStrokeWidth( 0.4 );
79 mPatchMarkerSymbol = qgis::make_unique< QgsMarkerSymbol >(
QgsSymbolLayerList() << simpleMarker.release() );
81 std::unique_ptr< QgsSimpleLineSymbolLayer > simpleLine = qgis::make_unique< QgsSimpleLineSymbolLayer >( QColor( 84, 176, 74 ), 0.6 );
82 mPatchLineSymbol = qgis::make_unique< QgsLineSymbol >(
QgsSymbolLayerList() << simpleLine.release() );
84 std::unique_ptr< QgsGradientFillSymbolLayer > gradientFill = qgis::make_unique< QgsGradientFillSymbolLayer >( QColor( 66, 150, 63 ), QColor( 84, 176, 74 ) );
85 std::unique_ptr< QgsSimpleLineSymbolLayer > simpleOutline = qgis::make_unique< QgsSimpleLineSymbolLayer >( QColor( 56, 128, 54 ), 0.26 );
86 mPatchFillSymbol = qgis::make_unique< QgsFillSymbol >(
QgsSymbolLayerList() << gradientFill.release() << simpleOutline.release() );
96 switch ( entity->
type() )
130 if ( !sDefaultStyle )
136 if ( !QFile::exists( styleFilename ) )
148 if ( sDefaultStyle->
load( styleFilename ) )
150 sDefaultStyle->upgradeIfRequired();
154 return sDefaultStyle;
159 delete sDefaultStyle;
160 sDefaultStyle =
nullptr;
165 qDeleteAll( mSymbols );
166 qDeleteAll( mColorRamps );
167 qDeleteAll( m3dSymbols );
171 mTextFormats.clear();
175 mCachedFavorites.clear();
180 if ( !
symbol || name.isEmpty() )
184 if ( mSymbols.contains( name ) )
187 delete mSymbols.value( name );
188 mSymbols.insert( name,
symbol );
194 mSymbols.insert( name,
symbol );
205 QDomDocument doc( QStringLiteral(
"dummy" ) );
207 if ( symEl.isNull() )
209 QgsDebugMsg( QStringLiteral(
"Couldn't convert symbol to valid XML!" ) );
214 QTextStream stream( &xmlArray );
215 stream.setCodec(
"UTF-8" );
216 symEl.save( stream, 4 );
218 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
220 if ( !runEmptyQuery( query ) )
222 QgsDebugMsg( QStringLiteral(
"Couldn't insert symbol into the database!" ) );
226 mCachedFavorites[
SymbolEntity ].insert( name, favorite );
278 return mSymbols.value( name );
283 return mSymbols.count();
288 return mSymbols.keys();
298 if ( mColorRamps.contains( name ) )
301 delete mColorRamps.value( name );
319 if ( mTextFormats.contains( name ) )
322 mTextFormats.remove( name );
323 mTextFormats.insert( name, format );
329 mTextFormats.insert( name, format );
340 if ( mLabelSettings.contains( name ) )
343 mLabelSettings.remove( name );
344 mLabelSettings.insert( name, settings );
350 mLabelSettings.insert( name, settings );
361 if ( mLegendPatchShapes.contains( name ) )
364 mLegendPatchShapes.remove( name );
365 mLegendPatchShapes.insert( name, shape );
371 mLegendPatchShapes.insert( name, shape );
382 if ( m3dSymbols.contains( name ) )
385 delete m3dSymbols.take( name );
386 m3dSymbols.insert( name,
symbol );
392 m3dSymbols.insert( name,
symbol );
403 QDomDocument doc( QStringLiteral(
"dummy" ) );
406 if ( rampEl.isNull() )
408 QgsDebugMsg( QStringLiteral(
"Couldn't convert color ramp to valid XML!" ) );
413 QTextStream stream( &xmlArray );
414 stream.setCodec(
"UTF-8" );
415 rampEl.save( stream, 4 );
416 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
417 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
418 if ( !runEmptyQuery( query ) )
420 QgsDebugMsg( QStringLiteral(
"Couldn't insert colorramp into the database!" ) );
442 return ramp ? ramp->
clone() :
nullptr;
447 return mColorRamps.value( name );
452 return mColorRamps.count();
457 return mColorRamps.keys();
460 void QgsStyle::handleDeferred3DSymbolCreation()
462 for (
auto it = mDeferred3DsymbolElements.constBegin(); it != mDeferred3DsymbolElements.constEnd(); ++it )
464 const QString symbolType = it.value().attribute( QStringLiteral(
"type" ) );
474 QgsDebugMsg(
"Cannot open 3d symbol " + it.key() );
478 mDeferred3DsymbolElements.clear();
481 bool QgsStyle::openDatabase(
const QString &filename )
483 int rc = mCurrentDB.
open( filename );
486 mErrorString = QStringLiteral(
"Couldn't open the style database: %1" ).arg( mCurrentDB.
errorMessage() );
495 mErrorString.clear();
496 if ( !openDatabase( filename ) )
498 mErrorString = QStringLiteral(
"Unable to create database" );
510 mErrorString.clear();
511 if ( !openDatabase( QStringLiteral(
":memory:" ) ) )
513 mErrorString = QStringLiteral(
"Unable to create temporary memory database" );
526 "id INTEGER PRIMARY KEY,"\
529 "favorite INTEGER);"\
530 "CREATE TABLE colorramp("\
531 "id INTEGER PRIMARY KEY,"\
534 "favorite INTEGER);"\
535 "CREATE TABLE textformat("\
536 "id INTEGER PRIMARY KEY,"\
539 "favorite INTEGER);"\
540 "CREATE TABLE labelsettings("\
541 "id INTEGER PRIMARY KEY,"\
544 "favorite INTEGER);"\
545 "CREATE TABLE legendpatchshapes("\
546 "id INTEGER PRIMARY KEY,"\
549 "favorite INTEGER);"\
550 "CREATE TABLE symbol3d("\
551 "id INTEGER PRIMARY KEY,"\
554 "favorite INTEGER);"\
556 "id INTEGER PRIMARY KEY,"\
558 "CREATE TABLE tagmap("\
559 "tag_id INTEGER NOT NULL,"\
560 "symbol_id INTEGER);"\
561 "CREATE TABLE ctagmap("\
562 "tag_id INTEGER NOT NULL,"\
563 "colorramp_id INTEGER);"\
564 "CREATE TABLE tftagmap("\
565 "tag_id INTEGER NOT NULL,"\
566 "textformat_id INTEGER);"\
567 "CREATE TABLE lstagmap("\
568 "tag_id INTEGER NOT NULL,"\
569 "labelsettings_id INTEGER);"\
570 "CREATE TABLE lpstagmap("\
571 "tag_id INTEGER NOT NULL,"\
572 "legendpatchshape_id INTEGER);"\
573 "CREATE TABLE symbol3dtagmap("\
574 "tag_id INTEGER NOT NULL,"\
575 "symbol3d_id INTEGER);"\
576 "CREATE TABLE smartgroup("\
577 "id INTEGER PRIMARY KEY,"\
580 runEmptyQuery( query );
585 mErrorString.clear();
588 if ( !openDatabase( filename ) )
590 mErrorString = QStringLiteral(
"Unable to open database file specified" );
596 QString query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='textformat'" );
599 statement = mCurrentDB.
prepare( query, rc );
600 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
603 "id INTEGER PRIMARY KEY,"\
606 "favorite INTEGER);"\
607 "CREATE TABLE tftagmap("\
608 "tag_id INTEGER NOT NULL,"\
609 "textformat_id INTEGER);" );
610 runEmptyQuery( query );
613 query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='labelsettings'" );
614 statement = mCurrentDB.
prepare( query, rc );
615 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
618 "id INTEGER PRIMARY KEY,"\
621 "favorite INTEGER);"\
622 "CREATE TABLE lstagmap("\
623 "tag_id INTEGER NOT NULL,"\
624 "labelsettings_id INTEGER);" );
625 runEmptyQuery( query );
628 query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='legendpatchshapes'" );
629 statement = mCurrentDB.
prepare( query, rc );
630 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
633 "id INTEGER PRIMARY KEY,"\
636 "favorite INTEGER);"\
637 "CREATE TABLE lpstagmap("\
638 "tag_id INTEGER NOT NULL,"\
639 "legendpatchshape_id INTEGER);" );
640 runEmptyQuery( query );
644 statement = mCurrentDB.
prepare( query, rc );
645 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
648 "id INTEGER PRIMARY KEY,"\
651 "favorite INTEGER);"\
652 "CREATE TABLE symbol3dtagmap("\
653 "tag_id INTEGER NOT NULL,"\
654 "symbol3d_id INTEGER);" );
655 runEmptyQuery( query );
660 "UPDATE colorramp SET favorite=0 WHERE favorite IS NULL;"
661 "UPDATE textformat SET favorite=0 WHERE favorite IS NULL;"
662 "UPDATE labelsettings SET favorite=0 WHERE favorite IS NULL;"
663 "UPDATE legendpatchshapes SET favorite=0 WHERE favorite IS NULL;"
664 "UPDATE symbol3d SET favorite=0 WHERE favorite IS NULL;"
666 runEmptyQuery( query );
672 statement = mCurrentDB.
prepare( query, rc );
674 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
680 if ( !doc.setContent( xmlstring ) )
686 QDomElement symElement = doc.documentElement();
689 mSymbols.insert( symbolName,
symbol );
696 statement = mCurrentDB.
prepare( query, rc );
697 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
703 if ( !doc.setContent( xmlstring ) )
708 QDomElement rampElement = doc.documentElement();
711 mColorRamps.insert( rampName, ramp );
718 statement = mCurrentDB.
prepare( query, rc );
719 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
725 if ( !doc.setContent( xmlstring ) )
727 QgsDebugMsg(
"Cannot open text format " + formatName );
730 QDomElement formatElement = doc.documentElement();
733 mTextFormats.insert( formatName, format );
740 statement = mCurrentDB.
prepare( query, rc );
741 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
747 if ( !doc.setContent( xmlstring ) )
749 QgsDebugMsg(
"Cannot open label settings " + settingsName );
752 QDomElement settingsElement = doc.documentElement();
755 mLabelSettings.insert( settingsName, settings );
762 statement = mCurrentDB.
prepare( query, rc );
763 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
769 if ( !doc.setContent( xmlstring ) )
771 QgsDebugMsg(
"Cannot open legend patch shape " + settingsName );
774 QDomElement settingsElement = doc.documentElement();
777 mLegendPatchShapes.insert( settingsName, shape );
784 statement = mCurrentDB.
prepare( query, rc );
788 while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
794 if ( !doc.setContent( xmlstring ) )
796 QgsDebugMsg(
"Cannot open 3d symbol " + settingsName );
799 QDomElement settingsElement = doc.documentElement();
801 if ( !registry3dPopulated )
803 mDeferred3DsymbolElements.insert( settingsName, settingsElement );
807 const QString symbolType = settingsElement.attribute( QStringLiteral(
"type" ) );
812 m3dSymbols.insert( settingsName,
symbol.release() );
816 QgsDebugMsg(
"Cannot open 3d symbol " + settingsName );
823 mFileName = filename;
831 mErrorString.clear();
833 if ( filename.isEmpty() )
834 filename = mFileName;
839 QDomDocument doc(
"qgis_style" );
840 QDomElement root = doc.createElement(
"qgis_style" );
842 doc.appendChild( root );
846 QDomElement rampsElem = doc.createElement(
"colorramps" );
849 for ( QMap<QString, QgsColorRamp *>::iterator itr = mColorRamps.begin(); itr != mColorRamps.end(); ++itr )
852 rampsElem.appendChild( rampEl );
855 root.appendChild( symbolsElem );
856 root.appendChild( rampsElem );
860 if ( !f.open( QFile::WriteOnly ) )
862 mErrorString =
"Couldn't open file for writing: " + filename;
865 QTextStream ts( &f );
866 ts.setCodec(
"UTF-8" );
871 mFileName = filename;
877 if ( mSymbols.contains( newName ) )
879 QgsDebugMsg( QStringLiteral(
"Symbol of new name already exists" ) );
887 mSymbols.insert( newName,
symbol );
891 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database to tag." ) );
898 QgsDebugMsg( QStringLiteral(
"No such symbol for tagging in database: " ) + oldName );
917 if ( mColorRamps.contains( newName ) )
919 QgsDebugMsg( QStringLiteral(
"Color ramp of new name already exists." ) );
927 mColorRamps.insert( newName, ramp );
933 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM colorramp WHERE name='%q'", oldName.toUtf8().constData() );
935 statement = mCurrentDB.
prepare( query, nErr );
936 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
938 rampid = sqlite3_column_int( statement.get(), 0 );
953 QDomDocument doc( QStringLiteral(
"dummy" ) );
956 if ( formatElem.isNull() )
958 QgsDebugMsg( QStringLiteral(
"Couldn't convert text format to valid XML!" ) );
963 QTextStream stream( &xmlArray );
964 stream.setCodec(
"UTF-8" );
965 formatElem.save( stream, 4 );
966 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO textformat VALUES (NULL, '%q', '%q', %d);",
967 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
968 if ( !runEmptyQuery( query ) )
970 QgsDebugMsg( QStringLiteral(
"Couldn't insert text format into the database!" ) );
991 if ( mTextFormats.contains( newName ) )
993 QgsDebugMsg( QStringLiteral(
"Text format of new name already exists." ) );
997 if ( !mTextFormats.contains( oldName ) )
1001 mTextFormats.insert( newName, format );
1007 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM textformat WHERE name='%q'", oldName.toUtf8().constData() );
1009 statement = mCurrentDB.
prepare( query, nErr );
1010 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1012 textFormatId = sqlite3_column_int( statement.get(), 0 );
1027 QDomDocument doc( QStringLiteral(
"dummy" ) );
1030 if ( settingsElem.isNull() )
1032 QgsDebugMsg( QStringLiteral(
"Couldn't convert label settings to valid XML!" ) );
1036 QByteArray xmlArray;
1037 QTextStream stream( &xmlArray );
1038 stream.setCodec(
"UTF-8" );
1039 settingsElem.save( stream, 4 );
1040 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO labelsettings VALUES (NULL, '%q', '%q', %d);",
1041 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
1042 if ( !runEmptyQuery( query ) )
1044 QgsDebugMsg( QStringLiteral(
"Couldn't insert label settings into the database!" ) );
1065 if ( mLabelSettings.contains( newName ) )
1067 QgsDebugMsg( QStringLiteral(
"Label settings of new name already exists." ) );
1071 if ( !mLabelSettings.contains( oldName ) )
1075 mLabelSettings.insert( newName, settings );
1081 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM labelsettings WHERE name='%q'", oldName.toUtf8().constData() );
1083 statement = mCurrentDB.
prepare( query, nErr );
1084 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1101 QDomDocument doc( QStringLiteral(
"dummy" ) );
1102 QDomElement shapeElem = doc.createElement( QStringLiteral(
"shape" ) );
1105 QByteArray xmlArray;
1106 QTextStream stream( &xmlArray );
1107 stream.setCodec(
"UTF-8" );
1108 shapeElem.save( stream, 4 );
1109 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO legendpatchshapes VALUES (NULL, '%q', '%q', %d);",
1110 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
1111 if ( !runEmptyQuery( query ) )
1113 QgsDebugMsg( QStringLiteral(
"Couldn't insert legend patch shape into the database!" ) );
1128 if ( mLegendPatchShapes.contains( newName ) )
1130 QgsDebugMsg( QStringLiteral(
"Legend patch shape of new name already exists." ) );
1134 if ( !mLegendPatchShapes.contains( oldName ) )
1138 mLegendPatchShapes.insert( newName, shape );
1144 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM legendpatchshapes WHERE name='%q'", oldName.toUtf8().constData() );
1146 statement = mCurrentDB.
prepare( query, nErr );
1147 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1165 if ( mDefaultPatchCache[ type ].contains( size ) )
1166 return mDefaultPatchCache[ type ].value( size );
1172 geom =
QgsGeometry( qgis::make_unique< QgsPoint >(
static_cast< int >( size.width() ) / 2,
static_cast< int >( size.height() ) / 2 ) );
1179 double y =
static_cast< int >( size.height() ) / 2 + 0.5;
1180 geom =
QgsGeometry( qgis::make_unique< QgsLineString >( ( QVector< double >() << 0 << size.width() ),
1181 ( QVector< double >() << y << y ) ) );
1187 geom =
QgsGeometry( qgis::make_unique< QgsPolygon >(
1188 new QgsLineString( QVector< double >() << 0 <<
static_cast< int >( size.width() ) <<
static_cast< int >( size.width() ) << 0 << 0,
1189 QVector< double >() <<
static_cast< int >( size.height() ) <<
static_cast< int >( size.height() ) << 0 << 0 <<
static_cast< int >( size.height() ) ) ) );
1198 mDefaultPatchCache[ type ][size ] = res;
1205 return QList<QList<QPolygonF> >();
1207 if ( mDefaultPatchQPolygonFCache[ type ].contains( size ) )
1208 return mDefaultPatchQPolygonFCache[ type ].value( size );
1211 mDefaultPatchQPolygonFCache[ type ][size ] = res;
1218 QDomDocument doc( QStringLiteral(
"dummy" ) );
1219 QDomElement elem = doc.createElement( QStringLiteral(
"symbol" ) );
1220 elem.setAttribute( QStringLiteral(
"type" ),
symbol->
type() );
1223 QByteArray xmlArray;
1224 QTextStream stream( &xmlArray );
1225 stream.setCodec(
"UTF-8" );
1226 elem.save( stream, 4 );
1227 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO symbol3d VALUES (NULL, '%q', '%q', %d);",
1228 name.toUtf8().constData(), xmlArray.constData(), ( favorite ? 1 : 0 ) );
1229 if ( !runEmptyQuery( query ) )
1231 QgsDebugMsg( QStringLiteral(
"Couldn't insert 3d symbol into the database!" ) );
1246 if ( m3dSymbols.contains( newName ) )
1248 QgsDebugMsg( QStringLiteral(
"3d symbol of new name already exists." ) );
1252 if ( !m3dSymbols.contains( oldName ) )
1256 m3dSymbols.insert( newName,
symbol );
1262 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM symbol3d WHERE name='%q'", oldName.toUtf8().constData() );
1264 statement = mCurrentDB.
prepare( query, nErr );
1265 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1280 return m3dSymbols.keys();
1287 QgsDebugMsg( QStringLiteral(
"Cannot Open database for getting favorite symbols" ) );
1288 return QStringList();
1296 QgsDebugMsg( QStringLiteral(
"No such style entity" ) );
1297 return QStringList();
1300 query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT name FROM %1 WHERE favorite=1" ).arg( entityTableName( type ) ).toLocal8Bit().data() );
1306 statement = mCurrentDB.
prepare( query, nErr );
1308 QStringList symbols;
1309 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1321 QgsDebugMsg( QStringLiteral(
"Cannot open database to get symbols of tagid %1" ).arg( tagid ) );
1322 return QStringList();
1330 QgsDebugMsg( QStringLiteral(
"Unknown Entity" ) );
1331 return QStringList();
1334 subquery =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT %1 FROM %2 WHERE tag_id=%d" ).arg( tagmapEntityIdFieldName( type ),
1335 tagmapTableName( type ) ).toLocal8Bit().data(), tagid );
1341 statement = mCurrentDB.
prepare( subquery, nErr );
1344 QStringList symbols;
1345 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1347 int id = sqlite3_column_int( statement.get(), 0 );
1349 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT name FROM %1 WHERE id=%d" ).arg( entityTableName( type ) ).toLocal8Bit().data(),
id );
1353 statement2 = mCurrentDB.
prepare( query, rc );
1354 while ( rc == SQLITE_OK && sqlite3_step( statement2.get() ) == SQLITE_ROW )
1369 QString query =
qgs_sqlite3_mprintf(
"INSERT INTO tag VALUES (NULL, '%q')", tagname.toUtf8().constData() );
1371 statement = mCurrentDB.
prepare( query, nErr );
1372 if ( nErr == SQLITE_OK )
1373 ( void )sqlite3_step( statement.get() );
1376 settings.
setValue( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 );
1380 return static_cast< int >( sqlite3_last_insert_rowid( mCurrentDB.get() ) );
1386 return QStringList();
1392 statement = mCurrentDB.
prepare( query, nError );
1394 QStringList tagList;
1395 while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1405 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"UPDATE %1 SET name='%q' WHERE id=%d" ).arg( entityTableName( type ) ).toLocal8Bit().data(), newName.toUtf8().constData(),
id );
1407 const bool result = runEmptyQuery( query );
1410 mErrorString = QStringLiteral(
"Could not rename!" );
1414 mCachedTags.clear();
1415 mCachedFavorites.clear();
1440 bool groupRemoved =
false;
1445 query =
qgs_sqlite3_mprintf(
"DELETE FROM tag WHERE id=%d; DELETE FROM tagmap WHERE tag_id=%d",
id,
id );
1446 groupRemoved =
true;
1450 groupRemoved =
true;
1454 query =
qgs_sqlite3_mprintf( QStringLiteral(
"DELETE FROM %1 WHERE id=%d; DELETE FROM %2 WHERE %3=%d" ).arg(
1455 entityTableName( type ),
1456 tagmapTableName( type ),
1457 tagmapEntityIdFieldName( type )
1458 ).toLocal8Bit().data(),
id,
id );
1462 bool result =
false;
1463 if ( !runEmptyQuery( query ) )
1465 QgsDebugMsg( QStringLiteral(
"Could not delete entity!" ) );
1469 mCachedTags.clear();
1470 mCachedFavorites.clear();
1475 settings.
setValue( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 );
1494 std::unique_ptr< QgsSymbol >
symbol( mSymbols.take( name ) );
1503 std::unique_ptr< QgsAbstract3DSymbol >
symbol( m3dSymbols.take( name ) );
1512 std::unique_ptr< QgsColorRamp > ramp( mColorRamps.take( name ) );
1520 if ( !mTextFormats.contains( name ) )
1523 mTextFormats.remove( name );
1529 if ( !mLabelSettings.contains( name ) )
1532 mLabelSettings.remove( name );
1538 if ( !mLegendPatchShapes.contains( name ) )
1541 mLegendPatchShapes.remove( name );
1548 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database to modify." ) );
1552 const int id =
entityId( type, name );
1555 QgsDebugMsg(
"No matching entity for deleting in database: " + name );
1558 const bool result =
remove( type,
id );
1561 mCachedTags[ type ].remove( name );
1562 mCachedFavorites[ type ].remove( name );
1591 bool QgsStyle::runEmptyQuery(
const QString &query )
1596 char *zErr =
nullptr;
1597 int nErr = sqlite3_exec( mCurrentDB.get(), query.toUtf8().constData(),
nullptr,
nullptr, &zErr );
1599 if ( nErr != SQLITE_OK )
1602 sqlite3_free( zErr );
1605 return nErr == SQLITE_OK;
1616 QgsDebugMsg( QStringLiteral(
"Wrong entity value. cannot apply group" ) );
1620 query =
qgs_sqlite3_mprintf( QStringLiteral(
"UPDATE %1 SET favorite=1 WHERE name='%q'" ).arg( entityTableName( type ) ).toLocal8Bit().data(),
1621 name.toUtf8().constData() );
1625 const bool res = runEmptyQuery( query );
1635 mCachedFavorites[ type ].insert( name,
true );
1652 QgsDebugMsg( QStringLiteral(
"Wrong entity value. cannot apply group" ) );
1656 query =
qgs_sqlite3_mprintf( QStringLiteral(
"UPDATE %1 SET favorite=0 WHERE name='%q'" ).arg( entityTableName( type ) ).toLocal8Bit().data(), name.toUtf8().constData() );
1660 const bool res = runEmptyQuery( query );
1663 mCachedFavorites[ type ].insert( name,
false );
1674 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database to search" ) );
1675 return QStringList();
1684 return QStringList();
1687 item = entityTableName( type );
1692 item.toUtf8().constData(), qword.toUtf8().constData() );
1695 int nErr; statement = mCurrentDB.
prepare( query, nErr );
1697 QSet< QString > symbols;
1698 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1704 query =
qgs_sqlite3_mprintf(
"SELECT id FROM tag WHERE name LIKE '%%%q%%'", qword.toUtf8().constData() );
1705 statement = mCurrentDB.
prepare( query, nErr );
1708 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1713 QString dummy = tagids.join( QLatin1String(
", " ) );
1714 query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT %1 FROM %2 WHERE tag_id IN (%q)" ).arg( tagmapEntityIdFieldName( type ),
1715 tagmapTableName( type ) ).toLocal8Bit().data(), dummy.toUtf8().constData() );
1717 statement = mCurrentDB.
prepare( query, nErr );
1719 QStringList symbolids;
1720 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1725 dummy = symbolids.join( QLatin1String(
", " ) );
1727 item.toUtf8().constData(), dummy.toUtf8().constData() );
1728 statement = mCurrentDB.
prepare( query, nErr );
1729 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1734 return qgis::setToList( symbols );
1741 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database to tag." ) );
1759 QgsDebugMsg( QStringLiteral(
"No such symbol for tagging in database: " ) +
symbol );
1764 const auto constTags =
tags;
1765 for (
const QString &t : constTags )
1768 if ( !
tag.isEmpty() )
1780 QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"INSERT INTO %1 VALUES (%d,%d)" ).arg( tagmapTableName( type ) ).toLocal8Bit().data(), tagid, symbolid );
1782 char *zErr =
nullptr;
1784 nErr = sqlite3_exec( mCurrentDB.get(), query.toUtf8().constData(),
nullptr,
nullptr, &zErr );
1788 sqlite3_free( zErr );
1794 clearCachedTags( type,
symbol );
1804 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database for detagging." ) );
1819 if ( symbolid == 0 )
1824 const auto constTags =
tags;
1825 for (
const QString &
tag : constTags )
1830 statement2 = mCurrentDB.
prepare( query, nErr );
1833 if ( nErr == SQLITE_OK && sqlite3_step( statement2.get() ) == SQLITE_ROW )
1835 tagid = sqlite3_column_int( statement2.get(), 0 );
1841 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 );
1842 runEmptyQuery( query );
1846 clearCachedTags( type,
symbol );
1859 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database for detagging." ) );
1874 if ( symbolid == 0 )
1880 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"DELETE FROM %1 WHERE %2=%d" ).arg( tagmapTableName( type ),
1881 tagmapEntityIdFieldName( type ) ).toLocal8Bit().data(), symbolid );
1882 runEmptyQuery( query );
1884 clearCachedTags( type,
symbol );
1899 return QStringList();
1902 if ( mCachedTags[ type ].contains(
symbol ) )
1903 return mCachedTags[ type ].value(
symbol );
1909 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database for getting the tags." ) );
1910 return QStringList();
1915 return QStringList();
1918 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT tag_id FROM %1 WHERE %2=%d" ).arg( tagmapTableName( type ),
1919 tagmapEntityIdFieldName( type ) ).toLocal8Bit().data(), symbolid );
1922 int nErr; statement = mCurrentDB.
prepare( query, nErr );
1924 QStringList tagList;
1925 while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1927 QString subquery =
qgs_sqlite3_mprintf(
"SELECT name FROM tag WHERE id=%d", sqlite3_column_int( statement.get(), 0 ) );
1931 statement2 = mCurrentDB.
prepare( subquery, pErr );
1932 if ( pErr == SQLITE_OK && sqlite3_step( statement2.get() ) == SQLITE_ROW )
1939 mCachedTags[ type ].insert(
symbol, tagList );
1948 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database for getting the tags." ) );
1959 if ( mCachedFavorites[ type ].contains( name ) )
1960 return mCachedFavorites[ type ].value( name );
1964 const QStringList names =
allNames( type );
1965 if ( !names.contains( name ) )
1971 for (
const QString &n : names )
1973 const bool isFav = favorites.contains( n );
1977 mCachedFavorites[ type ].insert( n, isFav );
1986 QgsDebugMsg( QStringLiteral(
"Sorry! Cannot open database for getting the tags." ) );
2013 const QString query =
qgs_sqlite3_mprintf( QStringLiteral(
"SELECT tag_id FROM %1 WHERE tag_id=%d AND %2=%d" ).arg( tagmapTableName( type ),
2014 tagmapEntityIdFieldName( type ) ).toLocal8Bit().data(), tagid, symbolid );
2017 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2019 return ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW );
2031 statement = mCurrentDB.
prepare( query, nError );
2034 if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2042 int QgsStyle::getId(
const QString &table,
const QString &name )
2044 QString lowerName( name.toLower() );
2045 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM %q WHERE LOWER(name)='%q'", table.toUtf8().constData(), lowerName.toUtf8().constData() );
2048 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2051 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2053 id = sqlite3_column_int( statement.get(), 0 );
2058 QString query =
qgs_sqlite3_mprintf(
"SELECT id FROM %q WHERE name='%q'", table.toUtf8().constData(), name.toUtf8().constData() );
2061 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2062 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2064 id = sqlite3_column_int( statement.get(), 0 );
2071 QString QgsStyle::getName(
const QString &table,
int id )
const
2073 QString query =
qgs_sqlite3_mprintf(
"SELECT name FROM %q WHERE id='%q'", table.toUtf8().constData(), QString::number(
id ).toUtf8().constData() );
2076 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2079 if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2089 return getId( QStringLiteral(
"symbol" ), name );
2094 return getId( entityTableName( type ), name );
2099 return getId( QStringLiteral(
"colorramp" ), name );
2104 return mTextFormats.value( name );
2109 return mTextFormats.count();
2114 return mTextFormats.keys();
2119 return getId( QStringLiteral(
"textformat" ), name );
2124 return mLabelSettings.value( name );
2129 return mLegendPatchShapes.value( name );
2134 return mLegendPatchShapes.count();
2139 if ( !mLegendPatchShapes.contains( name ) )
2142 return mLegendPatchShapes.value( name ).symbolType();
2147 return m3dSymbols.contains( name ) ? m3dSymbols.value( name )->clone() :
nullptr;
2152 return m3dSymbols.count();
2157 if ( !m3dSymbols.contains( name ) )
2158 return QList<QgsWkbTypes::GeometryType>();
2160 return m3dSymbols.value( name )->compatibleGeometryTypes();
2165 if ( !mLabelSettings.contains( name ) )
2168 return mLabelSettings.value( name ).layerType;
2173 return mLabelSettings.count();
2178 return mLabelSettings.keys();
2183 return getId( QStringLiteral(
"labelsettings" ), name );
2188 return mLegendPatchShapes.keys();
2196 return mPatchMarkerSymbol.get();
2199 return mPatchLineSymbol.get();
2202 return mPatchFillSymbol.get();
2212 return getId( QStringLiteral(
"tag" ), name );
2217 return getId( QStringLiteral(
"smartgroup" ), name );
2248 return QStringList();
2253 return addSmartgroup( name, op, conditions.values( QStringLiteral(
"tag" ) ),
2254 conditions.values( QStringLiteral(
"!tag" ) ),
2255 conditions.values( QStringLiteral(
"name" ) ),
2256 conditions.values( QStringLiteral(
"!name" ) ) );
2259 int QgsStyle::addSmartgroup(
const QString &name,
const QString &op,
const QStringList &matchTag,
const QStringList &noMatchTag,
const QStringList &matchName,
const QStringList &noMatchName )
2261 QDomDocument doc( QStringLiteral(
"dummy" ) );
2262 QDomElement smartEl = doc.createElement( QStringLiteral(
"smartgroup" ) );
2263 smartEl.setAttribute( QStringLiteral(
"name" ), name );
2264 smartEl.setAttribute( QStringLiteral(
"operator" ), op );
2266 auto addCondition = [&doc, &smartEl](
const QString & constraint,
const QStringList & parameters )
2268 for (
const QString ¶m : parameters )
2270 QDomElement condEl = doc.createElement( QStringLiteral(
"condition" ) );
2271 condEl.setAttribute( QStringLiteral(
"constraint" ), constraint );
2272 condEl.setAttribute( QStringLiteral(
"param" ), param );
2273 smartEl.appendChild( condEl );
2276 addCondition( QStringLiteral(
"tag" ), matchTag );
2277 addCondition( QStringLiteral(
"!tag" ), noMatchTag );
2278 addCondition( QStringLiteral(
"name" ), matchName );
2279 addCondition( QStringLiteral(
"!name" ), noMatchName );
2281 QByteArray xmlArray;
2282 QTextStream stream( &xmlArray );
2283 stream.setCodec(
"UTF-8" );
2284 smartEl.save( stream, 4 );
2286 name.toUtf8().constData(), xmlArray.constData() );
2288 if ( runEmptyQuery( query ) )
2291 settings.
setValue( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 );
2294 return static_cast< int >( sqlite3_last_insert_rowid( mCurrentDB.get() ) );
2298 QgsDebugMsg( QStringLiteral(
"Couldn't insert symbol into the database!" ) );
2307 QgsDebugMsg( QStringLiteral(
"Cannot open database for listing groups" ) );
2316 statement = mCurrentDB.
prepare( query, nError );
2319 while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2322 groupNames.insert( sqlite3_column_int( statement.get(),
SmartgroupId ), group );
2332 QgsDebugMsg( QStringLiteral(
"Cannot open database for listing groups" ) );
2333 return QStringList();
2341 statement = mCurrentDB.
prepare( query, nError );
2344 while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2354 QStringList symbols;
2359 int nErr; statement = mCurrentDB.
prepare( query, nErr );
2360 if ( !( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW ) )
2362 return QStringList();
2368 if ( !doc.setContent( xmlstr ) )
2370 QgsDebugMsg( QStringLiteral(
"Cannot open smartgroup id: %1" ).arg(
id ) );
2372 QDomElement smartEl = doc.documentElement();
2373 QString op = smartEl.attribute( QStringLiteral(
"operator" ) );
2374 QDomNodeList conditionNodes = smartEl.childNodes();
2376 bool firstSet =
true;
2377 for (
int i = 0; i < conditionNodes.count(); i++ )
2379 QDomElement condEl = conditionNodes.at( i ).toElement();
2380 QString constraint = condEl.attribute( QStringLiteral(
"constraint" ) );
2381 QString param = condEl.attribute( QStringLiteral(
"param" ) );
2383 QStringList resultNames;
2385 if ( constraint == QLatin1String(
"tag" ) )
2389 else if ( constraint == QLatin1String(
"name" ) )
2391 resultNames =
allNames( type ).filter( param, Qt::CaseInsensitive );
2393 else if ( constraint == QLatin1String(
"!tag" ) )
2397 for (
const QString &name : unwanted )
2399 resultNames.removeAll( name );
2402 else if ( constraint == QLatin1String(
"!name" ) )
2404 const QStringList all =
allNames( type );
2405 for (
const QString &str : all )
2407 if ( !str.contains( param, Qt::CaseInsensitive ) )
2415 symbols = resultNames;
2420 if ( op == QLatin1String(
"OR" ) )
2422 symbols << resultNames;
2424 else if ( op == QLatin1String(
"AND" ) )
2426 QStringList dummy = symbols;
2428 for (
const QString &result : qgis::as_const( resultNames ) )
2430 if ( dummy.contains( result ) )
2439 QStringList unique = qgis::setToList( qgis::listToSet( symbols ) );
2440 std::sort( unique.begin(), unique.end() );
2448 QgsDebugMsg( QStringLiteral(
"Cannot open database for listing groups" ) );
2458 statement = mCurrentDB.
prepare( query, nError );
2459 if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2463 if ( !doc.setContent( xmlstr ) )
2465 QgsDebugMsg( QStringLiteral(
"Cannot open smartgroup id: %1" ).arg(
id ) );
2468 QDomElement smartEl = doc.documentElement();
2469 QDomNodeList conditionNodes = smartEl.childNodes();
2471 for (
int i = 0; i < conditionNodes.count(); i++ )
2473 QDomElement condEl = conditionNodes.at( i ).toElement();
2474 QString constraint = condEl.attribute( QStringLiteral(
"constraint" ) );
2475 QString param = condEl.attribute( QStringLiteral(
"param" ) );
2477 condition.insert( constraint, param );
2488 QgsDebugMsg( QStringLiteral(
"Cannot open database for listing groups" ) );
2498 statement = mCurrentDB.
prepare( query, nError );
2499 if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
2503 if ( !doc.setContent( xmlstr ) )
2505 QgsDebugMsg( QStringLiteral(
"Cannot open smartgroup id: %1" ).arg(
id ) );
2507 QDomElement smartEl = doc.documentElement();
2508 op = smartEl.attribute( QStringLiteral(
"operator" ) );
2516 if ( filename.isEmpty() )
2518 QgsDebugMsg( QStringLiteral(
"Invalid filename for style export." ) );
2522 QDomDocument doc( QStringLiteral(
"qgis_style" ) );
2523 QDomElement root = doc.createElement( QStringLiteral(
"qgis_style" ) );
2525 doc.appendChild( root );
2535 QDomNodeList symbolsList = symbolsElem.elementsByTagName( QStringLiteral(
"symbol" ) );
2536 int nbSymbols = symbolsList.count();
2537 for (
int i = 0; i < nbSymbols; ++i )
2539 QDomElement
symbol = symbolsList.at( i ).toElement();
2540 QString name =
symbol.attribute( QStringLiteral(
"name" ) );
2542 if (
tags.count() > 0 )
2544 symbol.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2546 if ( favoriteSymbols.contains( name ) )
2548 symbol.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2553 QDomElement rampsElem = doc.createElement( QStringLiteral(
"colorramps" ) );
2554 for ( QMap<QString, QgsColorRamp *>::const_iterator itr = mColorRamps.constBegin(); itr != mColorRamps.constEnd(); ++itr )
2558 if (
tags.count() > 0 )
2560 rampEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2562 if ( favoriteColorramps.contains( itr.key() ) )
2564 rampEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2566 rampsElem.appendChild( rampEl );
2570 QDomElement textFormatsElem = doc.createElement( QStringLiteral(
"textformats" ) );
2571 for (
auto it = mTextFormats.constBegin(); it != mTextFormats.constEnd(); ++it )
2573 QDomElement textFormatEl = doc.createElement( QStringLiteral(
"textformat" ) );
2574 textFormatEl.setAttribute( QStringLiteral(
"name" ), it.key() );
2576 textFormatEl.appendChild( textStyleEl );
2578 if (
tags.count() > 0 )
2580 textFormatEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2582 if ( favoriteTextFormats.contains( it.key() ) )
2584 textFormatEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2586 textFormatsElem.appendChild( textFormatEl );
2590 QDomElement labelSettingsElem = doc.createElement( QStringLiteral(
"labelsettings" ) );
2591 for (
auto it = mLabelSettings.constBegin(); it != mLabelSettings.constEnd(); ++it )
2593 QDomElement labelSettingsEl = doc.createElement( QStringLiteral(
"labelsetting" ) );
2594 labelSettingsEl.setAttribute( QStringLiteral(
"name" ), it.key() );
2596 labelSettingsEl.appendChild( defEl );
2598 if (
tags.count() > 0 )
2600 labelSettingsEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2602 if ( favoriteTextFormats.contains( it.key() ) )
2604 labelSettingsEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2606 labelSettingsElem.appendChild( labelSettingsEl );
2610 QDomElement legendPatchShapesElem = doc.createElement( QStringLiteral(
"legendpatchshapes" ) );
2611 for (
auto it = mLegendPatchShapes.constBegin(); it != mLegendPatchShapes.constEnd(); ++it )
2613 QDomElement legendPatchShapeEl = doc.createElement( QStringLiteral(
"legendpatchshape" ) );
2614 legendPatchShapeEl.setAttribute( QStringLiteral(
"name" ), it.key() );
2615 QDomElement defEl = doc.createElement( QStringLiteral(
"definition" ) );
2617 legendPatchShapeEl.appendChild( defEl );
2619 if (
tags.count() > 0 )
2621 legendPatchShapeEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2623 if ( favoriteLegendShapes.contains( it.key() ) )
2625 legendPatchShapeEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2627 legendPatchShapesElem.appendChild( legendPatchShapeEl );
2631 QDomElement symbols3DElem = doc.createElement( QStringLiteral(
"symbols3d" ) );
2632 for (
auto it = m3dSymbols.constBegin(); it != m3dSymbols.constEnd(); ++it )
2634 QDomElement symbolEl = doc.createElement( QStringLiteral(
"symbol3d" ) );
2635 symbolEl.setAttribute( QStringLiteral(
"name" ), it.key() );
2636 QDomElement defEl = doc.createElement( QStringLiteral(
"definition" ) );
2637 defEl.setAttribute( QStringLiteral(
"type" ), it.value()->type() );
2639 symbolEl.appendChild( defEl );
2641 if (
tags.count() > 0 )
2643 symbolEl.setAttribute( QStringLiteral(
"tags" ),
tags.join(
',' ) );
2645 if ( favorite3DSymbols.contains( it.key() ) )
2647 symbolEl.setAttribute( QStringLiteral(
"favorite" ), QStringLiteral(
"1" ) );
2649 symbols3DElem.appendChild( symbolEl );
2652 root.appendChild( symbolsElem );
2653 root.appendChild( rampsElem );
2654 root.appendChild( textFormatsElem );
2655 root.appendChild( labelSettingsElem );
2656 root.appendChild( legendPatchShapesElem );
2657 root.appendChild( symbols3DElem );
2660 QFile f( filename );
2661 if ( !f.open( QFile::WriteOnly | QIODevice::Truncate ) )
2663 mErrorString =
"Couldn't open file for writing: " + filename;
2667 QTextStream ts( &f );
2668 ts.setCodec(
"UTF-8" );
2672 mFileName = filename;
2683 mErrorString = QString();
2684 QDomDocument doc( QStringLiteral(
"style" ) );
2685 QFile f( filename );
2686 if ( !f.open( QFile::ReadOnly ) )
2688 mErrorString = QStringLiteral(
"Unable to open the specified file" );
2689 QgsDebugMsg( QStringLiteral(
"Error opening the style XML file." ) );
2693 if ( !doc.setContent( &f ) )
2695 mErrorString = QStringLiteral(
"Unable to understand the style file: %1" ).arg( filename );
2696 QgsDebugMsg( QStringLiteral(
"XML Parsing error" ) );
2702 QDomElement docEl = doc.documentElement();
2703 if ( docEl.tagName() != QLatin1String(
"qgis_style" ) )
2705 mErrorString =
"Incorrect root tag in style: " + docEl.tagName();
2709 const QString version = docEl.attribute( QStringLiteral(
"version" ) );
2710 if ( version != QLatin1String(
STYLE_CURRENT_VERSION ) && version != QLatin1String(
"0" ) && version != QLatin1String(
"1" ) )
2712 mErrorString =
"Unknown style file version: " + version;
2718 QDomElement symbolsElement = docEl.firstChildElement( QStringLiteral(
"symbols" ) );
2719 QDomElement e = symbolsElement.firstChildElement();
2723 runEmptyQuery( query );
2728 while ( !e.isNull() )
2730 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2731 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2737 if ( e.tagName() == QLatin1String(
"symbol" ) )
2739 QString name = e.attribute( QStringLiteral(
"name" ) );
2741 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2743 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2745 bool favorite =
false;
2746 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2765 e = e.nextSiblingElement();
2774 for ( QMap<QString, QgsSymbol *>::iterator it = symbols.begin(); it != symbols.end(); ++it )
2781 QDomElement rampsElement = docEl.firstChildElement( QStringLiteral(
"colorramps" ) );
2782 e = rampsElement.firstChildElement();
2783 while ( !e.isNull() )
2785 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2786 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2792 if ( e.tagName() == QLatin1String(
"colorramp" ) )
2794 QString name = e.attribute( QStringLiteral(
"name" ) );
2796 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2798 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2800 bool favorite =
false;
2801 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2820 e = e.nextSiblingElement();
2826 const QDomElement textFormatElement = docEl.firstChildElement( QStringLiteral(
"textformats" ) );
2827 e = textFormatElement.firstChildElement();
2828 while ( !e.isNull() )
2830 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2831 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2837 if ( e.tagName() == QLatin1String(
"textformat" ) )
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" ) )
2852 const QDomElement styleElem = e.firstChildElement();
2864 e = e.nextSiblingElement();
2871 const QDomElement labelSettingsElement = docEl.firstChildElement( QStringLiteral(
"labelsettings" ) );
2872 e = labelSettingsElement.firstChildElement();
2873 while ( !e.isNull() )
2875 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2876 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2882 if ( e.tagName() == QLatin1String(
"labelsetting" ) )
2884 QString name = e.attribute( QStringLiteral(
"name" ) );
2886 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2888 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2890 bool favorite =
false;
2891 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2897 const QDomElement styleElem = e.firstChildElement();
2909 e = e.nextSiblingElement();
2916 const QDomElement legendPatchShapesElement = docEl.firstChildElement( QStringLiteral(
"legendpatchshapes" ) );
2917 e = legendPatchShapesElement.firstChildElement();
2918 while ( !e.isNull() )
2920 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2921 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2927 if ( e.tagName() == QLatin1String(
"legendpatchshape" ) )
2929 QString name = e.attribute( QStringLiteral(
"name" ) );
2931 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2933 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2935 bool favorite =
false;
2936 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2942 const QDomElement shapeElem = e.firstChildElement();
2954 e = e.nextSiblingElement();
2961 const QDomElement symbols3DElement = docEl.firstChildElement( QStringLiteral(
"symbols3d" ) );
2962 e = symbols3DElement.firstChildElement();
2963 while ( !e.isNull() )
2965 const int entityAddedVersion = e.attribute( QStringLiteral(
"addedVersion" ) ).toInt();
2966 if ( entityAddedVersion != 0 && sinceVersion != -1 && entityAddedVersion <= sinceVersion )
2972 if ( e.tagName() == QLatin1String(
"symbol3d" ) )
2974 QString name = e.attribute( QStringLiteral(
"name" ) );
2976 if ( e.hasAttribute( QStringLiteral(
"tags" ) ) )
2978 tags = e.attribute( QStringLiteral(
"tags" ) ).split(
',' );
2980 bool favorite =
false;
2981 if ( e.hasAttribute( QStringLiteral(
"favorite" ) ) && e.attribute( QStringLiteral(
"favorite" ) ) == QLatin1String(
"1" ) )
2986 const QDomElement symbolElem = e.firstChildElement();
2987 const QString type = symbolElem.attribute( QStringLiteral(
"type" ) );
3004 e = e.nextSiblingElement();
3009 runEmptyQuery( query );
3011 mFileName = filename;
3017 QFileInfo fileInfo( path );
3019 if ( fileInfo.suffix().compare( QLatin1String(
"xml" ), Qt::CaseInsensitive ) != 0 )
3023 if ( !QFile::exists( path ) )
3026 QFile inputFile( path );
3027 if ( !inputFile.open( QIODevice::ReadOnly ) )
3030 QTextStream stream( &inputFile );
3031 const QString line = stream.readLine();
3032 return line == QLatin1String(
"<!DOCTYPE qgis_style>" );
3035 bool QgsStyle::updateSymbol( StyleEntity type,
const QString &name )
3037 QDomDocument doc( QStringLiteral(
"dummy" ) );
3039 QByteArray xmlArray;
3040 QTextStream stream( &xmlArray );
3041 stream.setCodec(
"UTF-8" );
3052 QgsDebugMsg( QStringLiteral(
"Update request received for unavailable symbol" ) );
3057 if ( symEl.isNull() )
3059 QgsDebugMsg( QStringLiteral(
"Couldn't convert symbol to valid XML!" ) );
3062 symEl.save( stream, 4 );
3064 xmlArray.constData(), name.toUtf8().constData() );
3073 QgsDebugMsg( QStringLiteral(
"Update request received for unavailable symbol" ) );
3077 symEl = doc.createElement( QStringLiteral(
"symbol" ) );
3078 symEl.setAttribute( QStringLiteral(
"type" ), m3dSymbols.value( name )->type() );
3080 if ( symEl.isNull() )
3082 QgsDebugMsg( QStringLiteral(
"Couldn't convert symbol to valid XML!" ) );
3085 symEl.save( stream, 4 );
3087 xmlArray.constData(), name.toUtf8().constData() );
3095 QgsDebugMsg( QStringLiteral(
"Update requested for unavailable color ramp." ) );
3099 std::unique_ptr< QgsColorRamp > ramp(
colorRamp( name ) );
3101 if ( symEl.isNull() )
3103 QgsDebugMsg( QStringLiteral(
"Couldn't convert color ramp to valid XML!" ) );
3106 symEl.save( stream, 4 );
3108 xmlArray.constData(), name.toUtf8().constData() );
3116 QgsDebugMsg( QStringLiteral(
"Update requested for unavailable text format." ) );
3122 if ( symEl.isNull() )
3124 QgsDebugMsg( QStringLiteral(
"Couldn't convert text format to valid XML!" ) );
3127 symEl.save( stream, 4 );
3129 xmlArray.constData(), name.toUtf8().constData() );
3137 QgsDebugMsg( QStringLiteral(
"Update requested for unavailable label settings." ) );
3143 if ( symEl.isNull() )
3145 QgsDebugMsg( QStringLiteral(
"Couldn't convert label settings to valid XML!" ) );
3148 symEl.save( stream, 4 );
3150 xmlArray.constData(), name.toUtf8().constData() );
3158 QgsDebugMsg( QStringLiteral(
"Update requested for unavailable legend patch shape." ) );
3163 symEl = doc.createElement( QStringLiteral(
"shape" ) );
3165 symEl.save( stream, 4 );
3167 xmlArray.constData(), name.toUtf8().constData() );
3174 QgsDebugMsg( QStringLiteral(
"Updating the unsupported StyleEntity" ) );
3180 if ( !runEmptyQuery( query ) )
3182 QgsDebugMsg( QStringLiteral(
"Couldn't insert symbol into the database!" ) );
3218 mCachedTags[ type ].remove( name );
3221 void QgsStyle::upgradeIfRequired()
3224 QString query =
qgs_sqlite3_mprintf(
"SELECT name FROM sqlite_master WHERE name='stylemetadata'" );
3228 statement = mCurrentDB.
prepare( query, rc );
3230 if ( rc != SQLITE_OK || sqlite3_step( statement.get() ) != SQLITE_ROW )
3234 "id INTEGER PRIMARY KEY,"\
3237 runEmptyQuery( query );
3238 query =
qgs_sqlite3_mprintf(
"INSERT INTO stylemetadata VALUES (NULL, '%q', '%q')",
"version",
"31200" );
3239 runEmptyQuery( query );
3246 statement = mCurrentDB.
prepare( query, rc );
3247 if ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
3259 runEmptyQuery( query );
3269 return QStringLiteral(
"symbol" );
3272 return QStringLiteral(
"colorramp" );
3275 return QStringLiteral(
"textformat" );
3278 return QStringLiteral(
"labelsettings" );
3281 return QStringLiteral(
"legendpatchshapes" );
3284 return QStringLiteral(
"symbol3d" );
3287 return QStringLiteral(
"tag" );
3290 return QStringLiteral(
"smartgroup" );
3300 return QStringLiteral(
"tagmap" );
3303 return QStringLiteral(
"ctagmap" );
3306 return QStringLiteral(
"tftagmap" );
3309 return QStringLiteral(
"lstagmap" );
3312 return QStringLiteral(
"lpstagmap" );
3315 return QStringLiteral(
"symbol3dtagmap" );
3329 return QStringLiteral(
"symbol_id" );
3332 return QStringLiteral(
"colorramp_id" );
3335 return QStringLiteral(
"textformat_id" );
3338 return QStringLiteral(
"labelsettings_id" );
3341 return QStringLiteral(
"legendpatchshape_id" );
3344 return QStringLiteral(
"symbol3d_id" );
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(QgsSymbol::SymbolType type, QSizeF size) const
Converts the patch shape to a set of QPolygonF objects representing how the patch should be drawn for...
QgsSymbol::SymbolType symbolType() const
Returns the symbol type associated with this patch.
void writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
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.
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.
QgsSymbol::SymbolType legendPatchShapeSymbolType(const QString &name) const
Returns the symbol type corresponding to the legend patch shape with the specified name,...
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.
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.
QList< QList< QPolygonF > > defaultPatchAsQPolygonF(QgsSymbol::SymbolType type, QSizeF size) const
Returns the default patch geometry for the given symbol type and size as a set of QPolygonF objects (...
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.
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.
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...
QgsLegendPatchShape defaultPatch(QgsSymbol::SymbolType type, QSizeF size) const
Returns the default legend patch shape for the given symbol type.
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.
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.
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.
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.
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.
@ ScaleArea
Calculate scale by the area.
SymbolType type() const
Returns the symbol's type.
SymbolType
Type of the symbol.
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.
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