Skip to content

Commit 9fd7390

Browse files
committedSep 17, 2014
[composer] API docs and python bindings for QgsComposerTableV2 (sponsored
by City of Uster, Switzerland)
1 parent cb73905 commit 9fd7390

22 files changed

+1095
-134
lines changed
 

‎python/core/composer/qgscomposerattributetable.sip

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,4 @@ class QgsComposerAttributeTable : QgsComposerTable
232232
*/
233233
// bool getFeatureAttributes( QList<QgsAttributeMap>& attributeMaps );
234234

235-
236-
signals:
237-
/**This signal is emitted if the maximum number of feature changes (interactively)*/
238-
void maximumNumberOfFeaturesChanged( int n );
239235
};

‎python/core/composer/qgscomposerattributetablemodel.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class QgsComposerAttributeTableColumnModel: QAbstractTableModel
1919
* @param composerTable QgsComposerAttributeTable the model is attached to
2020
* @param parent optional parent
2121
*/
22-
QgsComposerAttributeTableColumnModel( QgsComposerAttributeTable *composerTable, QObject *parent = 0 );
22+
QgsComposerAttributeTableColumnModel( QgsComposerAttributeTable *composerTable, QObject *parent /TransferThis/ = 0 );
2323
virtual ~QgsComposerAttributeTableColumnModel();
2424

2525
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
@@ -114,7 +114,7 @@ class QgsComposerTableSortColumnsProxyModel : QSortFilterProxyModel
114114
* @param filterType filter for columns, controls whether sorted or unsorted columns are shown
115115
* @param parent optional parent
116116
*/
117-
QgsComposerTableSortColumnsProxyModel( QgsComposerAttributeTable *composerTable, ColumnFilterType filterType, QObject *parent = 0 );
117+
QgsComposerTableSortColumnsProxyModel( QgsComposerAttributeTable *composerTable, ColumnFilterType filterType, QObject *parent /TransferThis/ = 0 );
118118

119119
virtual ~QgsComposerTableSortColumnsProxyModel();
120120

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/**A model for displaying columns shown in a QgsComposerAttributeTableV2*/
2+
class QgsComposerAttributeTableColumnModelV2: QAbstractTableModel
3+
{
4+
%TypeHeaderCode
5+
#include <qgscomposerattributetablemodelv2.h>
6+
%End
7+
8+
public:
9+
10+
/*! Controls whether a row/column is shifted up or down
11+
*/
12+
enum ShiftDirection
13+
{
14+
ShiftUp, /*!< shift the row/column up */
15+
ShiftDown /*!< shift the row/column down */
16+
};
17+
18+
/**Constructor for QgsComposerAttributeTableColumnModel.
19+
/**Constructor for QgsComposerAttributeTableColumnModel.
20+
* @param composerTable QgsComposerAttributeTable the model is attached to
21+
* @param parent optional parent
22+
*/
23+
QgsComposerAttributeTableColumnModelV2( QgsComposerAttributeTableV2 *composerTable, QObject *parent /TransferThis/ = 0 );
24+
virtual ~QgsComposerAttributeTableColumnModelV2();
25+
26+
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
27+
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
28+
virtual QVariant data( const QModelIndex &index, int role ) const;
29+
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
30+
virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole );
31+
Qt::ItemFlags flags( const QModelIndex &index ) const;
32+
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );
33+
bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() );
34+
QModelIndex index( int row, int column, const QModelIndex &parent ) const;
35+
QModelIndex parent( const QModelIndex &child ) const;
36+
37+
/**Moves the specified row up or down in the model. Used for rearranging the attribute tables
38+
* columns.
39+
* @returns true if the move is allowed
40+
* @param row row in model representing attribute table column to move
41+
* @param direction direction to move the attribute table column
42+
* @note added in 2.3
43+
*/
44+
bool moveRow( int row , ShiftDirection direction );
45+
46+
/**Resets the attribute table's columns to match the source layer's fields. Remove all existing
47+
* attribute table columns and column customisations.
48+
* @note added in 2.3
49+
*/
50+
void resetToLayer();
51+
52+
/**Returns the QgsComposerTableColumn corresponding to an index in the model.
53+
* @returns QgsComposerTableColumn for specified index
54+
* @param index a QModelIndex
55+
* @note added in 2.3
56+
* @see indexFromColumn
57+
*/
58+
QgsComposerTableColumn* columnFromIndex( const QModelIndex & index ) const;
59+
60+
/**Returns a QModelIndex corresponding to a QgsComposerTableColumn in the model.
61+
* @returns QModelIndex for specified QgsComposerTableColumn
62+
* @param column a QgsComposerTableColumn
63+
* @note added in 2.3
64+
* @see columnFromIndex
65+
*/
66+
QModelIndex indexFromColumn( QgsComposerTableColumn *column );
67+
68+
/**Sets a specified column as a sorted column in the QgsComposerAttributeTable. The column will be
69+
* added to the end of the sort rank list, ie it will take the next largest available sort rank.
70+
* @param column a QgsComposerTableColumn
71+
* @param order sort order for column
72+
* @note added in 2.3
73+
* @see removeColumnFromSort
74+
* @see moveColumnInSortRank
75+
*/
76+
void setColumnAsSorted( QgsComposerTableColumn *column, Qt::SortOrder order );
77+
78+
/**Sets a specified column as an unsorted column in the QgsComposerAttributeTable. The column will be
79+
* removed from the sort rank list.
80+
* @param column a QgsComposerTableColumn
81+
* @note added in 2.3
82+
* @see setColumnAsSorted
83+
*/
84+
void setColumnAsUnsorted( QgsComposerTableColumn * column );
85+
86+
/**Moves a column up or down in the sort rank for the QgsComposerAttributeTable.
87+
* @param column a QgsComposerTableColumn
88+
* @param direction direction to move the column in the sort rank list
89+
* @note added in 2.3
90+
* @see setColumnAsSorted
91+
*/
92+
bool moveColumnInSortRank( QgsComposerTableColumn * column, ShiftDirection direction );
93+
94+
};
95+
96+
/**Allows for filtering QgsComposerAttributeTable columns by columns which are sorted or unsorted*/
97+
class QgsComposerTableSortColumnsProxyModelV2 : QSortFilterProxyModel
98+
{
99+
%TypeHeaderCode
100+
#include <qgscomposerattributetablemodelv2.h>
101+
%End
102+
103+
public:
104+
105+
/*! Controls whether the proxy model shows sorted or unsorted columns
106+
*/
107+
enum ColumnFilterType
108+
{
109+
ShowSortedColumns, /*!< show only sorted columns */
110+
ShowUnsortedColumns/*!< show only unsorted columns */
111+
};
112+
113+
/**Constructor for QgsComposerTableSortColumnsProxyModel.
114+
* @param composerTable QgsComposerAttributeTable the model is attached to
115+
* @param filterType filter for columns, controls whether sorted or unsorted columns are shown
116+
* @param parent optional parent
117+
*/
118+
QgsComposerTableSortColumnsProxyModelV2( QgsComposerAttributeTableV2 *composerTable, ColumnFilterType filterType, QObject *parent /TransferThis/ = 0 );
119+
120+
virtual ~QgsComposerTableSortColumnsProxyModelV2();
121+
122+
bool lessThan( const QModelIndex &left, const QModelIndex &right ) const;
123+
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
124+
virtual QVariant data( const QModelIndex &index, int role ) const;
125+
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
126+
Qt::ItemFlags flags( const QModelIndex &index ) const;
127+
virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole );
128+
129+
/**Returns the QgsComposerTableColumn corresponding to a row in the proxy model.
130+
* @returns QgsComposerTableColumn for specified row
131+
* @param row a row number
132+
* @note added in 2.3
133+
* @see columnFromIndex
134+
*/
135+
QgsComposerTableColumn* columnFromRow( int row );
136+
137+
/**Returns the QgsComposerTableColumn corresponding to an index in the proxy model.
138+
* @returns QgsComposerTableColumn for specified index
139+
* @param index a QModelIndex
140+
* @note added in 2.3
141+
* @see columnFromRow
142+
* @see columnFromSourceIndex
143+
*/
144+
QgsComposerTableColumn* columnFromIndex( const QModelIndex & index ) const;
145+
146+
/**Returns the QgsComposerTableColumn corresponding to an index from the source
147+
* QgsComposerAttributeTableColumnModel model.
148+
* @returns QgsComposerTableColumn for specified index from QgsComposerAttributeTableColumnModel
149+
* @param sourceIndex a QModelIndex
150+
* @note added in 2.3
151+
* @see columnFromRow
152+
* @see columnFromIndex
153+
*/
154+
QgsComposerTableColumn* columnFromSourceIndex( const QModelIndex& sourceIndex ) const;
155+
156+
/**Invalidates the current filter used by the proxy model
157+
* @note added in 2.3
158+
*/
159+
void resetFilter();
160+
161+
protected:
162+
bool filterAcceptsRow( int source_row, const QModelIndex & source_parent ) const;
163+
164+
};
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/**Helper class for sorting tables, takes into account sorting column and ascending / descending*/
2+
class QgsComposerAttributeTableCompareV2
3+
{
4+
%TypeHeaderCode
5+
#include <qgscomposerattributetablev2.h>
6+
%End
7+
8+
public:
9+
10+
QgsComposerAttributeTableCompareV2();
11+
12+
bool operator()( const QgsComposerTableRow& m1, const QgsComposerTableRow& m2 );
13+
14+
/**Sets column number to sort by
15+
* @param col column number for sorting
16+
*/
17+
void setSortColumn( int col );
18+
19+
/**Sets sort order for column sorting
20+
* @param asc set to true to sort in ascending order, false to sort in descending order
21+
*/
22+
void setAscending( bool asc );
23+
24+
};
25+
26+
/**A table that displays attributes from a vector layer*/
27+
class QgsComposerAttributeTableV2 : QgsComposerTableV2
28+
{
29+
%TypeHeaderCode
30+
#include <qgscomposerattributetablev2.h>
31+
%End
32+
33+
public:
34+
35+
QgsComposerAttributeTableV2( QgsComposition* composition, bool createUndoCommands );
36+
~QgsComposerAttributeTableV2();
37+
38+
/**Writes properties specific to attribute tables
39+
* @param elem an existing QDomElement in which to store the attribute table's properties.
40+
* @param doc QDomDocument for the destination xml.
41+
* @see readXML
42+
*/
43+
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
44+
45+
/**Reads the properties specific to an attribute table from xml.
46+
* @param itemElem a QDomElement holding the attribute table's desired properties.
47+
* @param doc QDomDocument for the source xml.
48+
* @see writeXML
49+
*/
50+
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
51+
52+
virtual void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
53+
54+
/**Sets the vector layer from which to display feature attributes
55+
* @param layer Vector layer for attribute table
56+
* @see vectorLayer
57+
*/
58+
void setVectorLayer( QgsVectorLayer* layer );
59+
60+
/**Returns the vector layer the attribute table is currently using
61+
* @returns attribute table's current vector layer
62+
* @see setVectorLayer
63+
*/
64+
QgsVectorLayer* vectorLayer() const;
65+
66+
/**Resets the attribute table's columns to match the vector layer's fields
67+
* @see setVectorLayer
68+
*/
69+
void resetColumns();
70+
71+
/**Sets the composer map to use to limit the extent of features shown in the
72+
* attribute table. This setting only has an effect if setDisplayOnlyVisibleFeatures is
73+
* set to true. Changing the composer map forces the table to refetch features from its
74+
* vector layer, and may result in the table changing size to accommodate the new displayed
75+
* feature attributes.
76+
* @param map QgsComposerMap which drives the extents of the table's features
77+
* @see composerMap
78+
* @see setDisplayOnlyVisibleFeatures
79+
*/
80+
void setComposerMap( const QgsComposerMap* map );
81+
82+
/**Returns the composer map whose extents are controlling the features shown in the
83+
* table. The extents of the map are only used if displayOnlyVisibleFeatures() is true.
84+
* @returns composer map controlling the attribute table
85+
* @see setComposerMap
86+
* @see displayOnlyVisibleFeatures
87+
*/
88+
const QgsComposerMap* composerMap() const;
89+
90+
/**Sets the maximum number of features shown by the table. Changing this setting may result
91+
* in the attribute table changing its size to accommodate the new number of rows, and requires
92+
* the table to refetch features from its vector layer.
93+
* @param features maximum number of features to show in the table
94+
* @see maximumNumberOfFeatures
95+
*/
96+
void setMaximumNumberOfFeatures( int features );
97+
98+
/**Returns the maximum number of features to be shown by the table.
99+
* @returns maximum number of features
100+
* @see setMaximumNumberOfFeatures
101+
*/
102+
int maximumNumberOfFeatures() const;
103+
104+
/**Sets attribute table to only show features which are visible in a composer map item. Changing
105+
* this setting forces the table to refetch features from its vector layer, and may result in
106+
* the table changing size to accommodate the new displayed feature attributes.
107+
* @param visibleOnly set to true to show only visible features
108+
* @see displayOnlyVisibleFeatures
109+
* @see setComposerMap
110+
*/
111+
void setDisplayOnlyVisibleFeatures( bool visibleOnly );
112+
113+
/**Returns true if the table is set to show only features visible on a corresponding
114+
* composer map item.
115+
* @returns true if table only shows visible features
116+
* @see composerMap
117+
* @see setDisplayOnlyVisibleFeatures
118+
*/
119+
bool displayOnlyVisibleFeatures() const;
120+
121+
/**Returns true if a feature filter is active on the attribute table
122+
* @returns bool state of the feature filter
123+
* @see setFilterFeatures
124+
* @see featureFilter
125+
*/
126+
bool filterFeatures() const;
127+
128+
/**Sets whether the feature filter is active for the attribute table. Changing
129+
* this setting forces the table to refetch features from its vector layer, and may result in
130+
* the table changing size to accommodate the new displayed feature attributes.
131+
* @param filter Set to true to enable the feature filter
132+
* @see filterFeatures
133+
* @see setFeatureFilter
134+
*/
135+
void setFilterFeatures( bool filter );
136+
137+
/**Returns the current expression used to filter features for the table. The filter is only
138+
* active if filterFeatures() is true.
139+
* @returns feature filter expression
140+
* @see setFeatureFilter
141+
* @see filterFeatures
142+
*/
143+
QString featureFilter() const;
144+
145+
/**Sets the expression used for filtering features in the table. The filter is only
146+
* active if filterFeatures() is set to true. Changing this setting forces the table
147+
* to refetch features from its vector layer, and may result in
148+
* the table changing size to accommodate the new displayed feature attributes.
149+
* @param expression filter to use for selecting which features to display in the table
150+
* @see featureFilter
151+
* @see setFilterFeatures
152+
*/
153+
void setFeatureFilter( const QString& expression );
154+
155+
/**Sets the attributes to display in the table.
156+
* @param attr QSet of integer values refering to the attributes from the vector layer to show.
157+
* Set to an empty QSet to show all feature attributes.
158+
* @param refresh set to true to force the table to refetch features from its vector layer
159+
* and immediately update the display of the table. This may result in the table changing size
160+
* to accommodate the new displayed feature attributes.
161+
* @see displayAttributes
162+
*/
163+
void setDisplayAttributes( const QSet<int>& attr, bool refresh = true );
164+
165+
/**Returns the attributes used to sort the table's features.
166+
* @returns a QList of integer/bool pairs, where the integer refers to the attribute index and
167+
* the bool to the sort order for the attribute. If true the attribute is sorted ascending,
168+
* if false, the attribute is sorted in descending order.
169+
* @note not available in python bindings
170+
*/
171+
//QList<QPair<int, bool> > sortAttributes() const;
172+
173+
/**Queries the attribute table's vector layer for attributes to show in the table.
174+
* @param attributeMaps list of QgsAttributeMaps where the fetched feature attributes will be stored
175+
* @returns true if attributes were successfully fetched
176+
* @note not available in python bindings
177+
*/
178+
bool getTableContents( QgsComposerTableContents &contents );
179+
180+
};
Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
/**Frame item for a composer multiframe item*/
22
class QgsComposerFrame: QgsComposerItem
33
{
44
%TypeHeaderCode
@@ -9,24 +9,37 @@ class QgsComposerFrame: QgsComposerItem
99
QgsComposerFrame( QgsComposition* c, QgsComposerMultiFrame* mf, qreal x, qreal y, qreal width, qreal height );
1010
~QgsComposerFrame();
1111

12-
/**Sets the part of this frame (relative to the total multiframe extent in mm)*/
12+
/**Sets the visible part of the multiframe's content which is visible within
13+
* this frame (relative to the total multiframe extent in mm).
14+
* @param section visible portion of content
15+
* @see extent
16+
*/
1317
void setContentSection( const QRectF& section );
14-
18+
19+
/**Returns the parent multiframe for the frame.
20+
* @returns parent multiframe
21+
*/
22+
QgsComposerMultiFrame* multiFrame() const;
23+
24+
//Overriden to allow multiframe to set display name
25+
virtual QString displayName() const;
26+
27+
//Overriden to handle fixed frame sizes set by multi frame
28+
void setSceneRect( const QRectF& rectangle );
29+
1530
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
16-
1731
void beginItemCommand( const QString& text );
1832
void endItemCommand();
19-
2033
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
2134
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
22-
2335
int type() const;
24-
25-
QgsComposerMultiFrame* multiFrame() const;
26-
27-
//Overriden to allow multiframe to set display name
28-
virtual QString displayName() const;
2936

30-
//Overriden to handle fixed frame sizes set by multi frame
31-
void setSceneRect( const QRectF& rectangle );
37+
/**Returns the visible portion of the multi frame's content which
38+
* is shown in this frame.
39+
* @returns extent of visible portion
40+
* @note added in QGIS 2.5
41+
* @see setContentSection
42+
*/
43+
QRectF extent() const;
44+
3245
};

‎python/core/composer/qgscomposerhtml.sip

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,6 @@ class QgsComposerHtml: QgsComposerMultiFrame
9494
*/
9595
void setEvaluateExpressions( bool evaluateExpressions );
9696

97-
QSizeF totalSize() const;
98-
99-
void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
100-
101-
bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
102-
bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
103-
104-
void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
105-
106-
//overriden to break frames without dividing lines of text
107-
double findNearbyPageBreak( double yPos );
108-
10997
/**Returns whether html item is using smart breaks. Smart breaks prevent
11098
* the html frame contents from breaking mid-way though a line of text.
11199
* @returns true if html item is using smart breaks
@@ -184,6 +172,13 @@ class QgsComposerHtml: QgsComposerMultiFrame
184172
bool userStylesheetEnabled() const;
185173

186174
virtual QString displayName() const;
175+
QSizeF totalSize() const;
176+
void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
177+
bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
178+
bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
179+
void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
180+
//overriden to break frames without dividing lines of text
181+
double findNearbyPageBreak( double yPos );
187182

188183
public slots:
189184

Lines changed: 173 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11

2-
/**Abstract base class for composer entries with the ability to distribute the content to several frames (items)*/
2+
/**
3+
* \ingroup composer
4+
* \class QgsComposerMultiFrame
5+
* Abstract base class for composer items with the ability to distribute the content to several frames
6+
* (QgsComposerFrame items).
7+
*/
8+
39
class QgsComposerMultiFrame: QgsComposerObject
410
{
511
%TypeHeaderCode
@@ -8,64 +14,182 @@ class QgsComposerMultiFrame: QgsComposerObject
814

915
public:
1016

17+
/*! Specifies the behaviour for creating new frames to fit the multiframe's content
18+
*/
1119
enum ResizeMode
1220
{
13-
UseExistingFrames,
14-
ExtendToNextPage, //uses the next page(s) until the content has been printed
15-
RepeatOnEveryPage, //repeats the same frame on every page
16-
RepeatUntilFinished //duplicates last frame to next page to fit the total size
21+
UseExistingFrames, /*!< don't automatically create new frames, just use existing frames */
22+
ExtendToNextPage, /*!< creates new full page frames on the following page(s) until the entire multiframe content is visible */
23+
RepeatOnEveryPage, /*!< repeats the same frame on every page */
24+
RepeatUntilFinished /*!< creates new frames with the same position and dimensions as the existing frame on the following page(s),
25+
until the entire multiframe content is visible */
1726
};
1827

28+
/**Construct a new multiframe item.
29+
* @param c parent composition
30+
* @param createUndoCommands
31+
*/
1932
QgsComposerMultiFrame( QgsComposition* c, bool createUndoCommands );
33+
2034
virtual ~QgsComposerMultiFrame();
35+
36+
/**Returns the total size of the multiframe's content.
37+
* @returns total size required for content
38+
*/
2139
virtual QSizeF totalSize() const = 0;
2240

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
41+
/**Returns the fixed size for a frame, if desired. If the fixed frame size changes,
42+
* the sizes of all frames can be recalculated by calling recalculateFrameRects().
43+
* @param frameIndex frame number
44+
* @returns fixed size for frame. If the size has a width or height of 0, then
2545
* the frame size is not fixed in that direction and frames can have variable width
2646
* or height accordingly.
2747
* @note added in version 2.5
48+
* @see minFrameSize
49+
* @see recalculateFrameRects
50+
*/
51+
virtual QSizeF fixedFrameSize( const int frameIndex = -1 ) const;
52+
53+
/**Returns the minimum size for a frames, if desired. If the minimum
54+
* size changes, the sizes of all frames can be recalculated by calling
55+
* recalculateFrameRects().
56+
* @param frameIndex frame number
57+
* @returns minimum size for frame. If the size has a width or height of 0, then
58+
* the frame size has no minimum in that direction.
59+
* @note added in version 2.5
60+
* @see fixedFrameSize
61+
* @see recalculateFrameRects
2862
*/
29-
virtual QSizeF fixedFrameSize() const;
63+
virtual QSizeF minFrameSize( const int frameIndex = -1 ) const;
64+
65+
/**Renders a portion of the multiframe's content into a painter.
66+
* @param p destination painter
67+
* @param renderExtent visible extent of content to render into the painter.
68+
* @deprecated use render( QPainter* painter, const QRectF& renderExtent, const int frameIndex ) instead
69+
*/
70+
virtual void render( QPainter* p, const QRectF& renderExtent ) /Deprecated/;
3071

31-
virtual void render( QPainter* p, const QRectF& renderExtent );
32-
virtual void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
72+
/**Renders a portion of the multiframe's content into a painter.
73+
* @param painter destination painter
74+
* @param renderExtent visible extent of content to render into the painter.
75+
* @param frameIndex frame number for content
76+
* @note added in version 2.5
77+
*/
78+
virtual void render( QPainter* painter, const QRectF& renderExtent, const int frameIndex );
3379

80+
/**Adds a frame to the multiframe.
81+
* @param frame frame to add
82+
* @param recalcFrameSizes set to true to force recalculation of all existing frame sizes
83+
* @see removeFrame
84+
*/
3485
virtual void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true ) = 0;
3586

3687
/**Finds the optimal position to break a frame at.
3788
* @param yPos maximum vertical position for break
3889
* @returns the optimal breakable position which occurs in the multi frame close
3990
* to and before the specified yPos
40-
* @note added in version 2.3*/
91+
* @note added in version 2.3
92+
*/
4193
virtual double findNearbyPageBreak( double yPos );
4294

95+
/**Removes a frame from the multiframe. This method automatically removes the frame from the
96+
* composition.
97+
* @param i index of frame to remove
98+
* @see addFrame
99+
* @see deleteFrames
100+
*/
43101
void removeFrame( int i );
102+
103+
/**Removes and deletes all child frames.
104+
* @see removeFrame
105+
*/
106+
void deleteFrames();
44107

45-
void update();
46-
108+
/**Sets the resize mode for the multiframe, and recalculates frame sizes to match.
109+
* @param mode resize mode
110+
* @see resizeMode
111+
*/
47112
void setResizeMode( ResizeMode mode );
113+
114+
/**Returns the resize mode for the multiframe.
115+
* @returns resize mode
116+
* @see setResizeMode
117+
*/
48118
ResizeMode resizeMode() const;
49119

120+
/**Stores state information about multiframe in DOM element. Implementations of writeXML
121+
* should also call the _writeXML method to save general multiframe properties.
122+
* @param elem is DOM element
123+
* @param doc is the DOM document
124+
* @param ignoreFrames set to false to avoid writing state information about child frames into DOM
125+
* @see _writeXML
126+
*/
50127
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const = 0;
128+
129+
/**Stores state information about base multiframe object in DOM element. Implementations of writeXML
130+
* should call this method.
131+
* @param elem is DOM element
132+
* @param doc is the DOM document
133+
* @param ignoreFrames set to false to avoid writing state information about child frames into DOM
134+
* @see writeXML
135+
*/
51136
bool _writeXML( QDomElement& elem, QDomDocument& doc, bool ignoreFrames = false ) const;
52137

138+
/**Reads multiframe state information from a DOM element. Implementations of readXML
139+
* should also call the _readXML method to restore general multiframe properties.
140+
* @param itemElem is DOM element
141+
* @param doc is the DOM document
142+
* @param ignoreFrames set to false to avoid read state information about child frames from DOM
143+
* @see _readXML
144+
*/
53145
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false ) = 0;
146+
147+
/**Restores state information about base multiframe object from a DOM element. Implementations of readXML
148+
* should call this method.
149+
* @param itemElem is DOM element
150+
* @param doc is the DOM document
151+
* @param ignoreFrames set to false to avoid reading state information about child frames from DOM
152+
* @see readXML
153+
*/
54154
bool _readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
55155

156+
/**Returns the parent composition for the multiframe.
157+
* @returns composition
158+
*/
56159
QgsComposition* composition();
57160

161+
/**Returns whether undo commands should be created for interactions with the multiframe.
162+
* @returns true if undo commands should be created
163+
* @see setCreateUndoCommands
164+
*/
58165
bool createUndoCommands() const;
166+
167+
/**Sets whether undo commands should be created for interactions with the multiframe.
168+
* @param enabled set to true if undo commands should be created
169+
* @see createUndoCommands
170+
*/
59171
void setCreateUndoCommands( bool enabled );
60172

61-
/**Removes and deletes all frames from mComposition*/
62-
void deleteFrames();
63-
64-
/** Return the number of frames associated with this multiframeset.
65-
@note added in 2.0, replaces nFrames
173+
/**Returns the number of frames associated with this multiframe.
174+
* @returns number of child frames
175+
* @note added in QGIS 2.0, replaces nFrames
66176
**/
67177
int frameCount() const;
178+
179+
/**Returns a child frame from the multiframe.
180+
* @param i index of frame
181+
* @returns child frame if found
182+
* @see frameIndex
183+
*/
68184
QgsComposerFrame* frame( int i );
185+
186+
/**Returns the index of a frame within the multiframe
187+
* @param frame frame to find index of
188+
* @returns index for frame if found, -1 if frame not found in multiframe
189+
* @note added in version 2.5
190+
* @see frame
191+
*/
192+
int frameIndex( QgsComposerFrame *frame ) const;
69193

70194
/**Creates a new frame and adds it to the multi frame and composition.
71195
* @param currentFrame an existing QgsComposerFrame from which to copy the size
@@ -85,24 +209,49 @@ class QgsComposerMultiFrame: QgsComposerObject
85209

86210
public slots:
87211

212+
/**Forces a redraw of all child frames.
213+
*/
214+
void update();
215+
88216
/**Recalculates the portion of the multiframe item which is shown in each of it's
89217
* component frames. If the resize mode is set to anything but UseExistingFrames then
90218
* this may cause new frames to be added or frames to be removed, in order to fit
91219
* the current size of the multiframe's content.
220+
* @see recalculateFrameRects
92221
*/
93-
void recalculateFrameSizes();
222+
virtual void recalculateFrameSizes();
94223

95-
protected slots:
96-
/**Called before a frame is going to be removed (update frame list)*/
97-
void handleFrameRemoval( QgsComposerItem* item );
98-
/**Adapts to changed number of pages if resize type is RepeatOnEveryPage*/
99-
void handlePageChange();
224+
/**Forces a recalculation of all the associated frame's scene rectangles. This
225+
* method is useful for multiframes which implement a minFrameSize() or
226+
* fixedFrameSize() method.
227+
* @note added in version 2.5
228+
* @see minFrameSize()
229+
* @see fixedFrameSize()
230+
* @see recalculateFrameSizes
231+
*/
232+
void recalculateFrameRects();
100233

101234
signals:
235+
236+
/**Emitted when the properties of a multi frame have changed, and the GUI item widget
237+
* must be updated.
238+
*/
102239
void changed();
103240

104241
/**Emitted when the contents of the multi frame have changed and the frames
105242
* must be redrawn.
106243
*/
107244
void contentsChanged();
245+
246+
protected slots:
247+
248+
/**Called before a frame is going to be removed. Updates frame list and recalculates
249+
* content of remaining frames.
250+
*/
251+
void handleFrameRemoval( QgsComposerItem* item );
252+
253+
/**Adapts to changed number of composition pages if resize type is RepeatOnEveryPage.
254+
*/
255+
void handlePageChange();
256+
108257
};

‎python/core/composer/qgscomposermultiframecommand.sip

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ class QgsComposerMultiFrameMergeCommand: QgsComposerMultiFrameCommand
4545
//composer html
4646
HtmlSource,
4747
HtmlStylesheet,
48-
HtmlBreakDistance
48+
HtmlBreakDistance,
49+
//attribute table
50+
TableMaximumFeatures,
51+
TableMargin,
52+
TableGridStrokeWidth
4953
};
5054

5155
QgsComposerMultiFrameMergeCommand( Context c, QgsComposerMultiFrame* multiFrame, const QString& text );
Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
1+
/**List of QVariants, representing a the contents of a single row in
2+
* a QgsComposerTable
3+
* \note Added in version 2.5
4+
*/
5+
typedef QList< QVariant > QgsComposerTableRow;
6+
7+
/**List of QgsComposerTableRows, representing rows and column cell contents
8+
* for a QgsComposerTable
9+
* \note Added in version 2.5
10+
*/
11+
typedef QList< QgsComposerTableRow > QgsComposerTableContents;
12+
13+
/**List of column definitions for a QgsComposerTable
14+
* \note Added in version 2.5
15+
*/
16+
typedef QList<QgsComposerTableColumn*> QgsComposerTableColumns;
17+
18+
/**A class to display a table in the print composer, and allow
19+
* the table to span over multiple frames
20+
* @note added in QGIS 2.5
21+
*/
22+
class QgsComposerTableV2: QgsComposerMultiFrame
23+
{
24+
%TypeHeaderCode
25+
#include <qgscomposertablev2.h>
26+
%End
27+
28+
public:
29+
30+
/*! Controls how headers are horizontally aligned in a table
31+
*/
32+
enum HeaderHAlignment
33+
{
34+
FollowColumn, /*!< header uses the same alignment as the column */
35+
HeaderLeft, /*!< align headers left */
36+
HeaderCenter, /*!< align headers to center */
37+
HeaderRight /*!< align headers right */
38+
};
39+
40+
/*! Controls where headers are shown in the table
41+
*/
42+
enum HeaderMode
43+
{
44+
FirstFrame, /*!< header shown on first frame only */
45+
AllFrames, /*!< headers shown on all frames */
46+
NoHeaders /*!< no headers shown for table */
47+
};
48+
49+
QgsComposerTableV2( QgsComposition* composition, bool createUndoCommands );
50+
QgsComposerTableV2();
51+
52+
virtual ~QgsComposerTableV2();
53+
54+
/**Sets the margin distance between cell borders and their contents.
55+
* @param margin margin for cell contents
56+
* @see cellMargin
57+
*/
58+
void setCellMargin( const double margin );
59+
60+
/**Returns the margin distance between cell borders and their contents.
61+
* @returns margin for cell contents
62+
* @see setCellMargin
63+
*/
64+
double cellMargin() const;
65+
66+
/**Sets the font used to draw header text in the table.
67+
* @param font font for header cells
68+
* @see headerFont
69+
* @see setContentFont
70+
*/
71+
void setHeaderFont( const QFont& font );
72+
73+
/**Returns the font used to draw header text in the table.
74+
* @returns font for header cells
75+
* @see setHeaderFont
76+
* @see contentFont
77+
*/
78+
QFont headerFont() const;
79+
80+
/**Sets the color used to draw header text in the table.
81+
* @param color header text color
82+
* @see headerFontColor
83+
* @see setHeaderFont
84+
* @see setContentFontColor
85+
*/
86+
void setHeaderFontColor( const QColor& color );
87+
88+
/**Returns the color used to draw header text in the table.
89+
* @returns color for header text
90+
* @see setHeaderFontColor
91+
* @see headerFont
92+
* @see contentFontColor
93+
*/
94+
QColor headerFontColor() const;
95+
96+
/**Sets the horizontal alignment for table headers
97+
* @param alignment Horizontal alignment for table header cells
98+
* @see headerHAlignment
99+
*/
100+
void setHeaderHAlignment( const HeaderHAlignment alignment );
101+
102+
/**Returns the horizontal alignment for table headers
103+
* @returns Horizontal alignment for table header cells
104+
* @see setHeaderHAlignment
105+
*/
106+
HeaderHAlignment headerHAlignment() const;
107+
108+
/**Sets the display mode for headers in the table. This property controls
109+
* if and where headers are shown in the table.
110+
* @param mode display mode for headers
111+
* @see headerMode
112+
*/
113+
void setHeaderMode( const HeaderMode mode );
114+
115+
/**Returns the display mode for headers in the table. This property controls
116+
* if and where headers are shown in the table.
117+
* @returns display mode for headers
118+
* @see setHeaderMode
119+
*/
120+
HeaderMode headerMode() const;
121+
122+
/**Sets the font used to draw text in table body cells.
123+
* @param font font for table cells
124+
* @see contentFont
125+
* @see setHeaderFont
126+
*/
127+
void setContentFont( const QFont& font );
128+
129+
/**Returns the font used to draw text in table body cells.
130+
* @returns font for table cells
131+
* @see setContentFont
132+
* @see headerFont
133+
*/
134+
QFont contentFont() const;
135+
136+
/**Sets the color used to draw text in table body cells.
137+
* @param color table cell text color
138+
* @see contentFontColor
139+
* @see setContentFont
140+
* @see setHeaderFontColor
141+
*/
142+
void setContentFontColor( const QColor& color );
143+
144+
/**Returns the color used to draw text in table body cells.
145+
* @returns text color for table cells
146+
* @see setContentFontColor
147+
* @see contentFont
148+
* @see headerFontColor
149+
*/
150+
QColor contentFontColor() const;
151+
152+
/**Sets whether grid lines should be drawn in the table
153+
* @param showGrid set to true to show grid lines
154+
* @see showGrid
155+
* @see setGridStrokeWidth
156+
* @see setGridColor
157+
*/
158+
void setShowGrid( const bool showGrid );
159+
160+
/**Returns whether grid lines are drawn in the table
161+
* @returns true if grid lines are shown
162+
* @see setShowGrid
163+
* @see gridStrokeWidth
164+
* @see gridColor
165+
*/
166+
bool showGrid() const;
167+
168+
/**Sets the width for grid lines in the table.
169+
* @param width grid line width
170+
* @see gridStrokeWidth
171+
* @see setShowGrid
172+
* @see setGridColor
173+
*/
174+
void setGridStrokeWidth( const double width );
175+
176+
/**Returns the width of grid lines in the table.
177+
* @returns grid line width
178+
* @see setGridStrokeWidth
179+
* @see showGrid
180+
* @see gridColor
181+
*/
182+
double gridStrokeWidth() const;
183+
184+
/**Sets color used for grid lines in the table.
185+
* @param color grid line color
186+
* @see gridColor
187+
* @see setShowGrid
188+
* @see setGridStrokeWidth
189+
*/
190+
void setGridColor( const QColor& color );
191+
192+
/**Returns the color used for grid lines in the table.
193+
* @returns grid line color
194+
* @see setGridColor
195+
* @see showGrid
196+
* @see gridStrokeWidth
197+
*/
198+
QColor gridColor() const;
199+
200+
/**Returns a pointer to the list of QgsComposerTableColumns shown in the table
201+
* @returns pointer to list of columns in table
202+
* @see setColumns
203+
*/
204+
QgsComposerTableColumns* columns();
205+
206+
/**Replaces the columns in the table with a specified list of QgsComposerTableColumns.
207+
* @param columns list of QgsComposerTableColumns to show in table
208+
* @see columns
209+
*/
210+
void setColumns( QgsComposerTableColumns columns );
211+
212+
/**Returns the text used in the column headers for the table.
213+
* @returns QMap of int to QString, where the int is the column index (starting at 0),
214+
* and the string is the text to use for the column's header
215+
* @note not available in python bindings
216+
*/
217+
virtual QMap<int, QString> headerLabels() const;
218+
219+
/**Fetches the contents used for the cells in the table.
220+
* @returns true if table contents were successfully retrieved.
221+
* @param contents QgsComposerTableContents to store retrieved row data in
222+
* @note not available in python bindings
223+
*/
224+
virtual bool getTableContents( QgsComposerTableContents &contents ) = 0;
225+
226+
//reimplemented to return fixed table width
227+
virtual QSizeF fixedFrameSize( const int frameIndex = -1 ) const;
228+
229+
//reimplemented to return min frame height
230+
virtual QSizeF minFrameSize( const int frameIndex = -1 ) const;
231+
232+
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
233+
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
234+
virtual QSizeF totalSize() const;
235+
virtual void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
236+
237+
public slots:
238+
239+
/**Refreshes the contents shown in the table by querying for new data.
240+
* This also causes the column widths and size of the table to change to accommodate the
241+
* new data.
242+
* @see adjustFrameToSize
243+
*/
244+
virtual void refreshAttributes();
245+
246+
void recalculateFrameSizes();
247+
248+
protected:
249+
250+
/**Calculates the maximum width of text shown in columns.
251+
*/
252+
virtual bool calculateMaxColumnWidths();
253+
254+
/**Returns total width of table contents.
255+
* @returns table width
256+
* @see totalHeight
257+
*/
258+
//not const, as needs to call calculateMaxColumnWidths()
259+
double totalWidth();
260+
261+
/**Returns total height of table contents.
262+
* @returns total height
263+
* @see totalWidth
264+
*/
265+
double totalHeight() const;
266+
267+
/**Calculates how many content rows are visible within a given frame
268+
* @param frameIndex index number for frame
269+
* @returns number of visible content rows (excludes header rows)
270+
*/
271+
int rowsVisible( const int frameIndex ) const;
272+
273+
/**Calculates how many content rows would be visible within a specified
274+
* height.
275+
* @param frameHeight height of frame
276+
* @param includeHeader set to true if frame would include a header row
277+
* @returns number of visible content rows (excluding header row)
278+
*/
279+
int rowsVisible( const double frameHeight, const bool includeHeader ) const;
280+
281+
/**Calculates a range of rows which should be visible in a given
282+
* frame extent.
283+
* @param extent visible extent
284+
* @param frameIndex index number for frame
285+
* @returns row range
286+
*/
287+
QPair<int, int> rowRange( const QRectF extent, const int frameIndex ) const;
288+
289+
/**Draws the horizontal grid lines for the table.
290+
* @param painter destination painter for grid lines
291+
* @param rows number of rows shown in table
292+
* @param drawHeaderLines set to true to include for the table header
293+
* @see drawVerticalGridLines
294+
*/
295+
void drawHorizontalGridLines( QPainter* painter, const int rows, const bool drawHeaderLines ) const;
296+
297+
/**Draws the vertical grid lines for the table.
298+
* @param painter destination painter for grid lines
299+
* @param maxWidthMap QMap of int to double, where the int contains the column number and the double is the
300+
* maximum width of text present in the column.
301+
* @param numberRows number of rows of content in table frame
302+
* @param hasHeader set to true if table frame includes header cells
303+
* @note not available in python bindings
304+
* @see drawVerticalGridLines
305+
* @see calculateMaxColumnWidths
306+
* @note not available in python bindings
307+
*/
308+
//void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, const int numberRows, const bool hasHeader ) const;
309+
310+
/**Recalculates and updates the size of the table and all table frames.
311+
*/
312+
void recalculateTableSize();
313+
314+
};

‎python/core/composer/qgscomposition.sip

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ class QgsComposition : QGraphicsScene
400400

401401
void beginMultiFrameCommand( QgsComposerMultiFrame* multiFrame, const QString& text, const QgsComposerMultiFrameMergeCommand::Context c = QgsComposerMultiFrameMergeCommand::Unknown );
402402
void endMultiFrameCommand();
403+
/**Deletes current multi frame command*/
404+
void cancelMultiFrameCommand();
403405

404406
/**Adds multiframe. The object is owned by QgsComposition until removeMultiFrame is called*/
405407
void addMultiFrame( QgsComposerMultiFrame* multiFrame );
@@ -422,8 +424,10 @@ class QgsComposition : QGraphicsScene
422424
void addComposerShape( QgsComposerShape* shape );
423425
/**Adds a composer table to the graphics scene and advices composer to create a widget for it (through signal)*/
424426
void addComposerTable( QgsComposerAttributeTable* table );
425-
/**Adds composer html frame and advices composer to create a widget for it (through signal)*/
427+
/**Adds composer html frame and advises composer to create a widget for it (through signal)*/
426428
void addComposerHtmlFrame( QgsComposerHtml* html /Transfer/, QgsComposerFrame* frame /Transfer/);
429+
/**Adds composer tablev2 frame and advises composer to create a widget for it (through signal)*/
430+
void addComposerTableFrame( QgsComposerAttributeTableV2* table /Transfer/, QgsComposerFrame* frame /Transfer/);
427431

428432
/**Remove item from the graphics scene. Additionally to QGraphicsScene::removeItem, this function considers undo/redo command*/
429433
void removeComposerItem( QgsComposerItem* item, const bool createCommand = true, const bool removeGroupItems = true );
@@ -589,6 +593,8 @@ class QgsComposition : QGraphicsScene
589593
void composerShapeAdded( QgsComposerShape* shape );
590594
/**Is emitted when a new composer table has been added*/
591595
void composerTableAdded( QgsComposerAttributeTable* table );
596+
/**Is emitted when a new composer table frame has been added to the view*/
597+
void composerTableFrameAdded( QgsComposerAttributeTableV2* table, QgsComposerFrame* frame );
592598
/**Is emitted when a composer item has been removed from the scene*/
593599
void itemRemoved( QgsComposerItem* );
594600

‎python/core/core.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@
121121
%Include composer/qgscomposerarrow.sip
122122
%Include composer/qgscomposerattributetable.sip
123123
%Include composer/qgscomposerattributetablemodel.sip
124+
%Include composer/qgscomposerattributetablemodelv2.sip
125+
%Include composer/qgscomposerattributetablev2.sip
124126
%Include composer/qgscomposerframe.sip
125127
%Include composer/qgscomposerhtml.sip
126128
%Include composer/qgscomposerobject.sip
@@ -139,6 +141,7 @@
139141
%Include composer/qgscomposershape.sip
140142
%Include composer/qgscomposertable.sip
141143
%Include composer/qgscomposertablecolumn.sip
144+
%Include composer/qgscomposertablev2.sip
142145
%Include composer/qgscomposerutils.sip
143146
%Include composer/qgscomposition.sip
144147
%Include composer/qgscomposermodel.sip

‎python/gui/qgscomposerview.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class QgsComposerView : QGraphicsView
3535
AddEllipse,
3636
AddTriangle,
3737
AddTable, // add attribute table
38+
AddAttributeTable,
3839
MoveItemContent, // move content of item (e.g. content of map)
3940
Pan,
4041
Zoom

‎src/app/composer/qgscomposerattributetablewidget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ QgsComposerAttributeTableWidget::QgsComposerAttributeTableWidget( QgsComposerAtt
5151
refreshMapComboBox();
5252

5353
mHeaderFontColorButton->setColorDialogTitle( tr( "Select header font color" ) );
54-
mHeaderFontColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
54+
mHeaderFontColorButton->setAllowAlpha( true );
5555
mHeaderFontColorButton->setContext( "composer" );
5656
mContentFontColorButton->setColorDialogTitle( tr( "Select content font color" ) );
57-
mContentFontColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
57+
mContentFontColorButton->setAllowAlpha( true );
5858
mContentFontColorButton->setContext( "composer" );
5959
mGridColorButton->setColorDialogTitle( tr( "Select grid color" ) );
60-
mGridColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
60+
mGridColorButton->setAllowAlpha( true );
6161
mGridColorButton->setContext( "composer" );
6262

6363
updateGuiElements();

‎src/core/composer/qgscomposerattributetablemodelv2.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ class CORE_EXPORT QgsComposerTableSortColumnsProxyModelV2: public QSortFilterPro
172172
*/
173173
QgsComposerTableColumn* columnFromIndex( const QModelIndex & index ) const;
174174

175-
176175
/**Returns the QgsComposerTableColumn corresponding to an index from the source
177176
* QgsComposerAttributeTableColumnModel model.
178177
* @returns QgsComposerTableColumn for specified index from QgsComposerAttributeTableColumnModel

‎src/core/composer/qgscomposerattributetablev2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ bool QgsComposerAttributeTableV2::getTableContents( QgsComposerTableContents &co
424424
qStableSort( contents.begin(), contents.end(), c );
425425
}
426426

427-
adjustFrameToSize();
427+
recalculateTableSize();
428428
return true;
429429
}
430430

‎src/core/composer/qgscomposerattributetablev2.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ class CORE_EXPORT QgsComposerAttributeTableCompareV2
4747
};
4848

4949

50-
/**A table class that displays a vector attribute table*/
50+
/**A table that displays attributes from a vector layer*/
5151
class CORE_EXPORT QgsComposerAttributeTableV2: public QgsComposerTableV2
5252
{
5353
Q_OBJECT
54+
5455
public:
5556
QgsComposerAttributeTableV2( QgsComposition* composition, bool createUndoCommands );
5657
~QgsComposerAttributeTableV2();

‎src/core/composer/qgscomposerframe.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@
2121
class QgsComposition;
2222
class QgsComposerMultiFrame;
2323

24-
/**Frame for html, table, text which can be divided onto several frames*/
24+
/**Frame item for a composer multiframe item*/
2525
class CORE_EXPORT QgsComposerFrame: public QgsComposerItem
2626
{
27+
2728
public:
29+
2830
QgsComposerFrame( QgsComposition* c, QgsComposerMultiFrame* mf, qreal x, qreal y, qreal width, qreal height );
31+
2932
~QgsComposerFrame();
3033

31-
/**Sets the part of this frame (relative to the total multiframe extent in mm)*/
34+
/**Sets the visible part of the multiframe's content which is visible within
35+
* this frame (relative to the total multiframe extent in mm).
36+
* @param section visible portion of content
37+
* @see extent
38+
*/
3239
void setContentSection( const QRectF& section ) { mSection = section; }
3340

34-
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
35-
36-
void beginItemCommand( const QString& text );
37-
void endItemCommand();
38-
39-
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
40-
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
41-
42-
int type() const { return ComposerFrame; }
43-
41+
/**Returns the parent multiframe for the frame.
42+
* @returns parent multiframe
43+
*/
4444
QgsComposerMultiFrame* multiFrame() const { return mMultiFrame; }
4545

4646
//Overriden to allow multiframe to set display name
@@ -49,10 +49,18 @@ class CORE_EXPORT QgsComposerFrame: public QgsComposerItem
4949
//Overriden to handle fixed frame sizes set by multi frame
5050
void setSceneRect( const QRectF& rectangle );
5151

52+
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
53+
void beginItemCommand( const QString& text );
54+
void endItemCommand();
55+
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
56+
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
57+
int type() const { return ComposerFrame; }
58+
5259
/**Returns the visible portion of the multi frame's content which
5360
* is shown in this frame.
5461
* @returns extent of visible portion
5562
* @note added in QGIS 2.5
63+
* @see setContentSection
5664
*/
5765
QRectF extent() const { return mSection; }
5866

‎src/core/composer/qgscomposerhtml.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,6 @@ class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
117117
*/
118118
void setEvaluateExpressions( bool evaluateExpressions );
119119

120-
QSizeF totalSize() const;
121-
void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
122-
123-
bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
124-
bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
125-
126-
void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
127-
128-
//overriden to break frames without dividing lines of text
129-
double findNearbyPageBreak( double yPos );
130-
131120
/**Returns whether html item is using smart breaks. Smart breaks prevent
132121
* the html frame contents from breaking mid-way though a line of text.
133122
* @returns true if html item is using smart breaks
@@ -206,6 +195,13 @@ class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
206195
bool userStylesheetEnabled() const { return mEnableUserStylesheet; }
207196

208197
virtual QString displayName() const;
198+
QSizeF totalSize() const;
199+
void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
200+
bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
201+
bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
202+
void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
203+
//overriden to break frames without dividing lines of text
204+
double findNearbyPageBreak( double yPos );
209205

210206
public slots:
211207

‎src/core/composer/qgscomposermultiframe.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ void QgsComposerMultiFrame::render( QPainter *p, const QRectF &renderExtent )
4747
Q_UNUSED( renderExtent );
4848
}
4949

50-
void QgsComposerMultiFrame::render( QPainter *p, const QRectF &renderExtent, const int frameIndex )
50+
void QgsComposerMultiFrame::render( QPainter *painter, const QRectF &renderExtent, const int frameIndex )
5151
{
5252
Q_UNUSED( frameIndex );
5353
//base implementation ignores frameIndex
5454
Q_NOWARN_DEPRECATED_PUSH
55-
render( p, renderExtent );
55+
render( painter, renderExtent );
5656
Q_NOWARN_DEPRECATED_POP
5757
}
5858

‎src/core/composer/qgscomposermultiframe.h

Lines changed: 145 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,47 @@ class QDomElement;
2929
class QRectF;
3030
class QPainter;
3131

32-
/**Abstract base class for composer entries with the ability to distribute the content to several frames (items)*/
32+
/**
33+
* \ingroup composer
34+
* \class QgsComposerMultiFrame
35+
* Abstract base class for composer items with the ability to distribute the content to several frames
36+
* (QgsComposerFrame items).
37+
*/
38+
3339
class CORE_EXPORT QgsComposerMultiFrame: public QgsComposerObject
3440
{
3541
Q_OBJECT
42+
3643
public:
3744

45+
/*! Specifies the behaviour for creating new frames to fit the multiframe's content
46+
*/
3847
enum ResizeMode
3948
{
40-
UseExistingFrames = 0,
41-
ExtendToNextPage, //uses the next page(s) until the content has been printed
42-
RepeatOnEveryPage, //repeats the same frame on every page
43-
RepeatUntilFinished //duplicates last frame to next page to fit the total size
49+
UseExistingFrames = 0, /*!< don't automatically create new frames, just use existing frames */
50+
ExtendToNextPage, /*!< creates new full page frames on the following page(s) until the entire multiframe content is visible */
51+
RepeatOnEveryPage, /*!< repeats the same frame on every page */
52+
RepeatUntilFinished /*!< creates new frames with the same position and dimensions as the existing frame on the following page(s),
53+
until the entire multiframe content is visible */
4454
};
4555

56+
/**Construct a new multiframe item.
57+
* @param c parent composition
58+
* @param createUndoCommands
59+
*/
4660
QgsComposerMultiFrame( QgsComposition* c, bool createUndoCommands );
61+
4762
virtual ~QgsComposerMultiFrame();
63+
64+
/**Returns the total size of the multiframe's content.
65+
* @returns total size required for content
66+
*/
4867
virtual QSizeF totalSize() const = 0;
4968

50-
/**Returns a fixed size for the frames, if desired. If the fixed frame size changes,
69+
/**Returns the fixed size for a frame, if desired. If the fixed frame size changes,
5170
* the sizes of all frames can be recalculated by calling recalculateFrameRects().
5271
* @param frameIndex frame number
53-
* @returns fixed size for frames. If the size has a width or height of 0, then
72+
* @returns fixed size for frame. If the size has a width or height of 0, then
5473
* the frame size is not fixed in that direction and frames can have variable width
5574
* or height accordingly.
5675
* @note added in version 2.5
@@ -59,63 +78,144 @@ class CORE_EXPORT QgsComposerMultiFrame: public QgsComposerObject
5978
*/
6079
virtual QSizeF fixedFrameSize( const int frameIndex = -1 ) const { Q_UNUSED( frameIndex ); return QSizeF( 0, 0 ); }
6180

62-
/**Returns the minimum size size for the frames, if desired. If the minimum
81+
/**Returns the minimum size for a frames, if desired. If the minimum
6382
* size changes, the sizes of all frames can be recalculated by calling
6483
* recalculateFrameRects().
6584
* @param frameIndex frame number
66-
* @returns minimum size for frames. If the size has a width or height of 0, then
85+
* @returns minimum size for frame. If the size has a width or height of 0, then
6786
* the frame size has no minimum in that direction.
6887
* @note added in version 2.5
6988
* @see fixedFrameSize
7089
* @see recalculateFrameRects
7190
*/
7291
virtual QSizeF minFrameSize( const int frameIndex = -1 ) const { Q_UNUSED( frameIndex ); return QSizeF( 0, 0 ); }
7392

93+
/**Renders a portion of the multiframe's content into a painter.
94+
* @param p destination painter
95+
* @param renderExtent visible extent of content to render into the painter.
96+
* @deprecated use render( QPainter* painter, const QRectF& renderExtent, const int frameIndex ) instead
97+
*/
7498
Q_DECL_DEPRECATED virtual void render( QPainter* p, const QRectF& renderExtent );
7599

76-
virtual void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
100+
/**Renders a portion of the multiframe's content into a painter.
101+
* @param painter destination painter
102+
* @param renderExtent visible extent of content to render into the painter.
103+
* @param frameIndex frame number for content
104+
* @note added in version 2.5
105+
*/
106+
virtual void render( QPainter* painter, const QRectF& renderExtent, const int frameIndex );
77107

108+
/**Adds a frame to the multiframe.
109+
* @param frame frame to add
110+
* @param recalcFrameSizes set to true to force recalculation of all existing frame sizes
111+
* @see removeFrame
112+
*/
78113
virtual void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true ) = 0;
79114

80115
/**Finds the optimal position to break a frame at.
81116
* @param yPos maximum vertical position for break
82117
* @returns the optimal breakable position which occurs in the multi frame close
83118
* to and before the specified yPos
84-
* @note added in version 2.3*/
119+
* @note added in version 2.3
120+
*/
85121
virtual double findNearbyPageBreak( double yPos ) { return yPos; }
86122

123+
/**Removes a frame from the multiframe. This method automatically removes the frame from the
124+
* composition.
125+
* @param i index of frame to remove
126+
* @see addFrame
127+
* @see deleteFrames
128+
*/
87129
void removeFrame( int i );
88130

89-
void update();
131+
/**Removes and deletes all child frames.
132+
* @see removeFrame
133+
*/
134+
void deleteFrames();
90135

136+
/**Sets the resize mode for the multiframe, and recalculates frame sizes to match.
137+
* @param mode resize mode
138+
* @see resizeMode
139+
*/
91140
void setResizeMode( ResizeMode mode );
141+
142+
/**Returns the resize mode for the multiframe.
143+
* @returns resize mode
144+
* @see setResizeMode
145+
*/
92146
ResizeMode resizeMode() const { return mResizeMode; }
93147

148+
/**Stores state information about multiframe in DOM element. Implementations of writeXML
149+
* should also call the _writeXML method to save general multiframe properties.
150+
* @param elem is DOM element
151+
* @param doc is the DOM document
152+
* @param ignoreFrames set to false to avoid writing state information about child frames into DOM
153+
* @see _writeXML
154+
*/
94155
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const = 0;
156+
157+
/**Stores state information about base multiframe object in DOM element. Implementations of writeXML
158+
* should call this method.
159+
* @param elem is DOM element
160+
* @param doc is the DOM document
161+
* @param ignoreFrames set to false to avoid writing state information about child frames into DOM
162+
* @see writeXML
163+
*/
95164
bool _writeXML( QDomElement& elem, QDomDocument& doc, bool ignoreFrames = false ) const;
96165

166+
/**Reads multiframe state information from a DOM element. Implementations of readXML
167+
* should also call the _readXML method to restore general multiframe properties.
168+
* @param itemElem is DOM element
169+
* @param doc is the DOM document
170+
* @param ignoreFrames set to false to avoid read state information about child frames from DOM
171+
* @see _readXML
172+
*/
97173
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false ) = 0;
174+
175+
/**Restores state information about base multiframe object from a DOM element. Implementations of readXML
176+
* should call this method.
177+
* @param itemElem is DOM element
178+
* @param doc is the DOM document
179+
* @param ignoreFrames set to false to avoid reading state information about child frames from DOM
180+
* @see readXML
181+
*/
98182
bool _readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
99183

184+
/**Returns the parent composition for the multiframe.
185+
* @returns composition
186+
*/
100187
QgsComposition* composition() { return mComposition; }
101188

189+
/**Returns whether undo commands should be created for interactions with the multiframe.
190+
* @returns true if undo commands should be created
191+
* @see setCreateUndoCommands
192+
*/
102193
bool createUndoCommands() const { return mCreateUndoCommands; }
103-
void setCreateUndoCommands( bool enabled ) { mCreateUndoCommands = enabled; }
104194

105-
/**Removes and deletes all frames from mComposition*/
106-
void deleteFrames();
195+
/**Sets whether undo commands should be created for interactions with the multiframe.
196+
* @param enabled set to true if undo commands should be created
197+
* @see createUndoCommands
198+
*/
199+
void setCreateUndoCommands( bool enabled ) { mCreateUndoCommands = enabled; }
107200

108-
/** Return the number of frames associated with this multiframeset.
109-
@note added in 2.0, replaces nFrames
201+
/**Returns the number of frames associated with this multiframe.
202+
* @returns number of child frames
203+
* @note added in QGIS 2.0, replaces nFrames
110204
**/
111205
int frameCount() const { return mFrameItems.size(); }
112206

207+
/**Returns a child frame from the multiframe.
208+
* @param i index of frame
209+
* @returns child frame if found
210+
* @see frameIndex
211+
*/
113212
QgsComposerFrame* frame( int i ) const;
114213

115214
/**Returns the index of a frame within the multiframe
116215
* @param frame frame to find index of
117216
* @returns index for frame if found, -1 if frame not found in multiframe
118217
* @note added in version 2.5
218+
* @see frame
119219
*/
120220
int frameIndex( QgsComposerFrame *frame ) const;
121221

@@ -137,10 +237,15 @@ class CORE_EXPORT QgsComposerMultiFrame: public QgsComposerObject
137237

138238
public slots:
139239

240+
/**Forces a redraw of all child frames.
241+
*/
242+
void update();
243+
140244
/**Recalculates the portion of the multiframe item which is shown in each of it's
141245
* component frames. If the resize mode is set to anything but UseExistingFrames then
142246
* this may cause new frames to be added or frames to be removed, in order to fit
143247
* the current size of the multiframe's content.
248+
* @see recalculateFrameRects
144249
*/
145250
virtual void recalculateFrameSizes();
146251

@@ -150,33 +255,47 @@ class CORE_EXPORT QgsComposerMultiFrame: public QgsComposerObject
150255
* @note added in version 2.5
151256
* @see minFrameSize()
152257
* @see fixedFrameSize()
258+
* @see recalculateFrameSizes
153259
*/
154260
void recalculateFrameRects();
155261

262+
signals:
263+
264+
/**Emitted when the properties of a multi frame have changed, and the GUI item widget
265+
* must be updated.
266+
*/
267+
void changed();
268+
269+
/**Emitted when the contents of the multi frame have changed and the frames
270+
* must be redrawn.
271+
*/
272+
void contentsChanged();
273+
156274
protected:
275+
157276
QList<QgsComposerFrame*> mFrameItems;
277+
158278
ResizeMode mResizeMode;
279+
159280
/**True: creates QgsMultiFrameCommands on internal changes (e.g. changing frames )*/
160281
bool mCreateUndoCommands;
161282

162283
protected slots:
163-
/**Called before a frame is going to be removed (update frame list)*/
284+
285+
/**Called before a frame is going to be removed. Updates frame list and recalculates
286+
* content of remaining frames.
287+
*/
164288
void handleFrameRemoval( QgsComposerItem* item );
165-
/**Adapts to changed number of pages if resize type is RepeatOnEveryPage*/
289+
290+
/**Adapts to changed number of composition pages if resize type is RepeatOnEveryPage.
291+
*/
166292
void handlePageChange();
167293

168294
private:
169295
QgsComposerMultiFrame(); //forbidden
170296

171297
bool mIsRecalculatingSize;
172298

173-
signals:
174-
void changed();
175-
176-
/**Emitted when the contents of the multi frame have changed and the frames
177-
* must be redrawn.
178-
*/
179-
void contentsChanged();
180299
};
181300

182301
#endif // QGSCOMPOSERMULTIFRAME_H

‎src/core/composer/qgscomposertablev2.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void QgsComposerTableV2::setCellMargin( const double margin )
342342
mCellMargin = margin;
343343

344344
//since spacing has changed, we need to recalculate the table size
345-
adjustFrameToSize();
345+
recalculateTableSize();
346346

347347
emit changed();
348348
}
@@ -356,7 +356,7 @@ void QgsComposerTableV2::setHeaderFont( const QFont &font )
356356

357357
mHeaderFont = font;
358358
//since font attributes have changed, we need to recalculate the table size
359-
adjustFrameToSize();
359+
recalculateTableSize();
360360

361361
emit changed();
362362
}
@@ -395,7 +395,7 @@ void QgsComposerTableV2::setHeaderMode( const QgsComposerTableV2::HeaderMode mod
395395
}
396396

397397
mHeaderMode = mode;
398-
adjustFrameToSize();
398+
recalculateTableSize();
399399

400400
emit changed();
401401
}
@@ -409,7 +409,7 @@ void QgsComposerTableV2::setContentFont( const QFont &font )
409409

410410
mContentFont = font;
411411
//since font attributes have changed, we need to recalculate the table size
412-
adjustFrameToSize();
412+
recalculateTableSize();
413413

414414
emit changed();
415415
}
@@ -436,7 +436,7 @@ void QgsComposerTableV2::setShowGrid( const bool showGrid )
436436

437437
mShowGrid = showGrid;
438438
//since grid spacing has changed, we need to recalculate the table size
439-
adjustFrameToSize();
439+
recalculateTableSize();
440440

441441
emit changed();
442442
}
@@ -450,7 +450,7 @@ void QgsComposerTableV2::setGridStrokeWidth( const double width )
450450

451451
mGridStrokeWidth = width;
452452
//since grid spacing has changed, we need to recalculate the table size
453-
adjustFrameToSize();
453+
recalculateTableSize();
454454

455455
emit changed();
456456
}
@@ -695,7 +695,7 @@ void QgsComposerTableV2::drawVerticalGridLines( QPainter *painter, const QMap<in
695695
}
696696
}
697697

698-
void QgsComposerTableV2::adjustFrameToSize()
698+
void QgsComposerTableV2::recalculateTableSize()
699699
{
700700
recalculateFrameSizes();
701701

‎src/core/composer/qgscomposertablev2.h

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ typedef QList< QgsComposerTableRow > QgsComposerTableContents;
4242
*/
4343
typedef QList<QgsComposerTableColumn*> QgsComposerTableColumns;
4444

45-
/**A class to display feature attributes in the print composer, and allow
45+
/**A class to display a table in the print composer, and allow
4646
* the table to span over multiple frames
4747
* @note added in QGIS 2.5
4848
*/
@@ -76,15 +76,6 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
7676

7777
virtual ~QgsComposerTableV2();
7878

79-
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
80-
81-
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
82-
83-
virtual QSizeF totalSize() const;
84-
85-
virtual void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
86-
87-
8879
/**Sets the margin distance between cell borders and their contents.
8980
* @param margin margin for cell contents
9081
* @see cellMargin
@@ -263,6 +254,11 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
263254
//reimplemented to return min frame height
264255
virtual QSizeF minFrameSize( const int frameIndex = -1 ) const;
265256

257+
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
258+
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
259+
virtual QSizeF totalSize() const;
260+
virtual void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
261+
266262
public slots:
267263

268264
/**Refreshes the contents shown in the table by querying for new data.
@@ -320,9 +316,17 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
320316
*/
321317
virtual bool calculateMaxColumnWidths();
322318

323-
//not const
319+
/**Returns total width of table contents.
320+
* @returns table width
321+
* @see totalHeight
322+
*/
323+
//not const, as needs to call calculateMaxColumnWidths()
324324
double totalWidth();
325325

326+
/**Returns total height of table contents.
327+
* @returns total height
328+
* @see totalWidth
329+
*/
326330
double totalHeight() const;
327331

328332
/**Calculates how many content rows are visible within a given frame
@@ -331,10 +335,16 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
331335
*/
332336
int rowsVisible( const int frameIndex ) const;
333337

338+
/**Calculates how many content rows would be visible within a specified
339+
* height.
340+
* @param frameHeight height of frame
341+
* @param includeHeader set to true if frame would include a header row
342+
* @returns number of visible content rows (excluding header row)
343+
*/
334344
int rowsVisible( const double frameHeight, const bool includeHeader ) const;
335345

336346
/**Calculates a range of rows which should be visible in a given
337-
* rectangle.
347+
* frame extent.
338348
* @param extent visible extent
339349
* @param frameIndex index number for frame
340350
* @returns row range
@@ -358,10 +368,13 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
358368
* @note not available in python bindings
359369
* @see drawVerticalGridLines
360370
* @see calculateMaxColumnWidths
371+
* @note not available in python bindings
361372
*/
362373
void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, const int numberRows, const bool hasHeader ) const;
363374

364-
void adjustFrameToSize();
375+
/**Recalculates and updates the size of the table and all table frames.
376+
*/
377+
void recalculateTableSize();
365378
};
366379

367380
#endif // QGSCOMPOSERTABLEV2_H

0 commit comments

Comments
 (0)
Please sign in to comment.