[QGIS Commit] r8545 -
branches/advanced_printing_branch/src/app/composer
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Fri May 30 07:10:29 EDT 2008
Author: mhugent
Date: 2008-05-30 07:10:29 -0400 (Fri, 30 May 2008)
New Revision: 8545
Modified:
branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h
branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposermap.h
branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp
Log:
More improvements to composer map, but there are still problems with the qt graphics view framework
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp 2008-05-29 19:38:24 UTC (rev 8544)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp 2008-05-30 11:10:29 UTC (rev 8545)
@@ -24,6 +24,7 @@
#include "qgscomposeritem.h"
#include <iostream>
+#include "qgsrect.h" //just for debugging
QgsComposerItem::QgsComposerItem(QGraphicsItem* parent): QGraphicsRectItem(0), mBoundingResizeRectangle(0)
{
@@ -96,19 +97,18 @@
//set current position and type of mouse move action
mMouseMoveStartPos = event->lastScenePos();
mLastMouseEventPos = event->lastPos();
- mCurrentMouseMoveAction = mouseMoveActionForPosition(event->lastPos());
+ mCurrentMouseMoveAction = mouseMoveActionForPosition(event->pos());
setCursor(QCursor(cursorForPosition(event->pos())));
//create and show bounding rectangle
- mBoundingResizeRectangle = new QGraphicsRectItem(QGraphicsRectItem::rect(), 0);
+ mBoundingResizeRectangle = new QGraphicsRectItem(rect(), 0); //problem. Maybe set rect after adding to scene?
scene()->addItem(mBoundingResizeRectangle);
- mBoundingResizeRectangle->moveBy(x(), y());
+ mBoundingResizeRectangle->setRect(rect());
+
mBoundingResizeRectangle->setBrush( Qt::NoBrush );
mBoundingResizeRectangle->setPen( QPen(QColor(0,0,0), 0) );
mBoundingResizeRectangle->setZValue(90);
mBoundingResizeRectangle->show();
-
- //QGraphicsRectItem::setVisible(false);
}
void QgsComposerItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
@@ -121,8 +121,6 @@
mBoundingResizeRectangle = 0;
}
- //QGraphicsRectItem::setVisible(true);
-
QPointF mouseMoveStopPoint = event->lastScenePos();
double diffX = mouseMoveStopPoint.x() - mMouseMoveStartPos.x();
double diffY = mouseMoveStopPoint.y() - mMouseMoveStartPos.y();
@@ -135,9 +133,14 @@
double mx, my, rx, ry;
rectangleChange(diffX, diffY, mx, my, rx, ry);
- moveBy(mx, my);
- resize(rx, ry);
+ QRectF currentRect = rect();
+ QRectF newRect(currentRect.x() + mx, currentRect.y() + my, currentRect.width() + rx, currentRect.height() + ry);
+ setRect(newRect);
+
+ update();
+ scene()->update();
+
//reset default action
mCurrentMouseMoveAction = QgsComposerItem::moveItem;
setCursor(Qt::ArrowCursor);
@@ -182,10 +185,6 @@
QgsComposerItem::mouseMoveAction QgsComposerItem::mouseMoveActionForPosition(const QPointF& itemCoordPos)
{
-
- qWarning("mouseMoveAction: itemcoordpos: " );
- qWarning(QString::number(itemCoordPos.x()).toLatin1());
- qWarning(QString::number(itemCoordPos.y()).toLatin1());
bool nearLeftBorder = false;
bool nearRightBorder = false;
bool nearLowerBorder = false;
@@ -199,11 +198,11 @@
{
nearUpperBorder = true;
}
- if(itemCoordPos.x() > (rect().right() - 5))
+ if(itemCoordPos.x() > (rect().width() - 5))
{
nearRightBorder = true;
}
- if(itemCoordPos.y() > (rect().bottom() - 5))
+ if(itemCoordPos.y() > (rect().height() - 5))
{
nearLowerBorder = true;
}
@@ -292,24 +291,45 @@
void QgsComposerItem::drawSelectionBoxes(QPainter* p)
{
- //p->setPen( mComposition->selectionPen() );
- //p->setBrush( mComposition->selectionBrush() );
p->setPen(QPen(QColor(0, 0, 255)));
- double s = 5;//mComposition->selectionBoxSize();
+ double s = 5;
p->drawRect (QRectF(0, 0, s, s));
- p->drawRect (QRectF(QGraphicsRectItem::rect().width() -s, 0, s, s));
- p->drawRect (QRectF(QGraphicsRectItem::rect().width() -s, QGraphicsRectItem::rect().height() -s, s, s));
- p->drawRect (QRectF(0, QGraphicsRectItem::rect().height() -s, s, s));
+ p->drawRect (QRectF(rect().width() -s, 0, s, s));
+ p->drawRect (QRectF(rect().width() -s, rect().height() -s, s, s));
+ p->drawRect (QRectF(0, rect().height() -s, s, s));
}
void QgsComposerItem::drawFrame(QPainter* p)
{
- QPen pen(QColor(0,0,0));
- pen.setWidthF(1.0);
- p->setPen( pen );
- p->setBrush( Qt::NoBrush );
+ p->setPen(pen());
p->setRenderHint(QPainter::Antialiasing, true);
- p->drawRect (QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() ));
+ p->drawRect (QRectF( 0, 0, rect().width(), rect().height()));
}
+
+void QgsComposerItem::setRect(const QRectF& rectangle)
+{
+ QPointF zeroPointPos = pos();
+ prepareGeometryChange();
+ QGraphicsRectItem::setRect(rectangle);
+ //set (0/0) point of item coordinates to top left point again
+ //strange that Qt doesn't do that itself
+ moveBy(rectangle.x() - zeroPointPos.x(), rectangle.y() - zeroPointPos.y());
+ setVisible(true);
+ update();
+}
+
+#if 0
+QRectF QgsComposerItem::boundingRect () const
+{
+ return rect();
+}
+#endif //0
+
+void QgsComposerItem::drawBackground(QPainter* p)
+{
+ p->setBrush(brush());
+ p->setRenderHint(QPainter::Antialiasing, true);
+ p->drawRect (QRectF( 0, 0, rect().width(), rect().height()));
+}
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h 2008-05-29 19:38:24 UTC (rev 8544)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h 2008-05-30 11:10:29 UTC (rev 8545)
@@ -84,6 +84,9 @@
/** resizes an item in x- and y direction (canvas coordinates)*/
virtual void resize(double dx, double dy){}
+ /**Sets new rect and adapts (0/0) point accordingly*/
+ virtual void setRect(const QRectF& rectangle);
+
/** stores state in DOM node
* @param node is DOM node corresponding to '???' tag
* @param temp write template file
@@ -95,9 +98,12 @@
*/
virtual bool readXML( QDomNode & node );
+ //virtual QRectF boundingRect () const;
+
protected:
QgsComposition::PlotStyle mPlotStyle;
int mId;
+
QgsComposerItem::mouseMoveAction mCurrentMouseMoveAction;
/**Start point of the last mouse move action (in scene coordinates)*/
QPointF mMouseMoveStartPos;
@@ -131,18 +137,15 @@
@param rx out: width of rectangle should be resized by rx
@param ry out: height of rectangle should be resized by ry*/
void rectangleChange(double dx, double dy, double& mx, double& my, double& rx, double& ry) const;
-
-#if 0 //todo: implement on item level if not provided by graphics view
- void drawBackground();
- void drawOutline();
- void drawSelectionBoxes();
-#endif //0
/**Draw selection boxes around item*/
void drawSelectionBoxes(QPainter* p);
/**Draw black frame around item*/
void drawFrame(QPainter* p);
+
+ /**Draw background*/
+ void drawBackground(QPainter* p);
};
#endif
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp 2008-05-29 19:38:24 UTC (rev 8544)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp 2008-05-30 11:10:29 UTC (rev 8545)
@@ -25,6 +25,7 @@
#include "qgsproject.h"
#include "qgsmaprender.h"
#include "qgsrendercontext.h"
+#include "qgsscalecalculator.h"
#include "qgsvectorlayer.h"
#include "qgslabel.h"
@@ -41,35 +42,40 @@
#endif
QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int id, int x, int y, int width, int height )
- : /*QWidget(),*/ QgsComposerItem(0,0,width,height,0)
+ : /*QWidget(),*/ QgsComposerItem(x, y, width,height,0)
{
-#ifdef QGISDEBUG
- std::cout << "QgsComposerMap::QgsComposerMap()" << std::endl;
-#endif
- //setupUi(this);
-
mComposition = composition;
mId = id;
mMapCanvas = mComposition->mapCanvas();
mName = QString(tr("Map %1").arg(mId));
+
+ // Cache
+ mCacheUpdated = false;
- init();
- recalculate();
+ mCalculate = Scale;
+ //mPlotStyle = QgsComposition::Preview;
+ setPlotStyle ( QgsComposition::Preview );
+ mDrawing = false;
+ //calculate mExtent based on width/height ratio and map canvas extent
+ mExtent = mMapCanvas->extent();
+ setRect(QRectF(x, y, width, height));
+
+ QGraphicsRectItem::setZValue(20);
+
+ connect ( mMapCanvas, SIGNAL(layersChanged()), this, SLOT(mapCanvasChanged()) );
+
// Add to scene
mComposition->canvas()->addItem(this);
- QGraphicsRectItem::setPos(x, y);
QGraphicsRectItem::show();
- writeSettings();
+ //writeSettings();
}
QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int id )
: QgsComposerItem(0,0,10,10,0)
{
- //setupUi(this);
-
mComposition = composition;
mId = id;
mMapCanvas = mComposition->mapCanvas();
@@ -173,53 +179,20 @@
void QgsComposerMap::cache ( void )
{
-#ifdef QGISDEBUG
- std::cout << "QgsComposerMap::cache()" << std::endl;
-#endif
-
- // Create preview on some reasonable size. It was slow with cca 1500x1500 points on 2x1.5GHz
- // Note: The resolution should also respect the line widths, it means that
- // 1 pixel in cache should have ia similar size as 1 pixel in canvas
- // but it can result in big cache -> limit
-
- int w = (int)(QGraphicsRectItem::rect().width() * mComposition->viewScale());
- w = w < 1000 ? w : 1000; //limit the cache pixmap to 1000 pixels wide
- int h = (int) ( mExtent.height() * w / mExtent.width() );
- // It can happen that extent is not initialised well -> check
- if ( h < 1 || h > 10000 ) h = w;
-
-#ifdef QGISDEBUG
- std::cout << "extent = " << mExtent.width() << " x " << mExtent.height() << std::endl;
- std::cout << "cache = " << w << " x " << h << std::endl;
-#endif
-
- mCacheExtent = QgsRect ( mExtent );
- double scale = mExtent.width() / w;
- mCacheExtent.setXmax ( mCacheExtent.xMin() + w * scale );
- mCacheExtent.setYmax ( mCacheExtent.yMin() + h * scale );
+ int w = rect().width();
+ int h = rect().height();
mCachePixmap = QPixmap( w, h );
+ double mupp = mExtent.width() / w;
// WARNING: ymax in QgsMapToPixel is device height!!!
- QgsMapToPixel transform(scale, h, mCacheExtent.yMin(), mCacheExtent.xMin() );
-
-//somthing about this transform isn't really what we want...
-/*Ideally, the cache pixmap wouldn't behave the same as the map canvas.
-* zooming in should make the lines become thicker, and symbols larger, rather than just
-* redrawing them to be n pixels wide.
-* We also want to make sure that changing the composition's resolution has the desired effect
-* on both the cache, screen render, and print.
-*/
-
-#ifdef QGISDEBUG
- std::cout << "transform = " << transform.showParameters().toLocal8Bit().data() << std::endl;
-#endif
+ QgsMapToPixel transform(mupp, h, mExtent.yMin(), mExtent.xMin() );
mCachePixmap.fill(QColor(255,255,255));
QPainter p(&mCachePixmap);
- draw( &p, mCacheExtent, QSize(w, h), mCachePixmap.logicalDpiX());
+ draw( &p, mExtent, QSize(w, h), mCachePixmap.logicalDpiX());
p.end();
mNumCachedLayers = mMapCanvas->layerCount();
@@ -235,6 +208,8 @@
}
mDrawing = true;
+ painter->setClipRect (QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() ));
+
#ifdef QGISDEBUG
std::cout << "QgsComposerMapt::paint mPlotStyle = " << plotStyle()
<< " mPreviewMode = " << mPreviewMode << std::endl;
@@ -277,7 +252,6 @@
QRectF bRect = boundingRect();
QSize theSize(bRect.width(), bRect.height());
- painter->setClipRect (QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() ));
draw( painter, mExtent, theSize, 25.4); //scene coordinates seem to be in mm
}
@@ -552,7 +526,14 @@
mCacheUpdated = u;
}
-double QgsComposerMap::scale ( void ) { return mScale; }
+//double QgsComposerMap::scale ( void ) { return mScale; }
+double QgsComposerMap::scale()
+{
+ QgsScaleCalculator calculator;
+ calculator.setMapUnits(mMapCanvas->mapUnits());
+ calculator.setDpi(25.4); //QGraphicsView units are mm
+ return calculator.calculate(mExtent, rect().width());
+}
QWidget *QgsComposerMap::options ( void )
{
@@ -668,15 +649,36 @@
void QgsComposerMap::resize(double dx, double dy)
{
//setRect
- QRectF currentRect = QGraphicsRectItem::rect();
+ QRectF currentRect = rect();
QRectF newRect = QRectF(currentRect.x(), currentRect.y(), currentRect.width() + dx, currentRect.height() + dy);
- setRect(newRect);
+ setRect(newRect);
}
-void QgsComposerMap::setRect(const QRectF rectangle)
+void QgsComposerMap::setRect(const QRectF& rectangle)
{
- QGraphicsRectItem::setRect(rectangle);
- recalculate();
+ double w = rectangle.width();
+ double h = rectangle.height();
+ prepareGeometryChange();
+
+ //debug
+ qWarning("QgsComposerMap::setRect");
+ QgsRect debugRect(rectangle.left(), rectangle.top(), rectangle.right(), rectangle.bottom());
+ qWarning(debugRect.stringRep().latin1());
+
+ QgsComposerItem::setRect(rectangle);
+
+ QGraphicsRectItem::update();
+ double newHeight = mExtent.width() * h / w ;
+ mExtent = QgsRect(mExtent.xMin(), mExtent.yMin(), mExtent.xMax(), mExtent.yMin() + newHeight);
emit extentChanged();
}
+void QgsComposerMap::setNewExtent(const QgsRect& extent)
+{
+ //soon...
+}
+
+void QgsComposerMap::setNewScale(double scaleDenominator)
+{
+ //soon...
+}
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.h 2008-05-29 19:38:24 UTC (rev 8544)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.h 2008-05-30 11:10:29 UTC (rev 8545)
@@ -109,7 +109,7 @@
void resize(double dx, double dy);
/**Sets new rect and does recalculate*/
- void setRect(const QRectF rectangle);
+ void setRect(const QRectF& rectangle);
/** \brief Scale */
double scale ( void );
@@ -229,6 +229,11 @@
/** \brief calculate mUserScale from mScale */
double userScaleFromScale ( double s );
+
+ /**Sets new Extent and changes only width and height*/
+ void setNewExtent(const QgsRect& extent);
+ /**Sets new scale and changes only mExtent*/
+ void setNewScale(double scaleDenominator);
};
#endif
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp 2008-05-29 19:38:24 UTC (rev 8544)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp 2008-05-30 11:10:29 UTC (rev 8545)
@@ -72,7 +72,8 @@
return;
}
QRectF composerMapRect = mComposerMap->rect();
- mComposerMap->resize(composerMapRect.width(), newHeight);
+ QRectF newRect(composerMapRect.x(), composerMapRect.y(), composerMapRect.width(), newHeight);
+ mComposerMap->setRect(newRect);
}
}
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp 2008-05-29 19:38:24 UTC (rev 8544)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp 2008-05-30 11:10:29 UTC (rev 8545)
@@ -42,7 +42,6 @@
setResizeAnchor ( QGraphicsView::AnchorViewCenter );
setMouseTracking(true);
setInteractive(true);
-
}
void QgsComposerView::mousePressEvent(QMouseEvent* e)
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp 2008-05-29 19:38:24 UTC (rev 8544)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp 2008-05-30 11:10:29 UTC (rev 8545)
@@ -249,7 +249,10 @@
selectedItem->setSelected(true);
if(selectedItem != mSelectedItem)
{
- mSelectedItem->setSelected(false);
+ if(mSelectedItem)
+ {
+ mSelectedItem->setSelected(false);
+ }
mSelectedItem = selectedItem;
mCanvas->update();
mComposer->showItemOptions(selectedItem);
@@ -440,10 +443,10 @@
switch ( mTool ) {
case AddMap: // mToolStep should be always 1 but rectangle can be 0 size
{
- int x = (int) mRectangleItem->rect().x();//use doubles?
- int y = (int) mRectangleItem->rect().y();
- int w = (int)mRectangleItem->rect().width();
- int h = (int)mRectangleItem->rect().height();
+ double x = mRectangleItem->rect().x();//use doubles?
+ double y = mRectangleItem->rect().y();
+ double w = mRectangleItem->rect().width();
+ double h = mRectangleItem->rect().height();
delete mRectangleItem;
mRectangleItem = 0;
@@ -459,7 +462,7 @@
m->setPos(x, y);
- m->setUserExtent( mMapCanvas->extent());
+ //m->setUserExtent( mMapCanvas->extent());
mItems.push_back(m);
m->setSelected ( true );
mCanvas->update();
More information about the QGIS-commit
mailing list