Skip to content

Commit 904b3b7

Browse files
author
timlinux
committed
Long awaited fix for clipping issues with hard markers.
Problem is caused by logic that wants to draw marker onto od number of pixel dimentions always, without having a large enough pixmap allocated to draw it onto. There is still a problem with diamond marker but other markers are looking good. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5151 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent ed8239e commit 904b3b7

File tree

2 files changed

+47
-48
lines changed

2 files changed

+47
-48
lines changed

src/core/qgsmarkercatalogue.cpp

+46-47
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ email : blazek@itc.it
2828
#include <QPicture>
2929
#include <QSvgRenderer>
3030

31+
#include "qgis.h"
3132
#include "qgsapplication.h"
3233
#include "qgsmarkercatalogue.h"
3334

@@ -89,36 +90,12 @@ QPixmap QgsMarkerCatalogue::marker ( QString fullName, int size, QPen pen, QBrus
8990
//std::cerr << "QgsMarkerCatalogue::marker " << fullName.toLocal8Bit().data() << " sice:" << size << std::endl;
9091
if ( fullName.left(5) == "hard:" )
9192
{
92-
QPicture myPicture = hardMarker ( fullName.mid(5), size, pen, brush, qtBug );
93-
QPixmap myPixmap = QPixmap (myPicture.width(),myPicture.height());
94-
95-
// The following is window-system-conditional since (at least)
96-
// the combination of Qt 4.1.0 and RealVNC's Xvnc 4.1
97-
// will result in the pixmap becoming invisible if it is filled
98-
// with a non-opaque colour.
99-
// This is probably because Xvnc 4.1 doesn't have the RENDER
100-
// extension compiled into it.
101-
#if defined(Q_WS_X11)
102-
// Do a runtime test to see if the X RENDER extension is available
103-
if ( myPixmap.x11PictureHandle() )
104-
{
105-
#endif
106-
myPixmap.fill(QColor(255,255,255,0)); // transparent
107-
#if defined(Q_WS_X11)
108-
}
109-
else
110-
{
111-
myPixmap.fill(QColor(255,255,255)); // opaque
112-
}
113-
#endif
114-
115-
QPainter myPainter(&myPixmap);
116-
myPainter.drawPicture(0,0,myPicture);
117-
return myPixmap;
118-
} else if ( fullName.left(4) == "svg:" ) {
93+
return hardMarker ( fullName.mid(5), size, pen, brush, qtBug );
94+
}
95+
else if ( fullName.left(4) == "svg:" )
96+
{
11997
return svgMarker ( fullName.mid(4), size );
12098
}
121-
12299
return QPixmap(); // empty
123100
}
124101

@@ -160,38 +137,61 @@ QPixmap QgsMarkerCatalogue::svgMarker ( QString filename, int scaleFactor)
160137
return myPixmap;
161138
}
162139

163-
QPicture QgsMarkerCatalogue::hardMarker ( QString name, int s, QPen pen, QBrush brush, bool qtBug )
140+
QPixmap QgsMarkerCatalogue::hardMarker ( QString name, int s, QPen pen, QBrush brush, bool qtBug )
164141
{
142+
QPixmap myPixmap = QPixmap (s+1,s+1);
143+
144+
// The following is window-system-conditional since (at least)
145+
// the combination of Qt 4.1.0 and RealVNC's Xvnc 4.1
146+
// will result in the pixmap becoming invisible if it is filled
147+
// with a non-opaque colour.
148+
// This is probably because Xvnc 4.1 doesn't have the RENDER
149+
// extension compiled into it.
150+
#if defined(Q_WS_X11)
151+
// Do a runtime test to see if the X RENDER extension is available
152+
if ( myPixmap.x11PictureHandle() )
153+
{
154+
#endif
155+
myPixmap.fill(QColor(255,255,255,0)); // transparent
156+
#if defined(Q_WS_X11)
157+
}
158+
else
159+
{
160+
myPixmap.fill(QColor(255,255,255)); // opaque
161+
}
162+
#endif
163+
164+
QPainter myPainter(&myPixmap);
165165
// Size of polygon symbols is calculated so that the area is equal to circle with
166166
// diameter mPointSize
167167

168-
QPicture picture;
169168

170169
// Size for circle
171170
int half = (int)floor(s/2.0); // number of points from center
172171
int size = 2*half + 1; // must be odd
173172
double area = 3.14 * (size/2.) * (size/2.);
174173

175174
// Picture
176-
QPainter picpainter;
177-
picpainter.begin(&picture);
178-
picpainter.setRenderHint(QPainter::Antialiasing);
175+
QPicture picture;
176+
myPainter.begin(&picture);
177+
myPainter.setRenderHint(QPainter::Antialiasing);
179178

180179
// Also width must be odd otherwise there are discrepancies visible in canvas!
181180
int lw = (int)(2*floor((double)pen.width()/2)+1); // -> lw > 0
182181
pen.setWidth(lw);
183-
picpainter.setPen ( pen );
184-
picpainter.setBrush( brush);
185-
182+
myPainter.setPen ( pen );
183+
myPainter.setBrush( brush);
186184
QRect box;
185+
187186
if ( name == "circle" )
188187
{
189-
picpainter.drawEllipse(0, 0, size, size);
188+
std::cout << "Drawing circle of " << size << std::endl;
189+
myPainter.drawEllipse(0, 0, size, size);
190190
}
191191
else if ( name == "rectangle" )
192192
{
193193
size = (int) (2*floor(sqrt(area)/2.) + 1);
194-
picpainter.drawRect(0, 0, size, size);
194+
myPainter.drawRect(0, 0, size, size);
195195
}
196196
else if ( name == "diamond" )
197197
{
@@ -201,9 +201,9 @@ QPicture QgsMarkerCatalogue::hardMarker ( QString name, int s, QPen pen, QBrush
201201
pa.setPoint ( 1, half, 2*half);
202202
pa.setPoint ( 2, 2*half, half);
203203
pa.setPoint ( 3, half, 0);
204-
picpainter.drawPolygon ( pa );
204+
myPainter.drawPolygon ( pa );
205205
}
206-
// Warning! if pen width > 0 picpainter.drawLine(x1,y1,x2,y2) will draw only (x1,y1,x2-1,y2-1) !
206+
// Warning! if pen width > 0 myPainter.drawLine(x1,y1,x2,y2) will draw only (x1,y1,x2-1,y2-1) !
207207
// It is impossible to draw lines as rectangles because line width scaling would not work
208208
// (QPicture is scaled later in QgsVectorLayer)
209209
// -> reset boundingRect for cross, cross2
@@ -219,8 +219,8 @@ QPicture QgsMarkerCatalogue::hardMarker ( QString name, int s, QPen pen, QBrush
219219
add = 0;
220220
}
221221

222-
picpainter.drawLine(0, half, size-1+add, half); // horizontal
223-
picpainter.drawLine(half, 0, half, size-1+add); // vertical
222+
myPainter.drawLine(0, half, size-1+add, half); // horizontal
223+
myPainter.drawLine(half, 0, half, size-1+add); // vertical
224224
box.setRect ( 0, 0, size, size );
225225
}
226226
else if ( name == "cross2" )
@@ -237,18 +237,17 @@ QPicture QgsMarkerCatalogue::hardMarker ( QString name, int s, QPen pen, QBrush
237237

238238
int addwidth = (int) ( 0.5 * lw ); // width correction, cca lw/2 * cos(45)
239239

240-
picpainter.drawLine( 0, 0, size-1+add, size-1+add);
241-
picpainter.drawLine( 0, size-1, size-1+add, 0-add);
240+
myPainter.drawLine( 0, 0, size-1+add, size-1+add);
241+
myPainter.drawLine( 0, size-1, size-1+add, 0-add);
242242

243243
box.setRect ( -addwidth, -addwidth, size + 2*addwidth, size + 2*addwidth );
244244
}
245-
picpainter.end();
246-
247245
if ( name == "cross" || name == "cross2" )
248246
{
249247
picture.setBoundingRect ( box );
250248
}
249+
myPainter.end();
251250

252-
return picture;
251+
return myPixmap;
253252
}
254253

src/core/qgsmarkercatalogue.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class QgsMarkerCatalogue{
5656
QStringList mList;
5757

5858
/** Hard coded */
59-
QPicture hardMarker ( QString name, int size, QPen pen, QBrush brush, bool qtBug = true );
59+
QPixmap hardMarker ( QString name, int size, QPen pen, QBrush brush, bool qtBug = true );
6060

6161
};
6262

0 commit comments

Comments
 (0)