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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Jun 3 10:33:53 EDT 2008


Author: mhugent
Date: 2008-06-03 10:33:52 -0400 (Tue, 03 Jun 2008)
New Revision: 8581

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/qgscomposeritemgroup.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposeritemgroup.h
Log:
Better resize for item groups

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp	2008-06-03 14:15:34 UTC (rev 8580)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp	2008-06-03 14:33:52 UTC (rev 8581)
@@ -307,6 +307,13 @@
     }
 }
 
+void QgsComposerItem::resize(double dx, double dy)
+{
+  //default implementation just calls setSceneRect
+  QRectF newSceneRect(transform().dx(), transform().dy(), rect().width() + dx, rect().height() + dy);
+  setSceneRect(newSceneRect);
+}
+
 void QgsComposerItem::move(double dx, double dy)
 {
   QTransform newTransform;

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h	2008-06-03 14:15:34 UTC (rev 8580)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h	2008-06-03 14:33:52 UTC (rev 8581)
@@ -74,7 +74,7 @@
     virtual bool removeSettings( void );
 
     /** resizes an item in x- and y direction (scene coordinates)*/
-    virtual void resize(double dx, double dy){}
+    virtual void resize(double dx, double dy);
 
     /** moves the whole item in scene coordinates*/
     virtual void move(double dx, double dy);

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposeritemgroup.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposeritemgroup.cpp	2008-06-03 14:15:34 UTC (rev 8580)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposeritemgroup.cpp	2008-06-03 14:33:52 UTC (rev 8581)
@@ -63,6 +63,7 @@
     }
   mItems.insert(item);
   item->setSelected(false);
+  item->setFlag(QGraphicsItem::ItemIsSelectable, false); //item in groups cannot be selected
 
   //update extent (which is in scene coordinates)
   double minXItem = item->transform().dx();
@@ -98,12 +99,17 @@
 	}
     }
 
-  setSceneRect(mSceneBoundingRectangle);
+  QgsComposerItem::setSceneRect(mSceneBoundingRectangle); //call method of superclass to avoid repositioning of items
 
 }
 
 void QgsComposerItemGroup::removeItems()
 {
+  QSet<QgsComposerItem*>::iterator item_it = mItems.begin();
+  for(; item_it != mItems.end(); ++item_it)
+    {
+      (*item_it)->setFlag(QGraphicsItem::ItemIsSelectable, true); //enable item selection again
+    }
   mItems.clear();
 }
 
@@ -126,6 +132,34 @@
   QgsComposerItem::move(dx, dy);
 }
 
+void QgsComposerItemGroup::setSceneRect(const QRectF& rectangle)
+{
+  //call resize and transform for every item
+
+  double transformX = rectangle.x() - transform().dx();
+  double transformY = rectangle.y() - transform().dy();
+
+  double dx = rectangle.width() - rect().width();
+  double dy = rectangle.height() - rect().height();
+  double widthRatio, heightRatio;
+
+  QSet<QgsComposerItem*>::iterator item_it = mItems.begin();
+  for(; item_it != mItems.end(); ++item_it)
+    {
+      (*item_it)->move(transformX, transformY);
+      widthRatio = (*item_it)->rect().width() / rect().width();
+      heightRatio = (*item_it)->rect().height() / rect().height();
+      (*item_it)->resize(dx * widthRatio, dy * heightRatio);
+    }
+
+  QgsComposerItem::setSceneRect(rectangle);
+}
+
+void QgsComposerItemGroup::resize(double dx, double dy)
+{
+  //soon...
+}
+
 void QgsComposerItemGroup::drawFrame(QPainter* p)
 {
   if(mFrame)

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposeritemgroup.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposeritemgroup.h	2008-06-03 14:15:34 UTC (rev 8580)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposeritemgroup.h	2008-06-03 14:33:52 UTC (rev 8581)
@@ -33,6 +33,11 @@
   void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
   /**Moves all contained items by dx/dy*/
   void move(double dx, double dy);
+  /**Sets this items bound in scene coordinates such that 1 item size units
+     corresponds to 1 scene size unit*/
+  void setSceneRect(const QRectF& rectangle);
+  /** resizes an item in x- and y direction (scene coordinates)*/
+  void resize(double dx, double dy);
 
  protected:
   void drawFrame(QPainter* p);



More information about the QGIS-commit mailing list