Skip to content

Commit

Permalink
Adapt number of features in composer table if height of the item is c…
Browse files Browse the repository at this point in the history
…hanged interactively

git-svn-id: http://svn.osgeo.org/qgis/trunk@12717 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 9, 2010
1 parent 76ef4ed commit d82a353
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/app/composer/qgscomposertablewidget.cpp
Expand Up @@ -62,6 +62,11 @@ QgsComposerTableWidget::QgsComposerTableWidget( QgsComposerTable* table ): QWidg
}

updateGuiElements();

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

QgsComposerTableWidget::~QgsComposerTableWidget()
Expand Down Expand Up @@ -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 );
}



3 changes: 3 additions & 0 deletions src/app/composer/qgscomposertablewidget.h
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion src/core/composer/qgscomposertable.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
}

8 changes: 8 additions & 0 deletions src/core/composer/qgscomposertable.h
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 d82a353

Please sign in to comment.