Skip to content
Permalink
Browse files

Merge patch for symbollevels in rule based renderer also to master (p…

…atch provided by Mayeul Kauffmann)
  • Loading branch information
mhugent committed Aug 19, 2011
1 parent b0b28f5 commit 9d113540971093fc9ed4dfcb9b4d46e1ac934824
@@ -347,8 +347,10 @@ QgsFeatureRendererV2* QgsFeatureRendererV2::load( QDomElement& element )

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

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

@@ -84,6 +84,10 @@ class CORE_EXPORT QgsFeatureRendererV2
bool usingSymbolLevels() const { return mUsingSymbolLevels; }
void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }

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


//! create a renderer from XML element
static QgsFeatureRendererV2* load( QDomElement& symbologyElem );

@@ -117,6 +121,7 @@ class CORE_EXPORT QgsFeatureRendererV2
QString mType;

bool mUsingSymbolLevels;
bool mUsingFirstRule;

/** The current type of editing marker */
int mCurrentVertexMarkerType;
@@ -128,8 +128,19 @@ QgsRuleBasedRendererV2::QgsRuleBasedRendererV2( QgsSymbolV2* defaultSymbol )

QgsSymbolV2* QgsRuleBasedRendererV2::symbolForFeature( QgsFeature& feature )
{
Q_UNUSED( feature );
return mCurrentSymbol;
if( ! usingFirstRule() )
return mCurrentSymbol;

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

if ( rule->isFilterOK( mCurrentFields, feature ) )
{
return rule->symbol(); //works with levels but takes only first rule
}
}
return 0;
}

void QgsRuleBasedRendererV2::renderFeature( QgsFeature& feature,
@@ -205,6 +216,10 @@ QgsFeatureRendererV2* QgsRuleBasedRendererV2::clone()
QgsSymbolV2* s = mDefaultSymbol->clone();
QgsRuleBasedRendererV2* r = new QgsRuleBasedRendererV2( s );
r->mRules = mRules;
r->setUsingSymbolLevels( usingSymbolLevels() );
r->setUsingFirstRule( usingFirstRule() );
setUsingFirstRule( usingFirstRule() );
setUsingSymbolLevels( usingSymbolLevels() );
return r;
}

@@ -224,6 +239,8 @@ QDomElement QgsRuleBasedRendererV2::save( QDomDocument& doc )
{
QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
rendererElem.setAttribute( "type", "RuleRenderer" );
rendererElem.setAttribute( "symbollevels", ( mUsingSymbolLevels ? "1" : "0" ) );
rendererElem.setAttribute( "firstrule", ( mUsingFirstRule ? "1" : "0" ) );

QDomElement rulesElem = doc.createElement( "rules" );

@@ -351,6 +368,12 @@ void QgsRuleBasedRendererV2::removeRuleAt( int index )
mRules.removeAt( index );
}

void QgsRuleBasedRendererV2::swapRules( int index1, int index2 )
{
mRules.swap( index1, index2 );
}


#include "qgscategorizedsymbolrendererv2.h"
#include "qgsgraduatedsymbolrendererv2.h"

@@ -44,7 +44,8 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
{
public:
//! Constructor takes ownership of the symbol
Rule( QgsSymbolV2* symbol, int scaleMinDenom = 0, int scaleMaxDenom = 0, QString filterExp = QString(), QString label = QString(), QString description = QString() );
Rule( QgsSymbolV2* symbol, int scaleMinDenom = 0, int scaleMaxDenom = 0, QString filterExp = QString(),
QString label = QString(), QString description = QString() );
Rule( const Rule& other );
~Rule();
QString dump() const;
@@ -130,6 +131,8 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
void updateRuleAt( int index, const Rule& rule );
//! remove the rule at the specified index
void removeRuleAt( int index );
//! swap the two rules specified by the indices
void swapRules( int index1, int index2);

//////

@@ -150,6 +153,7 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
QList<Rule*> mCurrentRules;
QgsFieldMap mCurrentFields;
QgsSymbolV2* mCurrentSymbol;

};

#endif // QGSRULEBASEDRENDERERV2_H
@@ -201,12 +201,30 @@ void QgsRendererV2PropertiesDialog::showSymbolLevels()
QgsSymbolV2List symbols = r->symbols();

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

if ( dlg.exec() )
{
r->setUsingSymbolLevels( dlg.usingLevels() );

if ( r->type() == "RuleRenderer" )
{
if( dlg.usingLevels() )
{
r->setUsingFirstRule( true );
emit forceChkUsingFirstRule();
}
else
{
emit forceUncheckSymbolLevels();
}
}
}

}


void QgsRendererV2PropertiesDialog::useOldSymbology()
{
int res = QMessageBox::question( this, tr( "Symbology" ),
@@ -34,6 +34,8 @@ class GUI_EXPORT QgsRendererV2PropertiesDialog : public QDialog, private Ui::Qgs

signals:
void useNewSymbology( bool );
void forceChkUsingFirstRule();
void forceUncheckSymbolLevels();

protected:

@@ -22,6 +22,8 @@
#include "qgsapplication.h"
#include "qgssearchtreenode.h"
#include "qgssymbolv2selectordialog.h"
#include "qgslogger.h"
#include "qstring.h"

#include <QMenu>
#include <QTreeWidgetItem>
@@ -66,17 +68,30 @@ QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* laye
btnAddRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.png" ) ) );
btnEditRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) );
btnRemoveRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.png" ) ) );
btnIncreasePriority->setIcon( QIcon( QgsApplication::iconPath( "symbologyUp.png" ) ) );
btnDecreasePriority->setIcon( QIcon( QgsApplication::iconPath( "symbologyDown.png" ) ) );

connect( treeRules, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( editRule() ) );

connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) );
connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) );
connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) );
connect( btnIncreasePriority, SIGNAL( clicked() ), this, SLOT( increasePriority() ) );
connect( btnDecreasePriority, SIGNAL( clicked() ), this, SLOT( decreasePriority() ) );

connect( radNoGrouping, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );
connect( radGroupFilter, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );
connect( radGroupScale, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );

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

treeRules->populateRules();
}

@@ -173,6 +188,99 @@ void QgsRuleBasedRendererV2Widget::removeRule()
}


void QgsRuleBasedRendererV2Widget::increasePriority()
{
QTreeWidgetItem * item = treeRules->currentItem();
if ( ! item ) return; // No rule selected, exit
int rule_index = item->data( 0, Qt::UserRole + 1 ).toInt();
if ( rule_index < 0 )
{
return;// Group of rules selected, exit
}
else
{
if ( rule_index > 0 ) // do not increase priority of first rule
{
mRenderer->swapRules(rule_index, rule_index - 1);
treeRules->populateRules();
// TODO: find out where the moved rule goes and reselect it (at least for non-grouped display)
// maybe based on the following functions :
// findItems(QString(rule_index - 1), Qt::MatchExactly, 4).first.index)
// setCurrentItem, setSelected, scrollToItem
}
}

}


void QgsRuleBasedRendererV2Widget::decreasePriority()
{
QTreeWidgetItem * item = treeRules->currentItem();
if ( ! item ) return; // No rule selected, exit
int rule_index = item->data( 0, Qt::UserRole + 1 ).toInt();
if ( rule_index < 0 )
{
return;// Group of rules selected, exit
}
else
{
if ( rule_index +1 < mRenderer->ruleCount() ) // do not increase priority of last rule
{
mRenderer->swapRules(rule_index, rule_index + 1);
treeRules->populateRules();
}
}
}


void QgsRuleBasedRendererV2Widget::usingFirstRuleChanged()
{
if ( chkUsingFirstRule->checkState() == Qt::Checked )
{
mRenderer->setUsingFirstRule(true);
}
else
{
mRenderer->setUsingFirstRule(false);
}

}


void QgsRuleBasedRendererV2Widget::forceUsingFirstRule()
{
chkEnableSymbolLevels->setChecked( true );
chkUsingFirstRule->setChecked( true );
chkUsingFirstRule->setEnabled(false);
mRenderer->setUsingFirstRule(true);
}


void QgsRuleBasedRendererV2Widget::forceNoSymbolLevels()
{
chkEnableSymbolLevels->setChecked( false );
chkUsingFirstRule->setEnabled( true );
mRenderer->setUsingSymbolLevels( false );
}


void QgsRuleBasedRendererV2Widget::symbolLevelsEnabledChanged()
{
if ( chkEnableSymbolLevels->checkState() == Qt::Checked )
{
mRenderer->setUsingSymbolLevels(true);
emit forceChkUsingFirstRule();
}
else
{
mRenderer->setUsingSymbolLevels(false);
chkUsingFirstRule->setEnabled(true);
}
}




#include "qgscategorizedsymbolrendererv2.h"
#include "qgscategorizedsymbolrendererv2widget.h"
#include "qgsgraduatedsymbolrendererv2.h"
@@ -493,6 +601,9 @@ void QgsRendererRulesTreeWidget::populateRulesNoGrouping()
//item->setBackground( 1, Qt::lightGray );
//item->setBackground( 3, Qt::lightGray );

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

@@ -557,6 +668,11 @@ void QgsRendererRulesTreeWidget::populateRulesGroupByScale()

//item->setBackground( 1, Qt::lightGray );
//item->setBackground( 3, Qt::lightGray );

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

}
addTopLevelItems( scale_items.values() );
}
@@ -608,6 +724,10 @@ void QgsRendererRulesTreeWidget::populateRulesGroupByFilter()
item->setTextAlignment( 2, Qt::AlignRight );
item->setTextAlignment( 3, Qt::AlignRight );
}

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

addTopLevelItems( filter_items.values() );
@@ -78,13 +78,24 @@ class GUI_EXPORT QgsRuleBasedRendererV2Widget : public QgsRendererV2Widget, priv
void addRule();
void editRule();
void removeRule();
void increasePriority();
void decreasePriority();

void setGrouping();

void refineRuleScales();
void refineRuleCategories();
void refineRuleRanges();

void usingFirstRuleChanged( );
void symbolLevelsEnabledChanged();
void forceNoSymbolLevels();
void forceUsingFirstRule();

signals:

void forceChkUsingFirstRule();

protected:

void refineRule( int type );

0 comments on commit 9d11354

Please sign in to comment.
You can’t perform that action at this time.