Skip to content
Permalink
Browse files

[ui] Fix tiny vertex marker on hidpi

  • Loading branch information
nirvn committed Feb 4, 2019
1 parent 41a04d0 commit 8ac762e5e191df19b2155f13830953abaeac34a8
@@ -1842,9 +1842,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();
@@ -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
@@ -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.
@@ -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

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

@@ -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
@@ -1035,7 +1035,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() );
@@ -1622,7 +1622,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() );
@@ -1690,8 +1690,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
@@ -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"
@@ -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;
@@ -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;

@@ -60,7 +60,7 @@ QgsFeatureRenderer::QgsFeatureRenderer( const QString &type )
: mType( type )
, mUsingSymbolLevels( false )
, mCurrentVertexMarkerType( QgsVectorLayer::Cross )
, mCurrentVertexMarkerSize( 3 )
, mCurrentVertexMarkerSize( 2 )
, mForceRaster( false )
, mOrderByEnabled( false )
{
@@ -337,7 +337,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;
@@ -350,9 +350,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 )
@@ -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.
@@ -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;

@@ -740,7 +740,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() )
@@ -1062,9 +1062,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 );
}

////////////////////
@@ -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.
@@ -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;
@@ -797,6 +797,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>
@@ -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 );

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

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

0 comments on commit 8ac762e

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