Skip to content

Commit 779e166

Browse files
committed
make attribute table and identify consistent with map canvas
1 parent 59e9942 commit 779e166

24 files changed

+350
-64
lines changed

src/app/legend/qgslegend.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,24 @@ void QgsLegend::refreshLayerSymbology( QString key, bool expandItem )
21042104
setItemExpanded( theLegendLayer, expandItem );//make sure the symbology items are visible
21052105
}
21062106

2107+
void QgsLegend::refreshLayerSymbology( QString key, QgsLegendItem::Expansion expandItem )
2108+
{
2109+
bool expand = true;
2110+
if ( expandItem == QgsLegendItem::DontChange )
2111+
{
2112+
QgsLegendLayer* theLegendLayer = findLegendLayer( key );
2113+
if ( !theLegendLayer )
2114+
{
2115+
return;
2116+
}
2117+
expand = theLegendLayer->isExpanded();
2118+
}
2119+
else if ( expandItem == QgsLegendItem::Collapse )
2120+
{
2121+
expand = false;
2122+
}
2123+
return refreshLayerSymbology( key, expand );
2124+
}
21072125

21082126
void QgsLegend::addPixmapWidthValue( int width )
21092127
{

src/app/legend/qgslegend.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
#include <QPair>
2424
#include <set>
2525

26+
#include "qgslegenditem.h"
27+
2628
class QgsLegendGroup;
2729
class QgsLegendLayer;
28-
class QgsLegendItem;
2930
class QgsMapLayer;
3031
class QgsMapCanvas;
3132
class QDomDocument;
@@ -220,6 +221,7 @@ class QgsLegend : public QTreeWidget
220221

221222
/**Updates symbology items for a layer*/
222223
void refreshLayerSymbology( QString key, bool expandItem = true );
224+
void refreshLayerSymbology( QString key, QgsLegendItem::Expansion expandItem );
223225

224226
/*!
225227
* Slot called to clear the tree of all items

src/app/legend/qgslegenditem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ class QgsLegendItem : public QTreeWidgetItem, public QObject
5757
NO_ACTION //do nothing
5858
};
5959

60+
enum Expansion
61+
{
62+
Expand,
63+
Collapse,
64+
DontChange // keep current state
65+
};
66+
6067
virtual LEGEND_ITEM_TYPE type() const { return mType; }
6168

6269
/**Subclasses which allow insertion of other items may implement this method.

src/app/legend/qgslegendlayer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ void QgsLegendLayer::updateItemListCountV2( SymbologyList& itemList, QgsVectorLa
601601
layer->select( layer->pendingAllAttributesList(), QgsRectangle(), false, false );
602602
QgsFeature f;
603603

604+
// Renderer (rule based) may depend on context scale, with scale is ignored if 0
605+
QgsRenderContext renderContext;
606+
renderContext.setRendererScale( 0 );
607+
renderer->startRender( renderContext, layer );
608+
604609
while ( layer->nextFeature( f ) )
605610
{
606611
QgsSymbolV2List symbolList = renderer->symbolsForFeature( f );
@@ -622,6 +627,7 @@ void QgsLegendLayer::updateItemListCountV2( SymbologyList& itemList, QgsVectorLa
622627
}
623628
}
624629
}
630+
renderer->stopRender( renderContext );
625631
p.setValue( nFeatures );
626632

627633
QMap<QString, QPixmap> itemMap;
@@ -632,7 +638,6 @@ void QgsLegendLayer::updateItemListCountV2( SymbologyList& itemList, QgsVectorLa
632638
}
633639
itemList.clear();
634640

635-
//
636641
symbolIt = symbolList.constBegin();
637642
for ( ; symbolIt != symbolList.constEnd(); ++symbolIt )
638643
{

src/app/qgisapp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7749,7 +7749,7 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
77497749
else
77507750
{
77517751
rlp = new QgsRasterLayerProperties( ml, mMapCanvas, this );
7752-
connect( rlp, SIGNAL( refreshLegend( QString, bool ) ), mMapLegend, SLOT( refreshLayerSymbology( QString, bool ) ) );
7752+
connect( rlp, SIGNAL( refreshLegend( QString, QgsLegendItem::Expansion ) ), mMapLegend, SLOT( refreshLayerSymbology( QString, QgsLegendItem::Expansion ) ) );
77537753
}
77547754

77557755
rlp->exec();
@@ -7767,7 +7767,7 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
77677767
else
77687768
{
77697769
vlp = new QgsVectorLayerProperties( vlayer, this );
7770-
connect( vlp, SIGNAL( refreshLegend( QString, bool ) ), mMapLegend, SLOT( refreshLayerSymbology( QString, bool ) ) );
7770+
connect( vlp, SIGNAL( refreshLegend( QString, QgsLegendItem::Expansion ) ), mMapLegend, SLOT( refreshLayerSymbology( QString, QgsLegendItem::Expansion ) ) );
77717771
}
77727772

77737773
if ( vlp->exec() )

src/app/qgsmaptoolidentify.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "qgsproject.h"
3232
#include "qgsmaplayerregistry.h"
3333
#include "qgisapp.h"
34+
#include "qgsrendererv2.h"
3435

3536
#include <QSettings>
3637
#include <QMessageBox>
@@ -193,9 +194,19 @@ bool QgsMapToolIdentify::identifyLayer( QgsMapLayer *layer, int x, int y )
193194

194195
bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int y )
195196
{
196-
if ( !layer )
197+
if ( !layer || !layer->rendererV2() )
197198
return false;
198199

200+
if ( layer->hasScaleBasedVisibility() &&
201+
( layer->minimumScale() > mCanvas->mapRenderer()->scale() ||
202+
layer->maximumScale() <= mCanvas->mapRenderer()->scale() ) )
203+
{
204+
QgsDebugMsg( "Out of scale limits" );
205+
return false;
206+
}
207+
208+
QgsFeatureRendererV2* renderer = layer->rendererV2();
209+
199210
QMap< QString, QString > attributes, derivedAttributes;
200211

201212
QgsPoint point = mCanvas->getCoordinateTransform()->toMapCoordinates( x, y );
@@ -252,11 +263,21 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
252263
}
253264
QgsFeatureList::iterator f_it = featureList.begin();
254265

266+
if ( renderer->capabilities() & QgsFeatureRendererV2::ScaleDependent )
267+
{
268+
// setup scale for scale dependent visibility (rule based)
269+
renderer->startRender( *( mCanvas->mapRenderer()->rendererContext() ), layer );
270+
}
271+
bool filter = renderer->capabilities() & QgsFeatureRendererV2::Filter;
272+
255273
for ( ; f_it != featureList.end(); ++f_it )
256274
{
275+
QgsFeatureId fid = f_it->id();
276+
277+
if ( filter && !renderer->willRenderFeature( *f_it ) ) continue;
278+
257279
featureCount++;
258280

259-
QgsFeatureId fid = f_it->id();
260281
QMap<QString, QString> derivedAttributes;
261282

262283
// Calculate derived attributes and insert:
@@ -307,6 +328,11 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
307328
results()->addFeature( layer, *f_it, derivedAttributes );
308329
}
309330

331+
if ( renderer->capabilities() & QgsFeatureRendererV2::ScaleDependent )
332+
{
333+
renderer->stopRender( *( mCanvas->mapRenderer()->rendererContext() ) );
334+
}
335+
310336
QgsDebugMsg( "Feature count on identify: " + QString::number( featureCount ) );
311337

312338
return featureCount > 0;

src/app/qgsrasterlayerproperties.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,3 +1723,14 @@ void QgsRasterLayerProperties::updatePipeItems()
17231723
#endif
17241724
}
17251725
}
1726+
1727+
void QgsRasterLayerProperties::on_mMinimumScaleSetCurrentPushButton_clicked()
1728+
{
1729+
cbMinimumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapRenderer()->scale() );
1730+
}
1731+
1732+
void QgsRasterLayerProperties::on_mMaximumScaleSetCurrentPushButton_clicked()
1733+
{
1734+
cbMaximumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapRenderer()->scale() );
1735+
}
1736+

src/app/qgsrasterlayerproperties.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
9494
void on_pbnSaveStyleAs_clicked();
9595
/** Help button */
9696
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
97+
void on_mMinimumScaleSetCurrentPushButton_clicked();
98+
void on_mMaximumScaleSetCurrentPushButton_clicked();
99+
97100
/**Enable or disable Build pyramids button depending on selection in pyramids list*/
98101
void toggleBuildPyramidsButton();
99102

src/app/qgsvectorlayerproperties.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "qgslabeldialog.h"
3535
#include "qgslabelinggui.h"
3636
#include "qgslabel.h"
37+
#include "qgslegenditem.h"
3738
#include "qgsgenericprojectionselector.h"
3839
#include "qgslogger.h"
3940
#include "qgsmaplayerregistry.h"
@@ -881,15 +882,14 @@ void QgsVectorLayerProperties::apply()
881882
layer->setAbstract( mLayerAbstractTextEdit->toPlainText() );
882883

883884
// update symbology
884-
emit refreshLegend( layer->id(), false );
885+
emit refreshLegend( layer->id(), QgsLegendItem::DontChange );
885886

886887
//no need to delete the old one, maplayer will do it if needed
887888
layer->setCacheImage( 0 );
888889

889890
layer->triggerRepaint();
890891
// notify the project we've made a change
891892
QgsProject::instance()->dirty( true );
892-
893893
}
894894

895895
void QgsVectorLayerProperties::on_pbnQueryBuilder_clicked()
@@ -1378,4 +1378,12 @@ void QgsVectorLayerProperties::enableLabelOptions( bool theFlag )
13781378
labelOptionsFrame->setEnabled( theFlag );
13791379
}
13801380

1381+
void QgsVectorLayerProperties::on_mMinimumScaleSetCurrentPushButton_clicked()
1382+
{
1383+
cbMinimumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapRenderer()->scale() );
1384+
}
13811385

1386+
void QgsVectorLayerProperties::on_mMaximumScaleSetCurrentPushButton_clicked()
1387+
{
1388+
cbMaximumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapRenderer()->scale() );
1389+
}

src/app/qgsvectorlayerproperties.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgsdelattrdialog.h"
2727
#include "qgsattributetypedialog.h"
2828
#include "qgsfield.h"
29+
#include "qgslegenditem.h"
2930
#include "qgsmapcanvas.h"
3031
#include "qgscontexthelp.h"
3132
#include "qgsexpressionbuilderdialog.h"
@@ -135,10 +136,14 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
135136
void on_mButtonAddJoin_clicked();
136137
void on_mButtonRemoveJoin_clicked();
137138

139+
void on_mMinimumScaleSetCurrentPushButton_clicked();
140+
void on_mMaximumScaleSetCurrentPushButton_clicked();
141+
138142
signals:
139143

140144
/** emitted when changes to layer were saved to update legend */
141145
void refreshLegend( QString layerID, bool expandItem );
146+
void refreshLegend( QString layerID, QgsLegendItem::Expansion expandItem );
142147

143148
void toggleEditing( QgsMapLayer * );
144149

src/core/qgsmaplayer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,11 @@ class CORE_EXPORT QgsMapLayer : public QObject
342342
/** Event handler for when a coordinate transform fails due to bad vertex error */
343343
virtual void invalidTransformInput();
344344

345-
/** Accessor and mutator for the minimum scale member */
345+
/** Accessor and mutator for the minimum scale denominator member */
346346
void setMinimumScale( float theMinScale );
347347
float minimumScale();
348348

349-
/** Accessor and mutator for the maximum scale member */
349+
/** Accessor and mutator for the maximum scale denominator member */
350350
void setMaximumScale( float theMaxScale );
351351
float maximumScale();
352352

@@ -474,9 +474,9 @@ class CORE_EXPORT QgsMapLayer : public QObject
474474
/** Tag for embedding additional information */
475475
QString mTag;
476476

477-
/** Minimum scale at which this layer should be displayed */
477+
/** Minimum scale denominator at which this layer should be displayed */
478478
float mMinScale;
479-
/** Maximum scale at which this layer should be displayed */
479+
/** Maximum scale denominator at which this layer should be displayed */
480480
float mMaxScale;
481481
/** A flag that tells us whether to use the above vars to restrict layer visibility */
482482
bool mScaleBasedVisibility;

src/core/qgsmaprenderer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class CORE_EXPORT QgsMapRenderer : public QObject
136136

137137
const QgsMapToPixel* coordinateTransform() { return &( mRenderContext.mapToPixel() ); }
138138

139+
//! Scale denominator
139140
double scale() const { return mScale; }
140141
/**Sets scale for scale based visibility. Normally, the scale is calculated automatically. This
141142
function is only used to force a preview scale (e.g. for print composer)*/
@@ -288,7 +289,7 @@ class CORE_EXPORT QgsMapRenderer : public QObject
288289
//! map units per pixel
289290
double mMapUnitsPerPixel;
290291

291-
//! Map scale at its current zoom level
292+
//! Map scale denominator at its current zoom level
292293
double mScale;
293294

294295
//! scale calculator

src/core/qgsscalecalculator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ double QgsScaleCalculator::calculate( const QgsRectangle &mapExtent, int canvasW
7474
delta = calculateGeographicDistance( mapExtent );
7575
break;
7676
}
77-
QgsDebugMsg( "Using conversionFactor of " + QString::number( conversionFactor ) );
7877
if ( canvasWidth == 0 || mDpi == 0 )
7978
{
8079
QgsDebugMsg( "Can't calculate scale from the input values" );
8180
return 0;
8281
}
8382
double scale = ( delta * conversionFactor ) / (( double )canvasWidth / mDpi );
83+
QgsDebugMsg( QString( "scale = %1 conversionFactor = %2" ).arg( scale ).arg( conversionFactor ) );
8484
return scale;
8585
}
8686

src/core/qgsscalecalculator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ class CORE_EXPORT QgsScaleCalculator
6666
QGis::UnitType mapUnits() const;
6767

6868
/**
69-
* Calculate the scale
69+
* Calculate the scale denominator
7070
* @param mapExtent QgsRectangle containing the current map extent
7171
* @param canvasWidth Width of the map canvas in pixel (physical) units
72-
* @return scale of current map view
72+
* @return scale denominator of current map view
7373
*/
7474
double calculate( const QgsRectangle &mapExtent, int canvasWidth );
7575

src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ void QgsCategorizedSymbolRendererV2::rebuildHash()
159159
QgsSymbolV2* QgsCategorizedSymbolRendererV2::symbolForValue( QVariant value )
160160
{
161161
// TODO: special case for int, double
162-
163162
QHash<QString, QgsSymbolV2*>::iterator it = mSymbolHash.find( value.toString() );
164163
if ( it == mSymbolHash.end() )
165164
{
@@ -169,7 +168,7 @@ QgsSymbolV2* QgsCategorizedSymbolRendererV2::symbolForValue( QVariant value )
169168
}
170169
else
171170
{
172-
//QgsDebugMsg( "attribute value not found: " + value.toString() );
171+
QgsDebugMsg( "attribute value not found: " + value.toString() );
173172
}
174173
return NULL;
175174
}
@@ -192,7 +191,12 @@ QgsSymbolV2* QgsCategorizedSymbolRendererV2::symbolForFeature( QgsFeature& featu
192191
if ( symbol == NULL )
193192
{
194193
// if no symbol found use default one
195-
return symbolForValue( QVariant( "" ) );
194+
//return symbolForValue( QVariant( "" ) );
195+
// What is default? Empty string may be a legal value, and features not found
196+
// should not be rendered using empty string value category symbology.
197+
// We also need to get NULL in that case so that willRenderFeature()
198+
// may be used to count features.
199+
return 0;
196200
}
197201

198202
if ( mRotationFieldIdx == -1 && mSizeScaleFieldIdx == -1 )
@@ -600,7 +604,7 @@ void QgsCategorizedSymbolRendererV2::setSourceColorRamp( QgsVectorColorRampV2* r
600604
void QgsCategorizedSymbolRendererV2::updateSymbols( QgsSymbolV2 * sym )
601605
{
602606
int i = 0;
603-
foreach( QgsRendererCategoryV2 cat, mCategories )
607+
foreach ( QgsRendererCategoryV2 cat, mCategories )
604608
{
605609
QgsSymbolV2* symbol = sym->clone();
606610
symbol->setColor( cat.symbol()->color() );

src/core/symbology-ng/qgscategorizedsymbolrendererv2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2
8181

8282
//! returns bitwise OR-ed capabilities of the renderer
8383
//! \note added in 2.0
84-
virtual int capabilities() { return SymbolLevels | RotationField; }
84+
virtual int capabilities() { return SymbolLevels | RotationField | Filter; }
8585

8686
virtual QgsSymbolV2List symbols();
8787
//! @note added in 2.0

src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
7676

7777
//! returns bitwise OR-ed capabilities of the renderer
7878
//! \note added in 2.0
79-
virtual int capabilities() { return SymbolLevels | RotationField; }
79+
virtual int capabilities() { return SymbolLevels | RotationField | Filter; }
8080

8181
virtual QgsSymbolV2List symbols();
8282

0 commit comments

Comments
 (0)