Skip to content
Permalink
Browse files

Merge pull request #901 from sbrunner/legend-rule

[qgis server] Add RULE parameter support in GetLegendGraphic
  • Loading branch information
mhugent committed Oct 21, 2013
2 parents 0f82df1 + 91c8a3c commit c777dc6de9add9499347a1613dc1498f524bb092
@@ -286,7 +286,7 @@ void QgsComposerLayerItem::readXML( const QDomElement& itemElem, bool xServerAva
}
}

void QgsComposerLayerItem::setDefaultStyle( double scaleDenominator )
void QgsComposerLayerItem::setDefaultStyle( double scaleDenominator, QString rule )
{
// set default style according to number of symbols
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerID() ) );
@@ -295,8 +295,8 @@ void QgsComposerLayerItem::setDefaultStyle( double scaleDenominator )
QgsFeatureRendererV2* renderer = vLayer->rendererV2();
if ( renderer )
{
QPair<QString, QgsSymbolV2*> symbolItem = renderer->legendSymbolItems( scaleDenominator ).value( 0 );
if ( renderer->legendSymbolItems().size() > 1 || !symbolItem.first.isEmpty() )
QPair<QString, QgsSymbolV2*> symbolItem = renderer->legendSymbolItems( scaleDenominator, rule ).value( 0 );
if ( renderer->legendSymbolItems( scaleDenominator, rule ).size() > 1 || !symbolItem.first.isEmpty() )
{
setStyle( QgsComposerLegendStyle::Subgroup );
}
@@ -138,7 +138,7 @@ class CORE_EXPORT QgsComposerLayerItem : public QgsComposerLegendItem
void setShowFeatureCount( bool show ) { mShowFeatureCount = show; }
bool showFeatureCount() const { return mShowFeatureCount; }

void setDefaultStyle( double scaleDenominator = -1 );
void setDefaultStyle( double scaleDenominator = -1, QString rule = "" );

private:
QString mLayerID;
@@ -98,7 +98,7 @@ void QgsLegendModel::setLayerSetAndGroups( const QStringList& layerIds, const QL
}
}

void QgsLegendModel::setLayerSet( const QStringList& layerIds, double scaleDenominator )
void QgsLegendModel::setLayerSet( const QStringList& layerIds, double scaleDenominator, QString rule )
{
mLayerIds = layerIds;

@@ -111,7 +111,7 @@ void QgsLegendModel::setLayerSet( const QStringList& layerIds, double scaleDenom
for ( ; idIter != mLayerIds.constEnd(); ++idIter )
{
currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *idIter );
addLayer( currentLayer, scaleDenominator );
addLayer( currentLayer, scaleDenominator, rule );
}
}

@@ -135,7 +135,7 @@ QStandardItem* QgsLegendModel::addGroup( QString text, int position )
return groupItem;
}

int QgsLegendModel::addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLayer* vlayer, double scaleDenominator )
int QgsLegendModel::addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLayer* vlayer, double scaleDenominator, QString rule )
{
QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( layerItem );

@@ -158,12 +158,12 @@ int QgsLegendModel::addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLa
}
}

QgsLegendSymbolList lst = renderer->legendSymbolItems( scaleDenominator );
QgsLegendSymbolList lst = renderer->legendSymbolItems( scaleDenominator, rule );
QgsLegendSymbolList::const_iterator symbolIt = lst.constBegin();
int row = 0;
for ( ; symbolIt != lst.constEnd(); ++symbolIt )
{
if ( scaleDenominator == -1 )
if ( scaleDenominator == -1 && rule.isEmpty() )
{
QgsComposerSymbolV2Item* currentSymbolItem = new QgsComposerSymbolV2Item( "" );

@@ -187,20 +187,24 @@ int QgsLegendModel::addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLa

// updateSymbolV2ItemText needs layer set
updateSymbolV2ItemText( currentSymbolItem );

row++;
}
else
{
QgsComposerSymbolV2Item* currentSymbolItem = new QgsComposerSymbolV2Item( "" );
currentSymbolItem->setIcon( QgsSymbolLayerV2Utils::symbolPreviewIcon( symbolIt->second, QSize( 30, 30 ) ) );
if ( mHasTopLevelWindow ) //only use QIcon / QPixmap if we have a running x-server
{
currentSymbolItem->setIcon( QgsSymbolLayerV2Utils::symbolPreviewIcon( symbolIt->second, QSize( 30, 30 ) ) );
}
currentSymbolItem->setSymbolV2( symbolIt->second );
layerItem->setChild( 0, 0, currentSymbolItem );
layerItem->setChild( row, 0, currentSymbolItem );
currentSymbolItem->setText( symbolIt->first );
}

row++;
}

if ( scaleDenominator == -1 )
// Don't remove row on getLegendGraphic (read only with filter)
if ( scaleDenominator == -1 && rule.isEmpty() )
{
// Delete following old items (if current number of items decreased)
for ( int i = layerItem->rowCount() - 1; i >= row; --i )
@@ -467,7 +471,7 @@ void QgsLegendModel::removeLayer( const QString& layerId )
}
}

void QgsLegendModel::addLayer( QgsMapLayer* theMapLayer, double scaleDenominator )
void QgsLegendModel::addLayer( QgsMapLayer* theMapLayer, double scaleDenominator, QString rule )
{
if ( !theMapLayer )
{
@@ -481,7 +485,7 @@ void QgsLegendModel::addLayer( QgsMapLayer* theMapLayer, double scaleDenominator
layerItem->setUserText( theMapLayer->title() );
}
layerItem->setLayerID( theMapLayer->id() );
layerItem->setDefaultStyle( scaleDenominator );
layerItem->setDefaultStyle( scaleDenominator, rule );
layerItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );

QList<QStandardItem *> itemsList;
@@ -495,7 +499,7 @@ void QgsLegendModel::addLayer( QgsMapLayer* theMapLayer, double scaleDenominator
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( theMapLayer );
if ( vl )
{
addVectorLayerItemsV2( layerItem, vl, scaleDenominator );
addVectorLayerItemsV2( layerItem, vl, scaleDenominator, rule );
}
break;
}
@@ -54,7 +54,7 @@ class CORE_EXPORT QgsLegendModel: public QStandardItemModel

/**Sets layer set and groups*/
void setLayerSetAndGroups( const QStringList& layerIds, const QList< GroupLayerInfo >& groupInfo );
void setLayerSet( const QStringList& layerIds, double scaleDenominator = -1 );
void setLayerSet( const QStringList& layerIds, double scaleDenominator = -1, QString rule = "" );
/**Adds a group
@param text name of group (defaults to translation of "Group")
@param position insertion position (toplevel position (or -1 if it should be placed at the end of the legend).
@@ -97,14 +97,14 @@ class CORE_EXPORT QgsLegendModel: public QStandardItemModel

public slots:
void removeLayer( const QString& layerId );
void addLayer( QgsMapLayer* theMapLayer, double scaleDenominator = -1 );
void addLayer( QgsMapLayer* theMapLayer, double scaleDenominator = -1, QString rule="" );

signals:
void layersChanged();

private:
/**Adds classification items of vector layers using new symbology*/
int addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLayer* vlayer, double scaleDenominator = -1 );
int addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLayer* vlayer, double scaleDenominator = -1, QString rule = "" );

/**Adds item of raster layer
@return 0 in case of success*/
@@ -635,7 +635,7 @@ QgsLegendSymbologyList QgsCategorizedSymbolRendererV2::legendSymbologyItems( QSi
return lst;
}

QgsLegendSymbolList QgsCategorizedSymbolRendererV2::legendSymbolItems( double scaleDenominator )
QgsLegendSymbolList QgsCategorizedSymbolRendererV2::legendSymbolItems( double scaleDenominator, QString rule )
{
Q_UNUSED( scaleDenominator );
QSettings settings;
@@ -649,7 +649,10 @@ QgsLegendSymbolList QgsCategorizedSymbolRendererV2::legendSymbolItems( double sc

foreach ( const QgsRendererCategoryV2& cat, mCategories )
{
lst << qMakePair( cat.label(), cat.symbol() );
if ( rule.isEmpty() || cat.label() == rule )
{
lst << qMakePair( cat.label(), cat.symbol() );
}
}
return lst;
}
@@ -125,7 +125,7 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2
//! return a list of item text / symbol
//! @note: this method was added in version 1.5
//! @note not available in python bindings
virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1 );
virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );

QgsSymbolV2* sourceSymbol();
void setSourceSymbol( QgsSymbolV2* sym );
@@ -1095,7 +1095,7 @@ QgsLegendSymbologyList QgsGraduatedSymbolRendererV2::legendSymbologyItems( QSize
return lst;
}

QgsLegendSymbolList QgsGraduatedSymbolRendererV2::legendSymbolItems( double scaleDenominator )
QgsLegendSymbolList QgsGraduatedSymbolRendererV2::legendSymbolItems( double scaleDenominator, QString rule )
{
Q_UNUSED( scaleDenominator );
QSettings settings;
@@ -1109,16 +1109,19 @@ QgsLegendSymbolList QgsGraduatedSymbolRendererV2::legendSymbolItems( double scal

foreach ( const QgsRendererRangeV2& range, mRanges )
{
QgsSymbolV2* symbol;
if ( mRotationFieldIdx == -1 && mSizeScaleFieldIdx == -1 )
if ( rule.isEmpty() || range.label() == rule )
{
symbol = range.symbol();
}
else
{
symbol = mTempSymbols[range.symbol()];
QgsSymbolV2* symbol;
if ( mRotationFieldIdx == -1 && mSizeScaleFieldIdx == -1 )
{
symbol = range.symbol();
}
else
{
symbol = mTempSymbols[range.symbol()];
}
lst << qMakePair( range.label(), symbol );
}
lst << qMakePair( range.label(), symbol );
}
return lst;
}
@@ -137,7 +137,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
//! return a list of item text / symbol
//! @note: this method was added in version 1.5
//! @note not available in python bindings
virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1 );
virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );

QgsSymbolV2* sourceSymbol();
void setSourceSymbol( QgsSymbolV2* sym );
@@ -330,11 +330,11 @@ QgsLegendSymbologyList QgsPointDisplacementRenderer::legendSymbologyItems( QSize
return QgsLegendSymbologyList();
}

QgsLegendSymbolList QgsPointDisplacementRenderer::legendSymbolItems()
QgsLegendSymbolList QgsPointDisplacementRenderer::legendSymbolItems( double scaleDenominator, QString rule )
{
if ( mRenderer )
{
return mRenderer->legendSymbolItems();
return mRenderer->legendSymbolItems( scaleDenominator, rule );
}
return QgsLegendSymbolList();
}
@@ -57,7 +57,7 @@ class CORE_EXPORT QgsPointDisplacementRenderer: public QgsFeatureRendererV2
QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );

//! @note not available in python bindings
QgsLegendSymbolList legendSymbolItems();
QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );

void setLabelAttributeName( const QString& name ) { mLabelAttributeName = name; }
QString labelAttributeName() const { return mLabelAttributeName; }
@@ -507,9 +507,10 @@ QgsLegendSymbologyList QgsFeatureRendererV2::legendSymbologyItems( QSize iconSiz
return QgsLegendSymbologyList();
}

QgsLegendSymbolList QgsFeatureRendererV2::legendSymbolItems( double scaleDenominator )
QgsLegendSymbolList QgsFeatureRendererV2::legendSymbolItems( double scaleDenominator, QString rule )
{
Q_UNUSED( scaleDenominator );
Q_UNUSED( rule );
return QgsLegendSymbolList();
}

@@ -149,7 +149,7 @@ class CORE_EXPORT QgsFeatureRendererV2
//! return a list of item text / symbol
//! @note: this method was added in version 1.5
//! @note: not available in python bindings
virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1 );
virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );

//! set type and size of editing vertex markers for subsequent rendering
void setVertexMarkerAppearance( int type, int size );
@@ -175,20 +175,17 @@ void QgsRuleBasedRendererV2::Rule::setSymbol( QgsSymbolV2* sym )
mSymbol = sym;
}

QgsLegendSymbolList QgsRuleBasedRendererV2::Rule::legendSymbolItems( double scaleDenominator )
QgsLegendSymbolList QgsRuleBasedRendererV2::Rule::legendSymbolItems( double scaleDenominator, QString ruleFilter )
{
QgsLegendSymbolList lst;
if ( mSymbol )
if ( mSymbol && ( ruleFilter.isEmpty() || mLabel == ruleFilter ) )
lst << qMakePair( mLabel, mSymbol );

for ( RuleList::iterator it = mChildren.begin(); it != mChildren.end(); ++it )
{
Rule* rule = *it;
if ( scaleDenominator == -1 || (
( rule->mScaleMinDenom == -1 || rule->mScaleMinDenom < scaleDenominator ) &&
( rule->mScaleMaxDenom == -1 || scaleDenominator < rule->mScaleMaxDenom ) ) )
{
lst << rule->legendSymbolItems( scaleDenominator );
if ( scaleDenominator == -1 || rule->isScaleOK(scaleDenominator) ) {
lst << rule->legendSymbolItems( scaleDenominator, ruleFilter );
}
}
return lst;
@@ -849,9 +846,9 @@ QgsLegendSymbologyList QgsRuleBasedRendererV2::legendSymbologyItems( QSize iconS
return lst;
}

QgsLegendSymbolList QgsRuleBasedRendererV2::legendSymbolItems( double scaleDenominator )
QgsLegendSymbolList QgsRuleBasedRendererV2::legendSymbolItems( double scaleDenominator, QString rule )
{
return mRootRule->legendSymbolItems( scaleDenominator );
return mRootRule->legendSymbolItems( scaleDenominator, rule );
}


@@ -93,7 +93,7 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
QSet<QString> usedAttributes();
QgsSymbolV2List symbols();
//! @note not available in python bindings
QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1 );
QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );
bool isFilterOK( QgsFeature& f ) const;
bool isScaleOK( double scale ) const;

@@ -226,7 +226,7 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
//! return a list of item text / symbol
//! @note: this method was added in version 1.5
//! @note not available in python bindings
virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1 );
virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );

//! for debugging
virtual QString dump() const;
@@ -373,9 +373,10 @@ QgsLegendSymbologyList QgsSingleSymbolRendererV2::legendSymbologyItems( QSize ic
return lst;
}

QgsLegendSymbolList QgsSingleSymbolRendererV2::legendSymbolItems( double scaleDenominator )
QgsLegendSymbolList QgsSingleSymbolRendererV2::legendSymbolItems( double scaleDenominator, QString rule )
{
Q_UNUSED( scaleDenominator );
Q_UNUSED( rule );
QgsLegendSymbolList lst;
lst << qMakePair( QString(), mSymbol );
return lst;
@@ -78,7 +78,7 @@ class CORE_EXPORT QgsSingleSymbolRendererV2 : public QgsFeatureRendererV2
//! return a list of item text / symbol
//! @note: this method was added in version 1.5
//! @note not available in python bindings
virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1 );
virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );

protected:
QgsSymbolV2* mSymbol;
@@ -318,7 +318,7 @@ void QgsLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<

void QgsFillSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size )
{
QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width() - 1, size.height() - 1 ) );
QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width(), size.height() ) );
startRender( context );
renderPolygon( poly, NULL, context );
stopRender( context );

0 comments on commit c777dc6

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