[QGIS Commit] r9961 - in branches/advanced_printing_branch2/src: app/composer core/composer ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Jan 10 11:23:44 EST 2009


Author: mhugent
Date: 2009-01-10 11:23:44 -0500 (Sat, 10 Jan 2009)
New Revision: 9961

Modified:
   branches/advanced_printing_branch2/src/app/composer/qgscompositionwidget.cpp
   branches/advanced_printing_branch2/src/app/composer/qgscompositionwidget.h
   branches/advanced_printing_branch2/src/core/composer/qgscomposition.cpp
   branches/advanced_printing_branch2/src/core/composer/qgscomposition.h
   branches/advanced_printing_branch2/src/core/composer/qgspaperitem.cpp
   branches/advanced_printing_branch2/src/ui/qgscompositionwidgetbase.ui
Log:
Support for different snapping grid styles. Not yet complete

Modified: branches/advanced_printing_branch2/src/app/composer/qgscompositionwidget.cpp
===================================================================
--- branches/advanced_printing_branch2/src/app/composer/qgscompositionwidget.cpp	2009-01-10 07:35:20 UTC (rev 9960)
+++ branches/advanced_printing_branch2/src/app/composer/qgscompositionwidget.cpp	2009-01-10 16:23:44 UTC (rev 9961)
@@ -16,6 +16,7 @@
 
 #include "qgscompositionwidget.h"
 #include "qgscomposition.h"
+#include <QColorDialog>
 #include <QWidget>
 #include <QPrinter> //for screen resolution
 
@@ -42,7 +43,24 @@
   if ( mComposition )
   {
     mResolutionLineEdit->setText( QString::number( mComposition->printResolution() ) );
+
+    //grid pen width
+    mPenWidthSpinBox->blockSignals(true);
+    mPenWidthSpinBox->setValue(mComposition->gridPen().widthF());
+    mPenWidthSpinBox->blockSignals(false);
+
+    //grid pen color
+    mGridColorButton->blockSignals(true);
+    mGridColorButton->setColor(mComposition->gridPen().color());
+    mGridColorButton->blockSignals(false);
   }
+
+  mGridStyleComboBox->blockSignals(true);
+  mGridStyleComboBox->insertItem( 0, tr("Solid"));
+  mGridStyleComboBox->insertItem( 1, tr("Dots"));
+  mGridStyleComboBox->insertItem( 2, tr("Crosses"));
+  mGridStyleComboBox->blockSignals(false);
+  mGridStyleComboBox->setCurrentIndex( 0 );
 }
 
 QgsCompositionWidget::QgsCompositionWidget(): QWidget( 0 ), mComposition( 0 )
@@ -360,3 +378,49 @@
       mComposition->setSnapGridOffsetY(d);
     }
 }
+
+void QgsCompositionWidget::on_mGridColorButton_clicked()
+{
+  QColor newColor = QColorDialog::getColor(mGridColorButton->color());
+  if( !newColor.isValid() )
+  {
+    return ; //dialog canceled by user
+  }
+  mGridColorButton->setColor(newColor);
+
+  if(mComposition)
+  {
+    QPen pen = mComposition->gridPen();
+    pen.setColor(newColor);
+    mComposition->setGridPen(pen);
+  }
+}
+
+void QgsCompositionWidget::on_mGridStyleComboBox_currentIndexChanged( const QString& text )
+{
+  if(mComposition)
+  {
+    if( mGridStyleComboBox->currentText() == tr("Solid") )
+    {
+      mComposition->setGridStyle(QgsComposition::Solid);
+    }
+    else if( mGridStyleComboBox->currentText() == tr("Dots") )
+    {
+      mComposition->setGridStyle(QgsComposition::Dots);
+    }
+    else if( mGridStyleComboBox->currentText() == tr("Crosses"))
+    {
+      mComposition->setGridStyle(QgsComposition::Crosses);
+    }
+  }
+}
+
+void QgsCompositionWidget::on_mPenWidthSpinBox_valueChanged(double d)
+{
+  if(mComposition)
+  {
+    QPen pen = mComposition->gridPen();
+    pen.setWidthF(d);
+    mComposition->setGridPen(pen);
+  }
+}

Modified: branches/advanced_printing_branch2/src/app/composer/qgscompositionwidget.h
===================================================================
--- branches/advanced_printing_branch2/src/app/composer/qgscompositionwidget.h	2009-01-10 07:35:20 UTC (rev 9960)
+++ branches/advanced_printing_branch2/src/app/composer/qgscompositionwidget.h	2009-01-10 16:23:44 UTC (rev 9961)
@@ -50,6 +50,9 @@
     void on_mResolutionSpinBox_valueChanged(double d);
     void on_mOffsetXSpinBox_valueChanged(double d);
     void on_mOffsetYSpinBox_valueChanged(double d);
+    void on_mGridColorButton_clicked();
+    void on_mGridStyleComboBox_currentIndexChanged( const QString& text );
+    void on_mPenWidthSpinBox_valueChanged(double d);
 
   private:
     QgsComposition* mComposition;

Modified: branches/advanced_printing_branch2/src/core/composer/qgscomposition.cpp
===================================================================
--- branches/advanced_printing_branch2/src/core/composer/qgscomposition.cpp	2009-01-10 07:35:20 UTC (rev 9960)
+++ branches/advanced_printing_branch2/src/core/composer/qgscomposition.cpp	2009-01-10 16:23:44 UTC (rev 9961)
@@ -32,6 +32,10 @@
   addItem( mPaperItem );
   mPaperItem->setZValue( 0 );
   mPrintResolution = 300; //hardcoded default
+
+  //snap grid settings
+  mGridPen = QPen(QColor(127, 127, 127));
+  mGridPen.setWidthF(0.3);
 }
 
 QgsComposition::QgsComposition(): QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mSnapToGrid(false), mSnapGridResolution(0.0), mSnapGridOffsetX(0.0), mSnapGridOffsetY(0.0)
@@ -642,3 +646,21 @@
       mPaperItem->update();
     } 
 }
+
+void QgsComposition::setGridPen(const QPen& p)
+{
+  mGridPen = p;
+  if(mPaperItem)
+    {
+      mPaperItem->update();
+    }
+}
+
+void QgsComposition::setGridStyle(GridStyle s)
+{
+  mGridStyle = s;
+  if(mPaperItem)
+    {
+      mPaperItem->update();
+    }
+}

Modified: branches/advanced_printing_branch2/src/core/composer/qgscomposition.h
===================================================================
--- branches/advanced_printing_branch2/src/core/composer/qgscomposition.h	2009-01-10 07:35:20 UTC (rev 9960)
+++ branches/advanced_printing_branch2/src/core/composer/qgscomposition.h	2009-01-10 16:23:44 UTC (rev 9961)
@@ -46,6 +46,14 @@
       Postscript   // Fonts need different scaling!
     };
 
+    /**Style to draw the snapping grid*/
+    enum GridStyle
+    {
+      Solid,
+      Dots,
+      Crosses
+    };
+
     QgsComposition( QgsMapRenderer* mapRenderer );
     ~QgsComposition();
 
@@ -70,6 +78,12 @@
     void setSnapGridOffsetY(double offset);
     double snapGridOffsetY() const {return mSnapGridOffsetY;}
 
+    void setGridPen(const QPen& p);
+    const QPen& gridPen() const {return mGridPen;}
+
+    void setGridStyle(GridStyle s);
+    GridStyle gridStyle() const {return mGridStyle;}
+
     /**Returns the topmose composer item. Ignores mPaperItem*/
     QgsComposerItem* composerItemAt( const QPointF & position );
 
@@ -153,6 +167,8 @@
     double mSnapGridResolution;
     double mSnapGridOffsetX;
     double mSnapGridOffsetY;
+    QPen mGridPen;
+    GridStyle mGridStyle;
 
     QgsComposition(); //default constructor is forbidden
 

Modified: branches/advanced_printing_branch2/src/core/composer/qgspaperitem.cpp
===================================================================
--- branches/advanced_printing_branch2/src/core/composer/qgspaperitem.cpp	2009-01-10 07:35:20 UTC (rev 9960)
+++ branches/advanced_printing_branch2/src/core/composer/qgspaperitem.cpp	2009-01-10 16:23:44 UTC (rev 9961)
@@ -55,27 +55,58 @@
     {
       if(mComposition->snapToGridEnabled() && mComposition->plotStyle() ==  QgsComposition::Preview 
 	 && mComposition->snapGridResolution() > 0)
-	{
-	  QPen pen(QColor(100, 100, 100));
-	  pen.setWidthF(0.3);
-	  painter->setPen(pen);
+      {
+        int gridMultiplyX = (int)(mComposition->snapGridOffsetX() / mComposition->snapGridResolution());
+        int gridMultiplyY = (int)(mComposition->snapGridOffsetY() / mComposition->snapGridResolution());
+        double currentXCoord = mComposition->snapGridOffsetX() - gridMultiplyX * mComposition->snapGridResolution();
+        double currentYCoord;
+        double minYCoord = mComposition->snapGridOffsetY() - gridMultiplyY * mComposition->snapGridResolution();
 
-	  //draw vertical lines  
-	  int gridMultiplyX = (int)(mComposition->snapGridOffsetX() / mComposition->snapGridResolution());  
-	  double currentXCoord = mComposition->snapGridOffsetX() - gridMultiplyX * mComposition->snapGridResolution();
-	  for(; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution())
-	    {
-	      painter->drawLine(QPointF(currentXCoord, 0), QPointF(currentXCoord, rect().height()));
-	    }
-	  
-	  //draw horizontal lines
-	  int gridMultiplyY = (int)(mComposition->snapGridOffsetY() / mComposition->snapGridResolution());
-	  double currentYCoord = mComposition->snapGridOffsetY() - gridMultiplyY * mComposition->snapGridResolution();
-	  for(; currentYCoord <= rect().height(); currentYCoord += mComposition->snapGridResolution())
-	    {
-	      painter->drawLine(QPointF(0, currentYCoord), QPointF(rect().width(), currentYCoord));
-	    }
-	}
+        if(mComposition->gridStyle() == QgsComposition::Solid)
+        {
+          painter->setPen(mComposition->gridPen());
+
+          //draw vertical lines
+
+
+          for(; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution())
+          {
+            painter->drawLine(QPointF(currentXCoord, 0), QPointF(currentXCoord, rect().height()));
+          }
+
+          //draw horizontal lines
+
+          for(; currentYCoord <= rect().height(); currentYCoord += mComposition->snapGridResolution())
+          {
+            painter->drawLine(QPointF(0, currentYCoord), QPointF(rect().width(), currentYCoord));
+          }
+        }
+        else //'Dots' or 'Crosses'
+        {
+          QPen gridPen = mComposition->gridPen();
+          painter->setPen(gridPen);
+          painter->setBrush(QBrush(gridPen.color()));
+          double halfCrossLength = mComposition->snapGridResolution() / 6;
+
+          for(; currentXCoord <= rect().width(); currentXCoord += mComposition->snapGridResolution())
+          {
+            currentYCoord = minYCoord;
+            for(; currentYCoord <= rect().height(); currentYCoord += mComposition->snapGridResolution())
+            {
+              if(mComposition->gridStyle() == QgsComposition::Dots)
+              {
+                QRectF pieRect(currentXCoord - gridPen.widthF() / 2, currentYCoord - gridPen.widthF() / 2, gridPen.widthF(), gridPen.widthF());
+                painter->drawChord(pieRect, 0, 5760);
+              }
+              else if(mComposition->gridStyle() == QgsComposition::Crosses)
+              {
+                painter->drawLine(QPointF(currentXCoord - halfCrossLength, currentYCoord), QPointF(currentXCoord + halfCrossLength, currentYCoord));
+                painter->drawLine(QPointF(currentXCoord, currentYCoord - halfCrossLength), QPointF(currentXCoord, currentYCoord + halfCrossLength));
+              }
+            }
+          }
+        }
+      }
     }
 }
 

Modified: branches/advanced_printing_branch2/src/ui/qgscompositionwidgetbase.ui
===================================================================
--- branches/advanced_printing_branch2/src/ui/qgscompositionwidgetbase.ui	2009-01-10 07:35:20 UTC (rev 9960)
+++ branches/advanced_printing_branch2/src/ui/qgscompositionwidgetbase.ui	2009-01-10 16:23:44 UTC (rev 9961)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>262</width>
-    <height>457</height>
+    <width>301</width>
+    <height>735</height>
    </rect>
   </property>
   <property name="sizePolicy" >
@@ -177,43 +177,83 @@
       <string>Snapping</string>
      </property>
      <layout class="QGridLayout" >
-      <item row="0" column="0" >
+      <item row="0" column="0" colspan="2" >
        <widget class="QCheckBox" name="mSnapToGridCheckBox" >
         <property name="text" >
          <string>Snap to grid</string>
         </property>
        </widget>
       </item>
-      <item row="1" column="0" >
+      <item row="1" column="0" colspan="2" >
        <widget class="QLabel" name="mResolutionLabel_2" >
         <property name="text" >
          <string>Grid resolution:</string>
         </property>
        </widget>
       </item>
-      <item row="1" column="1" >
+      <item row="1" column="2" >
        <widget class="QDoubleSpinBox" name="mResolutionSpinBox" />
       </item>
-      <item row="2" column="0" >
+      <item row="2" column="0" colspan="2" >
        <widget class="QLabel" name="mXOffsetLabel" >
         <property name="text" >
          <string>Offset x:</string>
         </property>
        </widget>
       </item>
-      <item row="2" column="1" >
+      <item row="2" column="2" >
        <widget class="QDoubleSpinBox" name="mOffsetXSpinBox" />
       </item>
-      <item row="3" column="0" >
+      <item row="3" column="0" colspan="2" >
        <widget class="QLabel" name="mYOffsetLabel" >
         <property name="text" >
          <string>Offset y:</string>
         </property>
        </widget>
       </item>
-      <item row="3" column="1" >
+      <item row="3" column="2" >
        <widget class="QDoubleSpinBox" name="mOffsetYSpinBox" />
       </item>
+      <item row="4" column="0" >
+       <widget class="QLabel" name="mPenWidthLabel" >
+        <property name="text" >
+         <string>Pen width:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="4" column="2" >
+       <widget class="QDoubleSpinBox" name="mPenWidthSpinBox" />
+      </item>
+      <item row="5" column="0" >
+       <widget class="QLabel" name="mGridColorLabel" >
+        <property name="text" >
+         <string>Grid color:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="5" column="2" >
+       <widget class="QgsColorButton" name="mGridColorButton" >
+        <property name="sizePolicy" >
+         <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="text" >
+         <string/>
+        </property>
+       </widget>
+      </item>
+      <item row="6" column="0" >
+       <widget class="QLabel" name="mGridStyleLabel" >
+        <property name="text" >
+         <string>Grid style:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="6" column="1" colspan="2" >
+       <widget class="QComboBox" name="mGridStyleComboBox" />
+      </item>
      </layout>
     </widget>
    </item>
@@ -239,6 +279,13 @@
   </layout>
  </widget>
  <layoutdefault spacing="6" margin="11" />
+ <customwidgets>
+  <customwidget>
+   <class>QgsColorButton</class>
+   <extends>QToolButton</extends>
+   <header>qgscolorbutton.h</header>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>



More information about the QGIS-commit mailing list