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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Jul 22 10:50:59 EDT 2008


Author: mhugent
Date: 2008-07-22 10:50:59 -0400 (Tue, 22 Jul 2008)
New Revision: 8824

Modified:
   branches/advanced_printing_branch/src/app/composer/qgscomposer.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposer.h
   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/qgscomposerview.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposerview.h
   branches/advanced_printing_branch/src/app/composer/qgsscalebarstyle.cpp
Log:
Added map tool to move composer map content and fixed a scalebar labeling bug

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposer.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposer.cpp	2008-07-22 12:36:18 UTC (rev 8823)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposer.cpp	2008-07-22 14:50:59 UTC (rev 8824)
@@ -66,6 +66,8 @@
   QString myIconPath = QgsApplication::themePath();
   qWarning(QString(myIconPath +"mActionGroupItems.png").latin1() );
 
+  toolBar->addAction(tr("Move Item content"), this, SLOT(moveItemContent()));
+
   toolBar->addAction(QIcon(QPixmap(myIconPath+"mActionGroupItems.png")), tr("&Group Items"), this, SLOT(groupItems()));
   toolBar->addAction(QIcon(QPixmap(myIconPath+"mActionUngroupItems.png")), tr("&Ungroup Items"), this, SLOT(ungroupItems()));
 
@@ -962,6 +964,14 @@
   mView->setCursor(QCursor(cross_hair_cursor));
 #endif //0
 }
+
+void QgsComposer::moveItemContent()
+{
+  if(mView)
+    {
+      mView->setCurrentTool(QgsComposerView::MoveItemContent);
+    }
+}
  
 void QgsComposer::groupItems(void)
 {

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposer.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposer.h	2008-07-22 12:36:18 UTC (rev 8823)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposer.h	2008-07-22 14:50:59 UTC (rev 8824)
@@ -141,6 +141,9 @@
     //! Add new picture
     void on_mActionAddImage_activated(void);
 
+    //! Set tool to move item content
+    void moveItemContent();
+
     //! Group selected items 
     void groupItems(void);
 

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp	2008-07-22 12:36:18 UTC (rev 8823)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp	2008-07-22 14:50:59 UTC (rev 8824)
@@ -175,6 +175,10 @@
 
 QgsComposerItem::mouseMoveAction QgsComposerItem::mouseMoveActionForPosition(const QPointF& itemCoordPos)
 {
+
+  //move content tool
+  
+
   bool nearLeftBorder = false;
   bool nearRightBorder = false;
   bool nearLowerBorder = false;

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h	2008-07-22 12:36:18 UTC (rev 8823)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h	2008-07-22 14:50:59 UTC (rev 8824)
@@ -67,6 +67,9 @@
     /**Moves item in canvas coordinates*/
     void move(double dx, double dy);
 
+    /**Move Content of item. Does nothing per default (but implemented in composer map)*/
+    virtual void moveContent(double dx, double dy){}
+
     /**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);

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp	2008-07-22 12:36:18 UTC (rev 8823)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp	2008-07-22 14:50:59 UTC (rev 8824)
@@ -140,6 +140,7 @@
   p.end();
   
   mNumCachedLayers = mMapCanvas->layerCount();
+  mCachedMapExtent = mExtent;
   mCacheUpdated = true;
 }
 
@@ -173,7 +174,7 @@
     
   if ( mComposition->plotStyle() == QgsComposition::Preview && mPreviewMode != Rectangle) 
     { // Draw from cache
-      if ( !mCacheUpdated || mMapCanvas->layerCount() != mNumCachedLayers ) 
+      if ( !mCacheUpdated || mMapCanvas->layerCount() != mNumCachedLayers || mCachedMapExtent != mExtent) 
 	{
 	  cache();
 	}
@@ -243,6 +244,22 @@
   setSceneRect(newSceneRect);
 }
 
+void QgsComposerMap::moveContent(double dx, double dy)
+{
+  QRectF itemRect = rect();
+  double xRatio = dx / itemRect.width();
+  double yRatio = dy / itemRect.height();
+
+  double xMoveMapCoord = mExtent.width() * xRatio;
+  double yMoveMapCoord = -(mExtent.height() * yRatio);
+
+  mExtent.setXmin(mExtent.xMin() + xMoveMapCoord);
+  mExtent.setXmax(mExtent.xMax() + xMoveMapCoord);
+  mExtent.setYmin(mExtent.yMin() + yMoveMapCoord);
+  mExtent.setYmax(mExtent.yMax() + yMoveMapCoord);
+  emit extentChanged();
+}
+
 void QgsComposerMap::setSceneRect(const QRectF& rectangle)
 {
   double w = rectangle.width();

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.h	2008-07-22 12:36:18 UTC (rev 8823)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.h	2008-07-22 14:50:59 UTC (rev 8824)
@@ -77,6 +77,11 @@
     /** resizes an item in x- and y direction (canvas coordinates)*/
     void resize(double dx, double dy);
 
+    /**Move content of map
+       @param dx move in x-direction (item and canvas coordinates)
+       @param dy move in y-direction (item and canvas coordinates)*/
+    void moveContent(double dx, double dy);
+
     /**Sets new scene rectangle bounds and recalculates hight and extent*/
     void setSceneRect(const QRectF& rectangle);
 
@@ -142,9 +147,14 @@
     /**Store last scale factor to avoid unnecessary repaints in case preview mode is 'Render'*/
     double mLastScaleFactorX;
 
+    /**Store the last map extent to decide if cache needs to be updatet*/
+    QgsRect mCachedMapExtent;
+
     /**For the generation of new unique ids*/
     static int mCurrentComposerId;
 
+    
+
     /**Returns the zoom factor of the graphics view. If no 
      graphics view exists, the default 1 is returned*/
     double horizontalViewScaleFactor() const;

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp	2008-07-22 12:36:18 UTC (rev 8823)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp	2008-07-22 14:50:59 UTC (rev 8824)
@@ -1,6 +1,6 @@
 /***************************************************************************
                          qgscomposerview.cpp
-                             -------------------
+                         -------------------
     begin                : January 2005
     copyright            : (C) 2005 by Radim Blazek
     email                : blazek at itc.it
@@ -26,7 +26,7 @@
 #include "qgscomposerscalebar.h"
 
 QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags f) :
-  QGraphicsView(parent), mShiftKeyPressed(false), mRubberBandItem(0)
+  QGraphicsView(parent), mShiftKeyPressed(false), mRubberBandItem(0), mMoveContentItem(0)
 {
     setResizeAnchor ( QGraphicsView::AnchorViewCenter );
     setMouseTracking(true);  
@@ -59,10 +59,23 @@
 	  selectedItem->setSelected(true);
 	}
 
+      
+      QGraphicsView::mousePressEvent(e);
       emit selectedItemChanged(selectedItem);
-      QGraphicsView::mousePressEvent(e);
+      break;
     }
-    break;
+
+  case MoveItemContent:
+    {
+      //store item as member if it is selected and cursor is over item
+      QgsComposerItem* item = dynamic_cast<QgsComposerItem*>(itemAt(e->pos()));
+      if(item)
+	{
+	  mMoveContentStartPos = scenePoint;
+	}
+      mMoveContentItem = item;
+      break;
+    }
     
   //create rubber band
   case AddMap:
@@ -140,12 +153,29 @@
       return;
     }
 
+  QPointF scenePoint = mapToScene(e->pos());
+
   switch(mCurrentTool)
     {
     case Select:
-     QGraphicsView::mouseReleaseEvent(e);
-     break;
+      {
+	QGraphicsView::mouseReleaseEvent(e);
+	break;
+      }
 
+     case MoveItemContent:
+       {
+	 if(mMoveContentItem)
+	   {
+	     double moveX = scenePoint.x() - mMoveContentStartPos.x();
+	     double moveY = scenePoint.y() - mMoveContentStartPos.y();
+	     mMoveContentItem->moveContent(-moveX, -moveY);
+	     mMoveContentItem->update();
+	     mMoveContentItem = 0;
+	   }
+	 break;
+       }
+
     case AddMap:
       {
 	if(!mRubberBandItem || mRubberBandItem->rect().width() < 0.1 || mRubberBandItem->rect().width() < 0.1)

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerview.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerview.h	2008-07-22 12:36:18 UTC (rev 8823)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerview.h	2008-07-22 14:50:59 UTC (rev 8824)
@@ -44,7 +44,8 @@
     AddLegend, // add vector legend
     AddLabel,        // add label
     AddScalebar,     // add scalebar
-    AddPicture       // add raster/vector picture
+    AddPicture,       // add raster/vector picture
+    MoveItemContent //move content of item (e.g. content of map)
   };
   
   QgsComposerView(QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
@@ -78,6 +79,10 @@
   QgsComposerView::Tool mCurrentTool;
   /**Rubber band item*/
   QGraphicsRectItem* mRubberBandItem;
+  /**Item to move content*/
+  QgsComposerItem* mMoveContentItem;
+  /**Start position of content move*/
+  QPointF mMoveContentStartPos;
 
   public slots:
   /**For QgsComposerItemGroup to send its signals to QgsComposer (or other classes that keep track of input widgets)*/

Modified: branches/advanced_printing_branch/src/app/composer/qgsscalebarstyle.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgsscalebarstyle.cpp	2008-07-22 12:36:18 UTC (rev 8823)
+++ branches/advanced_printing_branch/src/app/composer/qgsscalebarstyle.cpp	2008-07-22 14:50:59 UTC (rev 8824)
@@ -67,16 +67,26 @@
 	  //label first left segment
 	  currentNumericLabel = firstLabel;
 	} 
-      else if(segmentCounter >= nSegmentsLeft)
+      else if(segmentCounter != 0 && segmentCounter == nSegmentsLeft) //reset label number to 0 if there are left segments
 	{
+	  currentLabelNumber = 0;
+	}
+      
+      if(segmentCounter >= nSegmentsLeft)
+	{
 	  currentNumericLabel = QString::number(currentLabelNumber / mScaleBar->numMapUnitsPerScaleBarUnit());
 	}
-      p->drawText(QPointF(segmentIt->first - fontMetrics.width(currentNumericLabel) / 2 + xOffset, mScaleBar->fontHeight() + mScaleBar->boxContentSpace()), currentNumericLabel);
+
+      if(segmentCounter == 0 || segmentCounter >= nSegmentsLeft) //don't draw label for intermediate left segments
+	{
+	  p->drawText(QPointF(segmentIt->first - fontMetrics.width(currentNumericLabel) / 2 + xOffset, mScaleBar->fontHeight() + mScaleBar->boxContentSpace()), currentNumericLabel);
+	}
       
       if(segmentCounter >= nSegmentsLeft)
 	{
-	  ++segmentCounter;
+	  currentLabelNumber += mScaleBar->numUnitsPerSegment();
 	}
+      ++segmentCounter;
     }
 
   //also draw the last label



More information about the QGIS-commit mailing list