@@ -22,6 +22,7 @@ class TestQgsMapLayerStyleManager : public QObject
22
22
void testDefault ();
23
23
void testStyle ();
24
24
void testReadWrite ();
25
+ void testSwitchingStyles ();
25
26
26
27
private:
27
28
QgsVectorLayer* mVL ;
@@ -134,17 +135,17 @@ void TestQgsMapLayerStyleManager::testReadWrite()
134
135
sm0.writeXml ( mgrElem );
135
136
136
137
QString xml;
137
- QTextStream ts (&xml);
138
- doc.save (ts, 2 );
139
- qDebug (" %s" , xml.toAscii ().data ());
138
+ QTextStream ts ( &xml );
139
+ doc.save ( ts, 2 );
140
+ qDebug ( " %s" , xml.toAscii ().data () );
140
141
141
142
QgsMapLayerStyleManager sm1 ( mVL );
142
143
sm1.readXml ( mgrElem );
143
144
144
145
QCOMPARE ( sm1.styles ().count (), 2 );
145
- QCOMPARE ( sm1.style (QString ()).isValid (), true );
146
- QCOMPARE ( sm1.style (" blue" ).isValid (), true );
147
- QCOMPARE ( sm1.currentStyle (), QString (" blue" ) );
146
+ QCOMPARE ( sm1.style ( QString () ).isValid (), true );
147
+ QCOMPARE ( sm1.style ( " blue" ).isValid (), true );
148
+ QCOMPARE ( sm1.currentStyle (), QString ( " blue" ) );
148
149
149
150
// now use the default style - the symbol should get red color
150
151
sm1.setCurrentStyle ( QString () );
@@ -153,5 +154,44 @@ void TestQgsMapLayerStyleManager::testReadWrite()
153
154
QCOMPARE ( r2->symbol ()->color (), QColor ( Qt::red ) );
154
155
}
155
156
157
+ static void _setVLColor ( QgsVectorLayer* vl, const QColor& c )
158
+ {
159
+ dynamic_cast <QgsSingleSymbolRendererV2*>( vl->rendererV2 () )->symbol ()->setColor ( c );
160
+ }
161
+
162
+ static QColor _getVLColor ( QgsVectorLayer* vl )
163
+ {
164
+ return dynamic_cast <QgsSingleSymbolRendererV2*>( vl->rendererV2 () )->symbol ()->color ();
165
+ }
166
+
167
+ void TestQgsMapLayerStyleManager::testSwitchingStyles ()
168
+ {
169
+ _setVLColor ( mVL , Qt::red );
170
+
171
+ mVL ->enableStyleManager ();
172
+ mVL ->styleManager ()->addStyleFromLayer ( " s1" );
173
+ mVL ->styleManager ()->setCurrentStyle ( " s1" );
174
+
175
+ QCOMPARE ( mVL ->styleManager ()->currentStyle (), QString ( " s1" ) );
176
+ QCOMPARE ( _getVLColor ( mVL ), QColor ( Qt::red ) );
177
+
178
+ _setVLColor ( mVL , Qt::green );
179
+
180
+ mVL ->styleManager ()->setCurrentStyle ( QString () );
181
+ QCOMPARE ( _getVLColor ( mVL ), QColor ( Qt::red ) );
182
+
183
+ mVL ->styleManager ()->setCurrentStyle ( " s1" );
184
+ QCOMPARE ( _getVLColor ( mVL ), QColor ( Qt::green ) );
185
+
186
+ _setVLColor ( mVL , Qt::blue );
187
+
188
+ mVL ->styleManager ()->setCurrentStyle ( QString () );
189
+ QCOMPARE ( _getVLColor ( mVL ), QColor ( Qt::red ) );
190
+
191
+ mVL ->styleManager ()->setCurrentStyle ( " s1" );
192
+ QCOMPARE ( _getVLColor ( mVL ), QColor ( Qt::blue ) );
193
+ }
194
+
195
+
156
196
QTEST_MAIN ( TestQgsMapLayerStyleManager )
157
197
#include " testqgsmaplayerstylemanager.moc"
0 commit comments