Skip to content

Commit

Permalink
[FEATURE] configurable vertex marker size (fixes #1922)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@11599 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 8, 2009
1 parent 91dec3d commit 0a083f5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
{
mMarkerStyleComboBox->setCurrentIndex( mMarkerStyleComboBox->findText( tr( "None" ) ) );
}
mMarkerSizeSpinBox->setValue( settings.value( "/qgis/digitizing/marker_size", 7 ).toInt()*2+1 );

chkDisableAttributeValuesDlg->setChecked( settings.value( "/qgis/digitizing/disable_enter_attribute_values_dialog", false ).toBool() );

Expand Down Expand Up @@ -483,6 +484,7 @@ void QgsOptions::saveOptions()
{
settings.setValue( "/qgis/digitizing/marker_style", "None" );
}
settings.setValue( "/qgis/digitizing/marker_size", (mMarkerSizeSpinBox->value()-1)/2 );

settings.setValue( "/qgis/digitizing/disable_enter_attribute_values_dialog", chkDisableAttributeValuesDlg->isChecked() );

Expand Down
20 changes: 14 additions & 6 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,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 );
drawVertexMarker(( int )( *xIt ), ( int )( *yIt ), *p, mCurrentVertexMarkerType, mCurrentVertexMarkerSize );
}
}

Expand Down Expand Up @@ -631,7 +631,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 );
drawVertexMarker(( int )e.x, ( int )e.y, *p, mCurrentVertexMarkerType, mCurrentVertexMarkerSize );
}
}

Expand Down Expand Up @@ -668,13 +668,15 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
QImage marker;
//vertex marker type for selection
QgsVectorLayer::VertexMarkerType vertexMarker = QgsVectorLayer::NoMarker;
int vertexMarkerSize = 7;

if ( mEditable )
{
// Destroy all cached geometries and clear the references to them
deleteCachedGeometries();
mCachedGeometriesRect = rendererContext.extent();
vertexMarker = currentVertexMarkerType();
vertexMarkerSize = currentVertexMarkerSize();
mVertexMarkerOnlyForSelection = settings.value( "/qgis/digitizing/marker_only_for_selected", false ).toBool();
}

Expand Down Expand Up @@ -717,6 +719,7 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
bool sel = mSelectedFeatureIds.contains( fet.id() );

mCurrentVertexMarkerType = QgsVectorLayer::NoMarker;
mCurrentVertexMarkerSize = 7;

if ( mEditable )
{
Expand All @@ -726,6 +729,7 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
if ( !mVertexMarkerOnlyForSelection || sel )
{
mCurrentVertexMarkerType = vertexMarker;
mCurrentVertexMarkerSize = vertexMarkerSize;
}
}

Expand Down Expand Up @@ -777,18 +781,16 @@ void QgsVectorLayer::deleteCachedGeometries()
mCachedGeometriesRect = QgsRectangle();
}

void QgsVectorLayer::drawVertexMarker( int x, int y, QPainter& p, QgsVectorLayer::VertexMarkerType type )
void QgsVectorLayer::drawVertexMarker( int x, int y, QPainter& p, QgsVectorLayer::VertexMarkerType type, int m )
{
if ( type == QgsVectorLayer::SemiTransparentCircle )
{
p.setPen( QColor( 50, 100, 120, 200 ) );
p.setBrush( QColor( 200, 200, 210, 120 ) );
p.drawEllipse( QRectF( x - 7, y - 7, 14, 14 ) );
p.drawEllipse( x-m, y-m, m*2+1, m*2+1 );
}
else if ( type == QgsVectorLayer::Cross )
{
int size = 15;
int m = ( size - 1 ) / 2;
p.setPen( QColor( 255, 0, 0 ) );
p.drawLine( x - m, y + m, x + m, y - m );
p.drawLine( x - m, y - m, x + m, y + m );
Expand Down Expand Up @@ -3464,6 +3466,12 @@ QgsVectorLayer::VertexMarkerType QgsVectorLayer::currentVertexMarkerType()
}
}

int QgsVectorLayer::currentVertexMarkerSize()
{
QSettings settings;
return settings.value( "/qgis/digitizing/marker_size", 7 ).toInt();
}

void QgsVectorLayer::drawFeature( QgsRenderContext &renderContext,
QgsFeature& fet,
QImage * marker )
Expand Down
8 changes: 7 additions & 1 deletion src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
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 );
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
Expand All @@ -597,6 +597,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/**Reads vertex marker type from settings*/
QgsVectorLayer::VertexMarkerType currentVertexMarkerType();

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

/**Update feature with uncommited attribute updates*/
void updateFeatureAttributes( QgsFeature &f );

Expand Down Expand Up @@ -700,6 +703,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/**The current type of editing marker*/
QgsVectorLayer::VertexMarkerType mCurrentVertexMarkerType;

/** The current size of editing marker */
int mCurrentVertexMarkerSize;

/**Flag if the vertex markers should be drawn only for selection (true) or for all features (false)*/
bool mVertexMarkerOnlyForSelection;

Expand Down
35 changes: 34 additions & 1 deletion src/ui/qgsoptionsbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>4</number>
</property>
<widget class="QWidget" name="tabGeneral">
<attribute name="title">
Expand Down Expand Up @@ -859,6 +859,39 @@
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="mMarkerSizeSpinBox">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="minimum">
<number>3</number>
</property>
<property name="singleStep">
<number>2</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Marker size</string>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 0a083f5

Please sign in to comment.