@@ -64,11 +64,12 @@ QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* laye
64
64
// new ModelTest( mModel, this ); // for model validity checking
65
65
viewRules->setModel ( mModel );
66
66
67
- mRefineMenu = new QMenu ( btnRefineRule );
68
- mRefineMenu ->addAction ( tr ( " Add scales" ), this , SLOT ( refineRuleScales () ) );
69
- mRefineMenu ->addAction ( tr ( " Add categories" ), this , SLOT ( refineRuleCategories () ) );
70
- mRefineMenu ->addAction ( tr ( " Add ranges" ), this , SLOT ( refineRuleRanges () ) );
67
+ mRefineMenu = new QMenu ( " Refine current rule " , btnRefineRule );
68
+ mRefineMenu ->addAction ( tr ( " Add scales to rule " ), this , SLOT ( refineRuleScales () ) );
69
+ mRefineMenu ->addAction ( tr ( " Add categories to rule " ), this , SLOT ( refineRuleCategories () ) );
70
+ mRefineMenu ->addAction ( tr ( " Add ranges to rule " ), this , SLOT ( refineRuleRanges () ) );
71
71
btnRefineRule->setMenu ( mRefineMenu );
72
+ contextMenu->addMenu ( mRefineMenu );
72
73
73
74
btnAddRule->setIcon ( QIcon ( QgsApplication::iconPath ( " symbologyAdd.png" ) ) );
74
75
btnEditRule->setIcon ( QIcon ( QgsApplication::iconPath ( " symbologyEdit.png" ) ) );
@@ -187,21 +188,23 @@ void QgsRuleBasedRendererV2Widget::currentRuleChanged( const QModelIndex& curren
187
188
188
189
void QgsRuleBasedRendererV2Widget::refineRule ( int type )
189
190
{
190
- QModelIndex index = viewRules->selectionModel ()->currentIndex ();
191
- if ( !index.isValid () )
191
+ QModelIndexList indexlist = viewRules->selectionModel ()->selectedRows ();
192
+
193
+ if ( indexlist.isEmpty () )
192
194
return ;
193
195
194
196
195
197
if ( type == 0 ) // categories
196
- refineRuleCategoriesGui ( index );
198
+ refineRuleCategoriesGui ( indexlist );
197
199
else if ( type == 1 ) // ranges
198
- refineRuleRangesGui ( index );
200
+ refineRuleRangesGui ( indexlist );
199
201
else // scales
200
- refineRuleScalesGui ( index );
202
+ refineRuleScalesGui ( indexlist );
201
203
202
204
// TODO: set initial rule's symbol to NULL (?)
203
205
204
206
// show the newly added rules
207
+ foreach ( QModelIndex index, indexlist )
205
208
viewRules->expand ( index );
206
209
}
207
210
@@ -220,10 +223,8 @@ void QgsRuleBasedRendererV2Widget::refineRuleScales()
220
223
refineRule ( 2 );
221
224
}
222
225
223
- void QgsRuleBasedRendererV2Widget::refineRuleCategoriesGui ( const QModelIndex& index )
226
+ void QgsRuleBasedRendererV2Widget::refineRuleCategoriesGui ( const QModelIndexList& indexList )
224
227
{
225
- QgsRuleBasedRendererV2::Rule* initialRule = mModel ->ruleForIndex ( index );
226
-
227
228
QDialog dlg;
228
229
dlg.setWindowTitle ( tr ( " Refine a rule to categories" ) );
229
230
QVBoxLayout* l = new QVBoxLayout ();
@@ -240,15 +241,19 @@ void QgsRuleBasedRendererV2Widget::refineRuleCategoriesGui( const QModelIndex& i
240
241
241
242
// create new rules
242
243
QgsCategorizedSymbolRendererV2* r = static_cast <QgsCategorizedSymbolRendererV2*>( w->renderer () );
243
- mModel ->willAddRules ( index, r->categories ().count () );
244
- QgsRuleBasedRendererV2::refineRuleCategories ( initialRule, r );
244
+ foreach ( QModelIndex index, indexList )
245
+ {
246
+ QgsRuleBasedRendererV2::Rule* initialRule = mModel ->ruleForIndex ( index );
247
+ mModel ->willAddRules ( index, r->categories ().count () );
248
+ QgsRuleBasedRendererV2::refineRuleCategories ( initialRule, r );
249
+ }
245
250
mModel ->finishedAddingRules ();
246
251
}
247
252
248
253
249
- void QgsRuleBasedRendererV2Widget::refineRuleRangesGui ( const QModelIndex& index )
254
+ void QgsRuleBasedRendererV2Widget::refineRuleRangesGui ( const QModelIndexList& indexList )
250
255
{
251
- QgsRuleBasedRendererV2::Rule* initialRule = mModel -> ruleForIndex ( index );
256
+
252
257
253
258
QDialog dlg;
254
259
dlg.setWindowTitle ( tr ( " Refine a rule to ranges" ) );
@@ -266,20 +271,27 @@ void QgsRuleBasedRendererV2Widget::refineRuleRangesGui( const QModelIndex& index
266
271
267
272
// create new rules
268
273
QgsGraduatedSymbolRendererV2* r = static_cast <QgsGraduatedSymbolRendererV2*>( w->renderer () );
269
- mModel ->willAddRules ( index, r->ranges ().count () );
270
- QgsRuleBasedRendererV2::refineRuleRanges ( initialRule, r );
274
+ foreach ( QModelIndex index, indexList )
275
+ {
276
+ QgsRuleBasedRendererV2::Rule* initialRule = mModel ->ruleForIndex ( index );
277
+ mModel ->willAddRules ( index, r->ranges ().count () );
278
+ QgsRuleBasedRendererV2::refineRuleRanges ( initialRule, r );
279
+ }
271
280
mModel ->finishedAddingRules ();
272
281
}
273
282
274
- void QgsRuleBasedRendererV2Widget::refineRuleScalesGui ( const QModelIndex& index )
283
+ void QgsRuleBasedRendererV2Widget::refineRuleScalesGui ( const QModelIndexList& indexList )
275
284
{
276
- QgsRuleBasedRendererV2::Rule* initialRule = mModel ->ruleForIndex ( index );
277
-
278
-
279
- if ( initialRule->symbol () == NULL )
285
+ foreach ( QModelIndex index, indexList )
280
286
{
281
- QMessageBox::warning ( this , tr ( " Scale refinement" ), tr ( " Parent rule must have a symbol for this operation." ) );
282
- return ;
287
+ QgsRuleBasedRendererV2::Rule* initialRule = mModel ->ruleForIndex ( index );
288
+
289
+ // If any of the rules don't have a symbol let the user know and exit.
290
+ if ( initialRule->symbol () == NULL )
291
+ {
292
+ QMessageBox::warning ( this , tr ( " Scale refinement" ), tr ( " Parent rule %1 must have a symbol for this operation." ).arg ( initialRule->label () ) );
293
+ return ;
294
+ }
283
295
}
284
296
285
297
QString txt = QInputDialog::getText ( this ,
@@ -299,8 +311,12 @@ void QgsRuleBasedRendererV2Widget::refineRuleScalesGui( const QModelIndex& index
299
311
QMessageBox::information ( this , tr ( " Error" ), QString ( tr ( " \" %1\" is not valid scale denominator, ignoring it." ) ).arg ( item ) );
300
312
}
301
313
302
- mModel ->willAddRules ( index, scales.count () + 1 );
303
- QgsRuleBasedRendererV2::refineRuleScales ( initialRule, scales );
314
+ foreach ( QModelIndex index, indexList )
315
+ {
316
+ QgsRuleBasedRendererV2::Rule* initialRule = mModel ->ruleForIndex ( index );
317
+ mModel ->willAddRules ( index, scales.count () + 1 );
318
+ QgsRuleBasedRendererV2::refineRuleScales ( initialRule, scales );
319
+ }
304
320
mModel ->finishedAddingRules ();
305
321
}
306
322
0 commit comments