Skip to content
Permalink
Browse files

Use scale parameter to display concerned class

  • Loading branch information
Stéphane Brunner
Stéphane Brunner committed Sep 13, 2013
1 parent d8b8089 commit 0edf0d2764f20d2ca6ab4f6ee86d82e63a7259fc
@@ -286,7 +286,7 @@ void QgsComposerLayerItem::readXML( const QDomElement& itemElem, bool xServerAva
}
}

void QgsComposerLayerItem::setDefaultStyle()
void QgsComposerLayerItem::setDefaultStyle( double scaleDenominator )
{
// set default style according to number of symbols
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerID() ) );
@@ -295,7 +295,7 @@ void QgsComposerLayerItem::setDefaultStyle()
QgsFeatureRendererV2* renderer = vLayer->rendererV2();
if ( renderer )
{
QPair<QString, QgsSymbolV2*> symbolItem = renderer->legendSymbolItems().value( 0 );
QPair<QString, QgsSymbolV2*> symbolItem = renderer->legendSymbolItems( scaleDenominator ).value( 0 );
if ( renderer->legendSymbolItems().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();
void setDefaultStyle( double scaleDenominator=-1 );

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

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

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

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

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

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

QgsLegendSymbolList lst = renderer->legendSymbolItems();
QgsLegendSymbolList lst = renderer->legendSymbolItems( scaleDenominator );
QgsLegendSymbolList::const_iterator symbolIt = lst.constBegin();
int row = 0;
for ( ; symbolIt != lst.constEnd(); ++symbolIt )
@@ -454,7 +454,7 @@ void QgsLegendModel::removeLayer( const QString& layerId )
}
}

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

QList<QStandardItem *> itemsList;
@@ -482,7 +482,7 @@ void QgsLegendModel::addLayer( QgsMapLayer* theMapLayer )
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( theMapLayer );
if ( vl )
{
addVectorLayerItemsV2( layerItem, vl );
addVectorLayerItemsV2( layerItem, vl, scaleDenominator );
}
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 );
void setLayerSet( const QStringList& layerIds, double scaleDenominator=-1 );
/**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 );
void addLayer( QgsMapLayer* theMapLayer, double scaleDenominator=-1 );

signals:
void layersChanged();

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

/**Adds item of raster layer
@return 0 in case of success*/
@@ -507,7 +507,7 @@ QgsLegendSymbologyList QgsFeatureRendererV2::legendSymbologyItems( QSize iconSiz
return QgsLegendSymbologyList();
}

QgsLegendSymbolList QgsFeatureRendererV2::legendSymbolItems()
QgsLegendSymbolList QgsFeatureRendererV2::legendSymbolItems( double scaleDenominator )
{
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();
virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator=-1 );

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

QgsLegendSymbolList QgsRuleBasedRendererV2::Rule::legendSymbolItems()
QgsLegendSymbolList QgsRuleBasedRendererV2::Rule::legendSymbolItems( double scaleDenominator )
{
QgsLegendSymbolList lst;
if ( mSymbol )
@@ -184,7 +184,11 @@ QgsLegendSymbolList QgsRuleBasedRendererV2::Rule::legendSymbolItems()
for ( RuleList::iterator it = mChildren.begin(); it != mChildren.end(); ++it )
{
Rule* rule = *it;
lst << rule->legendSymbolItems();
if ( scaleDenominator == -1 || (
( rule->mScaleMinDenom == -1 || rule->mScaleMinDenom < scaleDenominator ) &&
( rule->mScaleMaxDenom == -1 || scaleDenominator < rule->mScaleMaxDenom ) ) ) {
lst << rule->legendSymbolItems( scaleDenominator );
}
}
return lst;
}
@@ -844,9 +848,9 @@ QgsLegendSymbologyList QgsRuleBasedRendererV2::legendSymbologyItems( QSize iconS
return lst;
}

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


@@ -93,7 +93,7 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
QSet<QString> usedAttributes();
QgsSymbolV2List symbols();
//! @note not available in python bindings
QgsLegendSymbolList legendSymbolItems();
QgsLegendSymbolList legendSymbolItems( double scaleDenominator=-1 );
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();
virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator=-1 );

//! for debugging
virtual QString dump() const;
@@ -334,7 +334,7 @@ QImage* QgsWMSServer::getLegendGraphics()
}

QgsLegendModel legendModel;
legendModel.setLayerSet( layerIds );
legendModel.setLayerSet( layerIds, scaleDenominator );

//create first image (to find out dpi)
QImage* theImage = createImage( 10, 10 );

0 comments on commit 0edf0d2

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