Skip to content
Permalink
Browse files

Formatting changes only

git-svn-id: http://svn.osgeo.org/qgis/trunk@5150 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux
timlinux committed Apr 3, 2006
1 parent d5391cf commit 0dfa5bd14630c410560ab4672d1a0f3a7e56bf7e
Showing with 148 additions and 144 deletions.
  1. +148 −144 src/core/qgsmarkercatalogue.cpp
@@ -1,9 +1,9 @@
/***************************************************************************
qgsmarkercatalogue.cpp
-------------------
begin : March 2005
copyright : (C) 2005 by Radim Blazek
email : blazek@itc.it
qgsmarkercatalogue.cpp
-------------------
begin : March 2005
copyright : (C) 2005 by Radim Blazek
email : blazek@itc.it
***************************************************************************/
/***************************************************************************
* *
@@ -35,40 +35,40 @@ QgsMarkerCatalogue *QgsMarkerCatalogue::mMarkerCatalogue = 0;

QgsMarkerCatalogue::QgsMarkerCatalogue()
{
// Init list

// Hardcoded markers
mList.append ( "hard:circle" );
mList.append ( "hard:rectangle" );
mList.append ( "hard:diamond" );
mList.append ( "hard:cross" );
mList.append ( "hard:cross2" );

// SVG
QString svgPath = QgsApplication::svgPath();

// TODO recursiv ?
QDir dir ( svgPath );

QStringList dl = dir.entryList(QDir::Dirs);

for ( QStringList::iterator it = dl.begin(); it != dl.end(); ++it ) {
if ( *it == "." || *it == ".." ) continue;

QDir dir2 ( svgPath + *it );

QStringList dl2 = dir2.entryList("*.svg",QDir::Files);

for ( QStringList::iterator it2 = dl2.begin(); it2 != dl2.end(); ++it2 ) {
// TODO test if it is correct SVG
mList.append ( "svg:" + svgPath + *it + "/" + *it2 );
}
// Init list

// Hardcoded markers
mList.append ( "hard:circle" );
mList.append ( "hard:rectangle" );
mList.append ( "hard:diamond" );
mList.append ( "hard:cross" );
mList.append ( "hard:cross2" );

// SVG
QString svgPath = QgsApplication::svgPath();

// TODO recursiv ?
QDir dir ( svgPath );

QStringList dl = dir.entryList(QDir::Dirs);

for ( QStringList::iterator it = dl.begin(); it != dl.end(); ++it ) {
if ( *it == "." || *it == ".." ) continue;

QDir dir2 ( svgPath + *it );

QStringList dl2 = dir2.entryList("*.svg",QDir::Files);

for ( QStringList::iterator it2 = dl2.begin(); it2 != dl2.end(); ++it2 ) {
// TODO test if it is correct SVG
mList.append ( "svg:" + svgPath + *it + "/" + *it2 );
}
}
}

QStringList QgsMarkerCatalogue::list()
{
return mList;
return mList;
}

QgsMarkerCatalogue::~QgsMarkerCatalogue()
@@ -77,49 +77,49 @@ QgsMarkerCatalogue::~QgsMarkerCatalogue()

QgsMarkerCatalogue *QgsMarkerCatalogue::instance()
{
if ( !QgsMarkerCatalogue::mMarkerCatalogue ) {
QgsMarkerCatalogue::mMarkerCatalogue = new QgsMarkerCatalogue();
}
return QgsMarkerCatalogue::mMarkerCatalogue;
if ( !QgsMarkerCatalogue::mMarkerCatalogue ) {
QgsMarkerCatalogue::mMarkerCatalogue = new QgsMarkerCatalogue();
}

return QgsMarkerCatalogue::mMarkerCatalogue;
}

QPixmap QgsMarkerCatalogue::marker ( QString fullName, int size, QPen pen, QBrush brush, bool qtBug )
{
//std::cerr << "QgsMarkerCatalogue::marker " << fullName.toLocal8Bit().data() << " sice:" << size << std::endl;
if ( fullName.left(5) == "hard:" )
{
QPicture myPicture = hardMarker ( fullName.mid(5), size, pen, brush, qtBug );
QPixmap myPixmap = QPixmap (myPicture.width(),myPicture.height());

// The following is window-system-conditional since (at least)
// the combination of Qt 4.1.0 and RealVNC's Xvnc 4.1
// will result in the pixmap becoming invisible if it is filled
// with a non-opaque colour.
// This is probably because Xvnc 4.1 doesn't have the RENDER
// extension compiled into it.
//std::cerr << "QgsMarkerCatalogue::marker " << fullName.toLocal8Bit().data() << " sice:" << size << std::endl;
if ( fullName.left(5) == "hard:" )
{
QPicture myPicture = hardMarker ( fullName.mid(5), size, pen, brush, qtBug );
QPixmap myPixmap = QPixmap (myPicture.width(),myPicture.height());

// The following is window-system-conditional since (at least)
// the combination of Qt 4.1.0 and RealVNC's Xvnc 4.1
// will result in the pixmap becoming invisible if it is filled
// with a non-opaque colour.
// This is probably because Xvnc 4.1 doesn't have the RENDER
// extension compiled into it.
#if defined(Q_WS_X11)
// Do a runtime test to see if the X RENDER extension is available
if ( myPixmap.x11PictureHandle() )
{
// Do a runtime test to see if the X RENDER extension is available
if ( myPixmap.x11PictureHandle() )
{
#endif
myPixmap.fill(QColor(255,255,255,0)); // transparent
myPixmap.fill(QColor(255,255,255,0)); // transparent
#if defined(Q_WS_X11)
}
else
{
myPixmap.fill(QColor(255,255,255)); // opaque
}
}
else
{
myPixmap.fill(QColor(255,255,255)); // opaque
}
#endif

QPainter myPainter(&myPixmap);
myPainter.drawPicture(0,0,myPicture);
return myPixmap;
} else if ( fullName.left(4) == "svg:" ) {
return svgMarker ( fullName.mid(4), size );
}
QPainter myPainter(&myPixmap);
myPainter.drawPicture(0,0,myPicture);
return myPixmap;
} else if ( fullName.left(4) == "svg:" ) {
return svgMarker ( fullName.mid(4), size );
}

return QPixmap(); // empty
return QPixmap(); // empty
}

QPixmap QgsMarkerCatalogue::svgMarker ( QString filename, int scaleFactor)
@@ -162,89 +162,93 @@ QPixmap QgsMarkerCatalogue::svgMarker ( QString filename, int scaleFactor)

QPicture QgsMarkerCatalogue::hardMarker ( QString name, int s, QPen pen, QBrush brush, bool qtBug )
{
// Size of polygon symbols is calculated so that the area is equal to circle with
// diameter mPointSize

QPicture picture;

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

// Picture
QPainter picpainter;
picpainter.begin(&picture);
picpainter.setRenderHint(QPainter::Antialiasing);

// Also width must be odd otherwise there are discrepancies visible in canvas!
int lw = (int)(2*floor((double)pen.width()/2)+1); // -> lw > 0
pen.setWidth(lw);
picpainter.setPen ( pen );
picpainter.setBrush( brush);

QRect box;
if ( name == "circle" )
{
picpainter.drawEllipse(0, 0, size, size);
}
else if ( name == "rectangle" )
// Size of polygon symbols is calculated so that the area is equal to circle with
// diameter mPointSize

QPicture picture;

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

// Picture
QPainter picpainter;
picpainter.begin(&picture);
picpainter.setRenderHint(QPainter::Antialiasing);

// Also width must be odd otherwise there are discrepancies visible in canvas!
int lw = (int)(2*floor((double)pen.width()/2)+1); // -> lw > 0
pen.setWidth(lw);
picpainter.setPen ( pen );
picpainter.setBrush( brush);

QRect box;
if ( name == "circle" )
{
picpainter.drawEllipse(0, 0, size, size);
}
else if ( name == "rectangle" )
{
size = (int) (2*floor(sqrt(area)/2.) + 1);
picpainter.drawRect(0, 0, size, size);
}
else if ( name == "diamond" )
{
half = (int) ( sqrt(area/2.) );
QPolygon pa(4);
pa.setPoint ( 0, 0, half);
pa.setPoint ( 1, half, 2*half);
pa.setPoint ( 2, 2*half, half);
pa.setPoint ( 3, half, 0);
picpainter.drawPolygon ( pa );
}
// Warning! if pen width > 0 picpainter.drawLine(x1,y1,x2,y2) will draw only (x1,y1,x2-1,y2-1) !
// It is impossible to draw lines as rectangles because line width scaling would not work
// (QPicture is scaled later in QgsVectorLayer)
// -> reset boundingRect for cross, cross2
else if ( name == "cross" )
{
int add;
if ( qtBug )
{
size = (int) (2*floor(sqrt(area)/2.) + 1);
picpainter.drawRect(0, 0, size, size);
add = 1; // lw always > 0
}
else if ( name == "diamond" )
{
half = (int) ( sqrt(area/2.) );
QPolygon pa(4);
pa.setPoint ( 0, 0, half);
pa.setPoint ( 1, half, 2*half);
pa.setPoint ( 2, 2*half, half);
pa.setPoint ( 3, half, 0);
picpainter.drawPolygon ( pa );
}
// Warning! if pen width > 0 picpainter.drawLine(x1,y1,x2,y2) will draw only (x1,y1,x2-1,y2-1) !
// It is impossible to draw lines as rectangles because line width scaling would not work
// (QPicture is scaled later in QgsVectorLayer)
// -> reset boundingRect for cross, cross2
else if ( name == "cross" )
else
{
int add;
if ( qtBug ) {
add = 1; // lw always > 0
} else {
add = 0;
}

picpainter.drawLine(0, half, size-1+add, half); // horizontal
picpainter.drawLine(half, 0, half, size-1+add); // vertical
box.setRect ( 0, 0, size, size );
add = 0;
}
else if ( name == "cross2" )
{
half = (int) floor( s/2/sqrt(2.0));
size = 2*half + 1;

int add;
if ( qtBug ) {
add = 1; // lw always > 0
} else {
add = 0;
}

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

picpainter.drawLine( 0, 0, size-1+add, size-1+add);
picpainter.drawLine( 0, size-1, size-1+add, 0-add);

box.setRect ( -addwidth, -addwidth, size + 2*addwidth, size + 2*addwidth );
}
picpainter.end();

if ( name == "cross" || name == "cross2" ) {
picture.setBoundingRect ( box );
picpainter.drawLine(0, half, size-1+add, half); // horizontal
picpainter.drawLine(half, 0, half, size-1+add); // vertical
box.setRect ( 0, 0, size, size );
}
else if ( name == "cross2" )
{
half = (int) floor( s/2/sqrt(2.0));
size = 2*half + 1;

int add;
if ( qtBug ) {
add = 1; // lw always > 0
} else {
add = 0;
}

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

picpainter.drawLine( 0, 0, size-1+add, size-1+add);
picpainter.drawLine( 0, size-1, size-1+add, 0-add);

box.setRect ( -addwidth, -addwidth, size + 2*addwidth, size + 2*addwidth );
}
picpainter.end();

if ( name == "cross" || name == "cross2" )
{
picture.setBoundingRect ( box );
}

return picture;
}

0 comments on commit 0dfa5bd

Please sign in to comment.
You can’t perform that action at this time.