patch_on_first_1_7_0_symbol-levels_rbr_jef.diff

Patch on freshly branched 1_7_0 commit:6c835b4cf5cd4a4be687e829bb57e3d51e7345f7 taking into accounts jef's comments at https://github.com/qgis/Quantum-GIS/pull/3 - Mayeul Kauffmann, 2011-05-07 03:32 AM

Download (16.9 KB)

View differences:

src/core/symbology-ng/qgsrendererv2.cpp 2011-05-07 10:51:30.710250118 +0200
347 347

  
348 348
  QgsFeatureRendererV2* r = m->createRenderer( element );
349 349
  if ( r )
350
  {
350 351
    r->setUsingSymbolLevels( element.attribute( "symbollevels", "0" ).toInt() );
351

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

  
355
-- src/core/symbology-ng/qgsrendererv2.h	2011-05-04 22:52:30.000000000 +0200
357
++ src/core/symbology-ng/qgsrendererv2.h	2011-05-05 00:18:01.000000000 +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
-- src/core/symbology-ng/qgsrulebasedrendererv2.cpp	2011-05-04 22:52:30.000000000 +0200
128
++ src/core/symbology-ng/qgsrulebasedrendererv2.cpp	2011-05-07 10:52:24.078518005 +0200
......
128 128

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

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

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

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

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

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

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

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

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

  
372

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

  
352
-- src/core/symbology-ng/qgsrulebasedrendererv2.h	2011-05-04 22:52:30.000000000 +0200
376
++ src/core/symbology-ng/qgsrulebasedrendererv2.h	2011-05-05 00:18:01.000000000 +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
-- src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp	2011-05-04 22:52:30.000000000 +0200
157
++ src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp	2011-05-05 00:18:01.000000000 +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
-- src/gui/symbology-ng/qgsrendererv2propertiesdialog.h	2011-05-04 22:52:30.000000000 +0200
231
++ src/gui/symbology-ng/qgsrendererv2propertiesdialog.h	2011-05-05 00:18:01.000000000 +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
-- src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp	2011-05-04 22:52:30.000000000 +0200
42
++ src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp	2011-05-07 11:46:08.954278394 +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>
......
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

  
......
171 186
}
172 187

  
173 188

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

  
211
}
212

  
213

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

  
233

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

  
245
}
246

  
247

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

  
256

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

  
264

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

  
279

  
280

  
281

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

  
598
    // Priority (Id): add 1 to rule number and convert to string
599
    item->setText( 4,  QString("%1").arg( i+1, 4 ) );
600
    item->setTextAlignment (4, Qt::AlignRight);
490 601
    lst << item;
491 602
  }
492 603

  
......
550 661

  
551 662
    //item->setBackground( 1, Qt::lightGray );
552 663
    //item->setBackground( 3, Qt::lightGray );
664

  
665
    // Priority (Id): add 1 to rule number and convert to string
666
    item->setText( 4,  QString("%1").arg( i+1, 4 ) );
667
    item->setTextAlignment (4, Qt::AlignRight);
668

  
553 669
  }
554 670
  addTopLevelItems( scale_items.values() );
555 671
}
......
601 717
      item->setTextAlignment( 2, Qt::AlignRight );
602 718
      item->setTextAlignment( 3, Qt::AlignRight );
603 719
    }
720

  
721
    // Priority (Id): add 1 to rule number and convert to string
722
    item->setText( 4,  QString("%1").arg( i+1, 4 ) );
723
    item->setTextAlignment (4, Qt::AlignRight);
604 724
  }
605 725

  
606 726
  addTopLevelItems( filter_items.values() );
607
-- src/gui/symbology-ng/qgsrulebasedrendererv2widget.h	2011-05-04 22:52:30.000000000 +0200
727
++ src/gui/symbology-ng/qgsrulebasedrendererv2widget.h	2011-05-05 00:18:01.000000000 +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
-- src/ui/qgsrulebasedrendererv2widget.ui	2011-05-04 22:52:31.000000000 +0200
102
++ src/ui/qgsrulebasedrendererv2widget.ui	2011-05-05 00:18:01.000000000 +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>