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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Jan 9 11:10:35 EST 2010


Author: mhugent
Date: 2010-01-09 11:10:34 -0500 (Sat, 09 Jan 2010)
New Revision: 12717

Modified:
   trunk/qgis/src/app/composer/qgscomposertablewidget.cpp
   trunk/qgis/src/app/composer/qgscomposertablewidget.h
   trunk/qgis/src/core/CMakeLists.txt
   trunk/qgis/src/core/composer/qgscomposertable.cpp
   trunk/qgis/src/core/composer/qgscomposertable.h
Log:
Adapt number of features in composer table if height of the item is changed interactively

Modified: trunk/qgis/src/app/composer/qgscomposertablewidget.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposertablewidget.cpp	2010-01-09 11:07:47 UTC (rev 12716)
+++ trunk/qgis/src/app/composer/qgscomposertablewidget.cpp	2010-01-09 16:10:34 UTC (rev 12717)
@@ -62,6 +62,11 @@
   }
 
   updateGuiElements();
+
+  if ( mComposerTable )
+  {
+    QObject::connect( mComposerTable, SIGNAL( maximumNumerOfFeaturesChanged( int ) ), this, SLOT( setMaximumNumberOfFeatures( int ) ) );
+  }
 }
 
 QgsComposerTableWidget::~QgsComposerTableWidget()
@@ -290,5 +295,12 @@
   mShowGridCheckBox->blockSignals( b );
 }
 
+void QgsComposerTableWidget::setMaximumNumberOfFeatures( int n )
+{
+  mMaximumColumnsSpinBox->blockSignals( true );
+  mMaximumColumnsSpinBox->setValue( n );
+  mMaximumColumnsSpinBox->blockSignals( false );
+}
 
 
+

Modified: trunk/qgis/src/app/composer/qgscomposertablewidget.h
===================================================================
--- trunk/qgis/src/app/composer/qgscomposertablewidget.h	2010-01-09 11:07:47 UTC (rev 12716)
+++ trunk/qgis/src/app/composer/qgscomposertablewidget.h	2010-01-09 16:10:34 UTC (rev 12717)
@@ -48,6 +48,9 @@
     void on_mHeaderFontPushButton_clicked();
     void on_mContentFontPushButton_clicked();
     void on_mShowGridCheckBox_stateChanged( int state );
+
+    /**Inserts a new maximum number of features into the spin box (without the spinbox emitting a signal)*/
+    void setMaximumNumberOfFeatures( int n );
 };
 
 #endif // QGSCOMPOSERTABLEWIDGET_H

Modified: trunk/qgis/src/core/CMakeLists.txt
===================================================================
--- trunk/qgis/src/core/CMakeLists.txt	2010-01-09 11:07:47 UTC (rev 12716)
+++ trunk/qgis/src/core/CMakeLists.txt	2010-01-09 16:10:34 UTC (rev 12717)
@@ -228,6 +228,7 @@
 composer/qgscomposeritem.h
 composer/qgscomposeritemgroup.h
 composer/qgscomposershape.h
+composer/qgscomposertable.h
 composer/qgscomposition.h
 composer/qgslegendmodel.h
 gps/qgsgpsconnection.h

Modified: trunk/qgis/src/core/composer/qgscomposertable.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposertable.cpp	2010-01-09 11:07:47 UTC (rev 12716)
+++ trunk/qgis/src/core/composer/qgscomposertable.cpp	2010-01-09 16:10:34 UTC (rev 12717)
@@ -401,7 +401,7 @@
   totalWidth += ( 2 * maxWidthMap.size() * mLineTextDistance );
   totalWidth += ( maxWidthMap.size() + 1 ) * mGridStrokeWidth;
   QTransform t = transform();
-  setSceneRect( QRectF( t.dx(), t.dy(), totalWidth, totalHeight ) );
+  QgsComposerItem::setSceneRect( QRectF( t.dx(), t.dy(), totalWidth, totalHeight ) );
 }
 
 void QgsComposerTable::drawHorizontalGridLines( QPainter* p, int nAttributes )
@@ -450,3 +450,19 @@
   }
 }
 
+void QgsComposerTable::setSceneRect( const QRectF& rectangle )
+{
+  double titleHeight =  2 * mGridStrokeWidth + 2 * mLineTextDistance + fontAscentMillimeters( mHeaderFont );
+  double attributeHeight = mGridStrokeWidth + 2 * mLineTextDistance + fontAscentMillimeters( mContentFont );
+  if (( rectangle.height() - titleHeight ) > 0 )
+  {
+    mMaximumNumberOfFeatures = ( rectangle.height() - titleHeight ) / attributeHeight;
+  }
+  else
+  {
+    mMaximumNumberOfFeatures = 0;
+  }
+  QgsComposerItem::setSceneRect( rectangle );
+  emit maximumNumerOfFeaturesChanged( mMaximumNumberOfFeatures );
+}
+

Modified: trunk/qgis/src/core/composer/qgscomposertable.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposertable.h	2010-01-09 11:07:47 UTC (rev 12716)
+++ trunk/qgis/src/core/composer/qgscomposertable.h	2010-01-09 16:10:34 UTC (rev 12717)
@@ -28,6 +28,7 @@
 /**A class to display feature attributes in the print composer*/
 class CORE_EXPORT QgsComposerTable: public QgsComposerItem
 {
+    Q_OBJECT
   public:
     QgsComposerTable( QgsComposition* composition );
     ~QgsComposerTable();
@@ -71,6 +72,9 @@
     QMap<int, QString> fieldAliasMap() const { return mFieldAliasMap; }
     void setFieldAliasMap( const QMap<int, QString>& map ) { mFieldAliasMap = map; }
 
+    /**Adapts mMaximumNumberOfFeatures depending on the rectangle height*/
+    void setSceneRect( const QRectF& rectangle );
+
   private:
     /**Associated vector layer*/
     QgsVectorLayer* mVectorLayer;
@@ -105,6 +109,10 @@
     void initializeAliasMap();
     /**Returns the attribute name to display in the item (attribute name or an alias if present)*/
     QString attributeDisplayName( int attributeIndex, const QString& name ) const;
+
+  signals:
+    /**This signal is emitted if the maximum number of feature changes (interactively)*/
+    void maximumNumerOfFeaturesChanged( int n );
 };
 
 #endif // QGSCOMPOSERTABLE_H



More information about the QGIS-commit mailing list