Skip to content
Permalink
Browse files

Show editing vertex markers with symbology-ng. Fixes #2171.

git-svn-id: http://svn.osgeo.org/qgis/trunk@12537 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Dec 20, 2009
1 parent 2fe98b8 commit b3f2966396e474d9beb637590cc8d9faf760709e
@@ -480,6 +480,24 @@ public:
/** Execute redo operation. To be called only from QgsVectorLayerUndoCommand. */
// (not necessary) void redoEditCommand(QgsUndoCommand* cmd);

/** Returns the index of a field name or -1 if the field does not exist
@note this method was added in version 1.4
*/
int fieldNameIndex( const QString& fieldName ) const;

/** Editing vertex markers
@note public from version 1.4 */
enum VertexMarkerType
{
SemiTransparentCircle,
Cross,
NoMarker /* added in version 1.1 */
};

/** Draws a vertex symbol at (screen) coordinates x, y. (Useful to assist vertex editing.)
@note public and static from version 1.4 */
static void drawVertexMarker( double x, double y, QPainter& p, QgsVectorLayer::VertexMarkerType type, int vertexSize );

public slots:

/** Select feature by its ID, optionally emit signal selectionChanged() */
@@ -498,11 +516,6 @@ public slots:
*/
virtual void updateExtents();

/** Returns the index of a field name or -1 if the field does not exist
@note this method was added in version 1.4
*/
int fieldNameIndex( const QString& fieldName ) const;

signals:

/** This signal is emited when selection was changed */
@@ -70,7 +70,7 @@ public:

virtual QgsSymbolV2List symbols()=0;

void renderFeature(QgsFeature& feature, QgsRenderContext& context, int layer = -1);
void renderFeature(QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool drawVertexMarker = false );

bool usingSymbolLevels() const;
void setUsingSymbolLevels(bool usingSymbolLevels);
@@ -84,9 +84,19 @@ public:
//! return a list of symbology items for the legend
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize);

//! set type and size of editing vertex markers for subsequent rendering
void setVertexMarkerAppearance( int type, int size );

protected:
QgsFeatureRendererV2(QString type);

//! render editing vertex marker at specified point
void renderVertexMarker( QPointF& pt, QgsRenderContext& context );
//! render editing vertex marker for a polyline
void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
//! render editing vertex marker for a polygon
void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );

};

///////////////
@@ -476,7 +476,7 @@ unsigned char *QgsVectorLayer::drawLineString( unsigned char *feature, QgsRender
std::vector<double>::const_iterator yIt;
for ( xIt = x.begin(), yIt = y.begin(); xIt != x.end(); ++xIt, ++yIt )
{
drawVertexMarker(( int )( *xIt ), ( int )( *yIt ), *p, mCurrentVertexMarkerType, mCurrentVertexMarkerSize );
drawVertexMarker( *xIt, *yIt, *p, mCurrentVertexMarkerType, mCurrentVertexMarkerSize );
}
}

@@ -669,7 +669,7 @@ unsigned char *QgsVectorLayer::drawPolygon( unsigned char *feature, QgsRenderCon
for ( int i = 0; i < path.elementCount(); ++i )
{
const QPainterPath::Element & e = path.elementAt( i );
drawVertexMarker(( int )e.x, ( int )e.y, *p, mCurrentVertexMarkerType, mCurrentVertexMarkerSize );
drawVertexMarker( e.x, e.y, *p, mCurrentVertexMarkerType, mCurrentVertexMarkerSize );
}
}

@@ -686,24 +686,33 @@ unsigned char *QgsVectorLayer::drawPolygon( unsigned char *feature, QgsRenderCon

void QgsVectorLayer::drawRendererV2( QgsRenderContext& rendererContext, bool labeling )
{
QSettings settings;
bool vertexMarkerOnlyForSelection = settings.value( "/qgis/digitizing/marker_only_for_selected", false ).toBool();

mRendererV2->startRender( rendererContext, this );

QgsSingleSymbolRendererV2* selRenderer = NULL;
if ( !mSelectedFeatureIds.isEmpty() )
{
selRenderer = new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol( geometryType() ) );
selRenderer->symbol()->setColor( QgsRenderer::selectionColor() );
selRenderer->setVertexMarkerAppearance( currentVertexMarkerType(), currentVertexMarkerSize() );
selRenderer->startRender( rendererContext, this );
}

QgsFeature fet;
while ( nextFeature( fet ) )
{
if ( mSelectedFeatureIds.contains( fet.id() ) )
selRenderer->renderFeature( fet, rendererContext );
bool sel = mSelectedFeatureIds.contains( fet.id() );
bool drawMarker = ( mEditable && ( !vertexMarkerOnlyForSelection || sel ) );

// render feature
if ( sel )
selRenderer->renderFeature( fet, rendererContext, -1, drawMarker );
else
mRendererV2->renderFeature( fet, rendererContext );
mRendererV2->renderFeature( fet, rendererContext, -1, drawMarker );

// labeling - register feature
if ( labeling && mRendererV2->symbolForFeature( fet ) != NULL )
rendererContext.labelingEngine()->registerFeature( this, fet );

@@ -727,6 +736,9 @@ void QgsVectorLayer::drawRendererV2Levels( QgsRenderContext& rendererContext, bo
{
QHash< QgsSymbolV2*, QList<QgsFeature> > features; // key = symbol, value = array of features

QSettings settings;
bool vertexMarkerOnlyForSelection = settings.value( "/qgis/digitizing/marker_only_for_selected", false ).toBool();

// startRender must be called before symbolForFeature() calls to make sure renderer is ready
mRendererV2->startRender( rendererContext, this );

@@ -735,6 +747,7 @@ void QgsVectorLayer::drawRendererV2Levels( QgsRenderContext& rendererContext, bo
{
selRenderer = new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol( geometryType() ) );
selRenderer->symbol()->setColor( QgsRenderer::selectionColor() );
selRenderer->setVertexMarkerAppearance( currentVertexMarkerType(), currentVertexMarkerSize() );
selRenderer->startRender( rendererContext, this );
}

@@ -792,10 +805,14 @@ void QgsVectorLayer::drawRendererV2Levels( QgsRenderContext& rendererContext, bo
QList<QgsFeature>::iterator fit;
for ( fit = lst.begin(); fit != lst.end(); ++fit )
{
if ( mSelectedFeatureIds.contains( fit->id() ) )
selRenderer->renderFeature( *fit, rendererContext );
bool sel = mSelectedFeatureIds.contains( fit->id() );
// maybe vertex markers should be drawn only during the last pass...
bool drawMarker = ( mEditable && ( !vertexMarkerOnlyForSelection || sel ) );

if ( sel )
selRenderer->renderFeature( *fit, rendererContext, -1, drawMarker );
else
mRendererV2->renderFeature( *fit, rendererContext, layer );
mRendererV2->renderFeature( *fit, rendererContext, layer, drawMarker );
}
}
}
@@ -823,6 +840,9 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
// Destroy all cached geometries and clear the references to them
deleteCachedGeometries();
mCachedGeometriesRect = rendererContext.extent();

// set editing vertex markers style
mRendererV2->setVertexMarkerAppearance( currentVertexMarkerType(), currentVertexMarkerSize() );
}

// TODO: really needed?
@@ -1009,7 +1029,7 @@ void QgsVectorLayer::deleteCachedGeometries()
mCachedGeometriesRect = QgsRectangle();
}

void QgsVectorLayer::drawVertexMarker( int x, int y, QPainter& p, QgsVectorLayer::VertexMarkerType type, int m )
void QgsVectorLayer::drawVertexMarker( double x, double y, QPainter& p, QgsVectorLayer::VertexMarkerType type, int m )
{
if ( type == QgsVectorLayer::SemiTransparentCircle )
{
@@ -533,6 +533,19 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
int fieldNameIndex( const QString& fieldName ) const;

/** Editing vertex markers
@note public from version 1.4 */
enum VertexMarkerType
{
SemiTransparentCircle,
Cross,
NoMarker /* added in version 1.1 */
};

/** Draws a vertex symbol at (screen) coordinates x, y. (Useful to assist vertex editing.)
@note public and static from version 1.4 */
static void drawVertexMarker( double x, double y, QPainter& p, QgsVectorLayer::VertexMarkerType type, int vertexSize );

public slots:
/** Select feature by its ID, optionally emit signal selectionChanged() */
void select( int featureId, bool emitSignal = TRUE );
@@ -569,13 +582,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer

private: // Private methods

enum VertexMarkerType
{
SemiTransparentCircle,
Cross,
NoMarker /* added in version 1.1 */
};

/** vector layers are not copyable */
QgsVectorLayer( QgsVectorLayer const & rhs );

@@ -616,9 +622,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/**Deletes the geometries in mCachedGeometries*/
void deleteCachedGeometries();

/** Draws a vertex symbol at (screen) coordinates x, y. (Useful to assist vertex editing.) */
void drawVertexMarker( int x, int y, QPainter& p, QgsVectorLayer::VertexMarkerType type, int vertexSize );

/**Snaps to a geometry and adds the result to the multimap if it is within the snapping result
@param startPoint start point of the snap
@param geom geometry to snap
@@ -634,10 +637,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
int boundingBoxFromPointList( const QList<QgsPoint>& list, double& xmin, double& ymin, double& xmax, double& ymax ) const;

/**Reads vertex marker type from settings*/
QgsVectorLayer::VertexMarkerType currentVertexMarkerType();
static QgsVectorLayer::VertexMarkerType currentVertexMarkerType();

/**Reads vertex marker size from settings*/
int currentVertexMarkerSize();
static int currentVertexMarkerSize();

/**Update feature with uncommited attribute updates*/
void updateFeatureAttributes( QgsFeature &f );
@@ -11,6 +11,7 @@
#include "qgsgeometry.h"
#include "qgsfeature.h"
#include "qgslogger.h"
#include "qgsvectorlayer.h"

#include <QDomElement>
#include <QDomDocument>
@@ -138,7 +139,9 @@ static unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsR


QgsFeatureRendererV2::QgsFeatureRendererV2( QString type )
: mType( type ), mUsingSymbolLevels( false )
: mType( type ), mUsingSymbolLevels( false ),
mCurrentVertexMarkerType( QgsVectorLayer::Cross ),
mCurrentVertexMarkerSize( 3 )
{
}

@@ -148,7 +151,7 @@ QgsFeatureRendererV2* QgsFeatureRendererV2::defaultRenderer( QGis::GeometryType
}


void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer )
void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer, bool drawVertexMarker )
{
QgsSymbolV2* symbol = symbolForFeature( feature );
if ( symbol == NULL )
@@ -170,6 +173,9 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
QPointF pt;
_getPoint( pt, context, geom->asWkb() );
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, context, layer );

//if ( drawVertexMarker )
// renderVertexMarker( pt, context );
}
break;

@@ -184,6 +190,9 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
QPolygonF pts;
_getLineString( pts, context, geom->asWkb() );
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, context, layer );

if ( drawVertexMarker )
renderVertexMarkerPolyline( pts, context );
}
break;

@@ -199,6 +208,9 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
QList<QPolygonF> holes;
_getPolygon( pts, holes, context, geom->asWkb() );
(( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), context, layer );

if ( drawVertexMarker )
renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
}
break;

@@ -220,6 +232,9 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
{
ptr = _getPoint( pt, context, ptr );
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, context, layer );

//if ( drawVertexMarker )
// renderVertexMarker( pt, context );
}
}
break;
@@ -242,6 +257,9 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
{
ptr = _getLineString( pts, context, ptr );
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, context, layer );

if ( drawVertexMarker )
renderVertexMarkerPolyline( pts, context );
}
}
break;
@@ -265,6 +283,9 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&
{
ptr = _getPolygon( pts, holes, context, ptr );
(( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), context, layer );

if ( drawVertexMarker )
renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
}
}
break;
@@ -314,3 +335,37 @@ QgsLegendSymbologyList QgsFeatureRendererV2::legendSymbologyItems( QSize iconSiz
// empty list by default
return QgsLegendSymbologyList();
}

void QgsFeatureRendererV2::setVertexMarkerAppearance( int type, int size )
{
mCurrentVertexMarkerType = type;
mCurrentVertexMarkerSize = size;
}

void QgsFeatureRendererV2::renderVertexMarker( QPointF& pt, QgsRenderContext& context )
{
QgsVectorLayer::drawVertexMarker( pt.x(), pt.y(), *context.painter(),
( QgsVectorLayer::VertexMarkerType ) mCurrentVertexMarkerType,
mCurrentVertexMarkerSize );
}

void QgsFeatureRendererV2::renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context )
{
foreach( QPointF pt, pts )
renderVertexMarker( pt, context );
}

void QgsFeatureRendererV2::renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context )
{
foreach( QPointF pt, pts )
renderVertexMarker( pt, context );

if ( rings )
{
foreach( QPolygonF ring, *rings )
{
foreach( QPointF pt, ring )
renderVertexMarker( pt, context );
}
}
}
@@ -72,7 +72,7 @@ class CORE_EXPORT QgsFeatureRendererV2

virtual QgsFeatureRendererV2* clone() = 0;

void renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1 );
void renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool drawVertexMarker = false );

//! for debugging
virtual QString dump();
@@ -92,12 +92,27 @@ class CORE_EXPORT QgsFeatureRendererV2
//! return a list of symbology items for the legend
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );

//! set type and size of editing vertex markers for subsequent rendering
void setVertexMarkerAppearance( int type, int size );

protected:
QgsFeatureRendererV2( QString type );

//! render editing vertex marker at specified point
void renderVertexMarker( QPointF& pt, QgsRenderContext& context );
//! render editing vertex marker for a polyline
void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
//! render editing vertex marker for a polygon
void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );

QString mType;

bool mUsingSymbolLevels;

/** The current type of editing marker */
int mCurrentVertexMarkerType;
/** The current size of editing marker */
int mCurrentVertexMarkerSize;
};


0 comments on commit b3f2966

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