Skip to content

Commit

Permalink
Make WMS server use QgsLegendRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Sep 1, 2014
1 parent 4d0c043 commit f96484f
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 317 deletions.
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposerlegenditem.h
Expand Up @@ -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 );

Expand Down
64 changes: 60 additions & 4 deletions src/core/composer/qgslegendmodel.cpp
Expand Up @@ -36,7 +36,6 @@

QgsLegendModel::QgsLegendModel()
: QStandardItemModel()
, mScaleDenominator( -1 )
, mAutoUpdate( true )
{
setColumnCount( 2 );
Expand Down Expand Up @@ -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();
Expand All @@ -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 )
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 0 additions & 2 deletions src/core/composer/qgslegendmodel.h
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/core/symbology-ng/qgslegendsymbolitemv2.h
Expand Up @@ -5,7 +5,7 @@

class QgsSymbolV2;

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

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


Expand Down

0 comments on commit f96484f

Please sign in to comment.