|
22 | 22 | #include "qgsapplication.h" |
23 | 23 | #include "qgssearchtreenode.h" |
24 | 24 | #include "qgssymbolv2selectordialog.h" |
| 25 | +#include "qgslogger.h" |
| 26 | +#include "qstring.h" |
25 | 27 |
|
26 | 28 | #include <QMenu> |
27 | 29 | #include <QTreeWidgetItem> |
@@ -66,17 +68,30 @@ QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* laye |
66 | 68 | btnAddRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.png" ) ) ); |
67 | 69 | btnEditRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) ); |
68 | 70 | btnRemoveRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.png" ) ) ); |
| 71 | + btnIncreasePriority->setIcon( QIcon( QgsApplication::iconPath( "symbologyUp.png" ) ) ); |
| 72 | + btnDecreasePriority->setIcon( QIcon( QgsApplication::iconPath( "symbologyDown.png" ) ) ); |
69 | 73 |
|
70 | 74 | connect( treeRules, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( editRule() ) ); |
71 | 75 |
|
72 | 76 | connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) ); |
73 | 77 | connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) ); |
74 | 78 | connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) ); |
| 79 | + connect( btnIncreasePriority, SIGNAL( clicked() ), this, SLOT( increasePriority() ) ); |
| 80 | + connect( btnDecreasePriority, SIGNAL( clicked() ), this, SLOT( decreasePriority() ) ); |
75 | 81 |
|
76 | 82 | connect( radNoGrouping, SIGNAL( clicked() ), this, SLOT( setGrouping() ) ); |
77 | 83 | connect( radGroupFilter, SIGNAL( clicked() ), this, SLOT( setGrouping() ) ); |
78 | 84 | connect( radGroupScale, SIGNAL( clicked() ), this, SLOT( setGrouping() ) ); |
79 | 85 |
|
| 86 | + // Make sure buttons are always in the correct state |
| 87 | + chkUsingFirstRule->setChecked( mRenderer->usingFirstRule() ); |
| 88 | + chkEnableSymbolLevels->setChecked( mRenderer->usingSymbolLevels() ); |
| 89 | + // If symbol levels are used, forcefully check and gray-out the chkUsingFirstRule checkbox |
| 90 | + if (mRenderer->usingSymbolLevels() ) { forceUsingFirstRule(); } |
| 91 | + connect( chkUsingFirstRule, SIGNAL( clicked() ), this, SLOT( usingFirstRuleChanged() )); |
| 92 | + connect( chkEnableSymbolLevels, SIGNAL( clicked() ), this, SLOT( symbolLevelsEnabledChanged() ) ); |
| 93 | + connect( this, SIGNAL( forceChkUsingFirstRule() ), this, SLOT( forceUsingFirstRule() ) ); |
| 94 | + |
80 | 95 | treeRules->populateRules(); |
81 | 96 | } |
82 | 97 |
|
@@ -173,6 +188,99 @@ void QgsRuleBasedRendererV2Widget::removeRule() |
173 | 188 | } |
174 | 189 |
|
175 | 190 |
|
| 191 | +void QgsRuleBasedRendererV2Widget::increasePriority() |
| 192 | +{ |
| 193 | + QTreeWidgetItem * item = treeRules->currentItem(); |
| 194 | + if ( ! item ) return; // No rule selected, exit |
| 195 | + int rule_index = item->data( 0, Qt::UserRole + 1 ).toInt(); |
| 196 | + if ( rule_index < 0 ) |
| 197 | + { |
| 198 | + return;// Group of rules selected, exit |
| 199 | + } |
| 200 | + else |
| 201 | + { |
| 202 | + if ( rule_index > 0 ) // do not increase priority of first rule |
| 203 | + { |
| 204 | + mRenderer->swapRules(rule_index, rule_index - 1); |
| 205 | + treeRules->populateRules(); |
| 206 | + // TODO: find out where the moved rule goes and reselect it (at least for non-grouped display) |
| 207 | + // maybe based on the following functions : |
| 208 | + // findItems(QString(rule_index - 1), Qt::MatchExactly, 4).first.index) |
| 209 | + // setCurrentItem, setSelected, scrollToItem |
| 210 | + } |
| 211 | + } |
| 212 | + |
| 213 | +} |
| 214 | + |
| 215 | + |
| 216 | +void QgsRuleBasedRendererV2Widget::decreasePriority() |
| 217 | +{ |
| 218 | + QTreeWidgetItem * item = treeRules->currentItem(); |
| 219 | + if ( ! item ) return; // No rule selected, exit |
| 220 | + int rule_index = item->data( 0, Qt::UserRole + 1 ).toInt(); |
| 221 | + if ( rule_index < 0 ) |
| 222 | + { |
| 223 | + return;// Group of rules selected, exit |
| 224 | + } |
| 225 | + else |
| 226 | + { |
| 227 | + if ( rule_index +1 < mRenderer->ruleCount() ) // do not increase priority of last rule |
| 228 | + { |
| 229 | + mRenderer->swapRules(rule_index, rule_index + 1); |
| 230 | + treeRules->populateRules(); |
| 231 | + } |
| 232 | + } |
| 233 | +} |
| 234 | + |
| 235 | + |
| 236 | +void QgsRuleBasedRendererV2Widget::usingFirstRuleChanged() |
| 237 | +{ |
| 238 | + if ( chkUsingFirstRule->checkState() == Qt::Checked ) |
| 239 | + { |
| 240 | + mRenderer->setUsingFirstRule(true); |
| 241 | + } |
| 242 | + else |
| 243 | + { |
| 244 | + mRenderer->setUsingFirstRule(false); |
| 245 | + } |
| 246 | + |
| 247 | +} |
| 248 | + |
| 249 | + |
| 250 | +void QgsRuleBasedRendererV2Widget::forceUsingFirstRule() |
| 251 | +{ |
| 252 | + chkEnableSymbolLevels->setChecked( true ); |
| 253 | + chkUsingFirstRule->setChecked( true ); |
| 254 | + chkUsingFirstRule->setEnabled(false); |
| 255 | + mRenderer->setUsingFirstRule(true); |
| 256 | +} |
| 257 | + |
| 258 | + |
| 259 | +void QgsRuleBasedRendererV2Widget::forceNoSymbolLevels() |
| 260 | +{ |
| 261 | + chkEnableSymbolLevels->setChecked( false ); |
| 262 | + chkUsingFirstRule->setEnabled( true ); |
| 263 | + mRenderer->setUsingSymbolLevels( false ); |
| 264 | +} |
| 265 | + |
| 266 | + |
| 267 | +void QgsRuleBasedRendererV2Widget::symbolLevelsEnabledChanged() |
| 268 | +{ |
| 269 | + if ( chkEnableSymbolLevels->checkState() == Qt::Checked ) |
| 270 | + { |
| 271 | + mRenderer->setUsingSymbolLevels(true); |
| 272 | + emit forceChkUsingFirstRule(); |
| 273 | + } |
| 274 | + else |
| 275 | + { |
| 276 | + mRenderer->setUsingSymbolLevels(false); |
| 277 | + chkUsingFirstRule->setEnabled(true); |
| 278 | + } |
| 279 | +} |
| 280 | + |
| 281 | + |
| 282 | + |
| 283 | + |
176 | 284 | #include "qgscategorizedsymbolrendererv2.h" |
177 | 285 | #include "qgscategorizedsymbolrendererv2widget.h" |
178 | 286 | #include "qgsgraduatedsymbolrendererv2.h" |
@@ -493,6 +601,9 @@ void QgsRendererRulesTreeWidget::populateRulesNoGrouping() |
493 | 601 | //item->setBackground( 1, Qt::lightGray ); |
494 | 602 | //item->setBackground( 3, Qt::lightGray ); |
495 | 603 |
|
| 604 | + // Priority (Id): add 1 to rule number and convert to string |
| 605 | + item->setText( 4, QString("%1").arg( i+1, 4 ) ); |
| 606 | + item->setTextAlignment (4, Qt::AlignRight); |
496 | 607 | lst << item; |
497 | 608 | } |
498 | 609 |
|
@@ -557,6 +668,11 @@ void QgsRendererRulesTreeWidget::populateRulesGroupByScale() |
557 | 668 |
|
558 | 669 | //item->setBackground( 1, Qt::lightGray ); |
559 | 670 | //item->setBackground( 3, Qt::lightGray ); |
| 671 | + |
| 672 | + // Priority (Id): add 1 to rule number and convert to string |
| 673 | + item->setText( 4, QString("%1").arg( i+1, 4 ) ); |
| 674 | + item->setTextAlignment (4, Qt::AlignRight); |
| 675 | + |
560 | 676 | } |
561 | 677 | addTopLevelItems( scale_items.values() ); |
562 | 678 | } |
@@ -608,6 +724,10 @@ void QgsRendererRulesTreeWidget::populateRulesGroupByFilter() |
608 | 724 | item->setTextAlignment( 2, Qt::AlignRight ); |
609 | 725 | item->setTextAlignment( 3, Qt::AlignRight ); |
610 | 726 | } |
| 727 | + |
| 728 | + // Priority (Id): add 1 to rule number and convert to string |
| 729 | + item->setText( 4, QString("%1").arg( i+1, 4 ) ); |
| 730 | + item->setTextAlignment (4, Qt::AlignRight); |
611 | 731 | } |
612 | 732 |
|
613 | 733 | addTopLevelItems( filter_items.values() ); |
|
0 commit comments