1
1
/* **************************************************************************
2
- qgsmarkercatalogue.cpp
3
- -------------------
4
- begin : March 2005
5
- copyright : (C) 2005 by Radim Blazek
6
- email : blazek@itc.it
2
+ qgsmarkercatalogue.cpp
3
+ -------------------
4
+ begin : March 2005
5
+ copyright : (C) 2005 by Radim Blazek
6
+ email : blazek@itc.it
7
7
***************************************************************************/
8
8
/* **************************************************************************
9
9
* *
@@ -35,40 +35,40 @@ QgsMarkerCatalogue *QgsMarkerCatalogue::mMarkerCatalogue = 0;
35
35
36
36
QgsMarkerCatalogue::QgsMarkerCatalogue ()
37
37
{
38
- // Init list
39
-
40
- // Hardcoded markers
41
- mList .append ( " hard:circle" );
42
- mList .append ( " hard:rectangle" );
43
- mList .append ( " hard:diamond" );
44
- mList .append ( " hard:cross" );
45
- mList .append ( " hard:cross2" );
46
-
47
- // SVG
48
- QString svgPath = QgsApplication::svgPath ();
49
-
50
- // TODO recursiv ?
51
- QDir dir ( svgPath );
52
-
53
- QStringList dl = dir.entryList (QDir::Dirs);
54
-
55
- for ( QStringList::iterator it = dl.begin (); it != dl.end (); ++it ) {
56
- if ( *it == " ." || *it == " .." ) continue ;
57
-
58
- QDir dir2 ( svgPath + *it );
59
-
60
- QStringList dl2 = dir2.entryList (" *.svg" ,QDir::Files);
61
-
62
- for ( QStringList::iterator it2 = dl2.begin (); it2 != dl2.end (); ++it2 ) {
63
- // TODO test if it is correct SVG
64
- mList .append ( " svg:" + svgPath + *it + " /" + *it2 );
65
- }
38
+ // Init list
39
+
40
+ // Hardcoded markers
41
+ mList .append ( " hard:circle" );
42
+ mList .append ( " hard:rectangle" );
43
+ mList .append ( " hard:diamond" );
44
+ mList .append ( " hard:cross" );
45
+ mList .append ( " hard:cross2" );
46
+
47
+ // SVG
48
+ QString svgPath = QgsApplication::svgPath ();
49
+
50
+ // TODO recursiv ?
51
+ QDir dir ( svgPath );
52
+
53
+ QStringList dl = dir.entryList (QDir::Dirs);
54
+
55
+ for ( QStringList::iterator it = dl.begin (); it != dl.end (); ++it ) {
56
+ if ( *it == " ." || *it == " .." ) continue ;
57
+
58
+ QDir dir2 ( svgPath + *it );
59
+
60
+ QStringList dl2 = dir2.entryList (" *.svg" ,QDir::Files);
61
+
62
+ for ( QStringList::iterator it2 = dl2.begin (); it2 != dl2.end (); ++it2 ) {
63
+ // TODO test if it is correct SVG
64
+ mList .append ( " svg:" + svgPath + *it + " /" + *it2 );
66
65
}
66
+ }
67
67
}
68
68
69
69
QStringList QgsMarkerCatalogue::list ()
70
70
{
71
- return mList ;
71
+ return mList ;
72
72
}
73
73
74
74
QgsMarkerCatalogue::~QgsMarkerCatalogue ()
@@ -77,49 +77,49 @@ QgsMarkerCatalogue::~QgsMarkerCatalogue()
77
77
78
78
QgsMarkerCatalogue *QgsMarkerCatalogue::instance ()
79
79
{
80
- if ( !QgsMarkerCatalogue::mMarkerCatalogue ) {
81
- QgsMarkerCatalogue::mMarkerCatalogue = new QgsMarkerCatalogue ();
82
- }
83
-
84
- return QgsMarkerCatalogue::mMarkerCatalogue ;
80
+ if ( !QgsMarkerCatalogue::mMarkerCatalogue ) {
81
+ QgsMarkerCatalogue::mMarkerCatalogue = new QgsMarkerCatalogue ();
82
+ }
83
+
84
+ return QgsMarkerCatalogue::mMarkerCatalogue ;
85
85
}
86
86
87
87
QPixmap QgsMarkerCatalogue::marker ( QString fullName, int size, QPen pen, QBrush brush, bool qtBug )
88
88
{
89
- // std::cerr << "QgsMarkerCatalogue::marker " << fullName.toLocal8Bit().data() << " sice:" << size << std::endl;
90
- if ( fullName.left (5 ) == " hard:" )
91
- {
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.
89
+ // std::cerr << "QgsMarkerCatalogue::marker " << fullName.toLocal8Bit().data() << " sice:" << size << std::endl;
90
+ if ( fullName.left (5 ) == " hard:" )
91
+ {
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
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
- {
102
+ // Do a runtime test to see if the X RENDER extension is available
103
+ if ( myPixmap.x11PictureHandle () )
104
+ {
105
105
#endif
106
- myPixmap.fill (QColor (255 ,255 ,255 ,0 )); // transparent
106
+ myPixmap.fill (QColor (255 ,255 ,255 ,0 )); // transparent
107
107
#if defined(Q_WS_X11)
108
- }
109
- else
110
- {
111
- myPixmap.fill (QColor (255 ,255 ,255 )); // opaque
112
- }
108
+ }
109
+ else
110
+ {
111
+ myPixmap.fill (QColor (255 ,255 ,255 )); // opaque
112
+ }
113
113
#endif
114
114
115
- QPainter myPainter (&myPixmap);
116
- myPainter.drawPicture (0 ,0 ,myPicture);
117
- return myPixmap;
118
- } else if ( fullName.left (4 ) == " svg:" ) {
119
- return svgMarker ( fullName.mid (4 ), size );
120
- }
115
+ QPainter myPainter (&myPixmap);
116
+ myPainter.drawPicture (0 ,0 ,myPicture);
117
+ return myPixmap;
118
+ } else if ( fullName.left (4 ) == " svg:" ) {
119
+ return svgMarker ( fullName.mid (4 ), size );
120
+ }
121
121
122
- return QPixmap (); // empty
122
+ return QPixmap (); // empty
123
123
}
124
124
125
125
QPixmap QgsMarkerCatalogue::svgMarker ( QString filename, int scaleFactor)
@@ -162,89 +162,93 @@ QPixmap QgsMarkerCatalogue::svgMarker ( QString filename, int scaleFactor)
162
162
163
163
QPicture QgsMarkerCatalogue::hardMarker ( QString name, int s, QPen pen, QBrush brush, bool qtBug )
164
164
{
165
- // Size of polygon symbols is calculated so that the area is equal to circle with
166
- // diameter mPointSize
167
-
168
- QPicture picture;
169
-
170
- // Size for circle
171
- int half = (int )floor (s/2.0 ); // number of points from center
172
- int size = 2 *half + 1 ; // must be odd
173
- double area = 3.14 * (size/2 .) * (size/2 .);
174
-
175
- // Picture
176
- QPainter picpainter;
177
- picpainter.begin (&picture);
178
- picpainter.setRenderHint (QPainter::Antialiasing);
179
-
180
- // Also width must be odd otherwise there are discrepancies visible in canvas!
181
- int lw = (int )(2 *floor ((double )pen.width ()/2 )+1 ); // -> lw > 0
182
- pen.setWidth (lw);
183
- picpainter.setPen ( pen );
184
- picpainter.setBrush ( brush);
185
-
186
- QRect box;
187
- if ( name == " circle" )
188
- {
189
- picpainter.drawEllipse (0 , 0 , size, size);
190
- }
191
- else if ( name == " rectangle" )
165
+ // Size of polygon symbols is calculated so that the area is equal to circle with
166
+ // diameter mPointSize
167
+
168
+ QPicture picture;
169
+
170
+ // Size for circle
171
+ int half = (int )floor (s/2.0 ); // number of points from center
172
+ int size = 2 *half + 1 ; // must be odd
173
+ double area = 3.14 * (size/2 .) * (size/2 .);
174
+
175
+ // Picture
176
+ QPainter picpainter;
177
+ picpainter.begin (&picture);
178
+ picpainter.setRenderHint (QPainter::Antialiasing);
179
+
180
+ // Also width must be odd otherwise there are discrepancies visible in canvas!
181
+ int lw = (int )(2 *floor ((double )pen.width ()/2 )+1 ); // -> lw > 0
182
+ pen.setWidth (lw);
183
+ picpainter.setPen ( pen );
184
+ picpainter.setBrush ( brush);
185
+
186
+ QRect box;
187
+ if ( name == " circle" )
188
+ {
189
+ picpainter.drawEllipse (0 , 0 , size, size);
190
+ }
191
+ else if ( name == " rectangle" )
192
+ {
193
+ size = (int ) (2 *floor (sqrt (area)/2 .) + 1 );
194
+ picpainter.drawRect (0 , 0 , size, size);
195
+ }
196
+ else if ( name == " diamond" )
197
+ {
198
+ half = (int ) ( sqrt (area/2 .) );
199
+ QPolygon pa (4 );
200
+ pa.setPoint ( 0 , 0 , half);
201
+ pa.setPoint ( 1 , half, 2 *half);
202
+ pa.setPoint ( 2 , 2 *half, half);
203
+ pa.setPoint ( 3 , half, 0 );
204
+ picpainter.drawPolygon ( pa );
205
+ }
206
+ // Warning! if pen width > 0 picpainter.drawLine(x1,y1,x2,y2) will draw only (x1,y1,x2-1,y2-1) !
207
+ // It is impossible to draw lines as rectangles because line width scaling would not work
208
+ // (QPicture is scaled later in QgsVectorLayer)
209
+ // -> reset boundingRect for cross, cross2
210
+ else if ( name == " cross" )
211
+ {
212
+ int add;
213
+ if ( qtBug )
192
214
{
193
- size = (int ) (2 *floor (sqrt (area)/2 .) + 1 );
194
- picpainter.drawRect (0 , 0 , size, size);
215
+ add = 1 ; // lw always > 0
195
216
}
196
- else if ( name == " diamond" )
197
- {
198
- half = (int ) ( sqrt (area/2 .) );
199
- QPolygon pa (4 );
200
- pa.setPoint ( 0 , 0 , half);
201
- pa.setPoint ( 1 , half, 2 *half);
202
- pa.setPoint ( 2 , 2 *half, half);
203
- pa.setPoint ( 3 , half, 0 );
204
- picpainter.drawPolygon ( pa );
205
- }
206
- // Warning! if pen width > 0 picpainter.drawLine(x1,y1,x2,y2) will draw only (x1,y1,x2-1,y2-1) !
207
- // It is impossible to draw lines as rectangles because line width scaling would not work
208
- // (QPicture is scaled later in QgsVectorLayer)
209
- // -> reset boundingRect for cross, cross2
210
- else if ( name == " cross" )
217
+ else
211
218
{
212
- int add;
213
- if ( qtBug ) {
214
- add = 1 ; // lw always > 0
215
- } else {
216
- add = 0 ;
217
- }
218
-
219
- picpainter.drawLine (0 , half, size-1 +add, half); // horizontal
220
- picpainter.drawLine (half, 0 , half, size-1 +add); // vertical
221
- box.setRect ( 0 , 0 , size, size );
219
+ add = 0 ;
222
220
}
223
- else if ( name == " cross2" )
224
- {
225
- half = (int ) floor ( s/2 /sqrt (2.0 ));
226
- size = 2 *half + 1 ;
227
-
228
- int add;
229
- if ( qtBug ) {
230
- add = 1 ; // lw always > 0
231
- } else {
232
- add = 0 ;
233
- }
234
-
235
- int addwidth = (int ) ( 0.5 * lw ); // width correction, cca lw/2 * cos(45)
236
-
237
- picpainter.drawLine ( 0 , 0 , size-1 +add, size-1 +add);
238
- picpainter.drawLine ( 0 , size-1 , size-1 +add, 0 -add);
239
-
240
- box.setRect ( -addwidth, -addwidth, size + 2 *addwidth, size + 2 *addwidth );
241
- }
242
- picpainter.end ();
243
221
244
- if ( name == " cross" || name == " cross2" ) {
245
- picture.setBoundingRect ( box );
222
+ picpainter.drawLine (0 , half, size-1 +add, half); // horizontal
223
+ picpainter.drawLine (half, 0 , half, size-1 +add); // vertical
224
+ box.setRect ( 0 , 0 , size, size );
225
+ }
226
+ else if ( name == " cross2" )
227
+ {
228
+ half = (int ) floor ( s/2 /sqrt (2.0 ));
229
+ size = 2 *half + 1 ;
230
+
231
+ int add;
232
+ if ( qtBug ) {
233
+ add = 1 ; // lw always > 0
234
+ } else {
235
+ add = 0 ;
246
236
}
247
237
248
- return picture;
238
+ int addwidth = (int ) ( 0.5 * lw ); // width correction, cca lw/2 * cos(45)
239
+
240
+ picpainter.drawLine ( 0 , 0 , size-1 +add, size-1 +add);
241
+ picpainter.drawLine ( 0 , size-1 , size-1 +add, 0 -add);
242
+
243
+ box.setRect ( -addwidth, -addwidth, size + 2 *addwidth, size + 2 *addwidth );
244
+ }
245
+ picpainter.end ();
246
+
247
+ if ( name == " cross" || name == " cross2" )
248
+ {
249
+ picture.setBoundingRect ( box );
250
+ }
251
+
252
+ return picture;
249
253
}
250
254
0 commit comments