Index: src/app/composer/qgscomposerpicture.cpp
===================================================================
--- src/app/composer/qgscomposerpicture.cpp (revision 7070)
+++ src/app/composer/qgscomposerpicture.cpp (working copy)
@@ -24,16 +24,21 @@
#include
#include
#include
+#include
+#include
+#include
#include
#include
#define PI 3.14159265358979323846
+#define QGISDEBUG 1
+
QgsComposerPicture::QgsComposerPicture ( QgsComposition *composition,
int id, QString file )
: QWidget(composition),
- Q3CanvasPolygonalItem(0),
+ QAbstractGraphicsShapeItem(0),
mPicturePath ( file ),
mPictureValid(false),
mCX(-10), mCY(-10),
@@ -54,18 +59,18 @@
init();
loadPicture();
- // Add to canvas
- setCanvas(mComposition->canvas());
+ // Add to scene
+ mComposition->canvas()->addItem(this);
- Q3CanvasPolygonalItem::show();
- Q3CanvasPolygonalItem::update();
+ QAbstractGraphicsShapeItem::show();
+ QAbstractGraphicsShapeItem::update();
writeSettings();
}
QgsComposerPicture::QgsComposerPicture ( QgsComposition *composition, int id ) :
QWidget(),
- Q3CanvasPolygonalItem(0),
+ QAbstractGraphicsShapeItem(0),
mFrame(false),
mAreaPoints(4),
mBoundingRect(0,0,0,0)
@@ -86,26 +91,25 @@
loadPicture();
adjustPictureSize();
- // Add to canvas
- setCanvas(mComposition->canvas());
+ // Add to scene
+ mComposition->canvas()->addItem(this);
recalculate();
- Q3CanvasPolygonalItem::show();
- Q3CanvasPolygonalItem::update();
+ QAbstractGraphicsShapeItem::show();
+ QAbstractGraphicsShapeItem::update();
}
void QgsComposerPicture::init ( void )
{
- mSelected = false;
- for ( int i = 0; i < 4; i++ )
- {
- mAreaPoints[i] = QPoint( 0, 0 );
- }
+ mSelected = false;
+ for ( int i = 0; i < 4; i++ )
+ {
+ mAreaPoints[i] = QPoint( 0, 0 );
+ }
- // Rectangle
- Q3CanvasPolygonalItem::setZ(60);
- setActive(true);
+ QAbstractGraphicsShapeItem::setZValue(60);
+
}
void QgsComposerPicture::loadPicture ( void )
@@ -113,71 +117,72 @@
#ifdef QGISDEBUG
std::cerr << "QgsComposerPicture::loadPicture() mPicturePath = " << mPicturePath.toLocal8Bit().data() << std::endl;
#endif
- mPicture = Q3Picture();
- mPictureValid = false;
- if ( !mPicturePath.isNull() )
- {
+ mPicture = QPicture();
+ mPictureValid = false;
+
+ if ( !mPicturePath.isNull() )
+ {
if ( mPicturePath.lower().right(3) == "svg" )
{
- if ( !mPicture.load ( mPicturePath, "svg" ) )
- {
+ if ( !mPicture.load ( mPicturePath, "svg" ) )
+ {
std::cerr << "Cannot load svg" << std::endl;
- }
- else
- {
+ }
+ else
+ {
mPictureValid = true;
- }
+ }
}
else
{
- QImage image;
- if ( !image.load(mPicturePath) )
- {
- std::cerr << "Cannot load raster" << std::endl;
- }
- else
- {
- QPainter p;
- p.begin( &mPicture );
- p.drawImage ( 0, 0, image );
- p.end();
- mPictureValid = true;
- }
+ QImage image;
+ if ( !image.load(mPicturePath) )
+ {
+ std::cerr << "Cannot load raster" << std::endl;
+ }
+ else
+ {
+ QPainter p;
+ p.begin( &mPicture );
+ p.drawImage ( 0, 0, image );
+ p.end();
+ mPictureValid = true;
+ }
}
- }
+ }
- if ( !mPictureValid )
- {
- // Dummy picture
- QPainter p;
+ if ( !mPictureValid )
+ {
+ // Dummy picture
+ QPainter p;
p.begin( &mPicture );
- QPen pen(QColor(0,0,0));
- pen.setWidthF(3.0);
- p.setPen( pen );
- p.setBrush( QBrush( QColor( 150, 150, 150) ) );
+ QPen pen(QColor(0,0,0));
+ pen.setWidthF(3.0);
+ p.setPen( pen );
+ p.setBrush( QBrush( QColor( 150, 150, 150) ) );
- int w, h;
- if ( mWidth > 0 && mHeight > 0
- && mWidth/mHeight > 0.001 && mWidth/mHeight < 1000 )
+ double w, h;
+ if ( mWidth > 0 && mHeight > 0
+ && mWidth/mHeight > 0.001 && mWidth/mHeight < 1000 )
{
- w = mWidth;
- h = mHeight;
- }
+ w = mWidth;
+ h = mHeight;
+ }
else
{
- w = 100;
- h = 100;
+ w = 100;
+ h = 100;
}
- p.drawRect ( 0, 0, w, h );
- p.drawLine ( 0, 0, w-1, h-1 );
- p.drawLine ( w-1, 0, 0, h-1 );
+ p.drawRect (QRectF(0, 0, w, h));
+ p.drawLine (QLineF(0, 0, w-1, h-1));
+ p.drawLine (QLineF(w-1, 0, 0, h-1));
p.end();
- mPicture.setBoundingRect ( QRect ( 0, 0, w, h ) );
- }
+ mPicture.setBoundingRect ( QRect( 0, 0, (int)w, (int)h ) );
+ }//END if(!mPictureValid)
}
bool QgsComposerPicture::pictureValid ( void )
@@ -190,111 +195,79 @@
#ifdef QGISDEBUG
std::cerr << "QgsComposerPicture::~QgsComposerPicture()" << std::endl;
#endif
- Q3CanvasItem::hide();
+ QGraphicsItem::hide();
}
-void QgsComposerPicture::draw ( QPainter & painter )
+void QgsComposerPicture::paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
{
#ifdef QGISDEBUG
- std::cerr << "QgsComposerPicture::draw()" << std::endl;
+ std::cerr << "QgsComposerPicture::paint()" << std::endl;
#endif
- QRect box = mPicture.boundingRect();
+ QRectF box = mPicture.boundingRect();
double scale = 1. * mWidth / box.width();
- painter.save();
+ painter->save();
- painter.translate ( mX, mY );
- painter.scale ( scale, scale );
- painter.rotate ( -mAngle );
+ painter->scale ( scale, scale );
+ painter->rotate ( -mAngle );
- painter.drawPicture ( -box.x(), -box.y(), mPicture );
+ painter->drawPicture (QPointF(-box.width()/2, -box.height()/2), mPicture );
- painter.restore();
+ painter->restore();
if ( mFrame ) {
- // TODO: rect is not correct, +/- 1 pixle - Qt3?
- painter.setPen( QPen(QColor(0,0,0), 1) );
- painter.setBrush( QBrush( Qt::NoBrush ) );
+ // TODO: rect is not correct, +/- 1 pixel - Qt3?
+ painter->setPen( QPen(QColor(0,0,0), .3) );
+ painter->setBrush( QBrush( Qt::NoBrush ) );
- painter.save();
- painter.translate ( mX, mY );
- painter.rotate ( -mAngle );
+ painter->save();
+ painter->rotate ( -mAngle );
- painter.drawRect ( 0, 0, mWidth, mHeight );
- painter.restore();
+ painter->drawRect (QRectF(-mWidth/2, -mHeight/2, mWidth, mHeight));
+
+ painter->restore();
}
// Show selected / Highlight
if ( mSelected && plotStyle() == QgsComposition::Preview ) {
- painter.setPen( mComposition->selectionPen() );
- painter.setBrush( mComposition->selectionBrush() );
+ painter->setPen( mComposition->selectionPen() );
+ painter->setBrush( mComposition->selectionBrush() );
- int s = mComposition->selectionBoxSize();
+ double s = mComposition->selectionBoxSize();
- for ( int i = 0; i < 4; i++ )
- {
- painter.save();
- painter.translate ( mAreaPoints.point(i).x(), mAreaPoints.point(i).y() );
- painter.rotate ( -mAngle + i * 90 );
-
- painter.drawRect ( 0, 0, s, s );
- painter.restore();
- }
- }
-}
+ for ( int i = 0; i < 4; i++ )
+ {
+ painter->save();
+ painter->translate ( mAreaPoints[i].x(), mAreaPoints[i].y() );
+ painter->rotate ( -mAngle + i * 90 );
+ painter->drawRect(QRectF(0, 0, s, s));
+ painter->restore();
+ }
+ }//END of drawing selected highlight
-void QgsComposerPicture::drawShape( QPainter & painter )
-{
-#ifdef QGISDEBUG
- std::cout << "QgsComposerPicture::drawShape" << std::endl;
-#endif
- draw ( painter );
}
-void QgsComposerPicture::setBox ( int x1, int y1, int x2, int y2 )
+void QgsComposerPicture::setSize(double width, double height )
{
- int tmp;
-
- if ( x1 > x2 ) { tmp = x1; x1 = x2; x2 = tmp; }
- if ( y1 > y2 ) { tmp = y1; y1 = y2; y2 = tmp; }
-
- // Center
- mCX = (x1 + x2) / 2;
- mCY = (y1 + y2) / 2;
-
- QRect box = mPicture.boundingRect();
- std::cout << "box.width() = " << box.width() << " box.height() = " << box.height() << std::endl;
-
- mWidth = x2-x1;
- mHeight = y2-y1;
+ mWidth = width;
+ mHeight = height;
adjustPictureSize();
recalculate();
}
-void QgsComposerPicture::moveBy( double x, double y )
-{
-#ifdef QGISDEBUG
- std::cout << "QgsComposerPicture::moveBy()" << std::endl;
-#endif
-
- mCX += (int) x;
- mCY += (int) y;
- recalculate();
-}
-
void QgsComposerPicture::recalculate()
{
#ifdef QGISDEBUG
std::cout << "QgsComposerPicture::recalculate" << std::endl;
#endif
- Q3CanvasPolygonalItem::invalidate();
+ QAbstractGraphicsShapeItem::prepareGeometryChange();
- QRect box = mPicture.boundingRect();
+ QRect box = mPicture.boundingRect(); //size of the image, in pixels
- double angle = PI * mAngle / 180;
+ double angle = PI * mAngle / 180; //convert angle to radians
// Angle between vertical in picture space and the vector
// from center to upper left corner of the picture
@@ -311,27 +284,24 @@
int dx = (int) ( r * cos ( anglePaper ) );
int dy = (int) ( r * sin ( anglePaper ) );
- mX = mCX - dx;
- mY = mCY - dy;
-
- // Area points
- mAreaPoints[0] = QPoint( mCX-dx, mCY-dy );
- mAreaPoints[2] = QPoint( mCX+dx, mCY+dy );
- anglePaper = angle + PI / 2 - anglePicture;
+ mAreaPoints[0] = QPointF( -dx, -dy ); //add the top-left point to the polygon
+ mAreaPoints[2] = QPointF( dx, dy ); //bottom-right
+
+ anglePaper = PI / 2 - anglePicture + angle;
dx = (int) ( r * cos ( anglePaper ) );
dy = (int) ( r * sin ( anglePaper ) );
- mAreaPoints[1] = QPoint( mCX+dx, mCY-dy );
- mAreaPoints[3] = QPoint( mCX-dx, mCY+dy );
+ mAreaPoints[1] = QPointF( dx, -dy ); //top right
+ mAreaPoints[3] = QPointF( -dx, dy ); //bottom left
+
mBoundingRect = mAreaPoints.boundingRect();
-
- Q3CanvasPolygonalItem::canvas()->setChanged(mBoundingRect);
- Q3CanvasPolygonalItem::update();
- Q3CanvasPolygonalItem::canvas()->update();
+
+ QAbstractGraphicsShapeItem::update();
+ QAbstractGraphicsShapeItem::scene()->update();
}
-QRect QgsComposerPicture::boundingRect ( void ) const
+QRectF QgsComposerPicture::boundingRect ( void ) const
{
#ifdef QGISDEBUG
std::cout << "QgsComposerPicture::boundingRect" << std::endl;
@@ -339,7 +309,7 @@
return mBoundingRect;
}
-Q3PointArray QgsComposerPicture::areaPoints() const
+QPolygonF QgsComposerPicture::areaPoints() const
{
#ifdef QGISDEBUG
std::cout << "QgsComposerPicture::areaPoints" << std::endl;
@@ -351,10 +321,14 @@
void QgsComposerPicture::on_mFrameCheckBox_stateChanged ( int )
{
+#ifdef QGISDEBUG
+ std::cout << "QgsComposerPicture::on_mFrameCheckBox_stateChanged" << std::endl;
+#endif
+
mFrame = mFrameCheckBox->isChecked();
- Q3CanvasPolygonalItem::update();
- Q3CanvasPolygonalItem::canvas()->update();
+ QAbstractGraphicsShapeItem::update();
+ QAbstractGraphicsShapeItem::scene()->update();
writeSettings();
}
@@ -364,12 +338,12 @@
#ifdef QGISDEBUG
std::cout << "QgsComposerPicture::on_mAngleLineEdit_returnPressed()" << std::endl;
#endif
-
mAngle = mAngleLineEdit->text().toDouble();
recalculate();
writeSettings();
+
}
void QgsComposerPicture::on_mWidthLineEdit_returnPressed ( )
@@ -416,7 +390,7 @@
loadPicture();
if ( !mPictureValid ) {
- QMessageBox::warning( this, tr("Warning"),
+ QMessageBox::warning( 0, tr("Warning"),
tr("Cannot load picture.") );
}
else
@@ -447,19 +421,19 @@
if ( 1.*box.width()/box.height() > 1.*mWidth/mHeight )
{
- mHeight = mWidth*box.height()/box.width();
+ mHeight = mWidth*box.height()/box.width();
}
else
{
- mWidth = mHeight*box.width()/box.height();
+ mWidth = mHeight*box.width()/box.height();
}
}
void QgsComposerPicture::setOptions ( void )
{
mPictureLineEdit->setText ( mPicturePath );
- mWidthLineEdit->setText ( QString("%1").arg( mComposition->toMM(mWidth), 0,'g') );
- mHeightLineEdit->setText ( QString("%1").arg( mComposition->toMM(mHeight), 0,'g') );
+ mWidthLineEdit->setText ( QString("%1").arg( mComposition->toMM((int)mWidth), 0,'g') );
+ mHeightLineEdit->setText ( QString("%1").arg( mComposition->toMM((int)mHeight), 0,'g') );
mAngleLineEdit->setText ( QString::number ( mAngle ) );
mFrameCheckBox->setChecked ( mFrame );
}
@@ -467,7 +441,7 @@
void QgsComposerPicture::setSelected ( bool s )
{
mSelected = s;
- Q3CanvasPolygonalItem::update(); // show highlight
+ QAbstractGraphicsShapeItem::update(); // show highlight
}
bool QgsComposerPicture::selected( void )
@@ -524,10 +498,10 @@
QgsProject::instance()->writeEntry( "Compositions", path+"picture", mPicturePath );
- QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM(mCX) );
- QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM(mCY) );
- QgsProject::instance()->writeEntry( "Compositions", path+"width", mComposition->toMM(mWidth) );
- QgsProject::instance()->writeEntry( "Compositions", path+"height", mComposition->toMM(mHeight) );
+ QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)QGraphicsItem::pos().x()) );
+ QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)QGraphicsItem::pos().y()) );
+ QgsProject::instance()->writeEntry( "Compositions", path+"width", mComposition->toMM((int)mWidth) );
+ QgsProject::instance()->writeEntry( "Compositions", path+"height", mComposition->toMM((int)mHeight) );
QgsProject::instance()->writeEntry( "Compositions", path+"angle", mAngle );
@@ -544,8 +518,10 @@
mPicturePath = QgsProject::instance()->readEntry( "Compositions", path+"picture", "", &ok) ;
- mCX = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok));
- mCY = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok));
+ double x = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok));
+ double y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok));
+ setPos(x, y);
+
mWidth = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"width", 0, &ok));
mHeight = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"height", 0, &ok));
@@ -576,4 +552,3 @@
{
return true;
}
-
Index: src/app/composer/qgscomposerscalebar.cpp
===================================================================
--- src/app/composer/qgscomposerscalebar.cpp (revision 7070)
+++ src/app/composer/qgscomposerscalebar.cpp (working copy)
@@ -13,524 +13,549 @@
* (at your option) any later version. *
* *
***************************************************************************/
+
#include "qgscomposerscalebar.h"
#include "qgscomposermap.h"
#include "qgsproject.h"
#include
#include
+#include
#include
#include
+//can we/should we remove the x and y parameters?
QgsComposerScalebar::QgsComposerScalebar ( QgsComposition *composition, int id,
int x, int y )
: QWidget(composition),
- Q3CanvasPolygonalItem(0),
+ QAbstractGraphicsShapeItem(0),
mComposition(composition),
mMap(0),
mBrush(QColor(150,150,150))
{
- setupUi(this);
+ setupUi(this);
- std::cout << "QgsComposerScalebar::QgsComposerScalebar()" << std::endl;
- mId = id;
- mSelected = false;
+ std::cout << "QgsComposerScalebar::QgsComposerScalebar()" << std::endl;
+ mId = id;
+ mSelected = false;
- mMapCanvas = mComposition->mapCanvas();
+ mMapCanvas = mComposition->mapCanvas();
- Q3CanvasPolygonalItem::setX(x);
- Q3CanvasPolygonalItem::setY(y);
+ QAbstractGraphicsShapeItem::setPos(x, y);
- init();
+ init();
- // Set map to the first available if any
- std::vector maps = mComposition->maps();
- if ( maps.size() > 0 ) {
- mMap = maps[0]->id();
+ // Set map to the first available if any
+ std::vector < QgsComposerMap * >maps = mComposition->maps();
+ if (maps.size() > 0)
+ {
+ mMap = maps[0]->id();
}
+ // Set default according to the map
+ QgsComposerMap *map = mComposition->map(mMap);
+ if (map)
+ {
+ mMapUnitsPerUnit = 1.;
+ mUnitLabel = "m";
- // Set default according to the map
- QgsComposerMap *map = mComposition->map ( mMap );
- if ( map ) {
- mMapUnitsPerUnit = 1.;
- mUnitLabel = "m";
+ // make one segment cca 1/10 of map width and it will be 1xxx, 2xxx or 5xxx
+ double mapwidth = 1. * map->QGraphicsRectItem::rect().width() / map->scale();
- // make one segment cca 1/10 of map width and it will be 1xxx, 2xxx or 5xxx
- double mapwidth = 1. * map->Q3CanvasRectangle::width() / map->scale();
+ mSegmentLength = mapwidth / 10;
- mSegmentLength = mapwidth / 10;
-
- int powerOf10 = int(pow(10.0, int(log(mSegmentLength) / log(10.0)))); // from scalebar plugin
+ int powerOf10 = int (pow(10.0, int (log(mSegmentLength) / log(10.0)))); // from scalebar plugin
- int isize = (int) ceil ( mSegmentLength / powerOf10 );
+ int isize = (int) ceil(mSegmentLength / powerOf10);
- if ( isize == 3 ) isize = 2;
- else if ( isize == 4 ) isize = 5;
- else if ( isize > 5 && isize < 8 ) isize = 5;
- else if ( isize > 7 ) isize = 10;
-
- mSegmentLength = isize * powerOf10 ;
-
- // the scale bar will take cca 1/4 of the map width
- mNumSegments = (int) ( mapwidth / 4 / mSegmentLength );
-
- int segsize = (int) ( mSegmentLength * map->scale() );
- mFont.setPointSize ( (int) ( segsize/10) );
- }
- else
+ if (isize == 3)
+ isize = 2;
+ else if (isize == 4)
+ isize = 5;
+ else if (isize > 5 && isize < 8)
+ isize = 5;
+ else if (isize > 7)
+ isize = 10;
+
+ mSegmentLength = isize * powerOf10;
+
+ // the scale bar will take cca 1/4 of the map width
+ mNumSegments = (int) (mapwidth / 4 / mSegmentLength);
+
+ int segsize = (int) (mSegmentLength * map->scale());
+
+ int fontsize = segsize / 3;
+
+ if(fontsize < 6)
+ {
+ fontsize = 6;
+ }
+
+ mFont.setPointSize(fontsize);
+ } else
{
- mMapUnitsPerUnit = 1.;
- mUnitLabel = "m";
- mSegmentLength = 1000.;
- mNumSegments = 5;
- mFont.setPointSize ( 8 );
+ mFont.setPointSize(6);
+ mMapUnitsPerUnit = 1.;
+ mUnitLabel = "m";
+ mSegmentLength = 1000.;
+ mNumSegments = 5;
}
-
- // Calc size
- recalculate();
- // Add to canvas
- setCanvas(mComposition->canvas());
+ // Calc size
+ recalculate();
- Q3CanvasPolygonalItem::show();
- Q3CanvasPolygonalItem::update();
-
- writeSettings();
+ // Add to scene
+ mComposition->canvas()->addItem(this);
+
+ QAbstractGraphicsShapeItem::show();
+ QAbstractGraphicsShapeItem::update();
+
+ writeSettings();
}
QgsComposerScalebar::QgsComposerScalebar ( QgsComposition *composition, int id )
- : Q3CanvasPolygonalItem(0),
+ : QAbstractGraphicsShapeItem(0),
mComposition(composition),
mMap(0),
mBrush(QColor(150,150,150))
{
- std::cout << "QgsComposerScalebar::QgsComposerScalebar()" << std::endl;
+ std::cout << "QgsComposerScalebar::QgsComposerScalebar()" << std::endl;
- setupUi(this);
+ setupUi(this);
- mId = id;
- mSelected = false;
+ mId = id;
+ mSelected = false;
- mMapCanvas = mComposition->mapCanvas();
+ mMapCanvas = mComposition->mapCanvas();
- init();
+ init();
- readSettings();
+ readSettings();
- // Calc size
- recalculate();
+ // Calc size
+ recalculate();
- // Add to canvas
- setCanvas(mComposition->canvas());
+ // Add to scene
+ mComposition->canvas()->addItem(this);
- Q3CanvasPolygonalItem::show();
- Q3CanvasPolygonalItem::update();
+ QAbstractGraphicsShapeItem::show();
+ QAbstractGraphicsShapeItem::update();
}
-void QgsComposerScalebar::init ( void )
+void QgsComposerScalebar::init(void)
{
- mUnitLabel = "m";
+ mUnitLabel = "m";
- // Rectangle
- Q3CanvasPolygonalItem::setZ(50);
- setActive(true);
+ // Rectangle
+ QAbstractGraphicsShapeItem::setZValue(50);
+// setActive(true);
- // Default value (map units?) for the scalebar border
- mPen.setWidthF(3.0);
+ // Default value (map units?) for the scalebar border
+ mPen.setWidthF(.5);
- // Plot style
- setPlotStyle ( QgsComposition::Preview );
-
- connect ( mComposition, SIGNAL(mapChanged(int)), this, SLOT(mapChanged(int)) );
+ // Plot style
+ setPlotStyle(QgsComposition::Preview);
+
+ connect(mComposition, SIGNAL(mapChanged(int)), this, SLOT(mapChanged(int)));
}
QgsComposerScalebar::~QgsComposerScalebar()
{
- std::cerr << "QgsComposerScalebar::~QgsComposerScalebar()" << std::endl;
- Q3CanvasItem::hide();
+ std::cerr << "QgsComposerScalebar::~QgsComposerScalebar()" << std::endl;
+ QGraphicsItem::hide();
}
-QRect QgsComposerScalebar::render ( QPainter *p )
+QRectF QgsComposerScalebar::render(QPainter * p)
{
- std::cout << "QgsComposerScalebar::render p = " << p << std::endl;
+ std::cout << "QgsComposerScalebar::render p = " << p << std::endl;
- // Painter can be 0, create dummy to avoid many if below
- QPainter *painter = NULL;
- QPixmap *pixmap = NULL;
- if ( p ) {
- painter = p;
- } else {
- pixmap = new QPixmap(1,1);
- painter = new QPainter( pixmap );
- }
+ // Painter can be 0, create dummy to avoid many if below
+ QPainter *painter;
+ QPixmap *pixmap;
+ if (p)
+ {
+ painter = p;
+ }else
+ {
+ pixmap = new QPixmap(1, 1);
+ painter = new QPainter(pixmap);
+ }
- std::cout << "mComposition->scale() = " << mComposition->scale() << std::endl;
+ std::cout << "mComposition->scale() = " << mComposition->scale() << std::endl;
- // Draw background rectangle
- painter->setPen( QPen(QColor(255,255,255), 1) );
- painter->setBrush( QBrush( QColor(255,255,255), Qt::SolidPattern) );
+ QgsComposerMap *map = mComposition->map(mMap); //Get the topmost map from the composition
- painter->drawRect ( mBoundingRect.x(), mBoundingRect.y(),
- mBoundingRect.width()+1, mBoundingRect.height()+1 ); // is it right?
-
+ double segwidth;
+ if(map)
+ {
+ segwidth = (mSegmentLength * map->scale()); //width of one segment
+ }
+ else //if there is no map, make up a segment width
+ {
+ segwidth = mSegmentLength/100;
+ }
+ double width = (segwidth * mNumSegments); //width of whole scalebar
+ double barLx = -width / 2; //x offset to the left
- // Font size in canvas units
- float size = 25.4 * mComposition->scale() * mFont.pointSizeFloat() / 72;
+ double barHeight = (25.4 * mComposition->scale() * mFont.pointSize() / 72);
- // Metrics
- QFont font ( mFont );
- font.setPointSizeFloat ( size );
- QFontMetrics metrics ( font );
-
- if ( plotStyle() == QgsComposition::Postscript )
- {
- font.setPointSizeF ( metrics.ascent() * 72.0 / mComposition->resolution() );
- }
+ double tickSize = barHeight * 1.5; //ticks go from the base of the bar to 1/2 the bar's height above it
- // Not sure about Style Strategy, QFont::PreferMatch?
- font.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
+ // Draw background rectangle
+ painter->setPen(QPen(QColor(255, 255, 255), 0));
+ painter->setBrush(QBrush(QColor(255, 255, 255), Qt::SolidPattern));
+ painter->drawRect(QRectF(barLx, -barHeight, width, barHeight));
- int xmin = 0; // min x
- int xmax = 0; // max x
- int ymin; // min y
- int ymax; // max y
+ // set the painter to have grey background and black border
+ painter->setPen(QPen(QColor(0, 0, 0), mPen.widthF()));
+ painter->setBrush(QBrush(QColor(127, 127, 127)));//default to solid brush
- int cx = (int) Q3CanvasPolygonalItem::x();
- int cy = (int) Q3CanvasPolygonalItem::y();
+ // fill every other segment with grey
+ for (int i = 0; i < mNumSegments; i += 2)
+ {
+ painter->drawRect(QRectF(barLx + ((double)i * segwidth), -barHeight, segwidth, barHeight));
+ }
- painter->setPen ( mPen );
- painter->setBrush ( mBrush );
- painter->setFont ( font );
+ // draw a box around the all of the segments
+ painter->setBrush(Qt::NoBrush);
+ painter->drawRect(QRectF(barLx, -barHeight, width, barHeight));
- QgsComposerMap *map = mComposition->map ( mMap );
- if ( map ) {
- // width of the whole scalebar in canvas points
- int segwidth = (int) ( mSegmentLength * map->scale() );
- int width = (int) ( segwidth * mNumSegments );
-
- int barLx = (int) ( cx - width/2 );
+ // set up the pen to draw the tick marks
+ painter->setPen(QPen(QColor(0, 0, 0), mPen.widthF()));
- int rectadd = 0;
- if ( plotStyle() == QgsComposition::Preview ) {
- rectadd = 1; // add 1 pixel in preview, must not be in PS
- }
+ // draw the tick marks
+ for (int i = 0; i <= mNumSegments; i++)
+ {
+ painter->drawLine(QLineF(barLx + ((double)i * segwidth), 0, barLx + (i * segwidth), -tickSize));
+ }
- // fill odd
- for ( int i = 0; i < mNumSegments; i += 2 ) {
- painter->drawRect( barLx+i*segwidth, cy, segwidth+rectadd, mHeight );
- }
- // ticks
- int ticksize = (int ) (3./4*mHeight);
- for ( int i = 0; i <= mNumSegments; i++ ) {
- painter->drawLine( barLx+i*segwidth, cy, barLx+i*segwidth, cy-ticksize );
- }
+ // labels
- painter->setBrush( Qt::NoBrush );
+ // Font size in canvas units
+ float size = 25.4 * mComposition->scale() * mFont.pointSizeFloat() / 72;
- painter->drawRect( barLx, cy, width+rectadd, mHeight );
-
- // labels
- int h = metrics.height();
- int offset = (int ) (1./2*ticksize);
- for ( int i = 0; i <= mNumSegments; i++ ) {
- int lab = (int) (1. * i * mSegmentLength / mMapUnitsPerUnit);
- QString txt = QString::number(lab);
- int w = metrics.width ( txt );
- int shift = (int) w/2;
-
- if ( i == 0 ) {
- xmin = (int) barLx - w/2;
- }
- if ( i == mNumSegments ) {
- txt.append ( " " + mUnitLabel );
- w = metrics.width ( txt );
+ // Create QFontMetrics so we can correctly place the text
+ QFont font(mFont);
+ font.setPointSizeFloat(size);
+ QFontMetrics metrics(font);
- xmax = (int) barLx + width - shift + w;
- }
-
- int x = barLx+i*segwidth-shift;
- int y = cy-ticksize-offset-metrics.descent();
+ if (plotStyle() == QgsComposition::Postscript)
+ {
+ font.setPointSizeF(metrics.ascent() * 72.0 / mComposition->resolution());
+std::cout << "scalebar using PS font size!" << std::endl;
+ }
- painter->drawText( x, y, txt );
- }
-
- ymin = cy - ticksize - offset - h;
- ymax = cy + mHeight;
- }
- else
- {
- int width = 50 * mComposition->scale();
+ painter->setFont(font);
- int barLx = (int) ( cx - width/2 );
- painter->drawRect( (int)barLx, (int)(cy-mHeight/2), width, mHeight );
+ // Not sure about Style Strategy, QFont::PreferMatch?
+ font.setStyleStrategy((QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias));
- xmin = barLx;
- xmax = barLx + width;
- ymin = cy - mHeight;
- ymax = cy + mHeight;
+ double offset = .5 * tickSize; //vertical offset above the top of the tick marks
+ double textRightOverhang;//amount the label text hangs over the right edge of the scalebar - used for the bounding box
+
+ for (int i = 0; i <= mNumSegments; i++)
+ {
+ int lab = (int) ((double)i * mSegmentLength / mMapUnitsPerUnit);
+
+ QString txt = QString::number(lab);
+ double shift = (double)metrics.width(txt) / 2;
+
+ if (i == mNumSegments) //on the last label, append the appropriate unit symbol
+ {
+ txt.append(" " + mUnitLabel);
+ textRightOverhang = (double)metrics.width(txt) - shift;
}
- if ( !p ) {
- delete painter;
- delete pixmap;
+ double x = barLx + (i * segwidth) - shift; //figure out the bottom left corner and draw the text
+ double y = -tickSize - offset - metrics.descent();
+ painter->drawText(QPointF(x, y), txt);
+
+ }//end of label drawing
+
+ double totalHeight = tickSize + offset + metrics.height();
+
+ if (!p)
+ {
+ delete painter;
+ delete pixmap;
}
- return QRect ( xmin-mMargin, ymin-mMargin, xmax-xmin+2*mMargin, ymax-ymin+2*mMargin);
+//Add the 1/2 the pen width to get the full bounding box
+return QRectF(barLx - (mPen.widthF()/2), -totalHeight, width + textRightOverhang, totalHeight + (mPen.widthF()/2));
}
-void QgsComposerScalebar::draw ( QPainter & painter )
+void QgsComposerScalebar::paint(QPainter * painter, const QStyleOptionGraphicsItem * itemStyle, QWidget * pWidget)
{
- std::cout << "draw mPlotStyle = " << plotStyle() << std::endl;
+ std::cout << "draw mPlotStyle = " << plotStyle() << std::endl;
- render( &painter );
+ mBoundingRect = render(painter);
- // Show selected / Highlight
- if ( mSelected && plotStyle() == QgsComposition::Preview ) {
- painter.setPen( mComposition->selectionPen() );
- painter.setBrush( mComposition->selectionBrush() );
-
- int s = mComposition->selectionBoxSize();
- QRect r = boundingRect();
+ // Show selected / Highlight
+ if (mSelected && plotStyle() == QgsComposition::Preview)
+ {
+ painter->setPen(mComposition->selectionPen());
+ painter->setBrush(mComposition->selectionBrush());
- painter.drawRect ( r.x(), r.y(), s, s );
- painter.drawRect ( r.x()+r.width()-s, r.y(), s, s );
- painter.drawRect ( r.x()+r.width()-s, r.y()+r.height()-s, s, s );
- painter.drawRect ( r.x(), r.y()+r.height()-s, s, s );
+ double s = mComposition->selectionBoxSize();
+ QRectF r = boundingRect();
+
+ painter->drawRect(QRectF(r.x(), r.y(), s, s));
+ painter->drawRect(QRectF(r.x() + r.width() - s, r.y(), s, s));
+ painter->drawRect(QRectF(r.x() + r.width() - s, r.y() + r.height() - s, s, s));
+ painter->drawRect(QRectF(r.x(), r.y() + r.height() - s, s, s));
}
}
+/*
void QgsComposerScalebar::drawShape ( QPainter & painter )
{
- draw ( painter );
+ paint ( painter );
}
-
-void QgsComposerScalebar::on_mFontButton_clicked ( void )
+*/
+void QgsComposerScalebar::on_mFontButton_clicked(void)
{
- bool result;
-
- mFont = QFontDialog::getFont(&result, mFont, this );
+ bool result;
- if ( result ) {
- recalculate();
- Q3CanvasPolygonalItem::update();
- Q3CanvasPolygonalItem::canvas()->update();
- writeSettings();
+ mFont = QFontDialog::getFont(&result, mFont, this);
+
+ if (result)
+ {
+ recalculate();
+ QAbstractGraphicsShapeItem::update();
+ QAbstractGraphicsShapeItem::scene()->update();
+ writeSettings();
}
}
-void QgsComposerScalebar::on_mUnitLabelLineEdit_returnPressed ( )
+void QgsComposerScalebar::on_mUnitLabelLineEdit_returnPressed()
{
- mUnitLabel = mUnitLabelLineEdit->text();
- recalculate();
- Q3CanvasPolygonalItem::update();
- Q3CanvasPolygonalItem::canvas()->update();
- writeSettings();
+ mUnitLabel = mUnitLabelLineEdit->text();
+ recalculate();
+ QAbstractGraphicsShapeItem::update();
+ QAbstractGraphicsShapeItem::scene()->update();
+ writeSettings();
}
-void QgsComposerScalebar::on_mMapComboBox_activated ( int i )
+void QgsComposerScalebar::on_mMapComboBox_activated(int i)
{
- mMap = mMaps[i];
- recalculate();
- Q3CanvasPolygonalItem::update();
- Q3CanvasPolygonalItem::canvas()->update();
- writeSettings();
+ mMap = mMaps[i];
+ recalculate();
+ QAbstractGraphicsShapeItem::update();
+ QAbstractGraphicsShapeItem::scene()->update();
+ writeSettings();
}
-void QgsComposerScalebar::mapChanged ( int id )
+void QgsComposerScalebar::mapChanged(int id)
{
- if ( id != mMap ) return;
- recalculate();
- Q3CanvasPolygonalItem::update();
- Q3CanvasPolygonalItem::canvas()->update();
+ if (id != mMap)
+ return;
+ recalculate();
+ QAbstractGraphicsShapeItem::update();
+ QAbstractGraphicsShapeItem::scene()->update();
}
-void QgsComposerScalebar::sizeChanged ( )
+void QgsComposerScalebar::sizeChanged()
{
- mSegmentLength = mSegmentLengthLineEdit->text().toDouble();
- mNumSegments = mNumSegmentsLineEdit->text().toInt();
- mPen.setWidthF ( mLineWidthSpinBox->value() );
- mMapUnitsPerUnit = mMapUnitsPerUnitLineEdit->text().toInt();
- recalculate();
- Q3CanvasPolygonalItem::update();
- Q3CanvasPolygonalItem::canvas()->update();
- writeSettings();
+ mSegmentLength = mSegmentLengthLineEdit->text().toDouble();
+ mNumSegments = mNumSegmentsLineEdit->text().toInt();
+ mPen.setWidthF(mLineWidthSpinBox->value());
+ mMapUnitsPerUnit = mMapUnitsPerUnitLineEdit->text().toInt();
+ recalculate();
+ QAbstractGraphicsShapeItem::update();
+ QAbstractGraphicsShapeItem::scene()->update();
+ writeSettings();
}
-void QgsComposerScalebar::on_mLineWidthSpinBox_valueChanged() { sizeChanged(); }
-void QgsComposerScalebar::on_mMapUnitsPerUnitLineEdit_returnPressed() { sizeChanged(); }
-void QgsComposerScalebar::on_mNumSegmentsLineEdit_returnPressed() { sizeChanged(); }
-void QgsComposerScalebar::on_mSegmentLengthLineEdit_returnPressed() { sizeChanged(); }
+void QgsComposerScalebar::on_mLineWidthSpinBox_valueChanged()
+{
+ sizeChanged();
+}
-void QgsComposerScalebar::moveBy(double x, double y )
+void QgsComposerScalebar::on_mMapUnitsPerUnitLineEdit_returnPressed()
{
- std::cout << "QgsComposerScalebar::move" << std::endl;
- Q3CanvasItem::moveBy ( x, y );
+ sizeChanged();
+}
- recalculate();
- //writeSettings(); // not necessary called by composition
+void QgsComposerScalebar::on_mNumSegmentsLineEdit_returnPressed()
+{
+ sizeChanged();
}
-void QgsComposerScalebar::recalculate ( void )
+void QgsComposerScalebar::on_mSegmentLengthLineEdit_returnPressed()
{
- std::cout << "QgsComposerScalebar::recalculate" << std::endl;
-
- mHeight = (int) ( 25.4 * mComposition->scale() * mFont.pointSize() / 72);
- mMargin = (int) (3.*mHeight/2);
-
- // !!! invalidate() MUST BE called before the value returned by areaPoints() changes
- Q3CanvasPolygonalItem::invalidate();
-
- mBoundingRect = render(0);
-
- Q3CanvasItem::update();
+ sizeChanged();
}
+/*
+void QgsComposerScalebar::moveBy(double x, double y)
+{
+ std::cout << "QgsComposerScalebar::move" << std::endl;
+ QGraphicsItem::moveBy(x, y);
-QRect QgsComposerScalebar::boundingRect ( void ) const
+ recalculate();
+ //writeSettings(); // not necessary called by composition
+}*/
+
+void QgsComposerScalebar::recalculate(void)
{
- std::cout << "QgsComposerScalebar::boundingRect" << std::endl;
- return mBoundingRect;
+ std::cout << "QgsComposerScalebar::recalculate" << std::endl;
+
+ // !!! prepareGeometryChange() MUST BE called before the value returned by areaPoints() changes
+ //Is this still true after the port to GraphicsView?
+ QAbstractGraphicsShapeItem::prepareGeometryChange();
+
+ mBoundingRect = render(0);
+
+ QGraphicsItem::update();
}
-Q3PointArray QgsComposerScalebar::areaPoints() const
+QRectF QgsComposerScalebar::boundingRect(void) const
{
- std::cout << "QgsComposerScalebar::areaPoints" << std::endl;
+ std::cout << "QgsComposerScalebar::boundingRect" << std::endl;
+ return mBoundingRect;
+}
- QRect r = boundingRect();
- Q3PointArray pa(4);
- pa[0] = QPoint( r.x(), r.y() );
- pa[1] = QPoint( r.x()+r.width(), r.y() );
- pa[2] = QPoint( r.x()+r.width(), r.y()+r.height() );
- pa[3] = QPoint( r.x(), r.y()+r.height() );
- return pa ;
+QPolygonF QgsComposerScalebar::areaPoints(void) const
+{
+ std::cout << "QgsComposerScalebar::areaPoints" << std::endl;
+
+ QRectF r = boundingRect();
+ QPolygonF pa;
+ pa << QPointF(r.x(), r.y());
+ pa << QPointF(r.x() + r.width(), r.y());
+ pa << QPointF(r.x() + r.width(), r.y() + r.height());
+ pa << QPointF(r.x(), r.y() + r.height());
+ return pa;
}
-void QgsComposerScalebar::setOptions ( void )
-{
- mSegmentLengthLineEdit->setText( QString::number(mSegmentLength) );
- mNumSegmentsLineEdit->setText( QString::number( mNumSegments ) );
- mUnitLabelLineEdit->setText( mUnitLabel );
- mMapUnitsPerUnitLineEdit->setText( QString::number(mMapUnitsPerUnit ) );
+void QgsComposerScalebar::setOptions(void)
+{
+ mSegmentLengthLineEdit->setText(QString::number(mSegmentLength));
+ mNumSegmentsLineEdit->setText(QString::number(mNumSegments));
+ mUnitLabelLineEdit->setText(mUnitLabel);
+ mMapUnitsPerUnitLineEdit->setText(QString::number(mMapUnitsPerUnit));
- mLineWidthSpinBox->setValue ( mPen.widthF() );
-
- // Maps
- mMapComboBox->clear();
- std::vector maps = mComposition->maps();
+ mLineWidthSpinBox->setValue(mPen.widthF());
- mMaps.clear();
-
- bool found = false;
- mMapComboBox->insertItem ( "", 0 );
- mMaps.push_back ( 0 );
- for ( uint i = 0; i < maps.size(); i++ ) {
- mMapComboBox->insertItem ( maps[i]->name(), i+1 );
- mMaps.push_back ( maps[i]->id() );
+ // Maps
+ mMapComboBox->clear();
+ std::vector < QgsComposerMap * >maps = mComposition->maps();
- if ( maps[i]->id() == mMap ) {
- found = true;
- mMapComboBox->setCurrentItem ( i+1 );
- }
+ mMaps.clear();
+
+ bool found = false;
+ mMapComboBox->insertItem("", 0);
+ mMaps.push_back(0);
+ for (int i = 0; i < (int)maps.size(); i++)
+ {
+ mMapComboBox->insertItem(maps[i]->name(), i + 1);
+ mMaps.push_back(maps[i]->id());
+
+ if (maps[i]->id() == mMap)
+ {
+ found = true;
+ mMapComboBox->setCurrentItem(i + 1);
+ }
}
- if ( ! found ) {
- mMap = 0;
- mMapComboBox->setCurrentItem ( 0 );
+ if (!found)
+ {
+ mMap = 0;
+ mMapComboBox->setCurrentItem(0);
}
}
-void QgsComposerScalebar::setSelected ( bool s )
+void QgsComposerScalebar::setSelected(bool s)
{
- mSelected = s;
- Q3CanvasPolygonalItem::update(); // show highlight
-}
+ mSelected = s;
+ QAbstractGraphicsShapeItem::update(); // show highlight
+}
-bool QgsComposerScalebar::selected( void )
+bool QgsComposerScalebar::selected(void)
{
- return mSelected;
+ return mSelected;
}
-QWidget *QgsComposerScalebar::options ( void )
+QWidget *QgsComposerScalebar::options(void)
{
- setOptions ();
- return ( dynamic_cast (this) );
+ setOptions();
+ return (dynamic_cast < QWidget * >(this));
}
-bool QgsComposerScalebar::writeSettings ( void )
+bool QgsComposerScalebar::writeSettings(void)
{
- std::cout << "QgsComposerScalebar::writeSettings" << std::endl;
- QString path;
- path.sprintf("/composition_%d/scalebar_%d/", mComposition->id(), mId );
+ std::cout << "QgsComposerScalebar::writeSettings" << std::endl;
+ QString path;
+ path.sprintf("/composition_%d/scalebar_%d/", mComposition->id(), mId);
- QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)Q3CanvasPolygonalItem::x()) );
- QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)Q3CanvasPolygonalItem::y()) );
+ QgsProject::instance()->writeEntry("Compositions", path + "x", mComposition->toMM((int) QAbstractGraphicsShapeItem::x()));
+ QgsProject::instance()->writeEntry("Compositions", path + "y", mComposition->toMM((int) QAbstractGraphicsShapeItem::y()));
- QgsProject::instance()->writeEntry( "Compositions", path+"map", mMap );
+ QgsProject::instance()->writeEntry("Compositions", path + "map", mMap);
- QgsProject::instance()->writeEntry( "Compositions", path+"unit/label", mUnitLabel );
- QgsProject::instance()->writeEntry( "Compositions", path+"unit/mapunits", mMapUnitsPerUnit );
+ QgsProject::instance()->writeEntry("Compositions", path + "unit/label", mUnitLabel);
+ QgsProject::instance()->writeEntry("Compositions", path + "unit/mapunits", mMapUnitsPerUnit);
- QgsProject::instance()->writeEntry( "Compositions", path+"segmentsize", mSegmentLength );
- QgsProject::instance()->writeEntry( "Compositions", path+"numsegments", mNumSegments );
+ QgsProject::instance()->writeEntry("Compositions", path + "segmentsize", mSegmentLength);
+ QgsProject::instance()->writeEntry("Compositions", path + "numsegments", mNumSegments);
- QgsProject::instance()->writeEntry( "Compositions", path+"font/size", mFont.pointSize() );
- QgsProject::instance()->writeEntry( "Compositions", path+"font/family", mFont.family() );
- QgsProject::instance()->writeEntry( "Compositions", path+"font/weight", mFont.weight() );
- QgsProject::instance()->writeEntry( "Compositions", path+"font/underline", mFont.underline() );
- QgsProject::instance()->writeEntry( "Compositions", path+"font/strikeout", mFont.strikeOut() );
-
- QgsProject::instance()->writeEntry( "Compositions", path+"pen/width", (double)mPen.widthF() );
+ QgsProject::instance()->writeEntry("Compositions", path + "font/size", mFont.pointSize());
+ QgsProject::instance()->writeEntry("Compositions", path + "font/family", mFont.family());
+ QgsProject::instance()->writeEntry("Compositions", path + "font/weight", mFont.weight());
+ QgsProject::instance()->writeEntry("Compositions", path + "font/underline", mFont.underline());
+ QgsProject::instance()->writeEntry("Compositions", path + "font/strikeout", mFont.strikeOut());
- return true;
+ QgsProject::instance()->writeEntry("Compositions", path + "pen/width", (double) mPen.widthF());
+
+ return true;
}
-bool QgsComposerScalebar::readSettings ( void )
+bool QgsComposerScalebar::readSettings(void)
{
- bool ok;
- QString path;
- path.sprintf("/composition_%d/scalebar_%d/", mComposition->id(), mId );
+ bool ok;
+ QString path;
+ path.sprintf("/composition_%d/scalebar_%d/", mComposition->id(), mId);
- Q3CanvasPolygonalItem::setX( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok)) );
- Q3CanvasPolygonalItem::setY( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok)) );
-
- mMap = QgsProject::instance()->readNumEntry("Compositions", path+"map", 0, &ok);
- mUnitLabel = QgsProject::instance()->readEntry("Compositions", path+"unit/label", "???", &ok);
- mMapUnitsPerUnit = QgsProject::instance()->readDoubleEntry("Compositions", path+"unit/mapunits", 1., &ok);
+ double x = mComposition->fromMM(QgsProject::instance()->readDoubleEntry("Compositions", path + "x", 0, &ok));
+ double y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry("Compositions", path + "y", 0, &ok));
+ QAbstractGraphicsShapeItem::setPos(x, y);
- mSegmentLength = QgsProject::instance()->readDoubleEntry("Compositions", path+"segmentsize", 1000., &ok);
- mNumSegments = QgsProject::instance()->readNumEntry("Compositions", path+"numsegments", 5, &ok);
-
- mFont.setFamily ( QgsProject::instance()->readEntry("Compositions", path+"font/family", "", &ok) );
- mFont.setPointSize ( QgsProject::instance()->readNumEntry("Compositions", path+"font/size", 10, &ok) );
- mFont.setWeight( QgsProject::instance()->readNumEntry("Compositions", path+"font/weight", (int)QFont::Normal, &ok) );
- mFont.setUnderline( QgsProject::instance()->readBoolEntry("Compositions", path+"font/underline", false, &ok) );
- mFont.setStrikeOut( QgsProject::instance()->readBoolEntry("Compositions", path+"font/strikeout", false, &ok) );
+ mMap = QgsProject::instance()->readNumEntry("Compositions", path + "map", 0, &ok);
+ mUnitLabel = QgsProject::instance()->readEntry("Compositions", path + "unit/label", "???", &ok);
+ mMapUnitsPerUnit = QgsProject::instance()->readDoubleEntry("Compositions", path + "unit/mapunits", 1., &ok);
- mPen.setWidthF( QgsProject::instance()->readDoubleEntry("Compositions", path+"pen/width", 1, &ok) );
-
- recalculate();
-
- return true;
+ mSegmentLength = QgsProject::instance()->readDoubleEntry("Compositions", path + "segmentsize", 1000., &ok);
+ mNumSegments = QgsProject::instance()->readNumEntry("Compositions", path + "numsegments", 5, &ok);
+
+ mFont.setFamily(QgsProject::instance()->readEntry("Compositions", path + "font/family", "", &ok));
+ mFont.setPointSize(QgsProject::instance()->readNumEntry("Compositions", path + "font/size", 10, &ok));
+ mFont.setWeight(QgsProject::instance()->readNumEntry("Compositions", path + "font/weight", (int) QFont::Normal, &ok));
+ mFont.setUnderline(QgsProject::instance()->readBoolEntry("Compositions", path + "font/underline", false, &ok));
+ mFont.setStrikeOut(QgsProject::instance()->readBoolEntry("Compositions", path + "font/strikeout", false, &ok));
+
+ mPen.setWidthF(QgsProject::instance()->readDoubleEntry("Compositions", path + "pen/width", 1, &ok));
+
+ recalculate();
+
+ return true;
}
-bool QgsComposerScalebar::removeSettings( void )
+bool QgsComposerScalebar::removeSettings(void)
{
- std::cerr << "QgsComposerScalebar::deleteSettings" << std::endl;
+ std::cerr << "QgsComposerScalebar::deleteSettings" << std::endl;
- QString path;
- path.sprintf("/composition_%d/scalebar_%d", mComposition->id(), mId );
- return QgsProject::instance()->removeEntry ( "Compositions", path );
+ QString path;
+ path.sprintf("/composition_%d/scalebar_%d", mComposition->id(), mId);
+ return QgsProject::instance()->removeEntry("Compositions", path);
}
-bool QgsComposerScalebar::writeXML( QDomNode & node, QDomDocument & document, bool temp )
+bool QgsComposerScalebar::writeXML(QDomNode & node, QDomDocument & document, bool temp)
{
- return true;
+ return true;
}
-bool QgsComposerScalebar::readXML( QDomNode & node )
+bool QgsComposerScalebar::readXML(QDomNode & node)
{
- return true;
+ return true;
}
-
Index: src/app/composer/qgscomposermap.cpp
===================================================================
--- src/app/composer/qgscomposermap.cpp (revision 7070)
+++ src/app/composer/qgscomposermap.cpp (working copy)
@@ -14,7 +14,9 @@
* (at your option) any later version. *
* *
***************************************************************************/
+
#include "qgscomposermap.h"
+
#include "qgscoordinatetransform.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayer.h"
@@ -22,12 +24,15 @@
#include "qgsproject.h"
#include "qgsmaprender.h"
#include "qgsvectorlayer.h"
+
+#include
+#include
#include
#include
#include
QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int id, int x, int y, int width, int height )
- : QWidget(), Q3CanvasRectangle(x,y,width,height,0)
+ : QWidget(), QGraphicsRectItem(x,y,width,height,0)
{
setupUi(this);
@@ -39,15 +44,16 @@
init();
recalculate();
- // Add to canvas
- setCanvas(mComposition->canvas());
- Q3CanvasRectangle::show();
+ // Add to scene
+ mComposition->canvas()->addItem(this);
+ QGraphicsRectItem::show();
+
writeSettings();
}
QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int id )
- : Q3CanvasRectangle(0,0,10,10,0)
+ : QGraphicsRectItem(0,0,10,10,0)
{
setupUi(this);
@@ -60,9 +66,9 @@
readSettings();
recalculate();
- // Add to canvas
- setCanvas(mComposition->canvas());
- Q3CanvasRectangle::show();
+ // Add to scene
+ mComposition->canvas()->addItem(this);
+ QGraphicsRectItem::show();
}
void QgsComposerMap::init ()
@@ -95,8 +101,7 @@
mFrame = true;
- Q3CanvasRectangle::setZ(20);
- setActive(true);
+ QGraphicsRectItem::setZValue(20);
connect ( mMapCanvas, SIGNAL(layersChanged()), this, SLOT(mapCanvasChanged()) );
}
@@ -106,6 +111,8 @@
std::cerr << "QgsComposerMap::~QgsComposerMap" << std::endl;
}
+/* This function is called by paint() and cache() to render the map. It does not override any functions
+from QGraphicsItem. */
void QgsComposerMap::draw ( QPainter *painter, QgsRect &extent, QgsMapToPixel *transform)
{
mMapCanvas->freeze(true); // necessary ?
@@ -114,7 +121,9 @@
for ( int i = nlayers - 1; i >= 0; i-- ) {
QgsMapLayer *layer = mMapCanvas->getZpos(i);
-
+
+ //if ( !layer->visible() ) continue;
+
if (mMapCanvas->projectionsEnabled())
{
ct = new QgsCoordinateTransform(layer->srs(), mMapCanvas->mapRender()->destinationSrs());
@@ -143,25 +152,24 @@
vector->draw( painter, r1, transform, ct, FALSE, widthScale, symbolScale);
- if ( split )
- {
- vector->draw( painter, r2, transform, ct, FALSE, widthScale, symbolScale);
- }
+ if ( split )
+ {
+ vector->draw( painter, r2, transform, ct, FALSE, widthScale, symbolScale);
+ }
} else {
// raster
if ( plotStyle() == QgsComposition::Print || plotStyle() == QgsComposition::Postscript ) {
// we have to rescale the raster to get requested resolution
-
+
// calculate relation between composition point size and requested resolution (in mm)
double multip = (1. / mComposition->scale()) / (25.4 / mComposition->resolution()) ;
-
- double sc = mExtent.width() / (multip*Q3CanvasRectangle::width());
-
- QgsMapToPixel trans ( sc, multip*Q3CanvasRectangle::height(), mExtent.yMin(), mExtent.xMin() );
-
+
+ double sc = mExtent.width() / (multip*QGraphicsRectItem::rect().width());
+
+ QgsMapToPixel trans ( sc, multip*QGraphicsRectItem::rect().height(), mExtent.yMin(), mExtent.xMin() );
+
painter->save();
painter->scale( 1./multip, 1./multip);
-
layer->draw( painter, extent, &trans, ct, FALSE);
painter->restore();
@@ -187,7 +195,9 @@
{
ct = NULL;
}
-
+
+// if ( !layer->visible() ) continue; //this doesn't work with the newer map layer code
+
if ( layer->type() == QgsMapLayer::VECTOR ) {
QgsVectorLayer *vector = dynamic_cast (layer);
@@ -219,9 +229,8 @@
mUserExtent = rect;
recalculate();
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
- Q3CanvasRectangle::update();
- Q3CanvasRectangle::canvas()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
}
void QgsComposerMap::cache ( void )
@@ -231,7 +240,7 @@
// 1 pixel in cache should have ia similar size as 1 pixel in canvas
// but it can result in big cache -> limit
- int w = static_cast(round(Q3CanvasRectangle::width() * mComposition->viewScale()));
+ int w = (int)(QGraphicsRectItem::rect().width() * mComposition->viewScale());
w = w < 1000 ? w : 1000;
int h = (int) ( mExtent.height() * w / mExtent.width() );
// It can happen that extent is not initialised well -> check
@@ -263,12 +272,12 @@
mCacheUpdated = true;
}
-void QgsComposerMap::draw ( QPainter & painter )
+void QgsComposerMap::paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget)
{
if ( mDrawing ) return;
mDrawing = true;
- std::cout << "draw mPlotStyle = " << plotStyle()
+ std::cout << "QgsComposerMapt::paint mPlotStyle = " << plotStyle()
<< " mPreviewMode = " << mPreviewMode << std::endl;
if ( plotStyle() == QgsComposition::Preview && mPreviewMode == Cache ) { // Draw from cache
@@ -280,18 +289,18 @@
}
// Scale so that the cache fills the map rectangle
- double scale = 1.0 * Q3CanvasRectangle::width() / mCachePixmap.width();
+ double scale = 1.0 * QGraphicsRectItem::rect().width() / mCachePixmap.width();
- painter.save();
+ painter->save();
- painter.translate ( Q3CanvasRectangle::x(), Q3CanvasRectangle::y() );
- painter.scale(scale,scale);
+ painter->translate(0, 0); //do we need this?
+ painter->scale(scale,scale);
std::cout << "scale = " << scale << std::endl;
- std::cout << "translate: " << Q3CanvasRectangle::x() << ", " << Q3CanvasRectangle::y() << std::endl;
+
// Note: drawing only a visible part of the pixmap doesn't make it much faster
- painter.drawPixmap(0,0, mCachePixmap);
+ painter->drawPixmap(0,0, mCachePixmap);
- painter.restore();
+ painter->restore();
}
else if ( (plotStyle() == QgsComposition::Preview && mPreviewMode == Render) ||
plotStyle() == QgsComposition::Print ||
@@ -299,46 +308,43 @@
{
std::cout << "render" << std::endl;
- double scale = mExtent.width() / Q3CanvasRectangle::width();
- QgsMapToPixel transform(scale, Q3CanvasRectangle::height(), mExtent.yMin(), mExtent.xMin() );
+ double scale = mExtent.width() / QGraphicsRectItem::rect().width();
+ QgsMapToPixel transform(scale, QGraphicsRectItem::rect().height(), mExtent.yMin(), mExtent.xMin() );
- painter.save();
- painter.translate ( Q3CanvasRectangle::x(), Q3CanvasRectangle::y() );
+ painter->save();
+ painter->translate(0, 0); //do we need this?
// TODO: Qt4 appears to force QPainter::CoordDevice - need to check if this is actually valid.
- painter.setClipRect ( 0, 0, Q3CanvasRectangle::width(), Q3CanvasRectangle::height() );
+ painter->setClipRect (QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() ));
- draw( &painter, mExtent, &transform);
- painter.restore();
+ draw( painter, mExtent, &transform);
+ painter->restore();
}
// Draw frame around
if ( mFrame ) {
QPen pen(QColor(0,0,0));
pen.setWidthF(0.6*mComposition->scale());
- painter.setPen( pen );
- painter.setBrush( Qt::NoBrush );
- painter.save();
- painter.translate ( Q3CanvasRectangle::x(), Q3CanvasRectangle::y() );
- painter.drawRect ( 0, 0, Q3CanvasRectangle::width(), Q3CanvasRectangle::height() );
- painter.restore();
+ painter->setPen( pen );
+ painter->setBrush( Qt::NoBrush );
+ painter->setRenderHint(QPainter::Antialiasing, true); //turn on antialiasing for drawing the box
+ painter->save();
+ painter->translate(0, 0);//do we need this?
+ painter->drawRect (QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() ));
+ painter->restore();
}
// Show selected / Highlight
if ( mSelected && plotStyle() == QgsComposition::Preview ) {
- painter.setPen( mComposition->selectionPen() );
- painter.setBrush( mComposition->selectionBrush() );
- int x = (int) Q3CanvasRectangle::x();
- int y = (int) Q3CanvasRectangle::y();
- int s = mComposition->selectionBoxSize();
+ painter->setPen( mComposition->selectionPen() );
+ painter->setBrush( mComposition->selectionBrush() );
- painter.drawRect ( x, y, s, s );
- x += Q3CanvasRectangle::width();
- painter.drawRect ( x-s, y, s, s );
- y += Q3CanvasRectangle::height();
- painter.drawRect ( x-s, y-s, s, s );
- x -= Q3CanvasRectangle::width();
- painter.drawRect ( x, y-s, s, s );
+ double s = mComposition->selectionBoxSize();
+
+ painter->drawRect (QRectF(0, 0, s, s));
+ painter->drawRect (QRectF(QGraphicsRectItem::rect().width() -s, 0, s, s));
+ painter->drawRect (QRectF(QGraphicsRectItem::rect().width() -s, QGraphicsRectItem::rect().height() -s, s, s));
+ painter->drawRect (QRectF(0, QGraphicsRectItem::rect().height() -s, s, s));
}
mDrawing = false;
@@ -350,12 +356,11 @@
w = mComposition->fromMM ( mWidthLineEdit->text().toDouble() );
h = mComposition->fromMM ( mHeightLineEdit->text().toDouble() );
- Q3CanvasRectangle::setSize ( w, h);
+ QGraphicsRectItem::setRect(0, 0, w, h);
recalculate();
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
- Q3CanvasRectangle::update();
- Q3CanvasRectangle::canvas()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
writeSettings();
}
@@ -367,15 +372,12 @@
{
mCalculate = mCalculateComboBox->currentItem();
- if ( mCalculate == Scale ) { // return to extent defined by user
- recalculate();
-
- mCacheUpdated = false;
- //QCanvasRectangle::canvas()->setAllChanged(); // must be setAllChanged(), not sure why
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
- Q3CanvasRectangle::canvas()->update();
-
- mComposition->emitMapChanged ( mId );
+ if ( mCalculate == Scale )
+ {
+ recalculate();
+ mCacheUpdated = false;
+ QGraphicsRectItem::scene()->update();
+ mComposition->emitMapChanged ( mId );
}
setOptions();
writeSettings();
@@ -383,7 +385,7 @@
double QgsComposerMap::scaleFromUserScale ( double us )
{
- double s=0;
+ double s;
switch ( mComposition->mapCanvas()->mapUnits() ) {
case QGis::METERS :
@@ -422,8 +424,9 @@
void QgsComposerMap::on_mScaleLineEdit_returnPressed()
{
+#ifdef QGISDEBUG
std::cout << "QgsComposerMap::on_mScaleLineEdit_returnPressed" << std::endl;
-
+#endif
mCalculate = mCalculateComboBox->currentItem();
mUserScale = mScaleLineEdit->text().toDouble();
@@ -433,9 +436,8 @@
recalculate();
mCacheUpdated = false;
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
- Q3CanvasRectangle::update();
- Q3CanvasRectangle::canvas()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
writeSettings();
mComposition->emitMapChanged ( mId );
@@ -448,9 +450,8 @@
mFontScale = mFontScaleLineEdit->text().toDouble();
mCacheUpdated = false;
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
- Q3CanvasRectangle::update();
- Q3CanvasRectangle::canvas()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
writeSettings();
mComposition->emitMapChanged ( mId );
@@ -465,7 +466,7 @@
std::cout << "QgsComposerMap::canvasChanged" << std::endl;
mCacheUpdated = false;
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
+ QGraphicsRectItem::update();
}
void QgsComposerMap::on_mPreviewModeComboBox_activated ( int i )
@@ -476,64 +477,65 @@
void QgsComposerMap::recalculate ( void )
{
- std::cout << "QgsComposerMap::recalculate mCalculate = " << mCalculate << std::endl;
+#ifdef QGISDEBUG
+ std::cout << "QgsComposerMap::recalculate mCalculate = " << mCalculate << std::endl;
+#endif
+ if ( mCalculate == Scale )
+ {
+ // Calculate scale from extent and rectangle
+ double xscale = QGraphicsRectItem::rect().width() / mUserExtent.width();
+ double yscale = QGraphicsRectItem::rect().height() / mUserExtent.height();
- if ( mCalculate == Scale )
+ mExtent = mUserExtent;
+
+ if ( xscale < yscale )
{
- // Calculate scale from extent and rectangle
- double xscale = Q3CanvasRectangle::width() / mUserExtent.width();
- double yscale = Q3CanvasRectangle::height() / mUserExtent.height();
-
- mExtent = mUserExtent;
-
- if ( xscale < yscale ) {
mScale = xscale;
// extend y
- double d = ( 1. * Q3CanvasRectangle::height() / mScale - mUserExtent.height() ) / 2 ;
+ double d = ( 1. * QGraphicsRectItem::rect().height() / mScale - mUserExtent.height() ) / 2 ;
mExtent.setYmin ( mUserExtent.yMin() - d );
mExtent.setYmax ( mUserExtent.yMax() + d );
- } else {
+ }
+ else
+ {
mScale = yscale;
// extend x
- double d = ( 1.* Q3CanvasRectangle::width() / mScale - mUserExtent.width() ) / 2 ;
+ double d = ( 1.* QGraphicsRectItem::rect().width() / mScale - mUserExtent.width() ) / 2 ;
mExtent.setXmin ( mUserExtent.xMin() - d );
mExtent.setXmax ( mUserExtent.xMax() + d );
- }
+ }
- mUserScale = userScaleFromScale ( mScale );
- }
- else
- {
- // Calculate extent
- double xc = ( mUserExtent.xMax() + mUserExtent.xMin() ) / 2;
- double yc = ( mUserExtent.yMax() + mUserExtent.yMin() ) / 2;
-
- double width = Q3CanvasRectangle::width() / mScale;
- double height = Q3CanvasRectangle::height() / mScale;
+ mUserScale = userScaleFromScale ( mScale );
+ }
+ else
+ {
+ // Calculate extent
+ double xc = ( mUserExtent.xMax() + mUserExtent.xMin() ) / 2;
+ double yc = ( mUserExtent.yMax() + mUserExtent.yMin() ) / 2;
- mExtent.setXmin ( xc - width/2 );
- mExtent.setXmax ( xc + width/2 );
- mExtent.setYmin ( yc - height/2 );
- mExtent.setYmax ( yc + height/2 );
+ double width = QGraphicsRectItem::rect().width() / mScale;
+ double height = QGraphicsRectItem::rect().height() / mScale;
+
+ mExtent.setXmin ( xc - width/2 );
+ mExtent.setXmax ( xc + width/2 );
+ mExtent.setYmin ( yc - height/2 );
+ mExtent.setYmax ( yc + height/2 );
+ }
- }
+ std::cout << "mUserExtent = " << mUserExtent.stringRep().toLocal8Bit().data() << std::endl;
+ std::cout << "mScale = " << mScale << std::endl;
+ std::cout << "mExtent = " << mExtent.stringRep().toLocal8Bit().data() << std::endl;
- std::cout << "mUserExtent = " << mUserExtent.stringRep().toLocal8Bit().data() << std::endl;
- std::cout << "mScale = " << mScale << std::endl;
- std::cout << "mExtent = " << mExtent.stringRep().toLocal8Bit().data() << std::endl;
-
- setOptions();
- mCacheUpdated = false;
+ setOptions();
+ mCacheUpdated = false;
}
void QgsComposerMap::on_mFrameCheckBox_clicked ( )
{
mFrame = mFrameCheckBox->isChecked();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
- Q3CanvasRectangle::update();
- Q3CanvasRectangle::canvas()->update();
-
writeSettings();
}
@@ -546,8 +548,8 @@
mCalculateComboBox->setCurrentItem( mCalculate );
- mWidthLineEdit->setText ( QString("%1").arg( mComposition->toMM(Q3CanvasRectangle::width()), 0,'g') );
- mHeightLineEdit->setText ( QString("%1").arg( mComposition->toMM(Q3CanvasRectangle::height()),0,'g') );
+ mWidthLineEdit->setText ( QString("%1").arg( mComposition->toMM((int)QGraphicsRectItem::rect().width()), 0,'g') );
+ mHeightLineEdit->setText ( QString("%1").arg( mComposition->toMM((int)QGraphicsRectItem::rect().height()),0,'g') );
// Scale
switch ( mComposition->mapCanvas()->mapUnits() ) {
@@ -579,9 +581,8 @@
{
mUserExtent = mMapCanvas->extent();
recalculate();
- Q3CanvasRectangle::canvas()->setChanged( Q3CanvasRectangle::boundingRect() );
- Q3CanvasRectangle::update();
- Q3CanvasRectangle::canvas()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
setOptions();
writeSettings();
mComposition->emitMapChanged ( mId );
@@ -590,7 +591,7 @@
void QgsComposerMap::setSelected ( bool s )
{
mSelected = s;
- Q3CanvasRectangle::update(); // show highlight
+ QGraphicsRectItem::update(); //re-paint, so we show the highlight boxes
}
bool QgsComposerMap::selected( void )
@@ -622,76 +623,81 @@
bool QgsComposerMap::writeSettings ( void )
{
- QString path;
- path.sprintf("/composition_%d/map_%d/", mComposition->id(), mId );
- QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)Q3CanvasRectangle::x()) );
- QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)Q3CanvasRectangle::y()) );
- QgsProject::instance()->writeEntry( "Compositions", path+"width", mComposition->toMM(Q3CanvasRectangle::width()) );
- QgsProject::instance()->writeEntry( "Compositions", path+"height", mComposition->toMM(Q3CanvasRectangle::height()) );
+ QString path;
+ path.sprintf("/composition_%d/map_%d/", mComposition->id(), mId );
- if ( mCalculate == Scale ) {
- QgsProject::instance()->writeEntry( "Compositions", path+"calculate", QString("scale") );
- } else {
- QgsProject::instance()->writeEntry( "Compositions", path+"calculate", QString("extent") );
- }
+ QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)QGraphicsRectItem::pos().x()) );
+ QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)QGraphicsRectItem::pos().y()) );
+
+
+ QgsProject::instance()->writeEntry( "Compositions", path+"width", mComposition->toMM((int)QGraphicsRectItem::rect().width()) );
+ QgsProject::instance()->writeEntry( "Compositions", path+"height", mComposition->toMM((int)QGraphicsRectItem::rect().height()) );
+
+ if ( mCalculate == Scale ) {
+ QgsProject::instance()->writeEntry( "Compositions", path+"calculate", QString("scale") );
+ } else {
+ QgsProject::instance()->writeEntry( "Compositions", path+"calculate", QString("extent") );
+ }
- QgsProject::instance()->writeEntry( "Compositions", path+"north", mUserExtent.yMax() );
- QgsProject::instance()->writeEntry( "Compositions", path+"south", mUserExtent.yMin() );
- QgsProject::instance()->writeEntry( "Compositions", path+"east", mUserExtent.xMax() );
- QgsProject::instance()->writeEntry( "Compositions", path+"west", mUserExtent.xMin() );
+ QgsProject::instance()->writeEntry( "Compositions", path+"north", mUserExtent.yMax() );
+ QgsProject::instance()->writeEntry( "Compositions", path+"south", mUserExtent.yMin() );
+ QgsProject::instance()->writeEntry( "Compositions", path+"east", mUserExtent.xMax() );
+ QgsProject::instance()->writeEntry( "Compositions", path+"west", mUserExtent.xMin() );
- QgsProject::instance()->writeEntry( "Compositions", path+"scale", mUserScale );
+ QgsProject::instance()->writeEntry( "Compositions", path+"scale", mUserScale );
- QgsProject::instance()->writeEntry( "Compositions", path+"widthscale", mWidthScale );
- QgsProject::instance()->writeEntry( "Compositions", path+"symbolscale", mSymbolScale );
- QgsProject::instance()->writeEntry( "Compositions", path+"fontscale", mFontScale );
+ QgsProject::instance()->writeEntry( "Compositions", path+"widthscale", mWidthScale );
+ QgsProject::instance()->writeEntry( "Compositions", path+"symbolscale", mSymbolScale );
+ QgsProject::instance()->writeEntry( "Compositions", path+"fontscale", mFontScale );
- QgsProject::instance()->writeEntry( "Compositions", path+"frame", mFrame );
+ QgsProject::instance()->writeEntry( "Compositions", path+"frame", mFrame );
- QgsProject::instance()->writeEntry( "Compositions", path+"previewmode", mPreviewMode );
+ QgsProject::instance()->writeEntry( "Compositions", path+"previewmode", mPreviewMode );
- return true;
+ return true;
}
bool QgsComposerMap::readSettings ( void )
{
- bool ok;
- QString path;
- path.sprintf("/composition_%d/map_%d/", mComposition->id(), mId );
-
+ bool ok;
+ QString path;
+ path.sprintf("/composition_%d/map_%d/", mComposition->id(), mId );
- Q3CanvasRectangle::setX( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok)) );
- Q3CanvasRectangle::setY( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok)) );
- int w = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"width", 100, &ok)) ;
- int h = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"height", 100, &ok)) ;
- Q3CanvasRectangle::setSize(w,h);
+ double x = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok));
+ double y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok));
+ int w = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"width", 100, &ok)) ;
+ int h = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"height", 100, &ok)) ;
+ QGraphicsRectItem::setRect(0, 0, w, h);
+ QGraphicsRectItem::setPos(x, y);
- QString calculate = QgsProject::instance()->readEntry("Compositions", path+"calculate", "scale", &ok);
- if ( calculate == "extent" ) {
- mCalculate = Extent;
- } else {
- mCalculate = Scale;
- }
+ QString calculate = QgsProject::instance()->readEntry("Compositions", path+"calculate", "scale", &ok);
+ if ( calculate == "extent" )
+ {
+ mCalculate = Extent;
+ }else
+ {
+ mCalculate = Scale;
+ }
- mUserExtent.setYmax ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"north", 100, &ok) );
- mUserExtent.setYmin ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"south", 0, &ok) );
- mUserExtent.setXmax ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"east", 100, &ok) );
- mUserExtent.setXmin ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"west", 0, &ok) );
+ mUserExtent.setYmax ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"north", 100, &ok) );
+ mUserExtent.setYmin ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"south", 0, &ok) );
+ mUserExtent.setXmax ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"east", 100, &ok) );
+ mUserExtent.setXmin ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"west", 0, &ok) );
- mUserScale = QgsProject::instance()->readDoubleEntry( "Compositions", path+"scale", 1000., &ok);
- mScale = scaleFromUserScale ( mUserScale );
+ mUserScale = QgsProject::instance()->readDoubleEntry( "Compositions", path+"scale", 1000., &ok);
+ mScale = scaleFromUserScale ( mUserScale );
- mWidthScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"widthscale", 1., &ok);
- mSymbolScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"symbolscale", 1., &ok);
- mFontScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"fontscale", 1., &ok);
+ mWidthScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"widthscale", 1., &ok);
+ mSymbolScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"symbolscale", 1., &ok);
+ mFontScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"fontscale", 1., &ok);
- mFrame = QgsProject::instance()->readBoolEntry("Compositions", path+"frame", true, &ok);
+ mFrame = QgsProject::instance()->readBoolEntry("Compositions", path+"frame", true, &ok);
- mPreviewMode = (PreviewMode) QgsProject::instance()->readNumEntry("Compositions", path+"previewmode", Cache, &ok);
+ mPreviewMode = (PreviewMode) QgsProject::instance()->readNumEntry("Compositions", path+"previewmode", Cache, &ok);
- recalculate();
+ recalculate();
- return true;
+ return true;
}
bool QgsComposerMap::removeSettings ( void )
@@ -700,7 +706,7 @@
path.sprintf("/composition_%d/map_%d", mComposition->id(), mId );
return QgsProject::instance()->removeEntry ( "Compositions", path );
}
-
+
bool QgsComposerMap::writeXML( QDomNode & node, QDomDocument & document, bool temp )
{
return true;
@@ -710,3 +716,4 @@
{
return true;
}
+
Index: src/app/composer/qgscomposerlabel.cpp
===================================================================
--- src/app/composer/qgscomposerlabel.cpp (revision 7070)
+++ src/app/composer/qgscomposerlabel.cpp (working copy)
@@ -15,15 +15,19 @@
* *
***************************************************************************/
#include "qgscomposerlabel.h"
+#include "qgsproject.h"
-#include "qgsproject.h"
+#include
+#include
+#include
#include
#include
+
#include
QgsComposerLabel::QgsComposerLabel ( QgsComposition *composition, int id,
int x, int y, QString text, int fontSize )
- : QWidget(composition), Q3CanvasPolygonalItem(0), mBox(false)
+ : QWidget(composition), QAbstractGraphicsShapeItem(0), mBox(false)
{
setupUi(this);
@@ -37,28 +41,29 @@
// Font and pen
mFont.setPointSize ( fontSize );
+
// Could make this user variable in the future
mPen.setWidthF (0.5);
- Q3CanvasPolygonalItem::setX(x);
- Q3CanvasPolygonalItem::setY(y);
+ QAbstractGraphicsShapeItem::setPos(x, y);
mSelected = false;
setOptions();
// Add to canvas
- setCanvas(mComposition->canvas());
- Q3CanvasPolygonalItem::setZ(100);
- setActive(true);
- Q3CanvasPolygonalItem::show();
- Q3CanvasPolygonalItem::update(); // ?
+ mComposition->canvas()->addItem(this);
+ QAbstractGraphicsShapeItem::setZValue(100);
+ //setActive(true); //no equivalent
+ QAbstractGraphicsShapeItem::show();
+ QAbstractGraphicsShapeItem::update();
+
writeSettings();
}
QgsComposerLabel::QgsComposerLabel ( QgsComposition *composition, int id )
- : Q3CanvasPolygonalItem(0)
+ : QAbstractGraphicsShapeItem(0)
{
std::cout << "QgsComposerLabel::QgsComposerLabel()" << std::endl;
@@ -73,63 +78,64 @@
setOptions();
// Add to canvas
- setCanvas(mComposition->canvas());
- Q3CanvasPolygonalItem::setZ(100);
- setActive(true);
- Q3CanvasPolygonalItem::show();
- Q3CanvasPolygonalItem::update(); // ?
+ mComposition->canvas()->addItem(this);
+ QAbstractGraphicsShapeItem::setZValue(100);
+ //setActive(true);//no equivalent
+ QAbstractGraphicsShapeItem::show();
+ QAbstractGraphicsShapeItem::update();
}
QgsComposerLabel::~QgsComposerLabel()
{
std::cout << "QgsComposerLabel::~QgsComposerLabel" << std::endl;
- Q3CanvasItem::hide();
+ QGraphicsItem::hide();
}
-
-void QgsComposerLabel::drawShape ( QPainter & painter )
+/*
+void QgsComposerLabel::drawShape ( QPainter & painter, const QStyleOptionGraphicsItem* item, QWidget* pWidget)
{
std::cout << "QgsComposerLabel::drawShape" << std::endl;
- draw ( painter );
+ paint ( painter, item, pWidget );
}
+*/
-void QgsComposerLabel::draw ( QPainter & painter )
+void QgsComposerLabel::paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
{
- std::cout << "QgsComposerLabel::render" << std::endl;
+ std::cout << "QgsComposerLabel::paint" << std::endl;
float size = 25.4 * mComposition->scale() * mFont.pointSizeFloat() / 72;
mBoxBuffer = (int) ( size / 10 * mComposition->scale() );
+ mBoxBuffer = 1;
+
QFont font ( mFont );
font.setPointSizeFloat ( size );
- QFontMetrics metrics ( font );
+ QFontMetricsF metrics ( font );
// Not sure about Style Strategy, QFont::PreferMatch ?
//font.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias ) );
- painter.setPen ( mPen );
- painter.setFont ( font );
+ painter->setPen ( mPen );
+ painter->setFont ( font );
- int x = (int) Q3CanvasPolygonalItem::x();
- int y = (int) Q3CanvasPolygonalItem::y();
-
- int w = metrics.width ( mText );
- int h = metrics.height() ;
+ double w = metrics.width ( mText );
+ double h = metrics.height() - metrics.descent();
- QRect r ( (int)(x - w/2), (int) (y - h/2), w, h );
+ QRectF r (0, -h, w, h); //used as the rectangle to draw the selection boxes on the corners of if there is no box
- QRect boxRect;
+ QRectF boxRect;
if ( mBox ) {
- // I don't know why, but the box seems to be too short -> add 1 * mBoxBuffer to width
- boxRect.setRect ( (int)(r.x()-1.5*mBoxBuffer), r.y()-mBoxBuffer, (int)(r.width()+3*mBoxBuffer), r.height()+2*mBoxBuffer );
- QBrush brush ( QColor(255,255,255) );
- painter.setBrush ( brush );
- painter.drawRect ( boxRect );
+ //I don't know why the top coordinate is -h rather than -(h+mBoxBuffer), but it seems to work better.
+ boxRect.setRect(-mBoxBuffer, -h, w + (2 * mBoxBuffer), h + (2 * mBoxBuffer));
+ QBrush brush ( QColor(255,255,255) );
+ painter->setBrush ( brush );
+ painter->setPen(QPen(QColor(0, 0, 0), .2));
+ painter->drawRect ( boxRect );
}
- painter.setPen ( mPen );
+ painter->setPen ( mPen );
// The width is not sufficient in postscript
- QRect tr = r;
+ QRectF tr = r;
tr.setWidth ( r.width() );
if ( plotStyle() == QgsComposition::Postscript )
@@ -137,26 +143,28 @@
// This metrics.ascent() is empirical
size = metrics.ascent() * 72.0 / mComposition->resolution();
font.setPointSizeF ( size );
- painter.setFont ( font );
+ painter->setFont ( font );
+std::cout << "label using PS render size" << std::endl;
}
- painter.drawText ( x-w/2,(int)(y+metrics.height()/2-metrics.descent()), mText );
+ painter->drawText(0, 0, mText);
// Show selected / Highlight
if ( mSelected && plotStyle() == QgsComposition::Preview ) {
- QRect hr;
- if ( mBox ) {
- hr = boxRect;
- } else {
- hr = r;
- }
- painter.setPen( mComposition->selectionPen() );
- painter.setBrush( mComposition->selectionBrush() );
- int s = mComposition->selectionBoxSize();
+ QRectF hr;
+ if ( mBox ) {
+ hr = boxRect;
+ } else {
+ hr = r;
+ }
+ painter->setPen( mComposition->selectionPen() );
+ painter->setBrush( mComposition->selectionBrush() );
+
+ double s = mComposition->selectionBoxSize();
- painter.drawRect ( hr.x(), hr.y(), s, s );
- painter.drawRect ( hr.x()+hr.width()-s, hr.y(), s, s );
- painter.drawRect ( hr.x()+hr.width()-s, hr.y()+hr.height()-s, s, s );
- painter.drawRect ( hr.x(), hr.y()+hr.height()-s, s, s );
+ painter->drawRect (QRectF(hr.x(), hr.y(), s, s ));
+ painter->drawRect (QRectF(hr.x()+hr.width()-s, hr.y(), s, s ));
+ painter->drawRect (QRectF(hr.x()+hr.width()-s, hr.y()+hr.height()-s, s, s ));
+ painter->drawRect (QRectF(hr.x(), hr.y()+hr.height()-s, s, s ));
}
}
@@ -164,70 +172,75 @@
{
bool result;
- QRect r = boundingRect();
+ QRectF r = boundingRect();
mFont = QFontDialog::getFont(&result, mFont, this );
if ( result ) {
- Q3CanvasPolygonalItem::invalidate();
- Q3CanvasPolygonalItem::canvas()->setChanged(r);
- Q3CanvasPolygonalItem::update();
- Q3CanvasPolygonalItem::canvas()->update();
+ QAbstractGraphicsShapeItem::prepareGeometryChange();
+ QAbstractGraphicsShapeItem::update();
}
writeSettings();
}
void QgsComposerLabel::on_mBoxCheckBox_clicked()
{
- QRect r = boundingRect();
+ QRectF r = boundingRect();
mBox = mBoxCheckBox->isChecked();
- Q3CanvasPolygonalItem::invalidate();
- Q3CanvasPolygonalItem::canvas()->setChanged(r);
- Q3CanvasPolygonalItem::update();
- Q3CanvasPolygonalItem::canvas()->update();
-
+ QAbstractGraphicsShapeItem::prepareGeometryChange();
+ QAbstractGraphicsShapeItem::update();
writeSettings();
}
-QRect QgsComposerLabel::boundingRect ( void ) const
+QRectF QgsComposerLabel::boundingRect ( void ) const
{
// Recalculate sizes according to current font size
- float size = 25.4 * mComposition->scale() * mFont.pointSize() / 72;
-
+ float size = 25.4 * mComposition->scale() * mFont.pointSizeFloat() / 72;
+
QFont font ( mFont );
font.setPointSizeFloat ( size );
-
QFontMetrics metrics ( font );
-
- int x = (int) Q3CanvasPolygonalItem::x();
- int y = (int) Q3CanvasPolygonalItem::y();
+
int w = metrics.width ( mText );
- int h = metrics.height() ;
-
+ int h = metrics.height() - metrics.descent();
+
+/*
int buf = 0;
if ( mBox ) {
buf = (int) ( size / 10 * mComposition->scale() + 2 ); // 2 is for line width
}
- QRect r ( (int)(x - w/2 - 1.5*buf), (int) (y - h/2 - buf), (int)(w+3*buf), h+2*buf );
+ QRectF r ( (int)(x - w/2 - 1.5*buf), (int) (y - h/2 - buf), (int)(w+3*buf), h+2*buf );
+*/
+QRectF r;
+
+ if(mBox){
+ //what happens if we haven't called paint() first?
+ r.setRect(-mBoxBuffer, -h, w + (2 * mBoxBuffer), h + (2 * mBoxBuffer));
+ }
+ else{
+ r.setRect(0, -h, w, h);
+ }
+
return r;
+
}
-Q3PointArray QgsComposerLabel::areaPoints() const
+QPolygonF QgsComposerLabel::areaPoints() const
{
std::cout << "QgsComposerLabel::areaPoints" << std::endl;
- QRect r = boundingRect();
+ QRectF r = boundingRect();
- Q3PointArray pa(4);
- pa[0] = QPoint( r.x(), r.y() );
- pa[1] = QPoint( r.x()+r.width(), r.y() );
- pa[2] = QPoint( r.x()+r.width(), r.y()+r.height() );
- pa[3] = QPoint( r.x(), r.y()+r.height() );
+ QPolygonF pa;
+ pa << QPointF( r.x(), r.y() );
+ pa << QPointF( r.x()+r.width(), r.y() );
+ pa << QPointF( r.x()+r.width(), r.y()+r.height() );
+ pa << QPointF( r.x(), r.y()+r.height() );
return pa ;
}
@@ -241,12 +254,10 @@
void QgsComposerLabel::on_mTextLineEdit_returnPressed()
{
- QRect r = boundingRect();
+ QRectF r = boundingRect();
mText = mTextLineEdit->text();
- Q3CanvasPolygonalItem::invalidate();
- Q3CanvasPolygonalItem::canvas()->setChanged(r);
- Q3CanvasPolygonalItem::update();
- Q3CanvasPolygonalItem::canvas()->update();
+ QAbstractGraphicsShapeItem::prepareGeometryChange();
+ QAbstractGraphicsShapeItem::update();
writeSettings();
}
@@ -254,7 +265,7 @@
{
std::cout << "QgsComposerLabel::setSelected" << std::endl;
mSelected = s;
- Q3CanvasPolygonalItem::update(); // show highlight
+ QAbstractGraphicsShapeItem::update(); // show highlight
std::cout << "mSelected = " << mSelected << std::endl;
}
@@ -277,8 +288,8 @@
QgsProject::instance()->writeEntry( "Compositions", path+"text", mText );
- QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)Q3CanvasPolygonalItem::x()) );
- QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)Q3CanvasPolygonalItem::y()) );
+ QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)QAbstractGraphicsShapeItem::x()) );
+ QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)QAbstractGraphicsShapeItem::y()) );
QgsProject::instance()->writeEntry( "Compositions", path+"font/size", mFont.pointSize() );
QgsProject::instance()->writeEntry( "Compositions", path+"font/family", mFont.family() );
@@ -302,9 +313,8 @@
mText = QgsProject::instance()->readEntry("Compositions", path+"text", "???", &ok);
int x = mComposition->fromMM( QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok) );
- Q3CanvasPolygonalItem::setX( x );
int y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok) );
- Q3CanvasPolygonalItem::setY( y );
+ QAbstractGraphicsShapeItem::setPos(x,y);
mFont.setFamily ( QgsProject::instance()->readEntry("Compositions", path+"font/family", "", &ok) );
mFont.setPointSize ( QgsProject::instance()->readNumEntry("Compositions", path+"font/size", 10, &ok) );
@@ -314,7 +324,7 @@
mBox = QgsProject::instance()->readBoolEntry("Compositions", path+"box", false, &ok);
- Q3CanvasPolygonalItem::update();
+ QAbstractGraphicsShapeItem::update();
return true;
}
Index: src/app/composer/qgscomposer.cpp
===================================================================
--- src/app/composer/qgscomposer.cpp (revision 7070)
+++ src/app/composer/qgscomposer.cpp (working copy)
@@ -31,18 +31,20 @@
#include
#include
#include
-#include
+
#include
#include
#include
#include
#include
+#include
#include
#include
#include
#include
#include
+#include
QgsComposer::QgsComposer( QgisApp *qgis): QMainWindow()
{
@@ -212,6 +214,8 @@
void QgsComposer::zoomFull(void)
{
+//can we just use QGraphicsView::fitInView with the "paper" rect?
+
QMatrix m;
// scale
@@ -226,22 +230,24 @@
m.translate ( dx, dy );
m.scale( scale, scale );
- mView->setWorldMatrix( m );
- mView->repaintContents();
+ mView->setMatrix( m );
+// mView->repaintContents(); //needed?
+
}
void QgsComposer::on_mActionZoomAll_activated(void)
{
zoomFull();
}
-
+/*
QMatrix QgsComposer::updateMatrix(double scaleChange)
{
- double scale = mView->worldMatrix().m11() * scaleChange; // get new scale
+ double scale = mView->matrix().m11() * scaleChange; // get new scale
+
double dx = ( mView->width() - scale * mComposition->canvas()->width() ) / 2;
double dy = ( mView->height() - scale * mComposition->canvas()->height() ) / 2;
-
+
// don't translate if composition is bigger than view
if (dx < 0) dx = 0;
if (dy < 0) dy = 0;
@@ -251,26 +257,25 @@
m.translate ( dx, dy );
m.scale ( scale, scale );
return m;
+
}
-
+*/
void QgsComposer::on_mActionZoomIn_activated(void)
{
- QMatrix m = updateMatrix(2);
- mView->setWorldMatrix( m );
- mView->repaintContents();
+ mView->scale(2, 2);
+ mView->update();
}
void QgsComposer::on_mActionZoomOut_activated(void)
{
- QMatrix m = updateMatrix(0.5);
- mView->setWorldMatrix( m );
- mView->repaintContents();
+ mView->scale(.5, .5);
+ mView->update();
}
void QgsComposer::on_mActionRefreshView_activated(void)
{
mComposition->refresh();
- mView->repaintContents();
+ mView->update();
}
void QgsComposer::on_mActionPrint_activated(void)
@@ -289,15 +294,16 @@
* important but bigger is better because it lefts enough space
* in BoundingBox definition), then the file is reopened,
* and the BoundingBox is redefined.
- */
+ */
// NOTE: QT 3.2 has QPrinter::setOptionEnabled but only for three options
- if ( !mPrinter ) {
+ if (!mPrinter)
+ {
- mPrinter = new QPrinter ( QPrinter::PrinterResolution );
+ mPrinter = new QPrinter(QPrinter::PrinterResolution);
//mPrinter = new QPrinter ( QPrinter::HighResolution );
//mPrinter = new QPrinter ( QPrinter::ScreenResolution );
- mPrinter->setFullPage ( true );
+ mPrinter->setFullPage(true);
#ifndef Q_OS_MACX
// For Qt/Mac 3, don't set outputToFile to true before calling setup
// because it wiil suppress the Print dialog and output to file without
@@ -305,287 +311,321 @@
// The Mac Print dialog provides an option to create a pdf which is
// intended to be invisible to the application. If an eps is desired,
// a custom Mac Print dialog is needed.
-
+
// There is a bug in Qt<=4.2.2 (dialog is not correct) if output is set to file
// => disable until they fix it
//mPrinter->setOutputToFile (true ) ;
//mPrinter->setOutputFileName ( QDir::convertSeparators ( QDir::home().path() + "/" + "qgis.eps") );
#endif
+ mPrinter->setColorMode(QPrinter::Color);
+ mPrinter->setPageSize(QPrinter::A4); //would be nice set this based on the composition paper size
+ } else
+ {
+ // Because of bug in Qt<=4.2.2 (dialog is not correct) we have to reset always
+ // to printer otherwise print to file is checked but printer combobox is in dialog
+ mPrinter->setOutputToFile(false);
+ }
- if ( mComposition->paperOrientation() == QgsComposition::Portrait ) {
- mPrinter->setOrientation ( QPrinter::Portrait );
- } else {
- mPrinter->setOrientation ( QPrinter::Landscape );
- }
- mPrinter->setColorMode ( QPrinter::Color );
- mPrinter->setPageSize ( QPrinter::A4 );
- }
- else
+ //set the resolution and paper orientation each time we call up the dialog, not just the first time we run it
+ mPrinter->setResolution(mComposition->resolution());
+ if (mComposition->paperOrientation() == QgsComposition::Portrait)
{
- // Because of bug in Qt<=4.2.2 (dialog is not correct) we have to reset always
- // to printer otherwise print to file is checked but printer combobox is in dialog
- mPrinter->setOutputToFile (false) ;
+ mPrinter->setOrientation(QPrinter::Portrait);
+ } else
+ {
+ mPrinter->setOrientation(QPrinter::Landscape);
}
- mPrinter->setResolution ( mComposition->resolution() );
//if ( mPrinter->setup(this) ) {
- QPrintDialog printDialog ( mPrinter, this);
- if ( printDialog.exec() == QDialog::Accepted )
- {
- // TODO: mPrinter->setup() moves the composer under Qgisapp, get it to foreground somehow
- // raise() for now, is it something better?
- raise ();
+ QPrintDialog printDialog(mPrinter, this);
+ if (printDialog.exec() == QDialog::Accepted)
+ {
+ // TODO: mPrinter->setup() moves the composer under Qgisapp, get it to foreground somehow
+ // raise() for now, is it something better?
+ raise();
- // TODO: Qt does not add pagesize to output file, it can cause problems if ps2pdf is used
- // or if default page on printer is different.
- // We should add somewhere in output file:
- // << /PageSize [ %d %d ] >> setpagedevice
- // %d %d is width and height in points
-
- // WARNING: If QCanvasView recieves repaint signal during the printing
- // (e.g. covered by QPrinter::setup dialog) it breaks somehow drawing of QCanvas items
- // (for example not all features in the map are drawn.
- // I don't know how to stop temporarily updating, (I don't want to reimplement
- // repaint in QCanvasView, so I unset the view, print and reset.
- mView->setCanvas(0);
+ // TODO: Qt does not add pagesize to output file, it can cause problems if ps2pdf is used
+ // or if default page on printer is different.
+ // We should add somewhere in output file:
+ // << /PageSize [ %d %d ] >> setpagedevice
+ // %d %d is width and height in points
- int resolution = mPrinter->resolution();
+ // WARNING: If QCanvasView recieves repaint signal during the printing
+ // (e.g. covered by QPrinter::setup dialog) it breaks somehow drawing of QCanvas items
+ // (for example not all features in the map are drawn.
+ // I don't know how to stop temporarily updating, (I don't want to reimplement
+ // repaint in QCanvasView, so I unset the view, print and reset.
+ mView->setScene(0);
- std::cout << "Resolution = " << resolution << std::endl;
+ int resolution = mPrinter->resolution();
- double scale = resolution / 25.4 / mComposition->scale();
+ std::cout << "Resolution = " << resolution << std::endl;
- mComposition->setPlotStyle ( QgsComposition::Postscript );
+ double scale = resolution / 25.4 / mComposition->scale();
- if ( !mPrinter->outputFileName().isNull() ) {
- try {
- std::cout << "Print to file" << std::endl;
+ mComposition->setPlotStyle(QgsComposition::Postscript);
- QPrinter::PageSize psize (QPrinter::A4); //default to A4
-
- // WARNING mPrinter->outputFormat() returns always 0 in Qt 4.2.2
- // => we have to check extension
- bool isPs = false;
- if ( mPrinter->outputFileName().right(3).toLower() == ".ps"
- || mPrinter->outputFileName().right(4).toLower() == ".eps" )
- {
- isPs = true;
- }
- //if ( mPrinter->outputFormat() == QPrinter::PostScriptFormat )
- if ( isPs )
- {
- // NOTE: setPageSize after setup() works, but setOrientation does not
- // -> the BoundingBox must follow the orientation
+ if (!mPrinter->outputFileName().isNull())
+ {
+ try
+ {
+ std::cout << "Print to file" << std::endl;
- psize = mPrinter->pageSize();
- // B0 ( 1000x1414mm = 2835x4008pt ) is the biggest defined in Qt, a map can be bigger
- // but probably not bigger than 9999x9999pt = 3527x3527mm
- mPrinter->setPageSize ( QPrinter::B0 );
- }
+ QPrinter::PageSize psize;
- QPainter p(mPrinter);
- p.scale ( scale, scale);
+ // WARNING mPrinter->outputFormat() returns always 0 in Qt 4.2.2
+ // => we have to check extension
+ bool isPs = false;
+ if (mPrinter->outputFileName().right(3).toLower() == ".ps" || mPrinter->outputFileName().right(4).toLower() == ".eps")
+ {
+ isPs = true;
+ }
+ //if ( mPrinter->outputFormat() == QPrinter::PostScriptFormat )
+ if (isPs)
+ {
+ // NOTE: setPageSize after setup() works, but setOrientation does not
+ // -> the BoundingBox must follow the orientation
- mComposition->canvas()->drawArea ( QRect(0,0,
- (int) (mComposition->paperWidth() * mComposition->scale()),
- (int) (mComposition->paperHeight() * mComposition->scale()) ),
- &p, FALSE );
+ psize = mPrinter->pageSize();
+ // B0 ( 1000x1414mm = 2835x4008pt ) is the biggest defined in Qt, a map can be bigger
+ // but probably not bigger than 9999x9999pt = 3527x3527mm
+ mPrinter->setPageSize(QPrinter::B0);
+ }
- p.end();
+ QPainter p(mPrinter);
+ p.scale(scale, scale);
- std::cout << "mPrinter->outputFormat() = " << mPrinter->outputFormat() << std::endl;
-
-
- //if ( mPrinter->outputFormat() == QPrinter::PostScriptFormat )
- if ( isPs )
- {
- // reset the page
- mPrinter->setPageSize ( psize );
-
- QFile f(mPrinter->outputFileName());
-
- // Overwrite the bounding box
- std::cout << "Overwrite the bounding box" << std::endl;
- if (!f.open( QIODevice::ReadWrite )) {
- throw QgsIOException(tr("Couldn't open " + f.name() + tr(" for read/write")));
- }
- Q_LONG offset = 0;
- Q_LONG size;
- bool found = false;
- QString s;
- char buf[101];
- while ( !f.atEnd() ) {
- size = f.readLine ( buf, 100 );
- s = QString(buf);
- if ( s.find ("%%BoundingBox:") == 0 ) {
- found = true;
- break;
- }
- offset += size;
- }
-
- if ( found ) {
- int w,h;
-
- w = (int) ( 72 * mComposition->paperWidth() / 25.4 );
- h = (int) ( 72 * mComposition->paperHeight() / 25.4 );
- if ( mPrinter->orientation() == QPrinter::Landscape ) {
- int tmp = w; w = h; h = tmp;
- }
- s.sprintf( "%%%%BoundingBox: 0 0 %d %d", w, h );
-
- if ( s.length() > size )
- {
- int shift = s.length() - size;
- shiftFileContent ( &f, offset + size + 1, shift );
- } else {
- if ( ! f.at(offset) ) {
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot seek"));
- } else {
- /* Write spaces (for case the size > s.length() ) */
- QString es;
- es.fill(' ', size-1 );
- f.flush();
- if ( f.writeBlock ( es.toLocal8Bit().data(), size-1 ) < size-1 ) {
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite BoundingBox"));
- }
- f.flush();
- f.at(offset);
- f.flush();
- if ( f.writeBlock ( s.toLocal8Bit().data(), s.length() ) < s.length()-1 ) {
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite BoundingBox"));
- }
- f.flush();
- }
- }
- } else {
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot find BoundingBox"));
- }
- f.close();
-
- // Overwrite translate
- if ( mPrinter->orientation() == QPrinter::Portrait ) {
- std::cout << "Orientation portraint -> overwrite translate" << std::endl;
- if (!f.open( QIODevice::ReadWrite )) {
- throw QgsIOException(tr("Couldn't open ") + f.name() + tr(" for read/write"));
- }
- offset = 0;
- found = false;
-
- //Example Qt3:
- //0 4008 translate 1 -1 scale/defM ...
- //QRegExp rx ( "^0 [^ ]+ translate ([^ ]+ [^ ]+) scale/defM matrix CM d \\} d" );
- //Example Qt4:
- //0 0 translate 0.239999 -0.239999 scale } def
- QRegExp rx ( "^0 [^ ]+ translate ([^ ]+ [^ ]+) scale \\} def" );
-
- while ( !f.atEnd() ) {
- size = f.readLine ( buf, 100 );
- s = QString(buf);
- if ( rx.search( s ) != -1 ) {
- found = true;
- break;
- }
- offset += size;
- }
-
- if ( found ) {
- int trans;
-
- trans = (int) ( 72 * mComposition->paperHeight() / 25.4 );
- std::cout << "trans = " << trans << std::endl;
- //Qt3:
- //s.sprintf( "0 %d translate %s scale/defM matrix CM d } d", trans, (const char *)rx.cap(1).toLocal8Bit().data() );
- //Qt4:
- s.sprintf( "0 %d translate %s scale } def\n", trans, (const char *)rx.cap(1).toLocal8Bit().data() );
-
-
- std::cout << "s.length() = " << s.length() << " size = " << size << std::endl;
- if ( s.length() > size ) {
- //QMessageBox::warning(this, tr("Error in Print"), tr("Cannot format translate"));
- // Move the content up
- int shift = s.length() - size;
- /*
- int last = f.size() + shift -1;
- for ( int i = last; i > offset + size; i-- )
- {
- f.at(i-shift);
- QByteArray ba = f.read(1);
- f.at(i);
- f.write(ba);
- }
- */
- shiftFileContent ( &f, offset + size + 1, shift );
- }
-
- // Overwrite the row
- if ( ! f.at(offset) ) {
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot seek"));
- } else {
- /* Write spaces (for case the size > s.length() ) */
- QString es;
- es.fill(' ', size-1 );
- f.flush();
- if ( f.writeBlock ( es.toLocal8Bit().data(), size-1 ) < size-1 ) {
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite translate"));
- }
- f.flush();
- f.at(offset);
- f.flush();
- if ( f.writeBlock ( s.toLocal8Bit().data(), s.length() ) < s.length()-1 ) {
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite translate"));
- }
- f.flush();
- }
- } else {
- QMessageBox::warning(this, tr("Error in Print"), tr("Cannot find translate"));
- }
- f.close();
- }
- }
- } catch (QgsIOException e) {
- QMessageBox::warning(this, tr("File IO Error"), e.what());
- }
- } else { // print to printer
- bool print = true;
+ QRectF renderArea(0, 0, (mComposition->paperWidth() * mComposition->scale()),
+ (mComposition->paperHeight() * mComposition->scale()));
- // Check size
- std::cout << "Paper: " << mPrinter->widthMM() << " x " << mPrinter->heightMM() << std::endl;
- if ( mComposition->paperWidth() != mPrinter->widthMM() ||
- mComposition->paperHeight() != mPrinter->heightMM() )
- {
- int answer = QMessageBox::warning ( this, tr("Paper does not match"),
- tr("The selected paper size does not match the composition size"),
- QMessageBox::Ok | QMessageBox::Abort );
+ mComposition->canvas()->render(&p, renderArea);
- if ( answer == QMessageBox::Abort )
- print = false;
+ p.end();
- }
+ std::cout << "mPrinter->outputFormat() = " << mPrinter->outputFormat() << std::endl;
- if ( print ) {
- std::cout << "Printing ... " << std::endl;
- QPainter p(mPrinter);
- p.scale ( scale, scale);
- mComposition->canvas()->drawArea ( QRect(0,0,
- (int) (mComposition->paperWidth() * mComposition->scale()),
- (int) (mComposition->paperHeight() * mComposition->scale()) ),
- &p, FALSE );
- p.end();
- std::cout << "... printing finished" << std::endl;
- }
- }
- mComposition->setPlotStyle ( QgsComposition::Preview );
- mView->setCanvas(mComposition->canvas());
- }
- else
- {
- raise ();
- }
+ //if ( mPrinter->outputFormat() == QPrinter::PostScriptFormat )
+ if (isPs)
+ {
+ // reset the page
+ mPrinter->setPageSize(psize);
+
+ QFile f(mPrinter->outputFileName());
+
+ // Overwrite the bounding box
+ std::cout << "Overwrite the bounding box" << std::endl;
+ if (!f.open(QIODevice::ReadWrite))
+ {
+ throw QgsIOException(tr("Couldn't open " + f.name() + tr(" for read/write")));
+ }
+ Q_LONG offset = 0;
+ Q_LONG size;
+ bool found = false;
+ QString s;
+ char buf[101];
+ while (!f.atEnd())
+ {
+ size = f.readLine(buf, 100);
+ s = QString(buf);
+ if (s.find("%%BoundingBox:") == 0)
+ {
+ found = true;
+ break;
+ }
+ offset += size;
+ }
+
+ if (found)
+ {
+ int w, h;
+
+ w = (int) (72 * mComposition->paperWidth() / 25.4);
+ h = (int) (72 * mComposition->paperHeight() / 25.4);
+ if (mPrinter->orientation() == QPrinter::Landscape)
+ {
+ int tmp = w;
+ w = h;
+ h = tmp;
+ }
+ s.sprintf("%%%%BoundingBox: 0 0 %d %d", w, h);
+
+ if (s.length() > size)
+ {
+ int shift = s.length() - size;
+ shiftFileContent(&f, offset + size + 1, shift);
+ } else
+ {
+ if (!f.at(offset))
+ {
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot seek"));
+ } else
+ {
+ // Write spaces (for case the size > s.length() )
+ QString es;
+ es.fill(' ', size - 1);
+ f.flush();
+ if (f.writeBlock(es.toLocal8Bit().data(), size - 1) < size - 1)
+ {
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite BoundingBox"));
+ }
+ f.flush();
+ f.at(offset);
+ f.flush();
+ if (f.writeBlock(s.toLocal8Bit().data(), s.length()) < s.length() - 1)
+ {
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite BoundingBox"));
+ }
+ f.flush();
+ } //END else (!f.at(offset))
+ } //END else (s.length() > size)
+ } //END if(found)
+ else
+ {
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot find BoundingBox"));
+ }
+ f.close();
+
+ // Overwrite translate
+ if (mPrinter->orientation() == QPrinter::Portrait)
+ {
+ std::cout << "Orientation portraint -> overwrite translate" << std::endl;
+ if (!f.open(QIODevice::ReadWrite))
+ {
+ throw QgsIOException(tr("Couldn't open ") + f.name() + tr(" for read/write"));
+ }
+ offset = 0;
+ found = false;
+
+ //Example Qt3:
+ //0 4008 translate 1 -1 scale/defM ...
+ //QRegExp rx ( "^0 [^ ]+ translate ([^ ]+ [^ ]+) scale/defM matrix CM d \\} d" );
+ //Example Qt4:
+ //0 0 translate 0.239999 -0.239999 scale } def
+ QRegExp rx("^0 [^ ]+ translate ([^ ]+ [^ ]+) scale \\} def");
+
+ while (!f.atEnd())
+ {
+ size = f.readLine(buf, 100);
+ s = QString(buf);
+ if (rx.search(s) != -1)
+ {
+ found = true;
+ break;
+ }
+ offset += size;
+ } //END while( !f.atEnd() )
+
+ if (found)
+ {
+ int trans;
+
+ trans = (int) (72 * mComposition->paperHeight() / 25.4);
+ std::cout << "trans = " << trans << std::endl;
+ //Qt3:
+ //s.sprintf( "0 %d translate %s scale/defM matrix CM d } d", trans, (const char *)rx.cap(1).toLocal8Bit().data() );
+ //Qt4:
+ s.sprintf("0 %d translate %s scale } def\n", trans, (const char *) rx.cap(1).toLocal8Bit().data());
+
+ std::cout << "s.length() = " << s.length() << " size = " << size << std::endl;
+ if (s.length() > size)
+ {
+ //QMessageBox::warning(this, tr("Error in Print"), tr("Cannot format translate"));
+ // Move the content up
+ int shift = s.length() - size;
+ /*
+ int last = f.size() + shift -1;
+ for ( int i = last; i > offset + size; i-- )
+ {
+ f.at(i-shift);
+ QByteArray ba = f.read(1);
+ f.at(i);
+ f.write(ba);
+ }
+ */
+ shiftFileContent(&f, offset + size + 1, shift);
+ } //END if( s.length() > size)
+
+ // Overwrite the row
+ if (!f.at(offset))
+ {
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot seek"));
+ } else
+ {
+ /* Write spaces (for case the size > s.length() ) */
+ QString es;
+ es.fill(' ', size - 1);
+ f.flush();
+ if (f.writeBlock(es.toLocal8Bit().data(), size - 1) < size - 1)
+ {
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite translate"));
+ }
+ f.flush();
+ f.at(offset);
+ f.flush();
+ if (f.writeBlock(s.toLocal8Bit().data(), s.length()) < s.length() - 1)
+ {
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite translate"));
+ }
+ f.flush();
+ } //END else
+ } else
+ {
+ QMessageBox::warning(this, tr("Error in Print"), tr("Cannot find translate"));
+ }
+ f.close();
+ }
+ }
+ }
+ catch(QgsIOException e)
+ {
+ QMessageBox::warning(this, tr("File IO Error"), e.what());
+ }
+ } else
+ { // print to printer
+ bool print = true;
+
+ // Check size
+ std::cout << "Paper: " << mPrinter->widthMM() << " x " << mPrinter->heightMM() << std::endl;
+ if (mComposition->paperWidth() != mPrinter->widthMM() || mComposition->paperHeight() != mPrinter->heightMM())
+ {
+ int answer = QMessageBox::warning(0, tr("Paper does not match"),
+ tr("The selected paper size does not match the composition size"),
+ QMessageBox::Ok, QMessageBox::Abort);
+
+ if (answer == QMessageBox::Abort)
+ {
+ print = false;
+ }
+ } //END if(compositionSize != paperSize)
+
+ if (print)
+ {
+ std::cout << "Printing ... " << std::endl;
+ QPainter p(mPrinter);
+ p.scale(scale, scale);
+
+ QRectF renderArea(0, 0, (mComposition->paperWidth() * mComposition->scale()),
+ (mComposition->paperHeight() * mComposition->scale()));
+
+ mComposition->canvas()->render(&p, renderArea);
+
+ p.end();
+ std::cout << "... printing finished" << std::endl;
+ } //END if ( print )
+ }
+
+ mComposition->setPlotStyle(QgsComposition::Preview);
+ mView->setScene(mComposition->canvas());
+ } else
+ {
+ raise();
+ }
+
}
+
bool QgsComposer::shiftFileContent ( QFile *file, Q_LONG start, int shift )
{
int last = file->size() + shift -1;
@@ -602,6 +642,7 @@
void QgsComposer::on_mActionExportAsImage_activated(void)
{
+
// Image size
int width = (int) (mComposition->resolution() * mComposition->paperWidth() / 25.4);
int height = (int) (mComposition->resolution() * mComposition->paperHeight() / 25.4);
@@ -613,12 +654,12 @@
#endif
if ( memuse > 200 ) { // cca 4500 x 4500
- int answer = QMessageBox::warning ( this, tr("Big image"),
+ int answer = QMessageBox::warning ( 0, tr("Big image"),
tr("To create image ") + QString::number(width) + " x "
+ QString::number(height)
+ tr(" requires circa ")
+ QString::number(memuse) + tr(" MB of memory"),
- QMessageBox::Ok | QMessageBox::Abort );
+ QMessageBox::Ok, QMessageBox::Abort );
raise ();
if ( answer == QMessageBox::Abort ) return;
@@ -633,7 +674,7 @@
//find out the last used filter
QSettings myQSettings; // where we keep last used filter in persistant state
- QString myLastUsedFormat = myQSettings.readEntry("/UI/lastSaveAsImageFormat", "PNG" );
+ QString myLastUsedFormat = myQSettings.readEntry("/UI/lastSaveAsImageFormat", "PNG" ); //<- BUG #729 is probably here
QString myLastUsedFile = myQSettings.readEntry("/UI/lastSaveAsImageFile","qgis.png");
QFileInfo file(myLastUsedFile);
@@ -704,27 +745,32 @@
double scale = (double) (mComposition->resolution() / 25.4 / mComposition->scale());
- mView->setCanvas(0);
+ mView->setScene(0);
mComposition->setPlotStyle ( QgsComposition::Print );
QPixmap pixmap ( width, height );
pixmap.fill ( QColor(255,255,255) ) ;
QPainter p(&pixmap);
- p.scale ( scale, scale);
- mComposition->canvas()->drawArea ( QRect(0,0,
- (int) (mComposition->paperWidth() * mComposition->scale()),
- (int) (mComposition->paperHeight() * mComposition->scale()) ),
- &p, FALSE );
+ p.scale ( scale, scale);
+
+QRectF renderArea(0,0,(mComposition->paperWidth() * mComposition->scale()),(mComposition->paperHeight() * mComposition->scale()));
+
+ mComposition->canvas()->render(&p, renderArea);
p.end();
mComposition->setPlotStyle ( QgsComposition::Preview );
- mView->setCanvas(mComposition->canvas());
+ mView->setScene(mComposition->canvas());
pixmap.save ( myOutputFileNameQString, myFilterMap[myFilterString].toLocal8Bit().data() );
}
+
void QgsComposer::on_mActionExportAsSVG_activated(void)
{
+
+// QT 4 QPicture does not support export to SVG, so we're still using Q3Picture.
+// When QGIS moves to Qt 4.3, we can use QSvgGenerator instead.
+
QSettings myQSettings;
bool displaySVGWarning = myQSettings.value("/UI/displaySVGWarning", true).toBool();
@@ -747,53 +793,56 @@
"to PostScript if the SVG output is not "
"satisfactory."
"
"));
- m->showMessage();
+ m->exec();
if (m->checkBoxState() == Qt::Checked)
- myQSettings.setValue("/UI/displaySVGWarning", false);
+ {
+ myQSettings.setValue("/UI/displaySVGWarning", false); //turn off the warning next time
+ }
else
+ {
myQSettings.setValue("/UI/displaySVGWarning", true);
+ }
+ //delete m; // this causes a segfault
+
}
-
QString myLastUsedFile = myQSettings.readEntry("/UI/lastSaveAsSvgFile","qgis.svg");
QFileInfo file(myLastUsedFile);
-
QFileDialog *myQFileDialog = new QFileDialog( this, tr("Choose a filename to save the map as"),
file.path(), tr("SVG Format") + " (*.svg *SVG)" );
-
myQFileDialog->selectFile( file.fileName() );
myQFileDialog->setMode(QFileDialog::AnyFile);
myQFileDialog->setAcceptMode(QFileDialog::AcceptSave);
int result = myQFileDialog->exec();
raise ();
-
if ( result != QDialog::Accepted) return;
+
QString myOutputFileNameQString = myQFileDialog->selectedFile();
-
if ( myOutputFileNameQString == "" ) return;
myQSettings.writeEntry("/UI/lastSaveAsSvgFile", myOutputFileNameQString);
- mView->setCanvas(0);
+ mView->setScene(0);//don't redraw the scene on the display while we render
mComposition->setPlotStyle ( QgsComposition::Print );
Q3Picture pic;
QPainter p(&pic);
- mComposition->canvas()->drawArea ( QRect(0,0,
- (int) (mComposition->paperWidth() * mComposition->scale()),
- (int) (mComposition->paperHeight() * mComposition->scale()) ),
- &p, FALSE );
+ QRectF renderArea(0,0, (mComposition->paperWidth() * mComposition->scale()), (mComposition->paperHeight() * mComposition->scale()) );
+
+ mComposition->canvas()->render(&p, renderArea);
p.end();
mComposition->setPlotStyle ( QgsComposition::Preview );
- mView->setCanvas(mComposition->canvas());
+ mView->setScene(mComposition->canvas()); //now that we're done, set the view to show the scene again
QRect br = pic.boundingRect();
pic.save ( myOutputFileNameQString, "svg" );
+
}
+
void QgsComposer::setToolActionsOff(void)
{
mActionOpenTemplate->setOn ( false );
@@ -875,6 +924,7 @@
#ifdef QGISDEBUG
std::cout << "QgsComposer::saveWindowState" << std::endl;
#endif
+
QSettings settings;
QPoint p = this->pos();
@@ -890,10 +940,15 @@
settings.writeEntry("/Composer/geometry/wiev", (int)(*it) );
it++;
settings.writeEntry("/Composer/geometry/options", (int)(*it) );
+
+if(this->isMaximized()){
+ std::cout << "maximized!" << std::endl;
}
+}
void QgsComposer::restoreWindowState()
{
+
QSettings settings;
QDesktopWidget *d = QApplication::desktop();
@@ -906,6 +961,10 @@
resize(w, h);
move(x, y);
+//We also need to save the maximized state
+
+//std::cout << "x: " << x << "y: " << y << "w: " << w << "h: " << h << std::endl;
+
// This doesn't work
Q3ValueList list;
w = settings.readNumEntry("/Composer/geometry/view", 300);
@@ -913,6 +972,7 @@
w = settings.readNumEntry("/Composer/geometry/options", 300);
list.push_back( w );
mSplitter->setSizes ( list );
+
}
void QgsComposer::on_helpPButton_clicked()
Index: src/app/composer/qgscomposerview.h
===================================================================
--- src/app/composer/qgscomposerview.h (revision 7070)
+++ src/app/composer/qgscomposerview.h (working copy)
@@ -18,14 +18,15 @@
#ifndef QGSCOMPOSERVIEW_H
#define QGSCOMPOSERVIEW_H
-#include
-#include
+#include
+#include
+
class QgsComposer;
class QKeyEvent;
class QMouseEvent;
-class QgsComposerView: public Q3CanvasView
+class QgsComposerView: public QGraphicsView
{
Q_OBJECT
@@ -33,9 +34,9 @@
QgsComposerView (QgsComposer *composer, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
protected:
- void contentsMousePressEvent(QMouseEvent*);
- void contentsMouseReleaseEvent(QMouseEvent*);
- void contentsMouseMoveEvent(QMouseEvent*);
+ void mousePressEvent(QMouseEvent*);
+ void mouseReleaseEvent(QMouseEvent*);
+ void mouseMoveEvent(QMouseEvent*);
void keyPressEvent ( QKeyEvent * e );
void resizeEvent ( QResizeEvent * );
Index: src/app/composer/qgscomposerpicture.h
===================================================================
--- src/app/composer/qgscomposerpicture.h (revision 7070)
+++ src/app/composer/qgscomposerpicture.h (working copy)
@@ -19,10 +19,10 @@
#include "ui_qgscomposerpicturebase.h"
#include "qgscomposeritem.h"
-#include
+#include
#include
-#include
-#include
+#include
+#include
#include
class QgsComposition;
@@ -36,8 +36,7 @@
// NOTE: QgsComposerPictureBase must be first, otherwise does not compile
// public QCanvasRectangle,
class QgsComposerPicture : public QWidget, private Ui::QgsComposerPictureBase,
- public Q3CanvasPolygonalItem,
- public QgsComposerItem
+ public QAbstractGraphicsShapeItem, public QgsComposerItem
{
Q_OBJECT
@@ -68,17 +67,12 @@
// Reimplement QCanvasItem::boundingRect
- QRect boundingRect ( void ) const;
+ QRectF boundingRect ( void ) const;
- Q3PointArray areaPoints() const;
+ QPolygonF areaPoints() const;
- // Reimplemented
- void moveBy( double x, double y);
-
- /** \brief Reimplementation of QCanvasItem::draw - draw on canvas */
- void draw ( QPainter & painter );
-
- void drawShape( QPainter & painter );
+ /** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
+ void paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
/** \brief Set values in GUI to current values */
void setOptions ( void );
@@ -88,7 +82,7 @@
// Set box, picture will be inside box, used when placed by mouse.
// Coordinates do not need to be oriented
- void setBox ( int x1, int y1, int x2, int y2 );
+ void setSize(double width, double height );
// Picture dialog, returns file name or empty string
static QString pictureDialog ( void );
@@ -117,7 +111,7 @@
QString mPicturePath;
// Picture
- Q3Picture mPicture;
+ QPicture mPicture;
bool mPictureValid;
@@ -127,8 +121,8 @@
// Coordinates of upper left picture corner
int mX, mY;
- // Picture width and height in paper
- int mWidth, mHeight;
+ // Picture width and height in scene units
+ double mWidth, mHeight;
// Scale, number of canvas units / image unit
@@ -147,13 +141,13 @@
/** \brief Calculate size according to current settings */
void recalculate ( void );
- Q3PointArray mAreaPoints;
+ QPolygonF mAreaPoints;
// Called when picture file is changed
void pictureChanged ( void );
// Current bounding box
- QRect mBoundingRect;
+ QRectF mBoundingRect;
// Adjust size so that picture fits to current box
void adjustPictureSize();
Index: src/app/composer/qgscomposervectorlegend.cpp
===================================================================
--- src/app/composer/qgscomposervectorlegend.cpp (revision 7070)
+++ src/app/composer/qgscomposervectorlegend.cpp (working copy)
@@ -14,6 +14,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
+
#include "qgscomposervectorlegend.h"
#include "qgscomposermap.h"
#include "qgscontinuouscolorrenderer.h"
@@ -27,13 +28,15 @@
#include
#include
#include
+#include
+
#include
#include
QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition, int id,
int x, int y, int fontSize )
- : QWidget(composition), Q3CanvasRectangle(x,y,10,10,0)
+ : QWidget(composition), QGraphicsRectItem(x,y,10,10,0)
{
setupUi(this);
@@ -57,18 +60,17 @@
// Calc size and cache
recalculate();
- // Add to canvas
- setCanvas(mComposition->canvas());
+ // Add to scene
+ mComposition->canvas()->addItem(this);
+ QGraphicsRectItem::show();
+ QGraphicsRectItem::update();
- Q3CanvasRectangle::show();
- Q3CanvasRectangle::update();
-
writeSettings();
}
QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition, int id )
- : Q3CanvasRectangle(0,0,10,10,0)
+ : QGraphicsRectItem(0,0,10,10,0)
{
std::cout << "QgsComposerVectorLegend::QgsComposerVectorLegend()" << std::endl;
@@ -85,11 +87,11 @@
// Calc size and cache
recalculate();
- // Add to canvas
- setCanvas(mComposition->canvas());
+ // Add to scene
+ mComposition->canvas()->addItem(this);
- Q3CanvasRectangle::show();
- Q3CanvasRectangle::update();
+ QGraphicsRectItem::show();
+ QGraphicsRectItem::update();
}
void QgsComposerVectorLegend::init ( void )
@@ -105,8 +107,8 @@
mCacheUpdated = false;
// Rectangle
- Q3CanvasRectangle::setZ(50);
- setActive(true);
+ QGraphicsRectItem::setZValue(50);
+// setActive(true);
// Layers list view
mLayersListView->setColumnText(0,tr("Layers"));
@@ -143,7 +145,7 @@
std::cerr << "QgsComposerVectorLegend::~QgsComposerVectorLegend()" << std::endl;
}
-QRect QgsComposerVectorLegend::render ( QPainter *p )
+QRectF QgsComposerVectorLegend::render ( QPainter *p )
{
std::cout << "QgsComposerVectorLegend::render p = " << p << std::endl;
@@ -177,13 +179,13 @@
QFontMetrics titleMetrics ( titleFont );
QFontMetrics sectionMetrics ( sectionFont );
QFontMetrics metrics ( font );
-
- // Fonts for rendering
- double psTitleSize = titleMetrics.ascent() * 72.0 / mComposition->resolution();
+
+ // Fonts for Postscript rendering
+ double psTitleSize = titleMetrics.ascent() * 72.0 / mComposition->resolution(); //What??
double psSectionSize = sectionMetrics.ascent() * 72.0 / mComposition->resolution();
double psSize = metrics.ascent() * 72.0 / mComposition->resolution();
- if ( plotStyle() == QgsComposition::Postscript)
+ if ( plotStyle() == QgsComposition::Postscript) //do we need seperate PostScript rendering settings?
{
titleFont.setPointSizeFloat ( psTitleSize );
sectionFont.setPointSizeFloat ( psSectionSize );
@@ -203,31 +205,33 @@
int x, y;
- // Title
+ // Legend title -if we do this later, we can center it
y = mMargin + titleMetrics.height();
painter->setPen ( mPen );
painter->setFont ( titleFont );
painter->drawText( (int) (2*mMargin), y, mTitle );
+//used to keep track of total width and height
int width = 4 * mMargin + titleMetrics.width ( mTitle );
int height = mMargin + mSymbolSpace + titleMetrics.height(); // mSymbolSpace?
-
+
// Layers
- QgsComposerMap *map = mComposition->map ( mMap );
+ QgsComposerMap *map = mComposition->map ( mMap ); //Get the map from the composition by ID number
if ( map ) {
+
std::map doneGroups;
int nlayers = mMapCanvas->layerCount();
for ( int i = nlayers - 1; i >= 0; i-- ) {
QgsMapLayer *layer = mMapCanvas->getZpos(i);
- // TODO: visibility [MD]
- //if ( !layer->visible() ) continue;
- if ( layer->type() != QgsMapLayer::VECTOR ) continue;
+// if ( !layer->visible() ) continue; // skip non-visible layers
+ if ( layer->type() != QgsMapLayer::VECTOR ) continue; //skip raster layers
QString layerId = layer->getLayerID();
- if( ! layerOn(layerId) ) continue;
-
+
+// if( ! layerOn(layerId) ) continue; //does this need to go away?
+
int group = layerGroup ( layerId );
if ( group > 0 ) {
if ( doneGroups.find(group) != doneGroups.end() ) {
@@ -237,20 +241,21 @@
}
}
- /* Make list of all layers in the group and count section items */
+ // Make list of all layers in the group and count section items
std::vector groupLayers; // vector of layers
std::vector itemHeights; // maximum item sizes
std::vector itemLabels; // item labels
int sectionItemsCount = 0;
QString sectionTitle;
- for ( int j = nlayers - 1; j >= 0; j-- ) {
+
+ for ( int j = nlayers - 1; j >= 0; j-- )
+ {
QgsMapLayer *layer2 = mMapCanvas->getZpos(j);
- // TODO: visibility [MD]
- //if ( !layer2->visible() ) continue;
+// if ( !layer2->visible() ) continue;
if ( layer2->type() != QgsMapLayer::VECTOR ) continue;
- QString layerId2 = layer2->getLayerID();;
+ QString layerId2 = layer2->getLayerID();
if( ! layerOn(layerId2) ) continue;
int group2 = layerGroup ( layerId2 );
@@ -314,8 +319,10 @@
//std::cout << "group size = " << groupLayers.size() << std::endl;
//std::cout << "sectionItemsCount = " << sectionItemsCount << std::endl;
+
// Section title
- if ( sectionItemsCount > 1 ) {
+ if ( sectionItemsCount > 1 )
+ {
height += mSymbolSpace;
x = (int) ( 2*mMargin );
@@ -323,7 +330,7 @@
painter->setPen ( mPen );
painter->setFont ( sectionFont );
- painter->drawText( x, y,sectionTitle );
+ painter->drawText( x, y, sectionTitle );
int w = 3*mMargin + sectionMetrics.width( sectionTitle );
if ( w > width ) width = w;
@@ -331,33 +338,36 @@
height += (int) (0.7*mSymbolSpace);
}
+
// Draw all layers in group
int groupStartHeight = height;
- for ( int j = groupLayers.size()-1; j >= 0; j-- ) {
- std::cout << "layer = " << groupLayers[j] << std::endl;
+ for ( int j = groupLayers.size()-1; j >= 0; j-- )
+ {
+ std::cout << "layer = " << groupLayers[j] << std::endl;
- int localHeight = groupStartHeight;
+ int localHeight = groupStartHeight;
- layer = mMapCanvas->getZpos(groupLayers[j]);
- QgsVectorLayer *vector = dynamic_cast (layer);
- const QgsRenderer *renderer = vector->renderer();
+ layer = mMapCanvas->getZpos(groupLayers[j]);
+ QgsVectorLayer *vector = dynamic_cast (layer);
+ const QgsRenderer *renderer = vector->renderer();
- // Symbol
- QList symbols = renderer->symbols();
+ // Get a list of the symbols from the renderer - some renderers can have several symbols
+ QList symbols = renderer->symbols();
- int icnt = 0;
- for ( QList::iterator it = symbols.begin(); it != symbols.end(); ++it ) {
+
+ int icnt = 0;
+ for ( QList::iterator it = symbols.begin(); it != symbols.end(); ++it ) {
localHeight += mSymbolSpace;
int symbolHeight = itemHeights[icnt];
QgsSymbol* sym = (*it);
QPen pen = sym->pen();
- double widthScale = map->widthScale() * mComposition->scale();
- if ( plotStyle() == QgsComposition::Preview && mPreviewMode == Render ) {
- widthScale *= mComposition->viewScale();
- }
- pen.setWidth ( (int) ( widthScale * pen.width() ) );
+ double widthScale = map->widthScale();
+
+std::cout << "widthScale: " << widthScale << std::endl;
+
+ pen.setWidthF( ( widthScale * pen.widthF() ) );
painter->setPen ( pen );
painter->setBrush ( sym->brush() );
@@ -378,6 +388,9 @@
painter->drawLine ( mMargin, localHeight+mSymbolHeight/2,
mMargin+mSymbolWidth, localHeight+mSymbolHeight/2 );
} else if ( vector->vectorType() == QGis::Polygon ) {
+ pen.setWidth(0); //use a cosmetic pen to outline the fill box
+ pen.setCapStyle(Qt::FlatCap);
+ painter->setPen ( pen );
painter->drawRect ( mMargin, localHeight, mSymbolWidth, mSymbolHeight );
}
@@ -391,7 +404,7 @@
lab = itemLabels[icnt];
}
- // drawText (x, y w, h, ...) was cutting last letter (the box was tto small)
+ // drawText (x, y w, h, ...) was cutting last letter (the box was too small)
QRect br = metrics.boundingRect ( lab );
x = (int) ( 2*mMargin + mSymbolWidth );
y = (int) ( localHeight + symbolHeight/2 + ( metrics.height()/2 - metrics.descent()) );
@@ -403,36 +416,50 @@
localHeight += symbolHeight;
icnt++;
- }
+
+ }//End of iterating through the symbols in the renderer
+
}
- /* add height of section items */
+ // add height of section items to the total height
height = groupStartHeight;
- for ( uint j = 0; j < itemHeights.size(); j++ ) {
- height += mSymbolSpace + itemHeights[j];
+ for ( int j = 0; j < (int)itemHeights.size(); j++ ) {
+ height += mSymbolSpace + itemHeights[j];
}
if ( sectionItemsCount > 1 ) { // add more space to separate section from next item
height += mSymbolSpace;
}
- }
+
+ }//End of iterating through the layers
+ }//END if(map)
+
+ height += mMargin;
+
+ if(mFrame)
+ {
+ QPen pen(QColor(0,0,0), 0.5);
+ painter->setPen( pen );
+ painter->setBrush( QBrush( QColor(255,255,255), Qt::NoBrush));
+ painter->setRenderHint(QPainter::Antialiasing, true);//turn on antialiasing
+ painter->drawRect ( 0, 0, width, height );
}
- height += mMargin;
- Q3CanvasRectangle::setSize ( width, height );
+// QGraphicsRectItem::setRect(0, 0, width, height); //BUG! - calling this causes a re-draw, which means we are continuously re-drawing.
if ( !p ) {
delete painter;
delete pixmap;
}
- return QRect ( 0, 0, width, height);
+ return QRectF ( 0, 0, width, height);
}
void QgsComposerVectorLegend::cache ( void )
{
std::cout << "QgsComposerVectorLegend::cache()" << std::endl;
- mCachePixmap.resize ( Q3CanvasRectangle::width(), Q3CanvasRectangle::height() );
+//typical boundingRect size is 15 units wide,
+ mCachePixmap.resize ((int)QGraphicsRectItem::rect().width(), (int)QGraphicsRectItem::rect().height() );
QPainter p(&mCachePixmap);
@@ -444,70 +471,50 @@
mCacheUpdated = true;
}
-void QgsComposerVectorLegend::draw ( QPainter & painter )
+void QgsComposerVectorLegend::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
{
- std::cout << "draw mPlotStyle = " << plotStyle()
- << " mPreviewMode = " << mPreviewMode << std::endl;
+#ifdef QGISDEBUG
+ std::cout << "paint mPlotStyle = " << plotStyle() << " mPreviewMode = " << mPreviewMode << std::endl;
+#endif
- // Draw background rectangle
-
- if ( mFrame ) {
- QPen pen(QColor(0,0,0));
- pen.setWidthF(0.5);
- painter.setPen( pen );
- painter.setBrush( QBrush( QColor(255,255,255), Qt::SolidPattern) );
-
- painter.save();
-
- painter.translate ( Q3CanvasRectangle::x(), Q3CanvasRectangle::y() );
- painter.drawRect ( 0, 0, Q3CanvasRectangle::width()+1, Q3CanvasRectangle::height()+1 ); // is it right?
- painter.restore();
- }
-
- if ( plotStyle() == QgsComposition::Preview && mPreviewMode == Cache ) { // Draw from cache
- std::cout << "use cache" << std::endl;
-
- if ( !mCacheUpdated || mMapCanvas->layerCount() != mNumCachedLayers ) {
+ if ( plotStyle() == QgsComposition::Preview && mPreviewMode == Cache )
+ {
+ if ( !mCacheUpdated || mMapCanvas->layerCount() != mNumCachedLayers ) //If the cache is out of date, update it.
+ {
cache();
}
-
- painter.save();
- painter.translate ( Q3CanvasRectangle::x(), Q3CanvasRectangle::y() );
- std::cout << "translate: " << Q3CanvasRectangle::x() << ", " << Q3CanvasRectangle::y() << std::endl;
- painter.drawPixmap(0,0, mCachePixmap);
-
- painter.restore();
-
- } else if ( (plotStyle() == QgsComposition::Preview && mPreviewMode == Render) ||
+ painter->drawPixmap(0,0, mCachePixmap);
+ }
+ else if(plotStyle() == QgsComposition::Preview && mPreviewMode == Rectangle)
+ {
+ QPen pen(QColor(0,0,0), 0.5);
+ painter->setPen( pen );
+ painter->setBrush( QBrush( QColor(255,255,255), Qt::NoBrush)); //use SolidPattern instead?
+ painter->drawRect(QRectF(0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height()));
+ }
+ else if ( (plotStyle() == QgsComposition::Preview && mPreviewMode == Render) ||
plotStyle() == QgsComposition::Print ||
plotStyle() == QgsComposition::Postscript )
- {
- std::cout << "render" << std::endl;
-
- painter.save();
- painter.translate ( Q3CanvasRectangle::x(), Q3CanvasRectangle::y() );
- render( &painter );
- painter.restore();
- }
+ //We're in render preview mode or printing, so do a full render of the legend.
+ {
+ painter->save();
+ render(painter);
+ painter->restore();
+ }
- // Show selected / Highlight
- std::cout << "mSelected = " << mSelected << std::endl;
+
+ // Draw the "selected highlight" boxes
if ( mSelected && plotStyle() == QgsComposition::Preview ) {
- std::cout << "highlight" << std::endl;
- painter.setPen( mComposition->selectionPen() );
- painter.setBrush( mComposition->selectionBrush() );
+
+ painter->setPen( mComposition->selectionPen() );
+ painter->setBrush( mComposition->selectionBrush() );
- int x = (int) Q3CanvasRectangle::x();
- int y = (int) Q3CanvasRectangle::y();
- int s = mComposition->selectionBoxSize();
+ double s = mComposition->selectionBoxSize();
- painter.drawRect ( x, y, s, s );
- x += Q3CanvasRectangle::width();
- painter.drawRect ( x-s, y, s, s );
- y += Q3CanvasRectangle::height();
- painter.drawRect ( x-s, y-s, s, s );
- x -= Q3CanvasRectangle::width();
- painter.drawRect ( x, y-s, s, s );
+ painter->drawRect(QRectF(0, 0, s, s)); //top left
+ painter->drawRect(QRectF(QGraphicsRectItem::rect().width()-s, 0, s, s)); //top right
+ painter->drawRect(QRectF(QGraphicsRectItem::rect().width()-s, QGraphicsRectItem::rect().height()-s, s, s)); //bottom right
+ painter->drawRect(QRectF(0, QGraphicsRectItem::rect().height()-s, s, s)); //bottom left
}
}
@@ -519,8 +526,8 @@
if ( result ) {
recalculate();
- Q3CanvasRectangle::update();
- Q3CanvasRectangle::canvas()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
writeSettings();
}
}
@@ -529,8 +536,8 @@
{
mTitle = mTitleLineEdit->text();
recalculate();
- Q3CanvasRectangle::update();
- Q3CanvasRectangle::canvas()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
writeSettings();
}
@@ -545,8 +552,8 @@
{
mMap = mMaps[i];
recalculate();
- Q3CanvasRectangle::update();
- Q3CanvasRectangle::canvas()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
writeSettings();
}
@@ -555,16 +562,16 @@
if ( id != mMap ) return;
recalculate();
- Q3CanvasRectangle::update();
- Q3CanvasRectangle::canvas()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
}
void QgsComposerVectorLegend::on_mFrameCheckBox_stateChanged ( int )
{
mFrame = mFrameCheckBox->isChecked();
- Q3CanvasRectangle::update();
- Q3CanvasRectangle::canvas()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
writeSettings();
}
@@ -595,9 +602,9 @@
std::cout << "mMargin = " << mMargin << " mSymbolHeight = " << mSymbolHeight
<< "mSymbolWidth = " << mSymbolWidth << " mSymbolSpace = " << mSymbolSpace << std::endl;
- QRect r = render(0);
+ QRectF r = render(0);
- Q3CanvasRectangle::setSize ( r.width(), r.height() );
+ QGraphicsRectItem::setRect(0, 0, r.width(), r.height() );
mCacheUpdated = false;
}
@@ -615,7 +622,7 @@
bool found = false;
mMapComboBox->insertItem ( "", 0 );
mMaps.push_back ( 0 );
- for ( uint i = 0; i < maps.size(); i++ ) {
+ for ( int i = 0; i < (int)maps.size(); i++ ) {
mMapComboBox->insertItem ( maps[i]->name(), i+1 );
mMaps.push_back ( maps[i]->id() );
@@ -643,9 +650,7 @@
for ( int i = 0; i < nlayers; i++ ) {
QgsMapLayer *layer = mMapCanvas->getZpos(i);
- // TODO: visibility [MD]
- //if ( !layer->visible() ) continue;
-
+// if ( !layer->visible() ) continue;
//if ( layer->type() != QgsMapLayer::VECTOR ) continue;
Q3CheckListItem *li = new Q3CheckListItem ( mLayersListView, layer->name(), Q3CheckListItem::CheckBox );
@@ -671,7 +676,7 @@
void QgsComposerVectorLegend::setSelected ( bool s )
{
mSelected = s;
- Q3CanvasRectangle::update(); // show highlight
+ QGraphicsRectItem::update(); // show highlight
}
bool QgsComposerVectorLegend::selected( void )
@@ -743,8 +748,8 @@
writeSettings();
recalculate();
- Q3CanvasRectangle::update();
- Q3CanvasRectangle::canvas()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
}
void QgsComposerVectorLegend::groupLayers ( void )
@@ -753,7 +758,7 @@
Q3ListViewItemIterator it( mLayersListView );
int count = 0;
- Q3ListViewItem *lastItem = NULL;
+ Q3ListViewItem *lastItem;
QString id;
while ( it.current() ) {
if ( it.current()->isSelected() ) {
@@ -783,8 +788,8 @@
writeSettings();
recalculate();
- Q3CanvasRectangle::update();
- Q3CanvasRectangle::canvas()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
}
QWidget *QgsComposerVectorLegend::options ( void )
@@ -799,8 +804,8 @@
QString path;
path.sprintf("/composition_%d/vectorlegend_%d/", mComposition->id(), mId );
- QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)Q3CanvasRectangle::x()) );
- QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)Q3CanvasRectangle::y()) );
+ QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)QGraphicsRectItem::x()) );
+ QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)QGraphicsRectItem::y()) );
QgsProject::instance()->writeEntry( "Compositions", path+"map", mMap );
@@ -826,8 +831,7 @@
for ( int i = 0; i < nlayers; i++ ) {
QgsMapLayer *layer = mMapCanvas->getZpos(i);
- // TODO: visibility [MD]
- //if ( !layer->visible() ) continue;
+// if ( !layer->visible() ) continue;
QString id = layer->getLayerID();
path.sprintf("/composition_%d/vectorlegend_%d/layers/layer_%s/", mComposition->id(), mId, id.toLocal8Bit().data() );
@@ -848,9 +852,11 @@
QString path;
path.sprintf("/composition_%d/vectorlegend_%d/", mComposition->id(), mId );
- Q3CanvasRectangle::setX( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok)) );
- Q3CanvasRectangle::setY( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok)) );
+ double x = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok));
+ double y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok));
+ QGraphicsRectItem::setPos(x, y);
+
mMap = QgsProject::instance()->readNumEntry("Compositions", path+"map", 0, &ok);
mTitle = QgsProject::instance()->readEntry("Compositions", path+"title", "???", &ok);
Index: src/app/composer/qgscomposerscalebar.h
===================================================================
--- src/app/composer/qgscomposerscalebar.h (revision 7070)
+++ src/app/composer/qgscomposerscalebar.h (working copy)
@@ -18,9 +18,10 @@
#include "ui_qgscomposerscalebarbase.h"
#include "qgscomposeritem.h"
-#include
+#include
#include
#include
+#include
class QgsMapCanvas;
class QgsComposition;
@@ -33,10 +34,9 @@
/** \class QgsComposerScalebar
* \brief Object representing map window.
- * x,y is center of upper side of the bar, the center position depends on scalebar style
*/
// NOTE: QgsComposerScalebarBase must be first, otherwise does not compile
-class QgsComposerScalebar : public QWidget, private Ui::QgsComposerScalebarBase, public Q3CanvasPolygonalItem, public QgsComposerItem
+class QgsComposerScalebar : public QWidget, private Ui::QgsComposerScalebarBase, public QAbstractGraphicsShapeItem, public QgsComposerItem
{
Q_OBJECT
@@ -66,19 +66,19 @@
bool writeXML( QDomNode & node, QDomDocument & document, bool temp = false );
bool readXML( QDomNode & node );
- QRect boundingRect ( void ) const;
+ QRectF boundingRect ( void ) const;
/** \brief Draw to paint device, internal use
* \param painter painter or 0
* \return bounding box
*/
- QRect render (QPainter *painter);
+ QRectF render (QPainter *painter);
- /** \brief Reimplementation of QCanvasItem::draw - draw on canvas */
- void draw ( QPainter & painter );
+ /** \brief Reimplementation of QGraphicsItem::paint - draw on canvas */
+ void paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget);
- void drawShape(QPainter&);
- Q3PointArray areaPoints() const;
+ //void drawShape(QPainter&);
+ QPolygonF areaPoints() const;
/** \brief Calculate size according to current settings */
void recalculate ( void );
@@ -87,7 +87,7 @@
void setOptions ( void );
// Move to position
- void moveBy ( double x, double y );
+// void moveBy ( double x, double y );
public slots:
// Open font dialog
@@ -122,7 +122,7 @@
std::vector mMaps;
// Current bounding box
- QRect mBoundingRect;
+ QRectF mBoundingRect;
// Number of map units in scalebar unit
double mMapUnitsPerUnit;
@@ -134,7 +134,7 @@
QFont mFont;
// Pen
- QPen mPen;
+ QPen mPen;
// Brush
QBrush mBrush;
@@ -146,7 +146,7 @@
double mSegmentLength;
// Height of scalebar box in canvas units (box style only)
- int mHeight;
+ double mHeight;
// Margin
int mMargin;
Index: src/app/composer/qgscomposermap.h
===================================================================
--- src/app/composer/qgscomposermap.h (revision 7070)
+++ src/app/composer/qgscomposermap.h (working copy)
@@ -20,7 +20,7 @@
#include "ui_qgscomposermapbase.h"
#include "qgscomposeritem.h"
#include "qgsrect.h"
-#include
+#include
#include
class QgsComposition;
@@ -34,7 +34,7 @@
* \brief Object representing map window.
*/
// NOTE: QgsComposerMapBase must be first, otherwise does not compile
-class QgsComposerMap : public QWidget, private Ui::QgsComposerMapBase, public Q3CanvasRectangle, public QgsComposerItem
+class QgsComposerMap : public QWidget, private Ui::QgsComposerMapBase, public QGraphicsRectItem, public QgsComposerItem
{
Q_OBJECT
@@ -74,8 +74,8 @@
/** \brief Draw to paint device */
void draw(QPainter *painter, QgsRect &extent, QgsMapToPixel *transform);
- /** \brief Reimplementation of QCanvasItem::draw - draw on canvas */
- void draw ( QPainter & painter );
+ /** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
+ void paint (QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget);
/** \brief Set extent requested by user */
void setUserExtent ( QgsRect const & rect);
Index: src/app/composer/qgscomposerlabel.h
===================================================================
--- src/app/composer/qgscomposerlabel.h (revision 7070)
+++ src/app/composer/qgscomposerlabel.h (working copy)
@@ -19,10 +19,10 @@
#include "ui_qgscomposerlabelbase.h"
#include "qgscomposeritem.h"
-#include
+#include
#include
#include
-#include
+#include
#include
#include
@@ -35,7 +35,7 @@
*/
// NOTE: QgsComposerLabelBase must be first, otherwise does not compile
//class QgsComposerLabel : public QgsComposerLabelBase, public QCanvasRectangle, public QgsComposerItem
-class QgsComposerLabel : public QWidget, private Ui::QgsComposerLabelBase, public Q3CanvasPolygonalItem, public QgsComposerItem
+class QgsComposerLabel : public QWidget, private Ui::QgsComposerLabelBase, public QAbstractGraphicsShapeItem, public QgsComposerItem
{
Q_OBJECT
@@ -63,13 +63,13 @@
bool writeXML( QDomNode & node, QDomDocument & document, bool temp = false );
bool readXML( QDomNode & node );
- QRect boundingRect ( void ) const;
+ QRectF boundingRect ( void ) const; //errors about overriding things?
- /** \brief Reimplementation of QCanvasItem::draw - draw on canvas */
- void draw ( QPainter & painter );
+ /** \brief Reimplementation of QGraphicsItem::paint() - draw on canvas */
+ void paint ( QPainter*, const QStyleOptionGraphicsItem*, QWidget* );
- void drawShape(QPainter&);
- Q3PointArray areaPoints() const;
+// void drawShape(QPainter&, const QStyleOptionGraphicsItem*, QWidget*);
+ QPolygonF areaPoints() const;
/** \brief Set values in GUI to current values */
void setOptions ( void );
Index: src/app/composer/qgscomposervectorlegend.h
===================================================================
--- src/app/composer/qgscomposervectorlegend.h (revision 7070)
+++ src/app/composer/qgscomposervectorlegend.h (working copy)
@@ -43,7 +43,9 @@
#include "ui_qgscomposervectorlegendbase.h"
#include "qgscomposeritem.h"
-#include
+
+#include
+#include
#include
#include