[QGIS Commit] r12688 - in trunk/qgis/src: app/composer core/composer ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Jan 7 08:29:24 EST 2010


Author: mhugent
Date: 2010-01-07 08:29:23 -0500 (Thu, 07 Jan 2010)
New Revision: 12688

Modified:
   trunk/qgis/src/app/composer/qgscomposertablewidget.cpp
   trunk/qgis/src/app/composer/qgscomposertablewidget.h
   trunk/qgis/src/core/composer/qgscomposertable.cpp
   trunk/qgis/src/core/composer/qgscomposertable.h
   trunk/qgis/src/ui/qgscomposertablewidgetbase.ui
Log:
More options for composer table

Modified: trunk/qgis/src/app/composer/qgscomposertablewidget.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposertablewidget.cpp	2010-01-07 12:03:33 UTC (rev 12687)
+++ trunk/qgis/src/app/composer/qgscomposertablewidget.cpp	2010-01-07 13:29:23 UTC (rev 12688)
@@ -21,6 +21,7 @@
 #include "qgscomposermap.h"
 #include "qgsmaplayerregistry.h"
 #include "qgsvectorlayer.h"
+#include <QColorDialog>
 #include <QFontDialog>
 
 QgsComposerTableWidget::QgsComposerTableWidget( QgsComposerTable* table ): QWidget( 0 ), mComposerTable( table )
@@ -167,6 +168,50 @@
   }
 }
 
+void QgsComposerTableWidget::on_mGridStrokeWidthSpinBox_valueChanged( double d )
+{
+  if ( !mComposerTable )
+  {
+    return;
+  }
+  mComposerTable->setGridStrokeWidth( d );
+  mComposerTable->update();
+}
+
+void QgsComposerTableWidget::on_mGridColorButton_clicked()
+{
+  if ( !mComposerTable )
+  {
+    return;
+  }
+
+  QColor newColor = QColorDialog::getColor( mComposerTable->gridColor(), 0, tr( "Select grid color" ) );
+  if ( !newColor.isValid() )
+  {
+    return;
+  }
+  mGridColorButton->setColor( newColor );
+  mComposerTable->setGridColor( newColor );
+  mComposerTable->update();
+}
+
+void QgsComposerTableWidget::on_mShowGridCheckBox_stateChanged( int state )
+{
+  if ( !mComposerTable )
+  {
+    return;
+  }
+
+  bool showGrid = false;
+  if ( state == Qt::Checked )
+  {
+    showGrid = true;
+  }
+  mComposerTable->setShowGrid( showGrid );
+  mComposerTable->update();
+}
+
+
 void QgsComposerTableWidget::updateGuiElements()
 {
   if ( !mComposerTable )
@@ -199,6 +244,16 @@
   }
   mMaximumColumnsSpinBox->setValue( mComposerTable->maximumNumberOfFeatures() );
   mMarginSpinBox->setValue( mComposerTable->lineTextDistance() );
+  mGridStrokeWidthSpinBox->setValue( mComposerTable->gridStrokeWidth() );
+  mGridColorButton->setColor( mComposerTable->gridColor() );
+  if ( mComposerTable->showGrid() )
+  {
+    mShowGridCheckBox->setCheckState( Qt::Checked );
+  }
+  else
+  {
+    mShowGridCheckBox->setCheckState( Qt::Unchecked );
+  }
   blockAllSignals( false );
 }
 
@@ -208,6 +263,9 @@
   mComposerMapComboBox->blockSignals( b );
   mMaximumColumnsSpinBox->blockSignals( b );
   mMarginSpinBox->blockSignals( b );
+  mGridColorButton->blockSignals( b );
+  mGridStrokeWidthSpinBox->blockSignals( b );
+  mShowGridCheckBox->blockSignals( b );
 }
 
 

Modified: trunk/qgis/src/app/composer/qgscomposertablewidget.h
===================================================================
--- trunk/qgis/src/app/composer/qgscomposertablewidget.h	2010-01-07 12:03:33 UTC (rev 12687)
+++ trunk/qgis/src/app/composer/qgscomposertablewidget.h	2010-01-07 13:29:23 UTC (rev 12688)
@@ -42,8 +42,11 @@
     void on_mComposerMapComboBox_currentIndexChanged( int index );
     void on_mMaximumColumnsSpinBox_valueChanged( int i );
     void on_mMarginSpinBox_valueChanged( double d );
+    void on_mGridStrokeWidthSpinBox_valueChanged( double d );
+    void on_mGridColorButton_clicked();
     void on_mHeaderFontPushButton_clicked();
     void on_mContentFontPushButton_clicked();
+    void on_mShowGridCheckBox_stateChanged( int state );
 };
 
 #endif // QGSCOMPOSERTABLEWIDGET_H

Modified: trunk/qgis/src/core/composer/qgscomposertable.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposertable.cpp	2010-01-07 12:03:33 UTC (rev 12687)
+++ trunk/qgis/src/core/composer/qgscomposertable.cpp	2010-01-07 13:29:23 UTC (rev 12688)
@@ -22,9 +22,10 @@
 #include "qgsvectorlayer.h"
 #include <QPainter>
 
-QgsComposerTable::QgsComposerTable( QgsComposition* composition ): QgsComposerItem( composition ), mVectorLayer( 0 ), mComposerMap( 0 ), mMaximumNumberOfFeatures( 5 )
+QgsComposerTable::QgsComposerTable( QgsComposition* composition ): QgsComposerItem( composition ), mVectorLayer( 0 ), mComposerMap( 0 ), \
+    mMaximumNumberOfFeatures( 5 ), mLineTextDistance( 1.0 ), mShowGrid( true ), mGridStrokeWidth( 0.5 ), mGridColor( QColor( 0, 0, 0 ) )
 {
-  mLineTextDistance = 1;
+
 }
 
 QgsComposerTable::~QgsComposerTable()
@@ -70,21 +71,24 @@
   //adapt item fram to max width / height
   adaptItemFrame( maxColumnWidthMap, attributeList );
 
+  drawBackground( painter );
+
   //now draw the text
-  double currentX = 0;
+  double currentX = mGridStrokeWidth;
   double currentY;
 
   QgsFieldMap vectorFields = mVectorLayer->pendingFields();
   QgsFieldMap::const_iterator fieldIt = vectorFields.constBegin();
   for ( ; fieldIt != vectorFields.constEnd(); ++fieldIt )
   {
-    currentY = 0;
+    currentY = mGridStrokeWidth;
     currentY += mLineTextDistance;
     currentY += fontAscentMillimeters( mHeaderFont );
     currentX += mLineTextDistance;
     drawText( painter, currentX, currentY, fieldIt.value().name(), mHeaderFont );
 
     currentY += mLineTextDistance;
+    currentY += mGridStrokeWidth;
 
     //draw the attribute values
     QList<QgsAttributeMap>::const_iterator attIt = attributeList.begin();
@@ -99,18 +103,25 @@
       {
         drawText( painter, currentX, currentY, attMapIt.value().toString(), mContentFont );
       }
-
       currentY += mLineTextDistance;
+      currentY += mGridStrokeWidth;
     }
 
+    currentX += maxColumnWidthMap[fieldIt.key()];
     currentX += mLineTextDistance;
-    currentX += maxColumnWidthMap[fieldIt.key()];
+    currentX += mGridStrokeWidth;
   }
 
   //and the borders
-  painter->setPen( mGridPen );
-  drawHorizontalGridLines( painter, attributeList.size() );
-  drawVerticalGridLines( painter, maxColumnWidthMap );
+  if ( mShowGrid )
+  {
+    QPen gridPen;
+    gridPen.setWidthF( mGridStrokeWidth );
+    gridPen.setColor( mGridColor );
+    painter->setPen( gridPen );
+    drawHorizontalGridLines( painter, attributeList.size() );
+    drawVerticalGridLines( painter, maxColumnWidthMap );
+  }
 
   //draw frame and selection boxes if necessary
   drawFrame( painter );
@@ -127,6 +138,12 @@
   composerTableElem.setAttribute( "lineTextDist", mLineTextDistance );
   composerTableElem.setAttribute( "headerFont", mHeaderFont.toString() );
   composerTableElem.setAttribute( "contentFont", mContentFont.toString() );
+  composerTableElem.setAttribute( "gridStrokeWidth", mGridStrokeWidth );
+  composerTableElem.setAttribute( "gridColorRed", mGridColor.red() );
+  composerTableElem.setAttribute( "gridColorGreen", mGridColor.green() );
+  composerTableElem.setAttribute( "gridColorBlue", mGridColor.blue() );
+  composerTableElem.setAttribute( "showGrid", mShowGrid );
+
   if ( mComposerMap )
   {
     composerTableElem.setAttribute( "composerMap", mComposerMap->id() );
@@ -154,7 +171,15 @@
   mHeaderFont.fromString( itemElem.attribute( "headerFont", "" ) );
   mContentFont.fromString( itemElem.attribute( "contentFont", "" ) );
   mLineTextDistance = itemElem.attribute( "lineTextDist", "1.0" ).toDouble();
+  mGridStrokeWidth = itemElem.attribute( "gridStrokeWidth", "0.5" ).toDouble();
+  mShowGrid = itemElem.attribute( "showGrid", "1" ).toInt();
 
+  //grid color
+  int gridRed = itemElem.attribute( "gridColorRed", "0" ).toInt();
+  int gridGreen = itemElem.attribute( "gridColorGreen", "0" ).toInt();
+  int gridBlue = itemElem.attribute( "gridColorBlue", "0" ).toInt();
+  mGridColor = QColor( gridRed, gridGreen, gridBlue );
+
   //composer map
   int composerMapId = itemElem.attribute( "composerMap", "-1" ).toInt();
   if ( composerMapId == -1 )
@@ -263,7 +288,8 @@
 void QgsComposerTable::adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeList )
 {
   //calculate height
-  double totalHeight = fontAscentMillimeters( mHeaderFont ) + attributeList.size() * fontAscentMillimeters( mContentFont ) + ( attributeList.size() + 1 ) * mLineTextDistance * 2;
+  double totalHeight = fontAscentMillimeters( mHeaderFont ) + attributeList.size() * fontAscentMillimeters( mContentFont ) \
+                       + ( attributeList.size() + 1 ) * mLineTextDistance * 2 + ( attributeList.size() + 2 ) * mGridStrokeWidth;
 
   //adapt frame to total width
   double totalWidth = 0;
@@ -273,6 +299,7 @@
     totalWidth += maxColWidthIt.value();
   }
   totalWidth += ( 2 * maxWidthMap.size() * mLineTextDistance );
+  totalWidth += ( maxWidthMap.size() + 1 ) * mGridStrokeWidth;
   QTransform t = transform();
   setSceneRect( QRectF( t.dx(), t.dy(), totalWidth, totalHeight ) );
 }
@@ -280,27 +307,33 @@
 void QgsComposerTable::drawHorizontalGridLines( QPainter* p, int nAttributes )
 {
   //horizontal lines
-  double currentY = 0;
-  p->drawLine( QPointF( 0, currentY ), QPointF( rect().width(), currentY ) );
+  double halfGridStrokeWidth = mGridStrokeWidth / 2.0;
+  double currentY = halfGridStrokeWidth;
+  p->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF( rect().width() - halfGridStrokeWidth, currentY ) );
+  currentY += mGridStrokeWidth;
   currentY += ( fontAscentMillimeters( mHeaderFont ) + 2 * mLineTextDistance );
   for ( int i = 0; i < nAttributes; ++i )
   {
-    p->drawLine( QPointF( 0, currentY ), QPointF( rect().width(), currentY ) );
+    p->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF( rect().width() - halfGridStrokeWidth, currentY ) );
+    currentY += mGridStrokeWidth;
     currentY += ( fontAscentMillimeters( mContentFont ) + 2 * mLineTextDistance );
   }
-  p->drawLine( QPointF( 0, currentY ), QPointF( rect().width(), currentY ) );
+  p->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF( rect().width() - halfGridStrokeWidth, currentY ) );
 }
 
 void QgsComposerTable::drawVerticalGridLines( QPainter* p, const QMap<int, double>& maxWidthMap )
 {
   //vertical lines
-  double currentX = 0;
-  p->drawLine( QPointF( currentX, 0 ), QPointF( currentX, rect().height() ) );
+  double halfGridStrokeWidth = mGridStrokeWidth / 2.0;
+  double currentX = halfGridStrokeWidth;
+  p->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, rect().height() - halfGridStrokeWidth ) );
+  currentX += mGridStrokeWidth;
   QMap<int, double>::const_iterator maxColWidthIt = maxWidthMap.constBegin();
   for ( ; maxColWidthIt != maxWidthMap.constEnd(); ++maxColWidthIt )
   {
     currentX += ( maxColWidthIt.value() + 2 * mLineTextDistance );
-    p->drawLine( QPointF( currentX, 0 ), QPointF( currentX, rect().height() ) );
+    p->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, rect().height() - halfGridStrokeWidth ) );
+    currentX += mGridStrokeWidth;
   }
 }
 

Modified: trunk/qgis/src/core/composer/qgscomposertable.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposertable.h	2010-01-07 12:03:33 UTC (rev 12687)
+++ trunk/qgis/src/core/composer/qgscomposertable.h	2010-01-07 13:29:23 UTC (rev 12688)
@@ -55,6 +55,15 @@
     void setContentFont( const QFont& f ) { mContentFont = f; }
     QFont contentFont() const { return mContentFont; }
 
+    void setShowGrid( bool show ) { mShowGrid = show;}
+    bool showGrid() const { return mShowGrid; }
+
+    void setGridStrokeWidth( double w ) { mGridStrokeWidth = w; }
+    double gridStrokeWidth() const { return mGridStrokeWidth; }
+
+    void setGridColor( const QColor& c ) { mGridColor = c; }
+    QColor gridColor() const { return mGridColor; }
+
   private:
     /**Associated vector layer*/
     QgsVectorLayer* mVectorLayer;
@@ -64,10 +73,14 @@
     int mMaximumNumberOfFeatures;
     /**Distance between table lines and text*/
     double mLineTextDistance;
-    QPen mGridPen;
+
     QFont mHeaderFont;
     QFont mContentFont;
 
+    bool mShowGrid;
+    double mGridStrokeWidth;
+    QColor mGridColor;
+
     /**Retrieves feature attributes*/
     bool getFeatureAttributes( QList<QgsAttributeMap>& attributes );
     /**Calculate the maximum width values of the vector attributes*/

Modified: trunk/qgis/src/ui/qgscomposertablewidgetbase.ui
===================================================================
--- trunk/qgis/src/ui/qgscomposertablewidgetbase.ui	2010-01-07 12:03:33 UTC (rev 12687)
+++ trunk/qgis/src/ui/qgscomposertablewidgetbase.ui	2010-01-07 13:29:23 UTC (rev 12688)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>287</width>
-    <height>238</height>
+    <width>239</width>
+    <height>281</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -24,8 +24,8 @@
        <rect>
         <x>0</x>
         <y>0</y>
-        <width>269</width>
-        <height>194</height>
+        <width>221</width>
+        <height>237</height>
        </rect>
       </property>
       <attribute name="label">
@@ -74,7 +74,7 @@
          </item>
         </layout>
        </item>
-       <item row="3" column="0">
+       <item row="3" column="0" colspan="2">
         <layout class="QHBoxLayout" name="horizontalLayout">
          <item>
           <widget class="QLabel" name="mMarginLabel">
@@ -88,14 +88,55 @@
          </item>
         </layout>
        </item>
-       <item row="4" column="0">
+       <item row="4" column="0" colspan="2">
+        <widget class="QCheckBox" name="mShowGridCheckBox">
+         <property name="text">
+          <string>Show grid</string>
+         </property>
+        </widget>
+       </item>
+       <item row="5" column="0" colspan="2">
+        <layout class="QHBoxLayout" name="horizontalLayout_5">
+         <item>
+          <widget class="QLabel" name="mGridStrokeWidthLabel">
+           <property name="text">
+            <string>Grid stroke width</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QDoubleSpinBox" name="mGridStrokeWidthSpinBox"/>
+         </item>
+        </layout>
+       </item>
+       <item row="6" column="0">
+        <widget class="QLabel" name="mGridColorLabel">
+         <property name="text">
+          <string>Grid color</string>
+         </property>
+        </widget>
+       </item>
+       <item row="6" column="1">
+        <widget class="QgsColorButton" name="mGridColorButton">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="text">
+          <string/>
+         </property>
+        </widget>
+       </item>
+       <item row="7" column="0">
         <widget class="QPushButton" name="mHeaderFontPushButton">
          <property name="text">
           <string>Header Font...</string>
          </property>
         </widget>
        </item>
-       <item row="4" column="1">
+       <item row="7" column="1">
         <widget class="QPushButton" name="mContentFontPushButton">
          <property name="text">
           <string>Content Font...</string>
@@ -103,18 +144,18 @@
         </widget>
        </item>
       </layout>
-      <zorder>mHeaderFontPushButton</zorder>
-      <zorder>mContentFontPushButton</zorder>
-      <zorder></zorder>
-      <zorder></zorder>
-      <zorder></zorder>
-      <zorder></zorder>
-      <zorder></zorder>
      </widget>
     </widget>
    </item>
   </layout>
  </widget>
+ <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