@@ -81,6 +81,8 @@ void QgsStyle::clear()
81
81
82
82
mSymbols .clear ();
83
83
mColorRamps .clear ();
84
+ mCachedColorRampTags .clear ();
85
+ mCachedSymbolTags .clear ();
84
86
}
85
87
86
88
bool QgsStyle::addSymbol ( const QString &name, QgsSymbol *symbol, bool update )
@@ -164,6 +166,7 @@ bool QgsStyle::removeSymbol( const QString &name )
164
166
const bool result = remove ( SymbolEntity, symbolid );
165
167
if ( result )
166
168
{
169
+ mCachedSymbolTags .remove ( name );
167
170
emit symbolRemoved ( name );
168
171
}
169
172
return result;
@@ -259,6 +262,8 @@ bool QgsStyle::removeColorRamp( const QString &name )
259
262
return false ;
260
263
}
261
264
265
+ mCachedColorRampTags .remove ( name );
266
+
262
267
emit rampRemoved ( name );
263
268
264
269
return true ;
@@ -494,6 +499,8 @@ bool QgsStyle::renameSymbol( const QString &oldName, const QString &newName )
494
499
return false ;
495
500
}
496
501
502
+ mCachedSymbolTags .remove ( oldName );
503
+
497
504
const bool result = rename ( SymbolEntity, symbolid, newName );
498
505
if ( result )
499
506
emit symbolRenamed ( oldName, newName );
@@ -514,6 +521,7 @@ bool QgsStyle::renameColorRamp( const QString &oldName, const QString &newName )
514
521
return false ;
515
522
516
523
mColorRamps .insert ( newName, ramp );
524
+ mCachedColorRampTags .remove ( oldName );
517
525
518
526
int rampid = 0 ;
519
527
sqlite3_statement_unique_ptr statement;
@@ -681,9 +689,17 @@ bool QgsStyle::rename( StyleEntity type, int id, const QString &newName )
681
689
}
682
690
else
683
691
{
692
+ mCachedColorRampTags .clear ();
693
+ mCachedSymbolTags .clear ();
694
+
684
695
switch ( type )
685
696
{
686
697
case TagEntity:
698
+ {
699
+ emit groupsModified ();
700
+ break ;
701
+ }
702
+
687
703
case SmartgroupEntity:
688
704
{
689
705
emit groupsModified ();
@@ -727,6 +743,9 @@ bool QgsStyle::remove( StyleEntity type, int id )
727
743
}
728
744
else
729
745
{
746
+ mCachedColorRampTags .clear ();
747
+ mCachedSymbolTags .clear ();
748
+
730
749
if ( groupRemoved )
731
750
{
732
751
QgsSettings settings;
@@ -917,6 +936,7 @@ bool QgsStyle::tagSymbol( StyleEntity type, const QString &symbol, const QString
917
936
}
918
937
}
919
938
939
+ clearCachedTags ( type, symbol );
920
940
emit entityTagsChanged ( type, symbol, tagsOfSymbol ( type, symbol ) );
921
941
922
942
return true ;
@@ -969,6 +989,7 @@ bool QgsStyle::detagSymbol( StyleEntity type, const QString &symbol, const QStri
969
989
}
970
990
}
971
991
992
+ clearCachedTags ( type, symbol );
972
993
emit entityTagsChanged ( type, symbol, tagsOfSymbol ( type, symbol ) );
973
994
974
995
// TODO Perform tag cleanup
@@ -1008,6 +1029,7 @@ bool QgsStyle::detagSymbol( StyleEntity type, const QString &symbol )
1008
1029
: QgsSqlite3Mprintf ( " DELETE FROM ctagmap WHERE colorramp_id=%d" , symbolid );
1009
1030
runEmptyQuery ( query );
1010
1031
1032
+ clearCachedTags ( type, symbol );
1011
1033
emit entityTagsChanged ( type, symbol, QStringList () );
1012
1034
1013
1035
// TODO Perform tag cleanup
@@ -1018,6 +1040,23 @@ bool QgsStyle::detagSymbol( StyleEntity type, const QString &symbol )
1018
1040
1019
1041
QStringList QgsStyle::tagsOfSymbol ( StyleEntity type, const QString &symbol )
1020
1042
{
1043
+ switch ( type )
1044
+ {
1045
+ case SymbolEntity:
1046
+ if ( mCachedSymbolTags .contains ( symbol ) )
1047
+ return mCachedSymbolTags .value ( symbol );
1048
+ break ;
1049
+
1050
+ case ColorrampEntity:
1051
+ if ( mCachedColorRampTags .contains ( symbol ) )
1052
+ return mCachedColorRampTags .value ( symbol );
1053
+ break ;
1054
+
1055
+ case TagEntity:
1056
+ case SmartgroupEntity:
1057
+ break ;
1058
+ }
1059
+
1021
1060
if ( !mCurrentDB )
1022
1061
{
1023
1062
QgsDebugMsg ( QStringLiteral ( " Sorry! Cannot open database for getting the tags." ) );
@@ -1050,6 +1089,22 @@ QStringList QgsStyle::tagsOfSymbol( StyleEntity type, const QString &symbol )
1050
1089
}
1051
1090
}
1052
1091
1092
+ // update cache
1093
+ switch ( type )
1094
+ {
1095
+ case SymbolEntity:
1096
+ mCachedSymbolTags [ symbol ] = tagList;
1097
+ break ;
1098
+
1099
+ case ColorrampEntity:
1100
+ mCachedColorRampTags [ symbol ] = tagList;
1101
+ break ;
1102
+
1103
+ case TagEntity:
1104
+ case SmartgroupEntity:
1105
+ break ;
1106
+ }
1107
+
1053
1108
return tagList;
1054
1109
}
1055
1110
@@ -1707,3 +1762,21 @@ bool QgsStyle::updateSymbol( StyleEntity type, const QString &name )
1707
1762
}
1708
1763
return true ;
1709
1764
}
1765
+
1766
+ void QgsStyle::clearCachedTags ( QgsStyle::StyleEntity type, const QString &name )
1767
+ {
1768
+ switch ( type )
1769
+ {
1770
+ case SymbolEntity:
1771
+ mCachedSymbolTags .remove ( name );
1772
+ break ;
1773
+
1774
+ case ColorrampEntity:
1775
+ mCachedColorRampTags .remove ( name );
1776
+ break ;
1777
+
1778
+ case TagEntity:
1779
+ case SmartgroupEntity:
1780
+ break ;
1781
+ }
1782
+ }
0 commit comments