Skip to content
Permalink
Browse files
Updates for marker cache so that I can support qpicture again (still …
…in progress - nearly done)

Markers now are drawn generically onto a QPainter device and there will be two wrappers - one that returns a qpicture and one that returns a qpixmap.



git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5539 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jun 23, 2006
1 parent a0cf5e3 commit 3169c34cc38031543fb5df0549ccadb740301045
Showing with 110 additions and 73 deletions.
  1. +4 −4 build.mac.sh
  2. +93 −64 src/core/qgsmarkercatalogue.cpp
  3. +9 −3 src/core/qgsmarkercatalogue.h
  4. +4 −2 src/gui/qgsmarkerdialog.cpp
@@ -24,14 +24,14 @@ then
export CFLAGS="-g -Wall"
export CXXFLAGS="-g -Wall"
#for mac fink users
export CPPFLAGS=-I/sw/include
#export CPPFLAGS=-I/sw/include
else
echo "Building without debug support"
AUTOGEN_FLAGS="--disable-debug"
export CFLAGS="-O2 -Wall"
export CXXFLAGS="-O2 -Wall"
#for mac fink users
export CPPFLAGS=-I/sw/include
#export CPPFLAGS=-I/sw/include
fi

if [ x$2 = "static" ]
@@ -48,7 +48,7 @@ then
#qt installed from debian apt
#export QTDIR=/usr
export QTDIR=/usr/local/Qt4.1.3
export PATH=$QTDIR/bin:$PATH
#export PATH=/usr/local/gislibs/bin:/usr/local/graphicslibs/bin/:$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib

# Note: --enable-static=no tells compiler
@@ -60,8 +60,8 @@ then
./autogen.sh $AUTOGEN_FLAGS --prefix=${1} \
--enable-static=no \
--with-qtdir=$QTDIR
#--with-grass=/usr/local/gislibs/grass
#--enable-unittests \
#--with-grass=/usr/lib/grass
make && make install

cd tests/src
@@ -86,33 +86,28 @@ QgsMarkerCatalogue *QgsMarkerCatalogue::instance()

return QgsMarkerCatalogue::mMarkerCatalogue;
}

QPixmap QgsMarkerCatalogue::pixmapMarker ( 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:" )
{
return hardPixmapMarker ( fullName.mid(5), size, pen, brush, qtBug );
}
else if ( fullName.left(4) == "svg:" )
{
return svgPixmapMarker ( fullName.mid(4), size );
}
return QPixmap(); // empty
}

QPixmap QgsMarkerCatalogue::svgPixmapMarker ( QString filename, int scaleFactor)
{
QSvgRenderer mySVG;
mySVG.load(filename);

// TODO Change this logic so width is scaleFactor and height is same
// proportion of scale factor as in oritignal SVG TS XXX
if (scaleFactor < 1) scaleFactor=1;

//QPixmap myPixmap = QPixmap(width,height);
QPixmap myPixmap = QPixmap(scaleFactor,scaleFactor);

//
// First prepare the paintdevice that the marker will be drawn onto
//
QPixmap myPixmap;
if ( fullName.left(5) == "hard:" )
{
//Note teh +1 offset below is required because the
//otherwise the icons are getting clipped
myPixmap = QPixmap (size+1,size+1);
}
else
{
// TODO Change this logic so width is size and height is same
// proportion of scale factor as in oritignal SVG TS XXX
if (size < 1) size=1;
//QPixmap myPixmap = QPixmap(width,height);
myPixmap = QPixmap(size,size);
}
// 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
@@ -134,67 +129,103 @@ QPixmap QgsMarkerCatalogue::svgPixmapMarker ( QString filename, int scaleFactor)
#endif
QPainter myPainter(&myPixmap);
myPainter.setRenderHint(QPainter::Antialiasing);
mySVG.render(&myPainter);

return myPixmap;
//
// Now pass the paintdevice along to have the marker rndered on it
//

if ( fullName.left(5) == "hard:" )
{
hardMarker ( &myPainter, fullName.mid(5), size, pen, brush, qtBug );
return myPixmap;
}
else if ( fullName.left(4) == "svg:" )
{
svgMarker ( &myPainter, fullName.mid(4), size );
return myPixmap;
}
return QPixmap(); // empty
}

QPixmap QgsMarkerCatalogue::hardPixmapMarker ( QString name, int s, QPen pen, QBrush brush, bool qtBug )
QPicture QgsMarkerCatalogue::pictureMarker ( QString fullName, int size, QPen pen, QBrush brush, bool qtBug )
{
//Note teh +1 offset below is required because the
//scaling to odd numbers below will cause clipping otherwise
QPixmap myPixmap = QPixmap (s+1,s+1);

// 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() )
{
#endif
myPixmap.fill(QColor(255,255,255,0)); // transparent
#if defined(Q_WS_X11)
}
//
// First prepare the paintdevice that the marker will be drawn onto
//
QPicture myPicture;
if ( fullName.left(5) == "hard:" )
{
//Note teh +1 offset below is required because the
//otherwise the icons are getting clipped
myPicture = QPicture (size+1);
}
else
{
// TODO Change this logic so width is size and height is same
// proportion of scale factor as in oritignal SVG TS XXX
if (size < 1) size=1;
//QPicture myPicture = QPicture(width,height);
myPicture = QPicture(size);
}
QPainter myPainter(&myPicture);
myPainter.setRenderHint(QPainter::Antialiasing);

//
// Now pass the paintdevice along to have the marker rndered on it
//

if ( fullName.left(5) == "hard:" )
{
myPixmap.fill(QColor(255,255,255)); // opaque
hardMarker ( &myPainter, fullName.mid(5), size, pen, brush, qtBug );
return myPicture;
}
else if ( fullName.left(4) == "svg:" )
{
svgMarker ( &myPainter, fullName.mid(4), size );
return myPicture;
}
#endif
return QPicture(); // empty
}

QPainter myPainter(&myPixmap);
void QgsMarkerCatalogue::svgMarker ( QPainter * thepPainter, QString filename, int scaleFactor)
{
QSvgRenderer mySVG;
mySVG.load(filename);
mySVG.render(thepPainter);
return ;
}

void QgsMarkerCatalogue::hardMarker (QPainter * thepPainter, 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


// 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
QPicture picture;
myPainter.begin(&picture);
myPainter.setRenderHint(QPainter::Antialiasing);
thepPainter->begin(&picture);
thepPainter->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);
myPainter.setPen ( pen );
myPainter.setBrush( brush);
thepPainter->setPen ( pen );
thepPainter->setBrush( brush);
QRect box;

if ( name == "circle" )
{
myPainter.drawEllipse(0, 0, size, size);
thepPainter->drawEllipse(0, 0, size, size);
}
else if ( name == "rectangle" )
{
size = (int) (2*floor(sqrt(area)/2.) + 1);
myPainter.drawRect(0, 0, size, size);
thepPainter->drawRect(0, 0, size, size);
}
else if ( name == "diamond" )
{
@@ -204,9 +235,9 @@ QPixmap QgsMarkerCatalogue::hardPixmapMarker ( QString name, int s, QPen pen, QB
pa.setPoint ( 1, half, 2*half);
pa.setPoint ( 2, 2*half, half);
pa.setPoint ( 3, half, 0);
myPainter.drawPolygon ( pa );
thepPainter->drawPolygon ( pa );
}
// Warning! if pen width > 0 myPainter.drawLine(x1,y1,x2,y2) will draw only (x1,y1,x2-1,y2-1) !
// Warning! if pen width > 0 thepPainter->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
@@ -222,8 +253,8 @@ QPixmap QgsMarkerCatalogue::hardPixmapMarker ( QString name, int s, QPen pen, QB
add = 0;
}

myPainter.drawLine(0, half, size-1+add, half); // horizontal
myPainter.drawLine(half, 0, half, size-1+add); // vertical
thepPainter->drawLine(0, half, size-1+add, half); // horizontal
thepPainter->drawLine(half, 0, half, size-1+add); // vertical
box.setRect ( 0, 0, size, size );
}
else if ( name == "cross2" )
@@ -240,8 +271,8 @@ QPixmap QgsMarkerCatalogue::hardPixmapMarker ( QString name, int s, QPen pen, QB

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

myPainter.drawLine( 0, 0, size-1+add, size-1+add);
myPainter.drawLine( 0, size-1, size-1+add, 0-add);
thepPainter->drawLine( 0, 0, size-1+add, size-1+add);
thepPainter->drawLine( 0, size-1, size-1+add, 0-add);

box.setRect ( -addwidth, -addwidth, size + 2*addwidth, size + 2*addwidth );
}
@@ -251,7 +282,7 @@ QPixmap QgsMarkerCatalogue::hardPixmapMarker ( QString name, int s, QPen pen, QB
pa.setPoint ( 0, 0, size);
pa.setPoint ( 1, size, size);
pa.setPoint ( 2, half, 0);
myPainter.drawPolygon ( pa );
thepPainter->drawPolygon ( pa );
}
else if (name == "star")
{
@@ -268,14 +299,12 @@ QPixmap QgsMarkerCatalogue::hardPixmapMarker ( QString name, int s, QPen pen, QB
pa.setPoint(7, twoThird, half);
pa.setPoint(8, size, oneThird);
pa.setPoint(9, twoThird, oneThird);
myPainter.drawPolygon ( pa );
thepPainter->drawPolygon ( pa );
}
if ( name == "cross" || name == "cross2" )
{
picture.setBoundingRect ( box );
}
myPainter.end();

return myPixmap;
thepPainter->end();
}

@@ -24,6 +24,8 @@ class QPicture;
class QPixmap;
class QPen;
class QBrush;
class QPainter;
class QPicture;

/** Catalogue of point symbols */
class QgsMarkerCatalogue{
@@ -41,11 +43,15 @@ class QgsMarkerCatalogue{
/** Returns pixmap of the marker
* \param fullName full name, e.g. hard:circle, svg:/home/usr1/marker1.svg
*/
QPixmap pixmapMarker ( QString fullName, int size, QPen pen, QBrush brush, bool qtBug = true );
QPixmap pixmapMarker (QString fullName, int size, QPen pen, QBrush brush, bool qtBug = true );
/** Returns qpicture of the marker
* \param fullName full name, e.g. hard:circle, svg:/home/usr1/marker1.svg
*/
QPicture pictureMarker (QString fullName, int size, QPen pen, QBrush brush, bool qtBug = true );

/* Returns a pixmap given a filename of a svg marker
* NOTE: this method needs to be public static for QgsMarkerDialog::visualizeMarkers */
static QPixmap svgPixmapMarker ( QString name, int size );
static void svgMarker (QPainter * thepPainter, QString name, int size );
private:

/**Constructor*/
@@ -57,7 +63,7 @@ class QgsMarkerCatalogue{
QStringList mList;

/** Hard coded */
QPixmap hardPixmapMarker ( QString name, int size, QPen pen, QBrush brush, bool qtBug = true );
void hardMarker (QPainter * thepPainter, QString name, int size, QPen pen, QBrush brush, bool qtBug = true );

};

@@ -23,6 +23,7 @@
#include <QFileDialog>
#include <Q3IconView>
#include <QPixmap>
#include <QPainter>

#include "qgsconfig.h"
#include <qgsmarkercatalogue.h>
@@ -88,8 +89,9 @@ void QgsMarkerDialog::visualizeMarkers(QString directory)
qWarning((*it).toLocal8Bit().data());

//render the SVG file to a pixmap and put it into mIconView
QPixmap pix = QgsMarkerCatalogue::svgPixmapMarker(mCurrentDir + "/" +
(*it), 1);
QPixmap pix (10,10);
QPainter myPainter(&pix);
QgsMarkerCatalogue::svgMarker(&myPainter,mCurrentDir + "/" + (*it), 1);
Q3IconViewItem* ivi=new Q3IconViewItem(mIconView,*it,pix);

}

0 comments on commit 3169c34

Please sign in to comment.