Skip to content

Commit d1e26f2

Browse files
committed
[composer] Option for fixed frame sizes set by multi frame (sponsored
by City of Uster, Switzerland)
1 parent fefc243 commit d1e26f2

7 files changed

+48
-0
lines changed

python/core/composer/qgscomposerframe.sip

+3
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ class QgsComposerFrame: QgsComposerItem
2626

2727
//Overriden to allow multiframe to set display name
2828
virtual QString displayName() const;
29+
30+
//Overriden to handle fixed frame sizes set by multi frame
31+
void setSceneRect( const QRectF& rectangle );
2932
};

python/core/composer/qgscomposermultiframe.sip

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ class QgsComposerMultiFrame: QgsComposerObject
1919
QgsComposerMultiFrame( QgsComposition* c, bool createUndoCommands );
2020
virtual ~QgsComposerMultiFrame();
2121
virtual QSizeF totalSize() const = 0;
22+
23+
/**Returns a fixed size for the frames, if desired.
24+
* @returns fixed size for frames. If the size has a width or height of 0, then
25+
* the frame size is not fixed in that direction and frames can have variable width
26+
* or height accordingly.
27+
* @note added in version 2.5
28+
*/
29+
virtual QSizeF fixedFrameSize() const;
30+
2231
virtual void render( QPainter* p, const QRectF& renderExtent ) = 0;
2332

2433
virtual void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true ) = 0;

src/core/composer/qgscomposerframe.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ QString QgsComposerFrame::displayName() const
7777
return tr( "<frame>" );
7878
}
7979

80+
void QgsComposerFrame::setSceneRect( const QRectF &rectangle )
81+
{
82+
QRectF fixedRect = rectangle;
83+
QSizeF fixedSize = mMultiFrame->fixedFrameSize();
84+
if ( fixedSize.width() > 0 )
85+
{
86+
fixedRect.setWidth( fixedSize.width() );
87+
}
88+
if ( fixedSize.height() > 0 )
89+
{
90+
fixedRect.setHeight( fixedSize.height() );
91+
}
92+
93+
QgsComposerItem::setSceneRect( fixedRect );
94+
}
95+
8096
void QgsComposerFrame::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
8197
{
8298
Q_UNUSED( itemStyle );

src/core/composer/qgscomposerframe.h

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class CORE_EXPORT QgsComposerFrame: public QgsComposerItem
4646
//Overriden to allow multiframe to set display name
4747
virtual QString displayName() const;
4848

49+
//Overriden to handle fixed frame sizes set by multi frame
50+
void setSceneRect( const QRectF& rectangle );
51+
4952
private:
5053
QgsComposerFrame(); //forbidden
5154
QgsComposerMultiFrame* mMultiFrame;

src/core/composer/qgscomposermultiframe.h

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ class CORE_EXPORT QgsComposerMultiFrame: public QgsComposerObject
4646
QgsComposerMultiFrame( QgsComposition* c, bool createUndoCommands );
4747
virtual ~QgsComposerMultiFrame();
4848
virtual QSizeF totalSize() const = 0;
49+
50+
/**Returns a fixed size for the frames, if desired.
51+
* @returns fixed size for frames. If the size has a width or height of 0, then
52+
* the frame size is not fixed in that direction and frames can have variable width
53+
* or height accordingly.
54+
* @note added in version 2.5
55+
*/
56+
virtual QSizeF fixedFrameSize() const { return QSizeF( 0, 0 ); }
57+
4958
virtual void render( QPainter* p, const QRectF& renderExtent ) = 0;
5059

5160
virtual void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true ) = 0;

src/core/composer/qgscomposertablev2.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ QMap<int, QString> QgsComposerTableV2::headerLabels() const
354354
return headers;
355355
}
356356

357+
QSizeF QgsComposerTableV2::fixedFrameSize() const
358+
{
359+
return QSizeF( mTableSize.width(), 0 );
360+
}
361+
357362
void QgsComposerTableV2::refreshAttributes()
358363
{
359364
mMaxColumnWidthMap.clear();

src/core/composer/qgscomposertablev2.h

+3
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
231231
*/
232232
virtual bool getTableContents( QgsComposerTableContents &contents ) = 0;
233233

234+
//reimplemented to return fixed table width
235+
virtual QSizeF fixedFrameSize() const;
236+
234237
public slots:
235238

236239
/**Refreshes the contents shown in the table by querying for new data.

0 commit comments

Comments
 (0)