patch_on_r15538-rbr_with_symbol_levels.diff

Patch agains r15538 adding symbol levels in rule-based renderer (on top of r15217) - Mayeul Kauffmann, 2011-03-21 02:56 PM

Download (5.34 KB)

View differences:

/hometb/mk/sig/dev/r15538-patched/qgis//src/core/symbology-ng/qgsrulebasedrendererv2.cpp 2011-03-20 00:23:38.414326467 +0100
128 128

  
129 129
QgsSymbolV2* QgsRuleBasedRendererV2::symbolForFeature( QgsFeature& feature )
130 130
{
131
  return mCurrentSymbol;
131
        QgsDebugMsg( "usingSymbolLevels:" );
132
    QgsDebugMsg( QString(usingSymbolLevels()?"T":"F") );
133
    QgsDebugMsg( QString(mUsingSymbolLevels?"T":"F") );
134

  
135
    if( !usingSymbolLevels() )    return mCurrentSymbol;
136

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

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

  
134 148
void QgsRuleBasedRendererV2::renderFeature( QgsFeature& feature,
......
200 214
  QgsSymbolV2* s = mDefaultSymbol->clone();
201 215
  QgsRuleBasedRendererV2* r = new QgsRuleBasedRendererV2( s );
202 216
  r->mRules = mRules;
217
  r->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" ) );
222 238

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

  
/hometb/mk/sig/dev/r15538-patched/qgis//src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp 2011-03-20 21:04:05.928573752 +0100
27 27
#include <QTreeWidgetItem>
28 28
#include <QVBoxLayout>
29 29
#include <QMessageBox>
30
#include <sstream>
30 31

  
31 32
QgsRendererV2Widget* QgsRuleBasedRendererV2Widget::create( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
32 33
{
......
487 488
    //item->setBackground( 1, Qt::lightGray );
488 489
    //item->setBackground( 3, Qt::lightGray );
489 490

  
491
    // Id: add 1 to rule number and convert to string
492
    std::ostringstream ioss;
493
    ioss << i+1;
494
    std::string ruleIdx = ioss.str();
495
    while( ruleIdx.size() < 4 ){ ruleIdx.insert( 0, " " );} // pad to left with spaces (to fix string-based sorting)
496
    item->setText( 4, QString(ruleIdx.c_str()) );// Insert Id in table (as 'Priority' column)
497
    item->setTextAlignment (4, Qt::AlignRight);
490 498
    lst << item;
491 499
  }
492 500

  
......
550 558

  
551 559
    //item->setBackground( 1, Qt::lightGray );
552 560
    //item->setBackground( 3, Qt::lightGray );
561

  
562
    // Id: add 1 to rule number and convert to string
563
    std::ostringstream ioss;
564
    ioss << i+1;
565
    std::string ruleIdx = ioss.str();
566
    while( ruleIdx.size() < 4 ){ ruleIdx.insert( 0, " " );} // pad to left with spaces (to fix string-based sorting)
567
    item->setText( 4, QString(ruleIdx.c_str()) );// Insert Id in table  TODO: base it on SymbolIdx ? How to access it?
568
    item->setTextAlignment (4, Qt::AlignRight);
569

  
553 570
  }
554 571
  addTopLevelItems( scale_items.values() );
555 572
}
......
601 618
      item->setTextAlignment( 2, Qt::AlignRight );
602 619
      item->setTextAlignment( 3, Qt::AlignRight );
603 620
    }
621

  
622
    // Id: add 1 to rule number and convert to string
623
    std::ostringstream ioss;
624
    ioss << i+1;
625
    std::string ruleIdx = ioss.str();
626
    while( ruleIdx.size() < 4 ){ ruleIdx.insert( 0, " " );} // pad to left with spaces (to fix string-based sorting)
627
    item->setText( 4, QString(ruleIdx.c_str()) );// Insert Id in table
628
    item->setTextAlignment (4, Qt::AlignRight);
604 629
  }
605 630

  
606 631
  addTopLevelItems( filter_items.values() );
/hometb/mk/sig/dev/r15538-patched/qgis//src/ui/qgsrulebasedrendererv2widget.ui 2011-03-20 00:48:48.341785748 +0100
51 51
       <set>AlignHCenter|AlignVCenter|AlignCenter</set>
52 52
      </property>
53 53
     </column>
54
     <column>
55
      <property name="text">
56
       <string>Priority</string>
57
      </property>
58
      <property name="textAlignment">
59
       <set>AlignHCenter|AlignVCenter|AlignCenter</set>
60
      </property>
61
     </column>
54 62
    </widget>
55 63
   </item>
56 64
   <item row="0" column="1">