Skip to content
Permalink
Browse files

make attribute table and identify consistent with map canvas

  • Loading branch information
blazek committed Oct 26, 2012
1 parent 59e9942 commit 779e16603ee3fb8781c85a0e95913a1f6bbd2d6a
@@ -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 )
{
@@ -23,9 +23,10 @@
#include <QPair>
#include <set>

#include "qgslegenditem.h"

class QgsLegendGroup;
class QgsLegendLayer;
class QgsLegendItem;
class QgsMapLayer;
class QgsMapCanvas;
class QDomDocument;
@@ -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
@@ -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.
@@ -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 );
@@ -622,6 +627,7 @@ void QgsLegendLayer::updateItemListCountV2( SymbologyList& itemList, QgsVectorLa
}
}
}
renderer->stopRender( renderContext );
p.setValue( nFeatures );

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

//
symbolIt = symbolList.constBegin();
for ( ; symbolIt != symbolList.constEnd(); ++symbolIt )
{
@@ -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();
@@ -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() )
@@ -31,6 +31,7 @@
#include "qgsproject.h"
#include "qgsmaplayerregistry.h"
#include "qgisapp.h"
#include "qgsrendererv2.h"

#include <QSettings>
#include <QMessageBox>
@@ -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 );
@@ -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:
@@ -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;
@@ -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() );
}

@@ -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();

@@ -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"
@@ -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()
@@ -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() );
}
@@ -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"
@@ -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 * );

@@ -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();

@@ -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;
@@ -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)*/
@@ -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
@@ -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;
}

@@ -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 );

@@ -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() )
{
@@ -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;
}
@@ -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 )
@@ -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() );
@@ -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
@@ -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();

0 comments on commit 779e166

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