Skip to content

Commit f96484f

Browse files
committed
Make WMS server use QgsLegendRenderer
1 parent 4d0c043 commit f96484f

File tree

6 files changed

+137
-317
lines changed

6 files changed

+137
-317
lines changed

src/core/composer/qgscomposerlegenditem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ class CORE_EXPORT QgsComposerSymbolV2Item : public QgsComposerBaseSymbolItem
167167
//! @note added in 2.6
168168
QString ruleKey() const { return mItem.key; }
169169

170+
//! @note added in 2.6
171+
const QgsLegendSymbolItemV2& itemData() const { return mItem; }
172+
170173
//! @note added in 2.6
171174
static QgsComposerSymbolV2Item* findItemByRuleKey( QgsComposerLayerItem* parentLayerItem, QString ruleKey );
172175

src/core/composer/qgslegendmodel.cpp

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
QgsLegendModel::QgsLegendModel()
3838
: QStandardItemModel()
39-
, mScaleDenominator( -1 )
4039
, mAutoUpdate( true )
4140
{
4241
setColumnCount( 2 );
@@ -131,8 +130,6 @@ void QgsLegendModel::setLayerSetAndGroups( const QStringList& layerIds, const QL
131130
void QgsLegendModel::setLayerSet( const QStringList& layerIds, double scaleDenominator, QString rule )
132131
{
133132
mLayerIds = layerIds;
134-
mScaleDenominator = scaleDenominator;
135-
mRule = rule;
136133

137134
//for now clear the model and add the new entries
138135
clear();
@@ -145,6 +142,62 @@ void QgsLegendModel::setLayerSet( const QStringList& layerIds, double scaleDenom
145142
currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *idIter );
146143
addLayer( currentLayer, scaleDenominator, rule );
147144
}
145+
146+
// filter out items where the rule is not matching - used by WMS to get symbol icon for a particular rule
147+
if ( !rule.isEmpty() )
148+
{
149+
for ( int i = rowCount() - 1 ; i >= 0; --i )
150+
{
151+
QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( invisibleRootItem()->child( i ) );
152+
if ( !lItem )
153+
continue;
154+
155+
// remove rules that do not match
156+
bool gotMatchingRule = false;
157+
for ( int j = 0; j < lItem->rowCount(); ++j )
158+
{
159+
QgsComposerSymbolV2Item* sItem = dynamic_cast<QgsComposerSymbolV2Item*>( lItem->child( j ) );
160+
if ( !sItem )
161+
continue;
162+
163+
if ( sItem->itemData().label == rule )
164+
{
165+
QStandardItem* takenSItem = lItem->takeChild( j );
166+
lItem->removeRows( 0, lItem->rowCount() );
167+
lItem->setChild( 0, takenSItem );
168+
gotMatchingRule = true;
169+
break;
170+
}
171+
}
172+
173+
if ( !gotMatchingRule )
174+
removeRow( i );
175+
}
176+
}
177+
178+
if ( scaleDenominator != -1 )
179+
{
180+
for ( int i = 0; i < rowCount(); ++i )
181+
{
182+
QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( invisibleRootItem()->child( i ) );
183+
if ( !lItem )
184+
continue;
185+
186+
for ( int j = lItem->rowCount() - 1; j >= 0; --j )
187+
{
188+
QgsComposerSymbolV2Item* sItem = dynamic_cast<QgsComposerSymbolV2Item*>( lItem->child( j ) );
189+
if ( !sItem )
190+
continue;
191+
192+
if ( sItem->itemData().scaleDenomMin > 0 && sItem->itemData().scaleDenomMax > 0 &&
193+
( sItem->itemData().scaleDenomMin > scaleDenominator || sItem->itemData().scaleDenomMax < scaleDenominator ) )
194+
{
195+
lItem->removeRow( j );
196+
}
197+
}
198+
199+
}
200+
}
148201
}
149202

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

257310
void QgsLegendModel::addLayer( QgsMapLayer* theMapLayer, double scaleDenominator, QString rule, QStandardItem* parentItem )
258311
{
259-
Q_UNUSED( scaleDenominator );
260312
Q_UNUSED( rule );
261313

262314
if ( !theMapLayer )
263315
{
264316
return;
265317
}
266318

319+
if ( scaleDenominator != -1 && theMapLayer->hasScaleBasedVisibility() &&
320+
( theMapLayer->minimumScale() > scaleDenominator || theMapLayer->maximumScale() < scaleDenominator ) )
321+
return;
322+
267323
if ( !parentItem )
268324
parentItem = invisibleRootItem();
269325

src/core/composer/qgslegendmodel.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ class CORE_EXPORT QgsLegendModel : public QStandardItemModel
120120

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

src/core/symbology-ng/qgslegendsymbolitemv2.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class QgsSymbolV2;
77

8-
class QgsLegendSymbolItemV2
8+
class CORE_EXPORT QgsLegendSymbolItemV2
99
{
1010
public:
1111
QgsLegendSymbolItemV2();
@@ -23,7 +23,6 @@ class QgsLegendSymbolItemV2
2323

2424
int scaleDenomMin;
2525
int scaleDenomMax;
26-
// TODO: QString rule;
2726
};
2827

2928

0 commit comments

Comments
 (0)