@@ -35,6 +35,12 @@ QgsGCPCanvasItem::QgsGCPCanvasItem( QgsMapCanvas* mapCanvas, const QgsGeorefData
35
35
36
36
void QgsGCPCanvasItem::paint ( QPainter* p )
37
37
{
38
+ QgsRenderContext context;
39
+ if ( !setRenderContextVariables ( p, context ) )
40
+ {
41
+ return ;
42
+ }
43
+
38
44
p->setRenderHint ( QPainter::Antialiasing );
39
45
40
46
bool enabled = true ;
@@ -57,29 +63,39 @@ void QgsGCPCanvasItem::paint( QPainter* p )
57
63
58
64
QSettings s;
59
65
bool showIDs = s.value ( " /Plugin-GeoReferencer/Config/ShowId" ).toBool ();
60
- if ( !showIDs && mIsGCPSource )
66
+ bool showCoords = s.value ( " /Plugin-GeoReferencer/Config/ShowCoords" ).toBool ();
67
+
68
+ QString msg;
69
+ if ( showIDs && showCoords )
61
70
{
62
- QString msg = QString ( " X %1\n Y %2" ).arg ( QString::number ( worldCoords.x (), ' f' ) ).
63
- arg ( QString::number ( worldCoords.y (), ' f' ) );
64
- p->setFont ( QFont ( " helvetica" , 9 ) );
65
- QRect textBounds = p->boundingRect ( 6 , 6 , 10 , 10 , Qt::AlignLeft, msg );
66
- p->setBrush ( mLabelBrush );
67
- p->drawRect ( textBounds.x () - 2 , textBounds.y () - 2 , textBounds.width () + 4 , textBounds.height () + 4 );
68
- p->drawText ( textBounds, Qt::AlignLeft, msg );
69
- mTextBounds = QSizeF ( textBounds.width () + 4 , textBounds.height () + 4 );
71
+ msg = QString ( " %1\n X %2\n Y %3" ).arg ( QString::number ( id ) ).arg ( QString::number ( worldCoords.x (), ' f' ) ).arg ( QString::number ( worldCoords.y (), ' f' ) );
70
72
}
71
73
else if ( showIDs )
72
74
{
73
- p->setFont ( QFont ( " helvetica" , 12 ) );
74
- QString msg = QString::number ( id );
75
+ msg = msg = QString::number ( id );
76
+ }
77
+ else if ( showCoords )
78
+ {
79
+ msg = QString ( " X %1\n Y %2" ).arg ( QString::number ( worldCoords.x (), ' f' ) ).arg ( QString::number ( worldCoords.y (), ' f' ) );
80
+ }
81
+
82
+ if ( !msg.isEmpty () )
83
+ {
75
84
p->setBrush ( mLabelBrush );
76
- p->drawRect ( 5 , 4 , p->fontMetrics ().width ( msg ) + 2 , 14 );
77
- p->drawText ( 6 , 16 , msg );
78
- QFontMetrics fm = p->fontMetrics ();
79
- mTextBounds = QSize ( fm.width ( msg ) + 4 , fm.height () + 4 );
85
+ QFont textFont ( " helvetica" );
86
+ textFont.setPixelSize ( fontSizePainterUnits ( 12 , context ) );
87
+ p->setFont ( textFont );
88
+ QRectF textBounds = p->boundingRect ( 3 * context.scaleFactor (), 3 * context.scaleFactor (), 5 * context.scaleFactor (), 5 * context.scaleFactor (), Qt::AlignLeft, msg );
89
+ mTextBoxRect = QRectF ( textBounds.x () - context.scaleFactor () * 1 , textBounds.y () - context.scaleFactor () * 1 , \
90
+ textBounds.width () + 2 * context.scaleFactor (), textBounds.height () + 2 * context.scaleFactor () );
91
+ p->drawRect ( mTextBoxRect );
92
+ p->drawText ( textBounds, Qt::AlignLeft, msg );
80
93
}
81
94
82
- drawResidualArrow ( p );
95
+ if ( data ( 0 ) != " composer" ) // draw residuals only on screen
96
+ {
97
+ drawResidualArrow ( p, context );
98
+ }
83
99
}
84
100
85
101
QRectF QgsGCPCanvasItem::boundingRect () const
@@ -91,6 +107,8 @@ QRectF QgsGCPCanvasItem::boundingRect() const
91
107
{
92
108
residual = mDataPoint ->residual ();
93
109
}
110
+
111
+ // only considering screen resolution is ok for the bounding box function
94
112
double rf = residualToScreenFactor ();
95
113
96
114
if ( residual.x () > 0 )
@@ -116,7 +134,12 @@ QRectF QgsGCPCanvasItem::boundingRect() const
116
134
117
135
QRectF residualArrowRect ( QPointF ( residualLeft, residualTop ), QPointF ( residualRight, residualBottom ) );
118
136
QRectF markerRect ( -2 , -2 , mTextBounds .width () + 6 , mTextBounds .height () + 6 );
119
- return residualArrowRect.united ( markerRect );
137
+ QRectF boundingRect = residualArrowRect.united ( markerRect );
138
+ if ( !mTextBoxRect .isNull () )
139
+ {
140
+ boundingRect = boundingRect.united ( mTextBoxRect );
141
+ }
142
+ return boundingRect;
120
143
}
121
144
122
145
QPainterPath QgsGCPCanvasItem::shape () const
@@ -138,9 +161,9 @@ void QgsGCPCanvasItem::updatePosition()
138
161
setPos ( toCanvasCoordinates ( mIsGCPSource ? mDataPoint ->pixelCoords () : mDataPoint ->mapCoords () ) );
139
162
}
140
163
141
- void QgsGCPCanvasItem::drawResidualArrow ( QPainter* p )
164
+ void QgsGCPCanvasItem::drawResidualArrow ( QPainter* p, const QgsRenderContext& context )
142
165
{
143
- if ( !mDataPoint || !mIsGCPSource )
166
+ if ( !mDataPoint || !mIsGCPSource || ! mMapCanvas )
144
167
{
145
168
return ;
146
169
}
@@ -188,3 +211,9 @@ void QgsGCPCanvasItem::checkBoundingRectChange()
188
211
{
189
212
prepareGeometryChange ();
190
213
}
214
+
215
+ double QgsGCPCanvasItem::fontSizePainterUnits ( double points, const QgsRenderContext& c )
216
+ {
217
+ return points * 0.3527 * c.scaleFactor ();
218
+ }
219
+
0 commit comments