Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbol levels in Rule-Based renderer #3

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsrendererv2.cpp
Expand Up @@ -348,7 +348,7 @@ 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() );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use scripts/prepare-commit.sh please and add braces here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jef,
Following your comments on indentation in my patch, I tried to use
prepare-commit.sh for more than one hour in vain. When applied after git
commit it says nothing has changed (in effect, after commit, my working
copy is ahead). So I created a new branch locally to restart from
scratch, reapplied my patch, tried the script, in vain again. The best I
get is:
"Unable to determine upstream SVN information from working tree history"

The only help I could find is a few lines on the following page:
http://www.qgis.org/wiki/Developers_Manual#Coding_Style

"There is a scripts/prepare-commit.sh that looks up the changed files
and reindents them using astyle. This should be run before committing.
As newer versions of astyle indent differently than the version used to
do a complete reindentation of the source, the script uses an old astyle
version, that we include in our repository."

I had to guess by reading the source code of the script that I needed to
install flip (and astyle?), and pass the path to the project as first
parameter, but I could not find any documentation on this. Should the
script be run form the root folder? Should I install astyle or not? (the
comment above on the astyle versions puzzles me).

Finally the following command took 10 minutes:
cd /hometb/mk/sig/dev/release-1_7_0-4May/Quantum-GIS
./scrips/prepare-commit.sh .
before telling me:
"Unable to determine upstream SVN information from working tree history"

I tried from several places with relative or absolute path, in vain.

So I tried to follow this advice on the same wiki:
"There is a .indent.pro file in the QGIS src directory that contains the
switches to be used when indenting code using the GNU indent program. If
you don't use GNU indent, you should emulate these settings."

So I installed GNU indent... but could not find the .indent.pro file in
the QGIS src directory. What indent options should I use?

If I cannot make scrips/prepare-commit.sh work, I do not mind formatting
my code manually, but which guidelines? The manual only says "Tab
spacing should be set to 2 spaces" and "Braces should start on the line
following the expression", which I tried to follow.
I do not mind to try and "emulate these settings", if I know where to
look for.

Still, thank you jef for you comments on coding style and other hints.
Could you please give me some hints on how to solve the above
indentation problem?

Thanks a lot in advance!

Mayeul

jef-n wrote at https://github.com/qgis/Quantum-GIS/pull/3/files#r26150 :

@@ -348,7 +348,7 @@ 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() );

use scripts/prepare-commit.sh please and braces here.

See also:

http://osgeo-org.1803224.n2.nabble.com/indentation-scripts-td3194208.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • prepare-commit.sh was not working on pure git trees yet. should be fixed in jef-n@4d480fc#diff-5
  • as the name suggests it should be run before commiting.
  • flip is optional and is replaced by a nop if it's not available.
  • our version of astyle is built in scripts/
  • prepare-commit.sh or better astyle.sh have all the options.

return r;
}

Expand Down
5 changes: 5 additions & 0 deletions src/core/symbology-ng/qgsrendererv2.h
Expand Up @@ -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 );

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

bool mUsingSymbolLevels;
bool mUsingFirstRule;

/** The current type of editing marker */
int mCurrentVertexMarkerType;
Expand Down
25 changes: 24 additions & 1 deletion src/core/symbology-ng/qgsrulebasedrendererv2.cpp
Expand Up @@ -128,7 +128,18 @@ QgsRuleBasedRendererV2::QgsRuleBasedRendererV2( QgsSymbolV2* defaultSymbol )

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

if( !( usingFirstRule() ) ) return mCurrentSymbol;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove one level of parens and add a newline.


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
}
}
}

void QgsRuleBasedRendererV2::renderFeature( QgsFeature& feature,
Expand Down Expand Up @@ -200,6 +211,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;
}

Expand All @@ -219,6 +234,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" );

Expand Down Expand Up @@ -346,6 +363,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"

Expand Down
6 changes: 5 additions & 1 deletion src/core/symbology-ng/qgsrulebasedrendererv2.h
Expand Up @@ -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;
Expand Down Expand Up @@ -127,6 +128,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);

//////

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

};

#endif // QGSRULEBASEDRENDERERV2_H
18 changes: 18 additions & 0 deletions src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp
Expand Up @@ -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" ),
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgsrendererv2propertiesdialog.h
Expand Up @@ -34,6 +34,8 @@ class GUI_EXPORT QgsRendererV2PropertiesDialog : public QDialog, private Ui::Qgs

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

protected:

Expand Down
134 changes: 134 additions & 0 deletions src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp
Expand Up @@ -22,11 +22,14 @@
#include "qgsapplication.h"
#include "qgssearchtreenode.h"
#include "qgssymbolv2selectordialog.h"
#include "qgslogger.h"
#include "qstring.h"

#include <QMenu>
#include <QTreeWidgetItem>
#include <QVBoxLayout>
#include <QMessageBox>
#include <sstream>

QgsRendererV2Widget* QgsRuleBasedRendererV2Widget::create( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
{
Expand Down Expand Up @@ -66,17 +69,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();
}

Expand Down Expand Up @@ -171,6 +187,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"
Expand Down Expand Up @@ -487,7 +596,15 @@ void QgsRendererRulesTreeWidget::populateRulesNoGrouping()
//item->setBackground( 1, Qt::lightGray );
//item->setBackground( 3, Qt::lightGray );

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

}


Expand Down Expand Up @@ -550,6 +667,15 @@ void QgsRendererRulesTreeWidget::populateRulesGroupByScale()

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

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

}
addTopLevelItems( scale_items.values() );
}
Expand Down Expand Up @@ -601,6 +727,14 @@ void QgsRendererRulesTreeWidget::populateRulesGroupByFilter()
item->setTextAlignment( 2, Qt::AlignRight );
item->setTextAlignment( 3, Qt::AlignRight );
}

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

addTopLevelItems( filter_items.values() );
Expand Down
11 changes: 11 additions & 0 deletions src/gui/symbology-ng/qgsrulebasedrendererv2widget.h
Expand Up @@ -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 );
Expand Down