Skip to content

Commit

Permalink
[ui] Fix tiny vertex marker on hidpi
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Feb 5, 2019
1 parent eb0a020 commit fef5176
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 29 deletions.
4 changes: 3 additions & 1 deletion python/core/auto_generated/qgsvectorlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1845,9 +1845,11 @@ Destroy active command and reverts all changes in it
NoMarker
};

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

.. deprecated:: Use the equivalent QgsSymbolLayerUtils.drawVertexMarker function instead
%End

void updateFields();
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/symbology/qgsrenderer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ If supported by the renderer, return classification attribute for the use in leg
.. versionadded:: 2.6
%End

void setVertexMarkerAppearance( int type, int size );
void setVertexMarkerAppearance( int type, double size );
%Docstring
Sets type and size of editing vertex markers for subsequent rendering
%End
Expand Down
4 changes: 2 additions & 2 deletions python/core/auto_generated/symbology/qgssymbol.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ Returns whether the symbol utilizes any data defined properties.
.. deprecated:: Will be removed in QGIS 4.0
%End

void renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false, int currentVertexMarkerType = 0, int currentVertexMarkerSize = 0 );
void renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false, int currentVertexMarkerType = 0, double currentVertexMarkerSize = 0.0 );
%Docstring
Render a feature. Before calling this the startRender() method should be called to initialize
the rendering process. After rendering all features stopRender() must be called.
Expand Down Expand Up @@ -487,7 +487,7 @@ This is required for layers that generate their own geometry from other
information in the rendering context.
%End

void renderVertexMarker( QPointF pt, QgsRenderContext &context, int currentVertexMarkerType, int currentVertexMarkerSize );
void renderVertexMarker( QPointF pt, QgsRenderContext &context, int currentVertexMarkerType, double currentVertexMarkerSize );
%Docstring
Render editing vertex marker at specified point

Expand Down
14 changes: 14 additions & 0 deletions python/core/auto_generated/symbology/qgssymbollayerutils.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class QgsSymbolLayerUtils
%End
public:

enum VertexMarkerType
{
SemiTransparentCircle,
Cross,
NoMarker
};

static QString encodeColor( const QColor &color );
static QColor decodeColor( const QString &str );

Expand Down Expand Up @@ -240,6 +247,13 @@ Returns a pixmap preview for a color ramp.

static void drawStippledBackground( QPainter *painter, QRect rect );

static void drawVertexMarker( double x, double y, QPainter &p, QgsSymbolLayerUtils::VertexMarkerType type, int markerSize );
%Docstring
Draws a vertex symbol at (painter) coordinates x, y. (Useful to assist vertex editing.)

.. versionadded:: 3.4.5
%End

static double estimateMaxSymbolBleed( QgsSymbol *symbol, const QgsRenderContext &context );
%Docstring
Returns the maximum estimated bleed for the symbol
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
{
mMarkerStyleComboBox->setCurrentIndex( mMarkerStyleComboBox->findText( tr( "None" ) ) );
}
mMarkerSizeSpinBox->setValue( mSettings->value( QStringLiteral( "/qgis/digitizing/marker_size" ), 3 ).toInt() );
mMarkerSizeSpinBox->setValue( mSettings->value( QStringLiteral( "/qgis/digitizing/marker_size_mm" ), 2.0 ).toDouble() );

chkReuseLastValues->setChecked( mSettings->value( QStringLiteral( "/qgis/digitizing/reuseLastValues" ), false ).toBool() );
chkDisableAttributeValuesDlg->setChecked( mSettings->value( QStringLiteral( "/qgis/digitizing/disable_enter_attribute_values_dialog" ), false ).toBool() );
Expand Down Expand Up @@ -1618,7 +1618,7 @@ void QgsOptions::saveOptions()
{
mSettings->setValue( QStringLiteral( "/qgis/digitizing/marker_style" ), "None" );
}
mSettings->setValue( QStringLiteral( "/qgis/digitizing/marker_size" ), ( mMarkerSizeSpinBox->value() ) );
mSettings->setValue( QStringLiteral( "/qgis/digitizing/marker_size_mm" ), ( mMarkerSizeSpinBox->value() ) );

mSettings->setValue( QStringLiteral( "/qgis/digitizing/reuseLastValues" ), chkReuseLastValues->isChecked() );
mSettings->setValue( QStringLiteral( "/qgis/digitizing/disable_enter_attribute_values_dialog" ), chkDisableAttributeValuesDlg->isChecked() );
Expand Down
7 changes: 5 additions & 2 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1692,8 +1692,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
NoMarker
};

//! Draws a vertex symbol at (screen) coordinates x, y. (Useful to assist vertex editing.)
static void drawVertexMarker( double x, double y, QPainter &p, QgsVectorLayer::VertexMarkerType type, int vertexSize );
/**
* Draws a vertex symbol at (screen) coordinates x, y. (Useful to assist vertex editing.)
* \deprecated Use the equivalent QgsSymbolLayerUtils::drawVertexMarker function instead
*/
Q_DECL_DEPRECATED static void drawVertexMarker( double x, double y, QPainter &p, QgsVectorLayer::VertexMarkerType type, int vertexSize );

/**
* Will regenerate the `fields` property of this layer by obtaining all fields
Expand Down
9 changes: 5 additions & 4 deletions src/core/qgsvectorlayerrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "qgsrendercontext.h"
#include "qgssinglesymbolrenderer.h"
#include "qgssymbollayer.h"
#include "qgssymbollayerutils.h"
#include "qgssymbol.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayerdiagramprovider.h"
Expand Down Expand Up @@ -67,18 +68,18 @@ QgsVectorLayerRenderer::QgsVectorLayerRenderer( QgsVectorLayer *layer, QgsRender
QString markerTypeString = settings.value( QStringLiteral( "qgis/digitizing/marker_style" ), "Cross" ).toString();
if ( markerTypeString == QLatin1String( "Cross" ) )
{
mVertexMarkerStyle = QgsVectorLayer::Cross;
mVertexMarkerStyle = QgsSymbolLayerUtils::Cross;
}
else if ( markerTypeString == QLatin1String( "SemiTransparentCircle" ) )
{
mVertexMarkerStyle = QgsVectorLayer::SemiTransparentCircle;
mVertexMarkerStyle = QgsSymbolLayerUtils::SemiTransparentCircle;
}
else
{
mVertexMarkerStyle = QgsVectorLayer::NoMarker;
mVertexMarkerStyle = QgsSymbolLayerUtils::NoMarker;
}

mVertexMarkerSize = settings.value( QStringLiteral( "qgis/digitizing/marker_size" ), 3 ).toInt();
mVertexMarkerSize = settings.value( QStringLiteral( "qgis/digitizing/marker_size_mm" ), 2.0 ).toDouble();

if ( !mRenderer )
return;
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsvectorlayerrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ class QgsVectorLayerRenderer : public QgsMapLayerRenderer

bool mDrawVertexMarkers;
bool mVertexMarkerOnlyForSelection;
int mVertexMarkerStyle, mVertexMarkerSize;
int mVertexMarkerStyle = 0;
double mVertexMarkerSize = 2.0;

QgsWkbTypes::GeometryType mGeometryType;

Expand Down
11 changes: 6 additions & 5 deletions src/core/symbology/qgsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ QgsFeatureRenderer::QgsFeatureRenderer( const QString &type )
: mType( type )
, mUsingSymbolLevels( false )
, mCurrentVertexMarkerType( QgsVectorLayer::Cross )
, mCurrentVertexMarkerSize( 3 )
, mCurrentVertexMarkerSize( 2 )
, mForceRaster( false )
, mOrderByEnabled( false )
{
Expand Down Expand Up @@ -336,7 +336,7 @@ QgsLegendSymbolList QgsFeatureRenderer::legendSymbolItems() const
return QgsLegendSymbolList();
}

void QgsFeatureRenderer::setVertexMarkerAppearance( int type, int size )
void QgsFeatureRenderer::setVertexMarkerAppearance( int type, double size )
{
mCurrentVertexMarkerType = type;
mCurrentVertexMarkerSize = size;
Expand All @@ -349,9 +349,10 @@ bool QgsFeatureRenderer::willRenderFeature( const QgsFeature &feature, QgsRender

void QgsFeatureRenderer::renderVertexMarker( QPointF pt, QgsRenderContext &context )
{
QgsVectorLayer::drawVertexMarker( pt.x(), pt.y(), *context.painter(),
static_cast< QgsVectorLayer::VertexMarkerType >( mCurrentVertexMarkerType ),
mCurrentVertexMarkerSize );
int markerSize = context.convertToPainterUnits( mCurrentVertexMarkerSize, QgsUnitTypes::RenderMillimeters );
QgsSymbolLayerUtils::drawVertexMarker( pt.x(), pt.y(), *context.painter(),
static_cast< QgsSymbolLayerUtils::VertexMarkerType >( mCurrentVertexMarkerType ),
markerSize );
}

void QgsFeatureRenderer::renderVertexMarkerPolyline( QPolygonF &pts, QgsRenderContext &context )
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology/qgsrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class CORE_EXPORT QgsFeatureRenderer
virtual QString legendClassificationAttribute() const { return QString(); }

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

/**
* Returns whether the renderer will render a feature or not.
Expand Down Expand Up @@ -505,7 +505,7 @@ class CORE_EXPORT QgsFeatureRenderer
//! The current type of editing marker
int mCurrentVertexMarkerType;
//! The current size of editing marker
int mCurrentVertexMarkerSize;
double mCurrentVertexMarkerSize;

QgsPaintEffect *mPaintEffect = nullptr;

Expand Down
7 changes: 4 additions & 3 deletions src/core/symbology/qgssymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ class GeometryRestorer
};
///@endcond PRIVATE

void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker, int currentVertexMarkerType, int currentVertexMarkerSize )
void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker, int currentVertexMarkerType, double currentVertexMarkerSize )
{
const QgsGeometry geom = feature.geometry();
if ( geom.isNull() )
Expand Down Expand Up @@ -1053,9 +1053,10 @@ QgsSymbolRenderContext *QgsSymbol::symbolRenderContext()
return mSymbolRenderContext.get();
}

void QgsSymbol::renderVertexMarker( QPointF pt, QgsRenderContext &context, int currentVertexMarkerType, int currentVertexMarkerSize )
void QgsSymbol::renderVertexMarker( QPointF pt, QgsRenderContext &context, int currentVertexMarkerType, double currentVertexMarkerSize )
{
QgsVectorLayer::drawVertexMarker( pt.x(), pt.y(), *context.painter(), static_cast< QgsVectorLayer::VertexMarkerType >( currentVertexMarkerType ), currentVertexMarkerSize );
int markerSize = context.convertToPainterUnits( currentVertexMarkerSize, QgsUnitTypes::RenderMillimeters );
QgsSymbolLayerUtils::drawVertexMarker( pt.x(), pt.y(), *context.painter(), static_cast< QgsSymbolLayerUtils::VertexMarkerType >( currentVertexMarkerType ), markerSize );
}

////////////////////
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology/qgssymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ class CORE_EXPORT QgsSymbol
* Render a feature. Before calling this the startRender() method should be called to initialize
* the rendering process. After rendering all features stopRender() must be called.
*/
void renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false, int currentVertexMarkerType = 0, int currentVertexMarkerSize = 0 );
void renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false, int currentVertexMarkerType = 0, double currentVertexMarkerSize = 0.0 );

/**
* Returns the symbol render context. Only valid between startRender and stopRender calls.
Expand Down Expand Up @@ -506,7 +506,7 @@ class CORE_EXPORT QgsSymbol
* Render editing vertex marker at specified point
* \since QGIS 2.16
*/
void renderVertexMarker( QPointF pt, QgsRenderContext &context, int currentVertexMarkerType, int currentVertexMarkerSize );
void renderVertexMarker( QPointF pt, QgsRenderContext &context, int currentVertexMarkerType, double currentVertexMarkerSize );

SymbolType mType;
QgsSymbolLayerList mLayers;
Expand Down
21 changes: 21 additions & 0 deletions src/core/symbology/qgssymbollayerutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,27 @@ void QgsSymbolLayerUtils::drawStippledBackground( QPainter *painter, QRect rect
painter->fillRect( rect, brush );
}

void QgsSymbolLayerUtils::drawVertexMarker( double x, double y, QPainter &p, QgsSymbolLayerUtils::VertexMarkerType type, int markerSize )
{
qreal s = ( markerSize - 1 ) / 2.0;

switch ( type )
{
case QgsSymbolLayerUtils::SemiTransparentCircle:
p.setPen( QColor( 50, 100, 120, 200 ) );
p.setBrush( QColor( 200, 200, 210, 120 ) );
p.drawEllipse( x - s, y - s, s * 2, s * 2 );
break;
case QgsSymbolLayerUtils::Cross:
p.setPen( QColor( 255, 0, 0 ) );
p.drawLine( x - s, y + s, x + s, y - s );
p.drawLine( x - s, y - s, x + s, y + s );
break;
case QgsSymbolLayerUtils::NoMarker:
break;
}
}

#include <QPolygonF>

#include <cmath>
Expand Down
14 changes: 14 additions & 0 deletions src/core/symbology/qgssymbollayerutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ class CORE_EXPORT QgsSymbolLayerUtils
{
public:

//! Editing vertex markers
enum VertexMarkerType
{
SemiTransparentCircle,
Cross,
NoMarker
};

static QString encodeColor( const QColor &color );
static QColor decodeColor( const QString &str );

Expand Down Expand Up @@ -234,6 +242,12 @@ class CORE_EXPORT QgsSymbolLayerUtils

static void drawStippledBackground( QPainter *painter, QRect rect );

/**
* Draws a vertex symbol at (painter) coordinates x, y. (Useful to assist vertex editing.)
* \since QGIS 3.4.5
*/
static void drawVertexMarker( double x, double y, QPainter &p, QgsSymbolLayerUtils::VertexMarkerType type, int markerSize );

//! Returns the maximum estimated bleed for the symbol
static double estimateMaxSymbolBleed( QgsSymbol *symbol, const QgsRenderContext &context );

Expand Down
8 changes: 4 additions & 4 deletions src/ui/qgsoptionsbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -4259,22 +4259,22 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="mMarkerSizeSpinBox">
<widget class="QDoubleSpinBox" name="mMarkerSizeSpinBox">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="minimum">
<number>3</number>
<number>0.4</number>
</property>
<property name="singleStep">
<number>1</number>
<number>0.2</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Marker size</string>
<string>Marker size (in millimeter)</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit fef5176

Please sign in to comment.