@@ -64,11 +64,12 @@ QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* laye
6464 // new ModelTest( mModel, this ); // for model validity checking
6565 viewRules->setModel ( mModel );
6666
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 () ) );
7171 btnRefineRule->setMenu ( mRefineMenu );
72+ contextMenu->addMenu ( mRefineMenu );
7273
7374 btnAddRule->setIcon ( QIcon ( QgsApplication::iconPath ( " symbologyAdd.png" ) ) );
7475 btnEditRule->setIcon ( QIcon ( QgsApplication::iconPath ( " symbologyEdit.png" ) ) );
@@ -187,21 +188,23 @@ void QgsRuleBasedRendererV2Widget::currentRuleChanged( const QModelIndex& curren
187188
188189void QgsRuleBasedRendererV2Widget::refineRule ( int type )
189190{
190- QModelIndex index = viewRules->selectionModel ()->currentIndex ();
191- if ( !index.isValid () )
191+ QModelIndexList indexlist = viewRules->selectionModel ()->selectedRows ();
192+
193+ if ( indexlist.isEmpty () )
192194 return ;
193195
194196
195197 if ( type == 0 ) // categories
196- refineRuleCategoriesGui ( index );
198+ refineRuleCategoriesGui ( indexlist );
197199 else if ( type == 1 ) // ranges
198- refineRuleRangesGui ( index );
200+ refineRuleRangesGui ( indexlist );
199201 else // scales
200- refineRuleScalesGui ( index );
202+ refineRuleScalesGui ( indexlist );
201203
202204 // TODO: set initial rule's symbol to NULL (?)
203205
204206 // show the newly added rules
207+ foreach ( QModelIndex index, indexlist )
205208 viewRules->expand ( index );
206209}
207210
@@ -220,10 +223,8 @@ void QgsRuleBasedRendererV2Widget::refineRuleScales()
220223 refineRule ( 2 );
221224}
222225
223- void QgsRuleBasedRendererV2Widget::refineRuleCategoriesGui ( const QModelIndex& index )
226+ void QgsRuleBasedRendererV2Widget::refineRuleCategoriesGui ( const QModelIndexList& indexList )
224227{
225- QgsRuleBasedRendererV2::Rule* initialRule = mModel ->ruleForIndex ( index );
226-
227228 QDialog dlg;
228229 dlg.setWindowTitle ( tr ( " Refine a rule to categories" ) );
229230 QVBoxLayout* l = new QVBoxLayout ();
@@ -240,15 +241,19 @@ void QgsRuleBasedRendererV2Widget::refineRuleCategoriesGui( const QModelIndex& i
240241
241242 // create new rules
242243 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+ }
245250 mModel ->finishedAddingRules ();
246251}
247252
248253
249- void QgsRuleBasedRendererV2Widget::refineRuleRangesGui ( const QModelIndex& index )
254+ void QgsRuleBasedRendererV2Widget::refineRuleRangesGui ( const QModelIndexList& indexList )
250255{
251- QgsRuleBasedRendererV2::Rule* initialRule = mModel -> ruleForIndex ( index );
256+
252257
253258 QDialog dlg;
254259 dlg.setWindowTitle ( tr ( " Refine a rule to ranges" ) );
@@ -266,20 +271,27 @@ void QgsRuleBasedRendererV2Widget::refineRuleRangesGui( const QModelIndex& index
266271
267272 // create new rules
268273 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+ }
271280 mModel ->finishedAddingRules ();
272281}
273282
274- void QgsRuleBasedRendererV2Widget::refineRuleScalesGui ( const QModelIndex& index )
283+ void QgsRuleBasedRendererV2Widget::refineRuleScalesGui ( const QModelIndexList& indexList )
275284{
276- QgsRuleBasedRendererV2::Rule* initialRule = mModel ->ruleForIndex ( index );
277-
278-
279- if ( initialRule->symbol () == NULL )
285+ foreach ( QModelIndex index, indexList )
280286 {
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+ }
283295 }
284296
285297 QString txt = QInputDialog::getText ( this ,
@@ -299,8 +311,12 @@ void QgsRuleBasedRendererV2Widget::refineRuleScalesGui( const QModelIndex& index
299311 QMessageBox::information ( this , tr ( " Error" ), QString ( tr ( " \" %1\" is not valid scale denominator, ignoring it." ) ).arg ( item ) );
300312 }
301313
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+ }
304320 mModel ->finishedAddingRules ();
305321}
306322
0 commit comments