patch_on_r15676-rbr_symbol-levels_reordering_1st-rule_buttons.diff

Same as previous + reordering of rules + allows to use only first matching rule (also without using symbol levels) - Mayeul Kauffmann, 2011-04-06 05:15 PM

Download (18.3 KB)

View differences:

/hometb/mk/sig/dev/r15676-patched/qgis/src/core/symbology-ng/qgsrendererv2.cpp 2011-04-07 00:54:06.625249760 +0200
348 348
  QgsFeatureRendererV2* r = m->createRenderer( element );
349 349
  if ( r )
350 350
    r->setUsingSymbolLevels( element.attribute( "symbollevels", "0" ).toInt() );
351

  
351
    r->setUsingFirstRule( element.attribute( "firstrule", "0" ).toInt() );
352 352
  return r;
353 353
}
354 354

  
355
-- /hometb/mk/sig/dev/r15676-backup/qgis/src/core/symbology-ng/qgsrendererv2.h	2011-04-07 00:51:06.740986188 +0200
355
++ /hometb/mk/sig/dev/r15676-patched/qgis/src/core/symbology-ng/qgsrendererv2.h	2011-04-07 00:54:06.625249760 +0200
......
84 84
    bool usingSymbolLevels() const { return mUsingSymbolLevels; }
85 85
    void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
86 86

  
87
    bool usingFirstRule() const { return mUsingFirstRule; }
88
    void setUsingFirstRule( bool usingFirstRule ) { mUsingFirstRule = usingFirstRule; }
89

  
90

  
87 91
    //! create a renderer from XML element
88 92
    static QgsFeatureRendererV2* load( QDomElement& symbologyElem );
89 93

  
......
117 121
    QString mType;
118 122

  
119 123
    bool mUsingSymbolLevels;
124
    bool mUsingFirstRule;
120 125

  
121 126
    /** The current type of editing marker */
122 127
    int mCurrentVertexMarkerType;
123
-- /hometb/mk/sig/dev/r15676-backup/qgis/src/core/symbology-ng/qgsrulebasedrendererv2.cpp	2011-04-07 00:51:06.740986188 +0200
128
++ /hometb/mk/sig/dev/r15676-patched/qgis/src/core/symbology-ng/qgsrulebasedrendererv2.cpp	2011-04-07 01:50:09.157592202 +0200
......
128 128

  
129 129
QgsSymbolV2* QgsRuleBasedRendererV2::symbolForFeature( QgsFeature& feature )
130 130
{
131
  return mCurrentSymbol;
131

  
132
  if( !( usingFirstRule() )  )    return mCurrentSymbol;
133

  
134
  for ( QList<Rule*>::iterator it = mCurrentRules.begin(); it != mCurrentRules.end(); ++it )
135
  {
136
    Rule* rule = *it;
137

  
138
    if ( rule->isFilterOK( mCurrentFields, feature ) )
139
    {
140
      return rule->symbol(); //works with levels but takes only first rule
141
    }
142
  }
132 143
}
133 144

  
134 145
void QgsRuleBasedRendererV2::renderFeature( QgsFeature& feature,
......
200 211
  QgsSymbolV2* s = mDefaultSymbol->clone();
201 212
  QgsRuleBasedRendererV2* r = new QgsRuleBasedRendererV2( s );
202 213
  r->mRules = mRules;
214
  r->setUsingSymbolLevels( usingSymbolLevels() );
215
  r->setUsingFirstRule( usingFirstRule() );
216
  setUsingFirstRule( usingFirstRule() );
217
  setUsingSymbolLevels( usingSymbolLevels() );
203 218
  return r;
204 219
}
205 220

  
......
219 234
{
220 235
  QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
221 236
  rendererElem.setAttribute( "type", "RuleRenderer" );
237
  rendererElem.setAttribute( "symbollevels", ( mUsingSymbolLevels ? "1" : "0" ) );
238
  rendererElem.setAttribute( "firstrule", ( mUsingFirstRule ? "1" : "0" ) );
222 239

  
223 240
  QDomElement rulesElem = doc.createElement( "rules" );
224 241

  
......
346 363
  mRules.removeAt( index );
347 364
}
348 365

  
366
void QgsRuleBasedRendererV2::swapRules( int index1,  int index2 )
367
{
368
  mRules.swap( index1, index2 );
369
}
370

  
371

  
349 372
#include "qgscategorizedsymbolrendererv2.h"
350 373
#include "qgsgraduatedsymbolrendererv2.h"
351 374

  
352
-- /hometb/mk/sig/dev/r15676-backup/qgis/src/core/symbology-ng/qgsrulebasedrendererv2.h	2011-04-07 00:51:06.740986188 +0200
375
++ /hometb/mk/sig/dev/r15676-patched/qgis/src/core/symbology-ng/qgsrulebasedrendererv2.h	2011-04-07 01:58:47.220914257 +0200
......
44 44
    {
45 45
      public:
46 46
        //! Constructor takes ownership of the symbol
47
        Rule( QgsSymbolV2* symbol, int scaleMinDenom = 0, int scaleMaxDenom = 0, QString filterExp = QString(), QString label = QString(), QString description = QString() );
47
        Rule( QgsSymbolV2* symbol, int scaleMinDenom = 0, int scaleMaxDenom = 0, QString filterExp = QString(),
48
          QString label = QString(), QString description = QString() );
48 49
        Rule( const Rule& other );
49 50
        ~Rule();
50 51
        QString dump() const;
......
127 128
    void updateRuleAt( int index, const Rule& rule );
128 129
    //! remove the rule at the specified index
129 130
    void removeRuleAt( int index );
131
    //! swap the two rules specified by the indices
132
    void swapRules( int index1,  int index2);
130 133

  
131 134
    //////
132 135

  
......
147 150
    QList<Rule*> mCurrentRules;
148 151
    QgsFieldMap mCurrentFields;
149 152
    QgsSymbolV2* mCurrentSymbol;
153

  
150 154
};
151 155

  
152 156
#endif // QGSRULEBASEDRENDERERV2_H
153
-- /hometb/mk/sig/dev/r15676-backup/qgis/src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp	2011-04-07 00:51:05.991010106 +0200
157
++ /hometb/mk/sig/dev/r15676-patched/qgis/src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp	2011-04-07 02:01:31.325619865 +0200
......
201 201
  QgsSymbolV2List symbols = r->symbols();
202 202

  
203 203
  QgsSymbolLevelsV2Dialog dlg( symbols, r->usingSymbolLevels(), this );
204
  connect( this, SIGNAL( forceChkUsingFirstRule() ), mActiveWidget, SLOT( forceUsingFirstRule() ), Qt::UniqueConnection );
205
  connect( this, SIGNAL( forceUncheckSymbolLevels() ), mActiveWidget, SLOT( forceNoSymbolLevels() ), Qt::UniqueConnection );
206

  
204 207
  if ( dlg.exec() )
205 208
  {
206 209
    r->setUsingSymbolLevels( dlg.usingLevels() );
210

  
211
    if ( r->type() == "RuleRenderer" )
212
    {
213
      if( dlg.usingLevels() )
214
      {
215
        r->setUsingFirstRule( true );
216
        emit forceChkUsingFirstRule();
217
      }
218
      else
219
      {
220
        emit forceUncheckSymbolLevels();
221
      }
222
    }
207 223
  }
224

  
208 225
}
209 226

  
227

  
210 228
void QgsRendererV2PropertiesDialog::useOldSymbology()
211 229
{
212 230
  int res = QMessageBox::question( this, tr( "Symbology" ),
213
-- /hometb/mk/sig/dev/r15676-backup/qgis/src/gui/symbology-ng/qgsrendererv2propertiesdialog.h	2011-04-07 00:51:05.991010106 +0200
231
++ /hometb/mk/sig/dev/r15676-patched/qgis/src/gui/symbology-ng/qgsrendererv2propertiesdialog.h	2011-04-07 00:54:06.635249441 +0200
......
34 34

  
35 35
  signals:
36 36
    void useNewSymbology( bool );
37
    void forceChkUsingFirstRule();
38
    void forceUncheckSymbolLevels();
37 39

  
38 40
  protected:
39 41

  
40
-- /hometb/mk/sig/dev/r15676-backup/qgis/src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp	2011-04-07 00:51:05.991010106 +0200
42
++ /hometb/mk/sig/dev/r15676-patched/qgis/src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp	2011-04-07 02:03:13.592321220 +0200
......
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>
28 30
#include <QVBoxLayout>
29 31
#include <QMessageBox>
32
#include <sstream>
30 33

  
31 34
QgsRendererV2Widget* QgsRuleBasedRendererV2Widget::create( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
32 35
{
......
66 69
  btnAddRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.png" ) ) );
67 70
  btnEditRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) );
68 71
  btnRemoveRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.png" ) ) );
72
  btnIncreasePriority->setIcon( QIcon( QgsApplication::iconPath( "symbologyUp.png" ) ) );
73
  btnDecreasePriority->setIcon( QIcon( QgsApplication::iconPath( "symbologyDown.png" ) ) );
69 74

  
70 75
  connect( treeRules, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( editRule() ) );
71 76

  
72 77
  connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) );
73 78
  connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) );
74 79
  connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) );
80
  connect( btnIncreasePriority, SIGNAL( clicked() ), this, SLOT( increasePriority() ) );
81
  connect( btnDecreasePriority, SIGNAL( clicked() ), this, SLOT( decreasePriority() ) );
75 82

  
76 83
  connect( radNoGrouping, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );
77 84
  connect( radGroupFilter, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );
78 85
  connect( radGroupScale, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );
79 86

  
87
  // Make sure buttons are always in the correct state
88
  chkUsingFirstRule->setChecked( mRenderer->usingFirstRule() );
89
  chkEnableSymbolLevels->setChecked( mRenderer->usingSymbolLevels() );
90
  // If symbol levels are used, forcefully check and gray-out the chkUsingFirstRule checkbox
91
  if (mRenderer->usingSymbolLevels() ) { forceUsingFirstRule(); }
92
  connect( chkUsingFirstRule, SIGNAL( clicked() ), this, SLOT( usingFirstRuleChanged() ));
93
  connect( chkEnableSymbolLevels, SIGNAL( clicked() ), this, SLOT( symbolLevelsEnabledChanged() ) );
94
  connect( this, SIGNAL( forceChkUsingFirstRule() ), this, SLOT( forceUsingFirstRule() ) );
95

  
80 96
  treeRules->populateRules();
81 97
}
82 98

  
......
171 187
}
172 188

  
173 189

  
190
void QgsRuleBasedRendererV2Widget::increasePriority()
191
{
192
  QTreeWidgetItem * item = treeRules->currentItem();
193
    if ( ! item ) return; // No rule selected, exit
194
  int rule_index = item->data( 0, Qt::UserRole + 1 ).toInt();
195
  if ( rule_index < 0 )
196
  {
197
    return;// Group of rules selected, exit
198
  }
199
  else
200
  {
201
   if ( rule_index > 0 ) // do not increase priority of first rule
202
   {
203
      mRenderer->swapRules(rule_index, rule_index - 1);
204
      treeRules->populateRules();
205
    // TODO: find out where the moved rule goes and reselect it (at least for non-grouped display)
206
    // maybe based on the following functions :
207
    //  findItems(QString(rule_index - 1), Qt::MatchExactly, 4).first.index)
208
    //  setCurrentItem, setSelected, scrollToItem
209
   }
210
  }
211

  
212
}
213

  
214

  
215
void QgsRuleBasedRendererV2Widget::decreasePriority()
216
{
217
  QTreeWidgetItem * item = treeRules->currentItem();
218
    if ( ! item ) return; // No rule selected, exit
219
  int rule_index = item->data( 0, Qt::UserRole + 1 ).toInt();
220
  if ( rule_index < 0 )
221
  {
222
    return;// Group of rules selected, exit
223
  }
224
  else
225
  {
226
   if ( rule_index +1 < mRenderer->ruleCount() ) // do not increase priority of last rule
227
   {
228
     mRenderer->swapRules(rule_index, rule_index + 1);
229
     treeRules->populateRules();
230
   }
231
  }
232
}
233

  
234

  
235
void QgsRuleBasedRendererV2Widget::usingFirstRuleChanged()
236
{
237
  if ( chkUsingFirstRule->checkState() == Qt::Checked )
238
  {
239
    mRenderer->setUsingFirstRule(true);
240
  }
241
  else
242
  {
243
    mRenderer->setUsingFirstRule(false);
244
  }
245

  
246
}
247

  
248

  
249
void QgsRuleBasedRendererV2Widget::forceUsingFirstRule()
250
{
251
  chkEnableSymbolLevels->setChecked( true );
252
  chkUsingFirstRule->setChecked( true );
253
  chkUsingFirstRule->setEnabled(false);
254
  mRenderer->setUsingFirstRule(true);
255
}
256

  
257

  
258
void QgsRuleBasedRendererV2Widget::forceNoSymbolLevels()
259
{
260
    chkEnableSymbolLevels->setChecked( false );
261
    chkUsingFirstRule->setEnabled( true );
262
    mRenderer->setUsingSymbolLevels( false );
263
}
264

  
265

  
266
void QgsRuleBasedRendererV2Widget::symbolLevelsEnabledChanged()
267
{
268
  if ( chkEnableSymbolLevels->checkState() == Qt::Checked )
269
  {
270
    mRenderer->setUsingSymbolLevels(true);
271
    emit forceChkUsingFirstRule();
272
  }
273
  else
274
  {
275
   mRenderer->setUsingSymbolLevels(false);
276
   chkUsingFirstRule->setEnabled(true);
277
  }
278
}
279

  
280

  
281

  
282

  
174 283
#include "qgscategorizedsymbolrendererv2.h"
175 284
#include "qgscategorizedsymbolrendererv2widget.h"
176 285
#include "qgsgraduatedsymbolrendererv2.h"
......
487 596
    //item->setBackground( 1, Qt::lightGray );
488 597
    //item->setBackground( 3, Qt::lightGray );
489 598

  
599
    // Priority (Id): add 1 to rule number and convert to string
600
    std::ostringstream ioss;
601
    ioss << i+1;
602
    std::string ruleIdx = ioss.str();
603
    while( ruleIdx.size() < 4 ){ ruleIdx.insert( 0, " " );} // pad to left with spaces (to fix string-based sorting)
604
    item->setText( 4, QString(ruleIdx.c_str()) );// Insert Id in table (as 'Priority' column)
605
    item->setTextAlignment (4, Qt::AlignRight);
490 606
    lst << item;
607

  
491 608
  }
492 609

  
493 610

  
......
550 667

  
551 668
    //item->setBackground( 1, Qt::lightGray );
552 669
    //item->setBackground( 3, Qt::lightGray );
670

  
671
    // Priority (Id): add 1 to rule number and convert to string
672
    std::ostringstream ioss;
673
    ioss << i+1;
674
    std::string ruleIdx = ioss.str();
675
    while( ruleIdx.size() < 4 ){ ruleIdx.insert( 0, " " );}
676
    item->setText( 4, QString(ruleIdx.c_str()) );
677
    item->setTextAlignment (4, Qt::AlignRight);
678

  
553 679
  }
554 680
  addTopLevelItems( scale_items.values() );
555 681
}
......
601 727
      item->setTextAlignment( 2, Qt::AlignRight );
602 728
      item->setTextAlignment( 3, Qt::AlignRight );
603 729
    }
730

  
731
    // Priority (Id): add 1 to rule number and convert to string
732
    std::ostringstream ioss;
733
    ioss << i+1;
734
    std::string ruleIdx = ioss.str();
735
    while( ruleIdx.size() < 4 ){ ruleIdx.insert( 0, " " );}
736
    item->setText( 4, QString(ruleIdx.c_str()) );
737
    item->setTextAlignment (4, Qt::AlignRight);
604 738
  }
605 739

  
606 740
  addTopLevelItems( filter_items.values() );
607
-- /hometb/mk/sig/dev/r15676-backup/qgis/src/gui/symbology-ng/qgsrulebasedrendererv2widget.h	2011-04-07 00:51:05.991010106 +0200
741
++ /hometb/mk/sig/dev/r15676-patched/qgis/src/gui/symbology-ng/qgsrulebasedrendererv2widget.h	2011-04-07 02:04:27.439939572 +0200
......
78 78
    void addRule();
79 79
    void editRule();
80 80
    void removeRule();
81
    void increasePriority();
82
    void decreasePriority();
81 83

  
82 84
    void setGrouping();
83 85

  
......
85 87
    void refineRuleCategories();
86 88
    void refineRuleRanges();
87 89

  
90
    void usingFirstRuleChanged( );
91
    void symbolLevelsEnabledChanged();
92
    void forceNoSymbolLevels();
93
    void forceUsingFirstRule();
94

  
95
  signals:
96

  
97
    void forceChkUsingFirstRule();
98

  
88 99
  protected:
89 100

  
90 101
    void refineRule( int type );
91
-- /hometb/mk/sig/dev/r15676-backup/qgis/src/ui/qgsrulebasedrendererv2widget.ui	2011-04-07 00:51:22.070497346 +0200
102
++ /hometb/mk/sig/dev/r15676-patched/qgis/src/ui/qgsrulebasedrendererv2widget.ui	2011-04-07 00:54:06.635249441 +0200
......
6 6
   <rect>
7 7
    <x>0</x>
8 8
    <y>0</y>
9
    <width>622</width>
10
    <height>273</height>
9
    <width>640</width>
10
    <height>401</height>
11 11
   </rect>
12 12
  </property>
13 13
  <property name="windowTitle">
......
16 16
  <layout class="QGridLayout" name="gridLayout">
17 17
   <item row="0" column="0">
18 18
    <widget class="QgsRendererRulesTreeWidget" name="treeRules">
19
     <property name="styleSheet">
20
      <string notr="true"/>
21
     </property>
19 22
     <property name="rootIsDecorated">
20 23
      <bool>false</bool>
21 24
     </property>
......
51 54
       <set>AlignHCenter|AlignVCenter|AlignCenter</set>
52 55
      </property>
53 56
     </column>
57
     <column>
58
      <property name="text">
59
       <string>Priority</string>
60
      </property>
61
      <property name="toolTip">
62
       <string>Priority when symbol levels are enabled (only first matching rule will be applied)</string>
63
      </property>
64
      <property name="textAlignment">
65
       <set>AlignHCenter|AlignVCenter|AlignCenter</set>
66
      </property>
67
     </column>
54 68
    </widget>
55 69
   </item>
56 70
   <item row="0" column="1">
......
63 77
      </widget>
64 78
     </item>
65 79
     <item>
80
      <widget class="QPushButton" name="btnEditRule">
81
       <property name="text">
82
        <string>Edit</string>
83
       </property>
84
      </widget>
85
     </item>
86
     <item>
87
      <widget class="QPushButton" name="btnRemoveRule">
88
       <property name="text">
89
        <string>Remove</string>
90
       </property>
91
      </widget>
92
     </item>
93
     <item>
66 94
      <widget class="QPushButton" name="btnRefineRule">
67 95
       <property name="text">
68 96
        <string>Refine</string>
......
70 98
      </widget>
71 99
     </item>
72 100
     <item>
73
      <widget class="QPushButton" name="btnEditRule">
101
      <widget class="QPushButton" name="btnIncreasePriority">
74 102
       <property name="text">
75
        <string>Edit</string>
103
        <string>Increase priority</string>
76 104
       </property>
77 105
      </widget>
78 106
     </item>
79 107
     <item>
80
      <widget class="QPushButton" name="btnRemoveRule">
108
      <widget class="QPushButton" name="btnDecreasePriority">
81 109
       <property name="text">
82
        <string>Remove</string>
110
        <string>Decrease priority</string>
83 111
       </property>
84 112
      </widget>
85 113
     </item>
86 114
    </layout>
87 115
   </item>
88
   <item row="1" column="0" colspan="2">
116
   <item row="3" column="0" colspan="2">
117
    <widget class="QGroupBox" name="groupBox_2">
118
     <property name="minimumSize">
119
      <size>
120
       <width>0</width>
121
       <height>35</height>
122
      </size>
123
     </property>
124
     <property name="baseSize">
125
      <size>
126
       <width>0</width>
127
       <height>0</height>
128
      </size>
129
     </property>
130
     <property name="title">
131
      <string/>
132
     </property>
133
     <widget class="QCheckBox" name="chkEnableSymbolLevels">
134
      <property name="geometry">
135
       <rect>
136
        <x>113</x>
137
        <y>10</y>
138
        <width>231</width>
139
        <height>24</height>
140
       </rect>
141
      </property>
142
      <property name="text">
143
       <string>Enable symbol levels</string>
144
      </property>
145
     </widget>
146
     <widget class="QCheckBox" name="chkUsingFirstRule">
147
      <property name="geometry">
148
       <rect>
149
        <x>360</x>
150
        <y>10</y>
151
        <width>271</width>
152
        <height>24</height>
153
       </rect>
154
      </property>
155
      <property name="text">
156
       <string>Use only first matched rule</string>
157
      </property>
158
     </widget>
159
     <widget class="QLabel" name="label_2">
160
      <property name="geometry">
161
       <rect>
162
        <x>10</x>
163
        <y>10</y>
164
        <width>84</width>
165
        <height>24</height>
166
       </rect>
167
      </property>
168
      <property name="text">
169
       <string>Behavior</string>
170
      </property>
171
     </widget>
172
    </widget>
173
   </item>
174
   <item row="2" column="0" colspan="2">
89 175
    <widget class="QGroupBox" name="groupBox">
90 176
     <property name="title">
91
      <string>Rule grouping</string>
177
      <string notr="true"/>
92 178
     </property>
93 179
     <layout class="QHBoxLayout" name="horizontalLayout">
94 180
      <item>
181
       <widget class="QLabel" name="label">
182
        <property name="text">
183
         <string>Rule grouping</string>
184
        </property>
185
       </widget>
186
      </item>
187
      <item>
95 188
       <widget class="QRadioButton" name="radNoGrouping">
96 189
        <property name="text">
97
         <string>No grouping</string>
190
         <string comment="No grouping for displaying rules">None</string>
98 191
        </property>
99 192
        <property name="checked">
100 193
         <bool>true</bool>
......
104 197
      <item>
105 198
       <widget class="QRadioButton" name="radGroupFilter">
106 199
        <property name="text">
107
         <string>Group by filter</string>
200
         <string comment="Group rules by filter">By filter</string>
108 201
        </property>
109 202
       </widget>
110 203
      </item>
111 204
      <item>
112 205
       <widget class="QRadioButton" name="radGroupScale">
113 206
        <property name="text">
114
         <string>Group by scale</string>
207
         <string comment="Group rules by scale">By scale</string>
115 208
        </property>
116 209
       </widget>
117 210
      </item>