Skip to content

Commit d82a353

Browse files
author
mhugent
committed
Adapt number of features in composer table if height of the item is changed interactively
git-svn-id: http://svn.osgeo.org/qgis/trunk@12717 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 76ef4ed commit d82a353

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

src/app/composer/qgscomposertablewidget.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ QgsComposerTableWidget::QgsComposerTableWidget( QgsComposerTable* table ): QWidg
6262
}
6363

6464
updateGuiElements();
65+
66+
if ( mComposerTable )
67+
{
68+
QObject::connect( mComposerTable, SIGNAL( maximumNumerOfFeaturesChanged( int ) ), this, SLOT( setMaximumNumberOfFeatures( int ) ) );
69+
}
6570
}
6671

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

298+
void QgsComposerTableWidget::setMaximumNumberOfFeatures( int n )
299+
{
300+
mMaximumColumnsSpinBox->blockSignals( true );
301+
mMaximumColumnsSpinBox->setValue( n );
302+
mMaximumColumnsSpinBox->blockSignals( false );
303+
}
304+
293305

294306

src/app/composer/qgscomposertablewidget.h

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class QgsComposerTableWidget: public QWidget, private Ui::QgsComposerTableWidget
4848
void on_mHeaderFontPushButton_clicked();
4949
void on_mContentFontPushButton_clicked();
5050
void on_mShowGridCheckBox_stateChanged( int state );
51+
52+
/**Inserts a new maximum number of features into the spin box (without the spinbox emitting a signal)*/
53+
void setMaximumNumberOfFeatures( int n );
5154
};
5255

5356
#endif // QGSCOMPOSERTABLEWIDGET_H

src/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ composer/qgscomposerscalebar.h
228228
composer/qgscomposeritem.h
229229
composer/qgscomposeritemgroup.h
230230
composer/qgscomposershape.h
231+
composer/qgscomposertable.h
231232
composer/qgscomposition.h
232233
composer/qgslegendmodel.h
233234
gps/qgsgpsconnection.h

src/core/composer/qgscomposertable.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ void QgsComposerTable::adaptItemFrame( const QMap<int, double>& maxWidthMap, con
401401
totalWidth += ( 2 * maxWidthMap.size() * mLineTextDistance );
402402
totalWidth += ( maxWidthMap.size() + 1 ) * mGridStrokeWidth;
403403
QTransform t = transform();
404-
setSceneRect( QRectF( t.dx(), t.dy(), totalWidth, totalHeight ) );
404+
QgsComposerItem::setSceneRect( QRectF( t.dx(), t.dy(), totalWidth, totalHeight ) );
405405
}
406406

407407
void QgsComposerTable::drawHorizontalGridLines( QPainter* p, int nAttributes )
@@ -450,3 +450,19 @@ QString QgsComposerTable::attributeDisplayName( int attributeIndex, const QStrin
450450
}
451451
}
452452

453+
void QgsComposerTable::setSceneRect( const QRectF& rectangle )
454+
{
455+
double titleHeight = 2 * mGridStrokeWidth + 2 * mLineTextDistance + fontAscentMillimeters( mHeaderFont );
456+
double attributeHeight = mGridStrokeWidth + 2 * mLineTextDistance + fontAscentMillimeters( mContentFont );
457+
if (( rectangle.height() - titleHeight ) > 0 )
458+
{
459+
mMaximumNumberOfFeatures = ( rectangle.height() - titleHeight ) / attributeHeight;
460+
}
461+
else
462+
{
463+
mMaximumNumberOfFeatures = 0;
464+
}
465+
QgsComposerItem::setSceneRect( rectangle );
466+
emit maximumNumerOfFeaturesChanged( mMaximumNumberOfFeatures );
467+
}
468+

src/core/composer/qgscomposertable.h

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class QgsVectorLayer;
2828
/**A class to display feature attributes in the print composer*/
2929
class CORE_EXPORT QgsComposerTable: public QgsComposerItem
3030
{
31+
Q_OBJECT
3132
public:
3233
QgsComposerTable( QgsComposition* composition );
3334
~QgsComposerTable();
@@ -71,6 +72,9 @@ class CORE_EXPORT QgsComposerTable: public QgsComposerItem
7172
QMap<int, QString> fieldAliasMap() const { return mFieldAliasMap; }
7273
void setFieldAliasMap( const QMap<int, QString>& map ) { mFieldAliasMap = map; }
7374

75+
/**Adapts mMaximumNumberOfFeatures depending on the rectangle height*/
76+
void setSceneRect( const QRectF& rectangle );
77+
7478
private:
7579
/**Associated vector layer*/
7680
QgsVectorLayer* mVectorLayer;
@@ -105,6 +109,10 @@ class CORE_EXPORT QgsComposerTable: public QgsComposerItem
105109
void initializeAliasMap();
106110
/**Returns the attribute name to display in the item (attribute name or an alias if present)*/
107111
QString attributeDisplayName( int attributeIndex, const QString& name ) const;
112+
113+
signals:
114+
/**This signal is emitted if the maximum number of feature changes (interactively)*/
115+
void maximumNumerOfFeaturesChanged( int n );
108116
};
109117

110118
#endif // QGSCOMPOSERTABLE_H

0 commit comments

Comments
 (0)