Skip to content

Commit

Permalink
make attribute table and identify consistent with map canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Oct 26, 2012
1 parent 59e9942 commit 779e166
Show file tree
Hide file tree
Showing 24 changed files with 350 additions and 64 deletions.
18 changes: 18 additions & 0 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -2104,6 +2104,24 @@ void QgsLegend::refreshLayerSymbology( QString key, bool expandItem )
setItemExpanded( theLegendLayer, expandItem );//make sure the symbology items are visible
}

void QgsLegend::refreshLayerSymbology( QString key, QgsLegendItem::Expansion expandItem )
{
bool expand = true;
if ( expandItem == QgsLegendItem::DontChange )
{
QgsLegendLayer* theLegendLayer = findLegendLayer( key );
if ( !theLegendLayer )
{
return;
}
expand = theLegendLayer->isExpanded();
}
else if ( expandItem == QgsLegendItem::Collapse )
{
expand = false;
}
return refreshLayerSymbology( key, expand );
}

void QgsLegend::addPixmapWidthValue( int width )
{
Expand Down
4 changes: 3 additions & 1 deletion src/app/legend/qgslegend.h
Expand Up @@ -23,9 +23,10 @@
#include <QPair>
#include <set>

#include "qgslegenditem.h"

class QgsLegendGroup;
class QgsLegendLayer;
class QgsLegendItem;
class QgsMapLayer;
class QgsMapCanvas;
class QDomDocument;
Expand Down Expand Up @@ -220,6 +221,7 @@ class QgsLegend : public QTreeWidget

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

/*!
* Slot called to clear the tree of all items
Expand Down
7 changes: 7 additions & 0 deletions src/app/legend/qgslegenditem.h
Expand Up @@ -57,6 +57,13 @@ class QgsLegendItem : public QTreeWidgetItem, public QObject
NO_ACTION //do nothing
};

enum Expansion
{
Expand,
Collapse,
DontChange // keep current state
};

virtual LEGEND_ITEM_TYPE type() const { return mType; }

/**Subclasses which allow insertion of other items may implement this method.
Expand Down
7 changes: 6 additions & 1 deletion src/app/legend/qgslegendlayer.cpp
Expand Up @@ -601,6 +601,11 @@ void QgsLegendLayer::updateItemListCountV2( SymbologyList& itemList, QgsVectorLa
layer->select( layer->pendingAllAttributesList(), QgsRectangle(), false, false );
QgsFeature f;

// Renderer (rule based) may depend on context scale, with scale is ignored if 0
QgsRenderContext renderContext;
renderContext.setRendererScale( 0 );
renderer->startRender( renderContext, layer );

while ( layer->nextFeature( f ) )
{
QgsSymbolV2List symbolList = renderer->symbolsForFeature( f );
Expand All @@ -622,6 +627,7 @@ void QgsLegendLayer::updateItemListCountV2( SymbologyList& itemList, QgsVectorLa
}
}
}
renderer->stopRender( renderContext );
p.setValue( nFeatures );

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

//
symbolIt = symbolList.constBegin();
for ( ; symbolIt != symbolList.constEnd(); ++symbolIt )
{
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -7749,7 +7749,7 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
else
{
rlp = new QgsRasterLayerProperties( ml, mMapCanvas, this );
connect( rlp, SIGNAL( refreshLegend( QString, bool ) ), mMapLegend, SLOT( refreshLayerSymbology( QString, bool ) ) );
connect( rlp, SIGNAL( refreshLegend( QString, QgsLegendItem::Expansion ) ), mMapLegend, SLOT( refreshLayerSymbology( QString, QgsLegendItem::Expansion ) ) );
}

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

if ( vlp->exec() )
Expand Down
30 changes: 28 additions & 2 deletions src/app/qgsmaptoolidentify.cpp
Expand Up @@ -31,6 +31,7 @@
#include "qgsproject.h"
#include "qgsmaplayerregistry.h"
#include "qgisapp.h"
#include "qgsrendererv2.h"

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

bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int y )
{
if ( !layer )
if ( !layer || !layer->rendererV2() )
return false;

if ( layer->hasScaleBasedVisibility() &&
( layer->minimumScale() > mCanvas->mapRenderer()->scale() ||
layer->maximumScale() <= mCanvas->mapRenderer()->scale() ) )
{
QgsDebugMsg( "Out of scale limits" );
return false;
}

QgsFeatureRendererV2* renderer = layer->rendererV2();

QMap< QString, QString > attributes, derivedAttributes;

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

if ( renderer->capabilities() & QgsFeatureRendererV2::ScaleDependent )
{
// setup scale for scale dependent visibility (rule based)
renderer->startRender( *( mCanvas->mapRenderer()->rendererContext() ), layer );
}
bool filter = renderer->capabilities() & QgsFeatureRendererV2::Filter;

for ( ; f_it != featureList.end(); ++f_it )
{
QgsFeatureId fid = f_it->id();

if ( filter && !renderer->willRenderFeature( *f_it ) ) continue;

featureCount++;

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

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

if ( renderer->capabilities() & QgsFeatureRendererV2::ScaleDependent )
{
renderer->stopRender( *( mCanvas->mapRenderer()->rendererContext() ) );
}

QgsDebugMsg( "Feature count on identify: " + QString::number( featureCount ) );

return featureCount > 0;
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -1723,3 +1723,14 @@ void QgsRasterLayerProperties::updatePipeItems()
#endif
}
}

void QgsRasterLayerProperties::on_mMinimumScaleSetCurrentPushButton_clicked()
{
cbMinimumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapRenderer()->scale() );
}

void QgsRasterLayerProperties::on_mMaximumScaleSetCurrentPushButton_clicked()
{
cbMaximumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapRenderer()->scale() );
}

3 changes: 3 additions & 0 deletions src/app/qgsrasterlayerproperties.h
Expand Up @@ -94,6 +94,9 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
void on_pbnSaveStyleAs_clicked();
/** Help button */
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
void on_mMinimumScaleSetCurrentPushButton_clicked();
void on_mMaximumScaleSetCurrentPushButton_clicked();

/**Enable or disable Build pyramids button depending on selection in pyramids list*/
void toggleBuildPyramidsButton();

Expand Down
12 changes: 10 additions & 2 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -34,6 +34,7 @@
#include "qgslabeldialog.h"
#include "qgslabelinggui.h"
#include "qgslabel.h"
#include "qgslegenditem.h"
#include "qgsgenericprojectionselector.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
Expand Down Expand Up @@ -881,15 +882,14 @@ void QgsVectorLayerProperties::apply()
layer->setAbstract( mLayerAbstractTextEdit->toPlainText() );

// update symbology
emit refreshLegend( layer->id(), false );
emit refreshLegend( layer->id(), QgsLegendItem::DontChange );

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

layer->triggerRepaint();
// notify the project we've made a change
QgsProject::instance()->dirty( true );

}

void QgsVectorLayerProperties::on_pbnQueryBuilder_clicked()
Expand Down Expand Up @@ -1378,4 +1378,12 @@ void QgsVectorLayerProperties::enableLabelOptions( bool theFlag )
labelOptionsFrame->setEnabled( theFlag );
}

void QgsVectorLayerProperties::on_mMinimumScaleSetCurrentPushButton_clicked()
{
cbMinimumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapRenderer()->scale() );
}

void QgsVectorLayerProperties::on_mMaximumScaleSetCurrentPushButton_clicked()
{
cbMaximumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapRenderer()->scale() );
}
5 changes: 5 additions & 0 deletions src/app/qgsvectorlayerproperties.h
Expand Up @@ -26,6 +26,7 @@
#include "qgsdelattrdialog.h"
#include "qgsattributetypedialog.h"
#include "qgsfield.h"
#include "qgslegenditem.h"
#include "qgsmapcanvas.h"
#include "qgscontexthelp.h"
#include "qgsexpressionbuilderdialog.h"
Expand Down Expand Up @@ -135,10 +136,14 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
void on_mButtonAddJoin_clicked();
void on_mButtonRemoveJoin_clicked();

void on_mMinimumScaleSetCurrentPushButton_clicked();
void on_mMaximumScaleSetCurrentPushButton_clicked();

signals:

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

void toggleEditing( QgsMapLayer * );

Expand Down
8 changes: 4 additions & 4 deletions src/core/qgsmaplayer.h
Expand Up @@ -342,11 +342,11 @@ class CORE_EXPORT QgsMapLayer : public QObject
/** Event handler for when a coordinate transform fails due to bad vertex error */
virtual void invalidTransformInput();

/** Accessor and mutator for the minimum scale member */
/** Accessor and mutator for the minimum scale denominator member */
void setMinimumScale( float theMinScale );
float minimumScale();

/** Accessor and mutator for the maximum scale member */
/** Accessor and mutator for the maximum scale denominator member */
void setMaximumScale( float theMaxScale );
float maximumScale();

Expand Down Expand Up @@ -474,9 +474,9 @@ class CORE_EXPORT QgsMapLayer : public QObject
/** Tag for embedding additional information */
QString mTag;

/** Minimum scale at which this layer should be displayed */
/** Minimum scale denominator at which this layer should be displayed */
float mMinScale;
/** Maximum scale at which this layer should be displayed */
/** Maximum scale denominator at which this layer should be displayed */
float mMaxScale;
/** A flag that tells us whether to use the above vars to restrict layer visibility */
bool mScaleBasedVisibility;
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsmaprenderer.h
Expand Up @@ -136,6 +136,7 @@ class CORE_EXPORT QgsMapRenderer : public QObject

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

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

//! Map scale at its current zoom level
//! Map scale denominator at its current zoom level
double mScale;

//! scale calculator
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsscalecalculator.cpp
Expand Up @@ -74,13 +74,13 @@ double QgsScaleCalculator::calculate( const QgsRectangle &mapExtent, int canvasW
delta = calculateGeographicDistance( mapExtent );
break;
}
QgsDebugMsg( "Using conversionFactor of " + QString::number( conversionFactor ) );
if ( canvasWidth == 0 || mDpi == 0 )
{
QgsDebugMsg( "Can't calculate scale from the input values" );
return 0;
}
double scale = ( delta * conversionFactor ) / (( double )canvasWidth / mDpi );
QgsDebugMsg( QString( "scale = %1 conversionFactor = %2" ).arg( scale ).arg( conversionFactor ) );
return scale;
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsscalecalculator.h
Expand Up @@ -66,10 +66,10 @@ class CORE_EXPORT QgsScaleCalculator
QGis::UnitType mapUnits() const;

/**
* Calculate the scale
* Calculate the scale denominator
* @param mapExtent QgsRectangle containing the current map extent
* @param canvasWidth Width of the map canvas in pixel (physical) units
* @return scale of current map view
* @return scale denominator of current map view
*/
double calculate( const QgsRectangle &mapExtent, int canvasWidth );

Expand Down
12 changes: 8 additions & 4 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
Expand Up @@ -159,7 +159,6 @@ void QgsCategorizedSymbolRendererV2::rebuildHash()
QgsSymbolV2* QgsCategorizedSymbolRendererV2::symbolForValue( QVariant value )
{
// TODO: special case for int, double

QHash<QString, QgsSymbolV2*>::iterator it = mSymbolHash.find( value.toString() );
if ( it == mSymbolHash.end() )
{
Expand All @@ -169,7 +168,7 @@ QgsSymbolV2* QgsCategorizedSymbolRendererV2::symbolForValue( QVariant value )
}
else
{
//QgsDebugMsg( "attribute value not found: " + value.toString() );
QgsDebugMsg( "attribute value not found: " + value.toString() );
}
return NULL;
}
Expand All @@ -192,7 +191,12 @@ QgsSymbolV2* QgsCategorizedSymbolRendererV2::symbolForFeature( QgsFeature& featu
if ( symbol == NULL )
{
// if no symbol found use default one
return symbolForValue( QVariant( "" ) );
//return symbolForValue( QVariant( "" ) );
// What is default? Empty string may be a legal value, and features not found
// should not be rendered using empty string value category symbology.
// We also need to get NULL in that case so that willRenderFeature()
// may be used to count features.
return 0;
}

if ( mRotationFieldIdx == -1 && mSizeScaleFieldIdx == -1 )
Expand Down Expand Up @@ -600,7 +604,7 @@ void QgsCategorizedSymbolRendererV2::setSourceColorRamp( QgsVectorColorRampV2* r
void QgsCategorizedSymbolRendererV2::updateSymbols( QgsSymbolV2 * sym )
{
int i = 0;
foreach( QgsRendererCategoryV2 cat, mCategories )
foreach ( QgsRendererCategoryV2 cat, mCategories )
{
QgsSymbolV2* symbol = sym->clone();
symbol->setColor( cat.symbol()->color() );
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgscategorizedsymbolrendererv2.h
Expand Up @@ -81,7 +81,7 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2

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

virtual QgsSymbolV2List symbols();
//! @note added in 2.0
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
Expand Up @@ -76,7 +76,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2

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

virtual QgsSymbolV2List symbols();

Expand Down

0 comments on commit 779e166

Please sign in to comment.