[QGIS Commit] r8569 - branches/advanced_printing_branch/src/app/composer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Jun 1 04:09:38 EDT 2008


Author: mhugent
Date: 2008-06-01 04:09:37 -0400 (Sun, 01 Jun 2008)
New Revision: 8569

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/qgscomposerlabel.cpp
   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/qgscomposerpicture.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposervectorlegend.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp
Log:
Fix for resize problems with composer map

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp	2008-06-01 07:45:03 UTC (rev 8568)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp	2008-06-01 08:09:37 UTC (rev 8569)
@@ -33,11 +33,15 @@
     setFlag(QGraphicsItem::ItemIsSelectable, true);
 }
 
-QgsComposerItem::QgsComposerItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem* parent): QGraphicsRectItem(x, y, width, height, parent), mBoundingResizeRectangle(0)
+QgsComposerItem::QgsComposerItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem* parent): QGraphicsRectItem(0, 0, width, height, parent), mBoundingResizeRectangle(0)
 {
   mPlotStyle = QgsComposition::Preview;
   setAcceptsHoverEvents(true);
   setFlag(QGraphicsItem::ItemIsSelectable, true);
+
+  QTransform t;
+  t.translate(x, y);
+  setTransform(t);
 }
 
 QgsComposerItem::~QgsComposerItem()
@@ -58,10 +62,6 @@
 
 int QgsComposerItem::id(void) { return mId; }
 
-void QgsComposerItem::showOptions ( QWidget * parent ) { }
-
-QWidget *QgsComposerItem::options ( void ) { return 0; }
-
 bool QgsComposerItem::writeSettings ( void )  { return true; }
 
 bool QgsComposerItem::readSettings ( void )  { return true; }
@@ -83,11 +83,13 @@
 
       rectangleChange(diffX, diffY, mx, my, rx, ry);
       
+      //QRectF r = mBoundingResizeRectangle->rect();
+      //r.translate(mx, my);
       QRectF r = mBoundingResizeRectangle->rect();
-      r.translate(mx, my);
       r.setWidth(r.width() + rx);
       r.setHeight(r.height() + ry);
       mBoundingResizeRectangle->setRect(r);
+      mBoundingResizeRectangle->moveBy(mx, my);
     }
   mLastMouseEventPos = event->lastPos();
 }
@@ -101,9 +103,12 @@
   setCursor(QCursor(cursorForPosition(event->pos())));
 
   //create and show bounding rectangle
-  mBoundingResizeRectangle = new QGraphicsRectItem(rect(), 0); //problem. Maybe set rect after adding to scene?
+  mBoundingResizeRectangle = new QGraphicsRectItem(0);
   scene()->addItem(mBoundingResizeRectangle);
-  mBoundingResizeRectangle->setRect(rect());
+  mBoundingResizeRectangle->setRect(QRectF(0, 0, rect().width(), rect().height()));
+  QTransform resizeTransform;
+  resizeTransform.translate(transform().dx(), transform().dy());
+  mBoundingResizeRectangle->setTransform(resizeTransform);
 
   mBoundingResizeRectangle->setBrush( Qt::NoBrush );
   mBoundingResizeRectangle->setPen( QPen(QColor(0,0,0), 0) );
@@ -135,8 +140,8 @@
   rectangleChange(diffX, diffY, mx, my, rx, ry);
 
   QRectF currentRect = rect();
-  QRectF newRect(currentRect.x() + mx, currentRect.y() + my, currentRect.width() + rx, currentRect.height() + ry);
-  setRect(newRect);
+  QRectF newRect(transform().dx() + mx, transform().dy() + my, currentRect.width() + rx, currentRect.height() + ry);
+  setSceneRect(newRect);
 
   update();
   scene()->update();
@@ -292,6 +297,7 @@
 void QgsComposerItem::drawSelectionBoxes(QPainter* p)
 {
   p->setPen(QPen(QColor(0, 0, 255)));
+  p->setBrush(QBrush(QColor(0, 0, 255)));
 
   double s = 5;
   
@@ -308,24 +314,17 @@
   p->drawRect (QRectF( 0, 0, rect().width(), rect().height()));
 }
 
-void QgsComposerItem::setRect(const QRectF& rectangle)
+void QgsComposerItem::setSceneRect(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();
-}
+  //setRect in item coordinates
+  QRectF newRect(0, 0, rectangle.width(), rectangle.height());
+  QGraphicsRectItem::setRect(newRect);
 
-#if 0
-QRectF QgsComposerItem::boundingRect () const
-{
-  return rect();
+  //set up transformation matrix for item coordinates
+  QTransform t;
+  t.translate(rectangle.x(), rectangle.y());
+  setTransform(t);
 }
-#endif //0
 
 void QgsComposerItem::drawBackground(QPainter* p)
 {

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h	2008-06-01 07:45:03 UTC (rev 8568)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h	2008-06-01 08:09:37 UTC (rev 8569)
@@ -64,14 +64,6 @@
     /** item id */
     int id ( void );
 
-    /** Update otions and return pointer to options widget */
-    virtual QWidget *options ( void );
-
-    /** Create option controls
-     * @param parent widget where options are created
-     */
-    virtual void showOptions ( QWidget * parent );
-
     /** stores state in project */
     virtual bool writeSettings ( void );
 
@@ -84,8 +76,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);
+    /**Sets this items bound in scene coordinates such that 1 item size units
+     corresponds to 1 scene size unit*/
+    virtual void setSceneRect(const QRectF& rectangle);
 
     /** stores state in DOM node
      * @param node is DOM node corresponding to '???' tag
@@ -98,8 +91,6 @@
      */
     virtual bool readXML( QDomNode & node );
 
-    //virtual QRectF boundingRect () const;
-
 protected:
     QgsComposition::PlotStyle mPlotStyle;
     int mId;
@@ -112,8 +103,6 @@
 
     /**Rectangle used during move and resize actions*/
     QGraphicsRectItem* mBoundingResizeRectangle;
-
-    bool mSelected;
  
     //event handlers
     virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerlabel.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerlabel.cpp	2008-06-01 07:45:03 UTC (rev 8568)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerlabel.cpp	2008-06-01 08:09:37 UTC (rev 8569)
@@ -48,7 +48,7 @@
 
     QGraphicsRectItem::setPos(x, y);
 
-    mSelected = false;
+    setSelected(false);
 
     setOptions();
 
@@ -73,7 +73,7 @@
 
     mComposition = composition;
     mId  = id;
-    mSelected = false;
+    setSelected(false);
 
     readSettings();
     
@@ -156,7 +156,7 @@
     painter->restore(); //undo our scaling of painter - End of the font workaround
 
     // Show selected / Highlight
-    if ( mSelected && plotStyle() == QgsComposition::Preview ) {
+    if ( isSelected() && plotStyle() == QgsComposition::Preview ) {
         QRectF hr;
         if ( mBox ) {
             hr = boxRect;
@@ -281,13 +281,13 @@
     std::cout << "QgsComposerLabel::setSelected" << std::endl;
 #endif
 
-    mSelected = s;
+    setSelected(s);
     QGraphicsRectItem::update(); // show highlight
 }    
 
 bool QgsComposerLabel::selected( void )
 {
-    return mSelected;
+  return isSelected();
 }
 
 QWidget *QgsComposerLabel::options ( void )

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp	2008-06-01 07:45:03 UTC (rev 8568)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp	2008-06-01 08:09:37 UTC (rev 8569)
@@ -58,7 +58,7 @@
 
     //calculate mExtent based on width/height ratio and map canvas extent
     mExtent = mMapCanvas->extent();
-    setRect(QRectF(x, y, width, height));
+    setSceneRect(QRectF(x, y, width, height));
 
     QGraphicsRectItem::setZValue(20);
 
@@ -233,11 +233,6 @@
     QGraphicsRectItem::update();
 }
 
-bool QgsComposerMap::selected( void )
-{
-    return mSelected;
-}
-
 void QgsComposerMap::setCacheUpdated ( bool u ) 
 {
     mCacheUpdated = u;
@@ -338,22 +333,17 @@
 {
   //setRect
   QRectF currentRect = rect();
-  QRectF newRect = QRectF(currentRect.x(), currentRect.y(), currentRect.width() + dx, currentRect.height() + dy);
-  setRect(newRect); 
+  QRectF newSceneRect = QRectF(transform().dx(), transform().dy(), currentRect.width() + dx, currentRect.height() + dy);
+  setSceneRect(newSceneRect); 
 }
 
-void QgsComposerMap::setRect(const QRectF& rectangle)
+void QgsComposerMap::setSceneRect(const QRectF& rectangle)
 {
   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);
+  QgsComposerItem::setSceneRect(rectangle);
   
   QGraphicsRectItem::update();
   double newHeight = mExtent.width() * h / w ;

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.h	2008-06-01 07:45:03 UTC (rev 8568)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.h	2008-06-01 08:09:37 UTC (rev 8569)
@@ -63,7 +63,6 @@
     void init ( void );
 
     // Reimplement QgsComposerItem:
-    bool selected( void );
     QWidget *options ( void );
     bool writeSettings ( void );
     bool readSettings ( void );
@@ -107,8 +106,8 @@
     /** resizes an item in x- and y direction (canvas coordinates)*/
     void resize(double dx, double dy);
 
-    /**Sets new rect and does recalculate*/
-    void setRect(const QRectF& rectangle);
+    /**Sets new scene rectangle bounds and recalculates hight and extent*/
+    void setSceneRect(const QRectF& rectangle);
 
     /** \brief Scale */
     double scale ( void );

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp	2008-06-01 07:45:03 UTC (rev 8568)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp	2008-06-01 08:09:37 UTC (rev 8569)
@@ -100,7 +100,7 @@
 
 void QgsComposerPicture::init ( void ) 
 {
-  mSelected = false;
+  setSelected(false);
   for ( int i = 0; i < 4; i++ ) 
   {
     mAreaPoints[i] = QPoint( 0, 0 );
@@ -236,7 +236,7 @@
     }
 
     // Show selected / Highlight
-    if ( mSelected && plotStyle() == QgsComposition::Preview ) {
+    if ( isSelected() && plotStyle() == QgsComposition::Preview ) {
       painter->setPen( mComposition->selectionPen() );
       painter->setBrush( mComposition->selectionBrush() );
   
@@ -457,13 +457,13 @@
 
 void QgsComposerPicture::setSelected (  bool s ) 
 {
-    mSelected = s;
-    QAbstractGraphicsShapeItem::update(); // show highlight
+  QGraphicsRectItem::setSelected(s);
+  QAbstractGraphicsShapeItem::update(); // show highlight
 }    
 
 bool QgsComposerPicture::selected( void )
 {
-    return mSelected;
+  return isSelected();
 }
 
 QWidget *QgsComposerPicture::options ( void )

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp	2008-06-01 07:45:03 UTC (rev 8568)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp	2008-06-01 08:09:37 UTC (rev 8569)
@@ -41,7 +41,7 @@
 #endif
 
   mId = id;
-  mSelected = false;
+  setSelected(false);
 
   mMapCanvas = mComposition->mapCanvas();
 
@@ -130,7 +130,7 @@
   setupUi(this);
 
   mId = id;
-  mSelected = false;
+  setSelected(false);
 
   mMapCanvas = mComposition->mapCanvas();
 
@@ -309,7 +309,7 @@
   setRect(render(painter));
 
   // Show selected / Highlight
-  if (mSelected && plotStyle() == QgsComposition::Preview)
+  if (isSelected() && plotStyle() == QgsComposition::Preview)
     {
       painter->setPen(mComposition->selectionPen());
       painter->setBrush(mComposition->selectionBrush());
@@ -482,13 +482,13 @@
 
 void QgsComposerScalebar::setSelected(bool s)
 {
-  mSelected = s;
+  setSelected(s);
   QGraphicsRectItem::update(); // show highlight
 }
 
 bool QgsComposerScalebar::selected(void)
 {
-  return mSelected;
+  return isSelected();
 }
 
 QWidget *QgsComposerScalebar::options(void)

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposervectorlegend.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposervectorlegend.cpp	2008-06-01 07:45:03 UTC (rev 8568)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposervectorlegend.cpp	2008-06-01 08:09:37 UTC (rev 8569)
@@ -105,7 +105,7 @@
 
 void QgsComposerVectorLegend::init ( void ) 
 {
-    mSelected = false;
+  setSelected(false);
     mNumCachedLayers = 0;
     mTitle = tr("Legend");
     mMap = 0;
@@ -524,7 +524,7 @@
 
 
   // Draw the "selected highlight" boxes
-  if ( mSelected && plotStyle() == QgsComposition::Preview ) {
+  if ( isSelected() && plotStyle() == QgsComposition::Preview ) {
 
     painter->setPen( mComposition->selectionPen() );
     painter->setBrush( mComposition->selectionBrush() );
@@ -702,13 +702,13 @@
 
 void QgsComposerVectorLegend::setSelected (  bool s ) 
 {
-    mSelected = s;
-    QGraphicsRectItem::update(); // show highlight
+  QGraphicsRectItem::setSelected(s);
+  QGraphicsRectItem::update(); // show highlight
 }    
 
 bool QgsComposerVectorLegend::selected( void )
 {
-    return mSelected;
+  return isSelected();
 }
 
 void QgsComposerVectorLegend::contextMenuEvent( QContextMenuEvent *event)

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp	2008-06-01 07:45:03 UTC (rev 8568)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp	2008-06-01 08:09:37 UTC (rev 8569)
@@ -460,8 +460,6 @@
 	    QgsComposerMapWidget* w = new QgsComposerMapWidget(m);
 	    mComposer->addItem(m, w);
 
-	    m->setPos(x, y);
-
 	    //m->setUserExtent( mMapCanvas->extent());
 	    mItems.push_back(m);
 	    m->setSelected ( true );



More information about the QGIS-commit mailing list