@@ -28,6 +28,7 @@ email : blazek@itc.it
28
28
#include < QPicture>
29
29
#include < QSvgRenderer>
30
30
31
+ #include " qgis.h"
31
32
#include " qgsapplication.h"
32
33
#include " qgsmarkercatalogue.h"
33
34
@@ -89,36 +90,12 @@ QPixmap QgsMarkerCatalogue::marker ( QString fullName, int size, QPen pen, QBrus
89
90
// std::cerr << "QgsMarkerCatalogue::marker " << fullName.toLocal8Bit().data() << " sice:" << size << std::endl;
90
91
if ( fullName.left (5 ) == " hard:" )
91
92
{
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
+ {
119
97
return svgMarker ( fullName.mid (4 ), size );
120
98
}
121
-
122
99
return QPixmap (); // empty
123
100
}
124
101
@@ -160,38 +137,61 @@ QPixmap QgsMarkerCatalogue::svgMarker ( QString filename, int scaleFactor)
160
137
return myPixmap;
161
138
}
162
139
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 )
164
141
{
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);
165
165
// Size of polygon symbols is calculated so that the area is equal to circle with
166
166
// diameter mPointSize
167
167
168
- QPicture picture;
169
168
170
169
// Size for circle
171
170
int half = (int )floor (s/2.0 ); // number of points from center
172
171
int size = 2 *half + 1 ; // must be odd
173
172
double area = 3.14 * (size/2 .) * (size/2 .);
174
173
175
174
// 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);
179
178
180
179
// Also width must be odd otherwise there are discrepancies visible in canvas!
181
180
int lw = (int )(2 *floor ((double )pen.width ()/2 )+1 ); // -> lw > 0
182
181
pen.setWidth (lw);
183
- picpainter.setPen ( pen );
184
- picpainter.setBrush ( brush);
185
-
182
+ myPainter.setPen ( pen );
183
+ myPainter.setBrush ( brush);
186
184
QRect box;
185
+
187
186
if ( name == " circle" )
188
187
{
189
- picpainter.drawEllipse (0 , 0 , size, size);
188
+ std::cout << " Drawing circle of " << size << std::endl;
189
+ myPainter.drawEllipse (0 , 0 , size, size);
190
190
}
191
191
else if ( name == " rectangle" )
192
192
{
193
193
size = (int ) (2 *floor (sqrt (area)/2 .) + 1 );
194
- picpainter .drawRect (0 , 0 , size, size);
194
+ myPainter .drawRect (0 , 0 , size, size);
195
195
}
196
196
else if ( name == " diamond" )
197
197
{
@@ -201,9 +201,9 @@ QPicture QgsMarkerCatalogue::hardMarker ( QString name, int s, QPen pen, QBrush
201
201
pa.setPoint ( 1 , half, 2 *half);
202
202
pa.setPoint ( 2 , 2 *half, half);
203
203
pa.setPoint ( 3 , half, 0 );
204
- picpainter .drawPolygon ( pa );
204
+ myPainter .drawPolygon ( pa );
205
205
}
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) !
207
207
// It is impossible to draw lines as rectangles because line width scaling would not work
208
208
// (QPicture is scaled later in QgsVectorLayer)
209
209
// -> reset boundingRect for cross, cross2
@@ -219,8 +219,8 @@ QPicture QgsMarkerCatalogue::hardMarker ( QString name, int s, QPen pen, QBrush
219
219
add = 0 ;
220
220
}
221
221
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
224
224
box.setRect ( 0 , 0 , size, size );
225
225
}
226
226
else if ( name == " cross2" )
@@ -237,18 +237,17 @@ QPicture QgsMarkerCatalogue::hardMarker ( QString name, int s, QPen pen, QBrush
237
237
238
238
int addwidth = (int ) ( 0.5 * lw ); // width correction, cca lw/2 * cos(45)
239
239
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);
242
242
243
243
box.setRect ( -addwidth, -addwidth, size + 2 *addwidth, size + 2 *addwidth );
244
244
}
245
- picpainter.end ();
246
-
247
245
if ( name == " cross" || name == " cross2" )
248
246
{
249
247
picture.setBoundingRect ( box );
250
248
}
249
+ myPainter.end ();
251
250
252
- return picture ;
251
+ return myPixmap ;
253
252
}
254
253
0 commit comments