Skip to content
Permalink
Browse files

Adapt number of features in composer table if height of the item is c…

…hanged interactively

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12717 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Jan 9, 2010
1 parent 579aae3 commit 07689a3799540c23309bc3c291eb176d17a573e8
@@ -62,6 +62,11 @@ QgsComposerTableWidget::QgsComposerTableWidget( QgsComposerTable* table ): QWidg
}

updateGuiElements();

if ( mComposerTable )
{
QObject::connect( mComposerTable, SIGNAL( maximumNumerOfFeaturesChanged( int ) ), this, SLOT( setMaximumNumberOfFeatures( int ) ) );
}
}

QgsComposerTableWidget::~QgsComposerTableWidget()
@@ -290,5 +295,12 @@ void QgsComposerTableWidget::blockAllSignals( bool b )
mShowGridCheckBox->blockSignals( b );
}

void QgsComposerTableWidget::setMaximumNumberOfFeatures( int n )
{
mMaximumColumnsSpinBox->blockSignals( true );
mMaximumColumnsSpinBox->setValue( n );
mMaximumColumnsSpinBox->blockSignals( false );
}



@@ -48,6 +48,9 @@ class QgsComposerTableWidget: public QWidget, private Ui::QgsComposerTableWidget
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
@@ -228,6 +228,7 @@ composer/qgscomposerscalebar.h
composer/qgscomposeritem.h
composer/qgscomposeritemgroup.h
composer/qgscomposershape.h
composer/qgscomposertable.h
composer/qgscomposition.h
composer/qgslegendmodel.h
gps/qgsgpsconnection.h
@@ -401,7 +401,7 @@ void QgsComposerTable::adaptItemFrame( const QMap<int, double>& maxWidthMap, con
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 @@ QString QgsComposerTable::attributeDisplayName( int attributeIndex, const QStrin
}
}

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 );
}

@@ -28,6 +28,7 @@ class QgsVectorLayer;
/**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 @@ class CORE_EXPORT QgsComposerTable: public QgsComposerItem
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 @@ class CORE_EXPORT QgsComposerTable: public QgsComposerItem
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

0 comments on commit 07689a3

Please sign in to comment.