Skip to content

Commit 0c6c957

Browse files
author
mhugent
committedMay 17, 2008
Fix for problems with floating point outline width for hard markers
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8447 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed
 

‎src/core/symbology/qgsmarkercatalogue.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ QgsMarkerCatalogue *QgsMarkerCatalogue::instance()
9191
return QgsMarkerCatalogue::mMarkerCatalogue;
9292
}
9393

94-
QImage QgsMarkerCatalogue::imageMarker ( QString fullName, int size, QPen pen, QBrush brush, bool qtBug )
94+
QImage QgsMarkerCatalogue::imageMarker ( QString fullName, double size, QPen pen, QBrush brush, bool qtBug )
9595
{
9696

9797
//
@@ -100,15 +100,15 @@ QImage QgsMarkerCatalogue::imageMarker ( QString fullName, int size, QPen pen, Q
100100
QImage myImage;
101101
if ( fullName.left(5) == "hard:" )
102102
{
103-
myImage = QImage (size, size, QImage::Format_ARGB32_Premultiplied);
103+
myImage = QImage (size + 1, size + 1, QImage::Format_ARGB32_Premultiplied);
104104
}
105105
else
106106
{
107107
// TODO Change this logic so width is size and height is same
108108
// proportion of scale factor as in oritignal SVG TS XXX
109109
if (size < 1) size=1;
110110
//QPixmap myPixmap = QPixmap(width,height);
111-
myImage = QImage(size,size, QImage::Format_ARGB32_Premultiplied);
111+
myImage = QImage(size ,size , QImage::Format_ARGB32_Premultiplied);
112112
}
113113

114114
// starting with transparent QImage
@@ -141,7 +141,7 @@ QImage QgsMarkerCatalogue::imageMarker ( QString fullName, int size, QPen pen, Q
141141
return QImage(); // empty
142142
}
143143

144-
QPicture QgsMarkerCatalogue::pictureMarker ( QString fullName, int size, QPen pen, QBrush brush, bool qtBug )
144+
QPicture QgsMarkerCatalogue::pictureMarker ( QString fullName, double size, QPen pen, QBrush brush, bool qtBug )
145145
{
146146

147147
//
@@ -182,42 +182,42 @@ QPicture QgsMarkerCatalogue::pictureMarker ( QString fullName, int size, QPen pe
182182
return QPicture(); // empty
183183
}
184184

185-
void QgsMarkerCatalogue::svgMarker ( QPainter * thepPainter, QString filename, int scaleFactor)
185+
void QgsMarkerCatalogue::svgMarker ( QPainter * thepPainter, QString filename, double scaleFactor)
186186
{
187187
QSvgRenderer mySVG;
188188
mySVG.load(filename);
189189
mySVG.render(thepPainter);
190190
}
191191

192-
void QgsMarkerCatalogue::hardMarker (QPainter * thepPainter, QString name, int s, QPen pen, QBrush brush, bool qtBug )
192+
void QgsMarkerCatalogue::hardMarker (QPainter * thepPainter, QString name, double s, QPen pen, QBrush brush, bool qtBug )
193193
{
194194
// Size of polygon symbols is calculated so that the boundingbox is circumscribed
195195
// around a circle with diameter mPointSize
196196

197-
int half = s/2; // number of points from center
197+
double half = s/2; // number of points from center
198198

199199
QgsDebugMsg(QString("Hard marker size %1").arg(s));
200200

201201
// Find out center coordinates.
202-
int x_c = s/2;
203-
int y_c = x_c;
202+
double x_c = s/2;
203+
double y_c = x_c;
204204

205205
// Picture
206206
QPicture picture;
207207
thepPainter->begin(&picture);
208208
thepPainter->setRenderHint(QPainter::Antialiasing);
209209

210210
// Also width must be odd otherwise there are discrepancies visible in canvas!
211-
int lw = (int)(2*floor((double)pen.width()/2)+1); // -> lw > 0
212-
pen.setWidth(lw);
211+
double lw = pen.widthF();//(int)(2*floor((double)pen.widthF()/2)+1); // -> lw > 0
212+
pen.setWidthF(lw);
213213
thepPainter->setPen ( pen );
214214
thepPainter->setBrush( brush);
215215
QRect box;
216216

217217
// Circle radius, is used for other figures also, when compensating for line
218218
// width is necessary.
219219

220-
int r = (s-2*lw)/2-1;
220+
double r = (s-2*lw)/2-1;
221221
QgsDebugMsg(QString("Hard marker radius %1").arg(r));
222222

223223
if ( name == "circle" )

‎src/core/symbology/qgsmarkercatalogue.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ class CORE_EXPORT QgsMarkerCatalogue
4343
/** Returns pixmap of the marker
4444
* \param fullName full name, e.g. hard:circle, svg:/home/usr1/marker1.svg
4545
*/
46-
QImage imageMarker (QString fullName, int size, QPen pen, QBrush brush, bool qtBug = true );
46+
QImage imageMarker (QString fullName, double size, QPen pen, QBrush brush, bool qtBug = true );
4747

4848
/** Returns qpicture of the marker
4949
* \param fullName full name, e.g. hard:circle, svg:/home/usr1/marker1.svg
5050
*/
51-
QPicture pictureMarker (QString fullName, int size, QPen pen, QBrush brush, bool qtBug = true );
51+
QPicture pictureMarker (QString fullName, double size, QPen pen, QBrush brush, bool qtBug = true );
5252

5353
/** Returns a pixmap given a filename of a svg marker
5454
* NOTE: this method needs to be public static for QgsMarkerDialog::visualizeMarkers */
55-
static void svgMarker (QPainter * thepPainter, QString name, int size );
55+
static void svgMarker (QPainter * thepPainter, QString name, double size );
5656
private:
5757

5858
/**Constructor*/
@@ -64,7 +64,7 @@ class CORE_EXPORT QgsMarkerCatalogue
6464
QStringList mList;
6565

6666
/** Hard coded */
67-
void hardMarker (QPainter * thepPainter, QString name, int size, QPen pen, QBrush brush, bool qtBug = true );
67+
void hardMarker (QPainter * thepPainter, QString name, double size, QPen pen, QBrush brush, bool qtBug = true );
6868

6969
};
7070

‎src/core/symbology/qgssymbol.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ void QgsSymbol::cache2( double widthScale, QColor selectionColor )
384384
//std::cerr << "QgsSymbol::cache2 widthScale = " << widthScale << std::endl;
385385

386386
QPen pen = mPen;
387-
pen.setWidth ( (int) ( widthScale * pen.width() ) );
388-
387+
pen.setWidthF(widthScale * pen.widthF());
389388

390389
mPointSymbolImage2 = QgsMarkerCatalogue::instance()->imageMarker ( mPointSymbolName, mPointSize * widthScale,
391390
pen, mBrush, false );

0 commit comments

Comments
 (0)
Please sign in to comment.