Skip to content
Permalink
Browse files

Make WMS server use QgsLegendRenderer

  • Loading branch information
wonder-sk committed Sep 1, 2014
1 parent 4d0c043 commit f96484fb916e42b4a6b6f35ac29dc3ad9c8189a0
@@ -167,6 +167,9 @@ class CORE_EXPORT QgsComposerSymbolV2Item : public QgsComposerBaseSymbolItem
//! @note added in 2.6
QString ruleKey() const { return mItem.key; }

//! @note added in 2.6
const QgsLegendSymbolItemV2& itemData() const { return mItem; }

//! @note added in 2.6
static QgsComposerSymbolV2Item* findItemByRuleKey( QgsComposerLayerItem* parentLayerItem, QString ruleKey );

@@ -36,7 +36,6 @@

QgsLegendModel::QgsLegendModel()
: QStandardItemModel()
, mScaleDenominator( -1 )
, mAutoUpdate( true )
{
setColumnCount( 2 );
@@ -131,8 +130,6 @@ void QgsLegendModel::setLayerSetAndGroups( const QStringList& layerIds, const QL
void QgsLegendModel::setLayerSet( const QStringList& layerIds, double scaleDenominator, QString rule )
{
mLayerIds = layerIds;
mScaleDenominator = scaleDenominator;
mRule = rule;

//for now clear the model and add the new entries
clear();
@@ -145,6 +142,62 @@ void QgsLegendModel::setLayerSet( const QStringList& layerIds, double scaleDenom
currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *idIter );
addLayer( currentLayer, scaleDenominator, rule );
}

// filter out items where the rule is not matching - used by WMS to get symbol icon for a particular rule
if ( !rule.isEmpty() )
{
for ( int i = rowCount() - 1 ; i >= 0; --i )
{
QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( invisibleRootItem()->child( i ) );
if ( !lItem )
continue;

// remove rules that do not match
bool gotMatchingRule = false;
for ( int j = 0; j < lItem->rowCount(); ++j )
{
QgsComposerSymbolV2Item* sItem = dynamic_cast<QgsComposerSymbolV2Item*>( lItem->child( j ) );
if ( !sItem )
continue;

if ( sItem->itemData().label == rule )
{
QStandardItem* takenSItem = lItem->takeChild( j );
lItem->removeRows( 0, lItem->rowCount() );
lItem->setChild( 0, takenSItem );
gotMatchingRule = true;
break;
}
}

if ( !gotMatchingRule )
removeRow( i );
}
}

if ( scaleDenominator != -1 )
{
for ( int i = 0; i < rowCount(); ++i )
{
QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( invisibleRootItem()->child( i ) );
if ( !lItem )
continue;

for ( int j = lItem->rowCount() - 1; j >= 0; --j )
{
QgsComposerSymbolV2Item* sItem = dynamic_cast<QgsComposerSymbolV2Item*>( lItem->child( j ) );
if ( !sItem )
continue;

if ( sItem->itemData().scaleDenomMin > 0 && sItem->itemData().scaleDenomMax > 0 &&
( sItem->itemData().scaleDenomMin > scaleDenominator || sItem->itemData().scaleDenomMax < scaleDenominator ) )
{
lItem->removeRow( j );
}
}

}
}
}

QStandardItem* QgsLegendModel::addGroup( QString text, int position, QStandardItem* parentItem )
@@ -256,14 +309,17 @@ void QgsLegendModel::removeLayer( const QString& layerId )

void QgsLegendModel::addLayer( QgsMapLayer* theMapLayer, double scaleDenominator, QString rule, QStandardItem* parentItem )
{
Q_UNUSED( scaleDenominator );
Q_UNUSED( rule );

if ( !theMapLayer )
{
return;
}

if ( scaleDenominator != -1 && theMapLayer->hasScaleBasedVisibility() &&
( theMapLayer->minimumScale() > scaleDenominator || theMapLayer->maximumScale() < scaleDenominator ) )
return;

if ( !parentItem )
parentItem = invisibleRootItem();

@@ -120,8 +120,6 @@ class CORE_EXPORT QgsLegendModel : public QStandardItemModel

protected:
QStringList mLayerIds;
double mScaleDenominator;
QString mRule;
/**True if this application has toplevel windows (normally true). If this is false, this means that the application
might not have a running x-server on unix systems and so QPixmap and QIcon cannot be used*/
bool mHasTopLevelWindow;
@@ -5,7 +5,7 @@

class QgsSymbolV2;

class QgsLegendSymbolItemV2
class CORE_EXPORT QgsLegendSymbolItemV2
{
public:
QgsLegendSymbolItemV2();
@@ -23,7 +23,6 @@ class QgsLegendSymbolItemV2

int scaleDenomMin;
int scaleDenomMax;
// TODO: QString rule;
};


0 comments on commit f96484f

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