[composer] API docs and python bindings for QgsComposerTableV2 (sponsored

by City of Uster, Switzerland)
This commit is contained in:
Nyall Dawson 2014-09-17 21:52:19 +10:00
parent cb73905644
commit 9fd73901a6
22 changed files with 1123 additions and 162 deletions

View File

@ -232,8 +232,4 @@ class QgsComposerAttributeTable : QgsComposerTable
*/
// bool getFeatureAttributes( QList<QgsAttributeMap>& attributeMaps );
signals:
/**This signal is emitted if the maximum number of feature changes (interactively)*/
void maximumNumberOfFeaturesChanged( int n );
};

View File

@ -19,7 +19,7 @@ class QgsComposerAttributeTableColumnModel: QAbstractTableModel
* @param composerTable QgsComposerAttributeTable the model is attached to
* @param parent optional parent
*/
QgsComposerAttributeTableColumnModel( QgsComposerAttributeTable *composerTable, QObject *parent = 0 );
QgsComposerAttributeTableColumnModel( QgsComposerAttributeTable *composerTable, QObject *parent /TransferThis/ = 0 );
virtual ~QgsComposerAttributeTableColumnModel();
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
@ -114,7 +114,7 @@ class QgsComposerTableSortColumnsProxyModel : QSortFilterProxyModel
* @param filterType filter for columns, controls whether sorted or unsorted columns are shown
* @param parent optional parent
*/
QgsComposerTableSortColumnsProxyModel( QgsComposerAttributeTable *composerTable, ColumnFilterType filterType, QObject *parent = 0 );
QgsComposerTableSortColumnsProxyModel( QgsComposerAttributeTable *composerTable, ColumnFilterType filterType, QObject *parent /TransferThis/ = 0 );
virtual ~QgsComposerTableSortColumnsProxyModel();

View File

@ -0,0 +1,164 @@
/**A model for displaying columns shown in a QgsComposerAttributeTableV2*/
class QgsComposerAttributeTableColumnModelV2: QAbstractTableModel
{
%TypeHeaderCode
#include <qgscomposerattributetablemodelv2.h>
%End
public:
/*! Controls whether a row/column is shifted up or down
*/
enum ShiftDirection
{
ShiftUp, /*!< shift the row/column up */
ShiftDown /*!< shift the row/column down */
};
/**Constructor for QgsComposerAttributeTableColumnModel.
/**Constructor for QgsComposerAttributeTableColumnModel.
* @param composerTable QgsComposerAttributeTable the model is attached to
* @param parent optional parent
*/
QgsComposerAttributeTableColumnModelV2( QgsComposerAttributeTableV2 *composerTable, QObject *parent /TransferThis/ = 0 );
virtual ~QgsComposerAttributeTableColumnModelV2();
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
virtual QVariant data( const QModelIndex &index, int role ) const;
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole );
Qt::ItemFlags flags( const QModelIndex &index ) const;
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );
bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() );
QModelIndex index( int row, int column, const QModelIndex &parent ) const;
QModelIndex parent( const QModelIndex &child ) const;
/**Moves the specified row up or down in the model. Used for rearranging the attribute tables
* columns.
* @returns true if the move is allowed
* @param row row in model representing attribute table column to move
* @param direction direction to move the attribute table column
* @note added in 2.3
*/
bool moveRow( int row , ShiftDirection direction );
/**Resets the attribute table's columns to match the source layer's fields. Remove all existing
* attribute table columns and column customisations.
* @note added in 2.3
*/
void resetToLayer();
/**Returns the QgsComposerTableColumn corresponding to an index in the model.
* @returns QgsComposerTableColumn for specified index
* @param index a QModelIndex
* @note added in 2.3
* @see indexFromColumn
*/
QgsComposerTableColumn* columnFromIndex( const QModelIndex & index ) const;
/**Returns a QModelIndex corresponding to a QgsComposerTableColumn in the model.
* @returns QModelIndex for specified QgsComposerTableColumn
* @param column a QgsComposerTableColumn
* @note added in 2.3
* @see columnFromIndex
*/
QModelIndex indexFromColumn( QgsComposerTableColumn *column );
/**Sets a specified column as a sorted column in the QgsComposerAttributeTable. The column will be
* added to the end of the sort rank list, ie it will take the next largest available sort rank.
* @param column a QgsComposerTableColumn
* @param order sort order for column
* @note added in 2.3
* @see removeColumnFromSort
* @see moveColumnInSortRank
*/
void setColumnAsSorted( QgsComposerTableColumn *column, Qt::SortOrder order );
/**Sets a specified column as an unsorted column in the QgsComposerAttributeTable. The column will be
* removed from the sort rank list.
* @param column a QgsComposerTableColumn
* @note added in 2.3
* @see setColumnAsSorted
*/
void setColumnAsUnsorted( QgsComposerTableColumn * column );
/**Moves a column up or down in the sort rank for the QgsComposerAttributeTable.
* @param column a QgsComposerTableColumn
* @param direction direction to move the column in the sort rank list
* @note added in 2.3
* @see setColumnAsSorted
*/
bool moveColumnInSortRank( QgsComposerTableColumn * column, ShiftDirection direction );
};
/**Allows for filtering QgsComposerAttributeTable columns by columns which are sorted or unsorted*/
class QgsComposerTableSortColumnsProxyModelV2 : QSortFilterProxyModel
{
%TypeHeaderCode
#include <qgscomposerattributetablemodelv2.h>
%End
public:
/*! Controls whether the proxy model shows sorted or unsorted columns
*/
enum ColumnFilterType
{
ShowSortedColumns, /*!< show only sorted columns */
ShowUnsortedColumns/*!< show only unsorted columns */
};
/**Constructor for QgsComposerTableSortColumnsProxyModel.
* @param composerTable QgsComposerAttributeTable the model is attached to
* @param filterType filter for columns, controls whether sorted or unsorted columns are shown
* @param parent optional parent
*/
QgsComposerTableSortColumnsProxyModelV2( QgsComposerAttributeTableV2 *composerTable, ColumnFilterType filterType, QObject *parent /TransferThis/ = 0 );
virtual ~QgsComposerTableSortColumnsProxyModelV2();
bool lessThan( const QModelIndex &left, const QModelIndex &right ) const;
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
virtual QVariant data( const QModelIndex &index, int role ) const;
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
Qt::ItemFlags flags( const QModelIndex &index ) const;
virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole );
/**Returns the QgsComposerTableColumn corresponding to a row in the proxy model.
* @returns QgsComposerTableColumn for specified row
* @param row a row number
* @note added in 2.3
* @see columnFromIndex
*/
QgsComposerTableColumn* columnFromRow( int row );
/**Returns the QgsComposerTableColumn corresponding to an index in the proxy model.
* @returns QgsComposerTableColumn for specified index
* @param index a QModelIndex
* @note added in 2.3
* @see columnFromRow
* @see columnFromSourceIndex
*/
QgsComposerTableColumn* columnFromIndex( const QModelIndex & index ) const;
/**Returns the QgsComposerTableColumn corresponding to an index from the source
* QgsComposerAttributeTableColumnModel model.
* @returns QgsComposerTableColumn for specified index from QgsComposerAttributeTableColumnModel
* @param sourceIndex a QModelIndex
* @note added in 2.3
* @see columnFromRow
* @see columnFromIndex
*/
QgsComposerTableColumn* columnFromSourceIndex( const QModelIndex& sourceIndex ) const;
/**Invalidates the current filter used by the proxy model
* @note added in 2.3
*/
void resetFilter();
protected:
bool filterAcceptsRow( int source_row, const QModelIndex & source_parent ) const;
};

View File

@ -0,0 +1,180 @@
/**Helper class for sorting tables, takes into account sorting column and ascending / descending*/
class QgsComposerAttributeTableCompareV2
{
%TypeHeaderCode
#include <qgscomposerattributetablev2.h>
%End
public:
QgsComposerAttributeTableCompareV2();
bool operator()( const QgsComposerTableRow& m1, const QgsComposerTableRow& m2 );
/**Sets column number to sort by
* @param col column number for sorting
*/
void setSortColumn( int col );
/**Sets sort order for column sorting
* @param asc set to true to sort in ascending order, false to sort in descending order
*/
void setAscending( bool asc );
};
/**A table that displays attributes from a vector layer*/
class QgsComposerAttributeTableV2 : QgsComposerTableV2
{
%TypeHeaderCode
#include <qgscomposerattributetablev2.h>
%End
public:
QgsComposerAttributeTableV2( QgsComposition* composition, bool createUndoCommands );
~QgsComposerAttributeTableV2();
/**Writes properties specific to attribute tables
* @param elem an existing QDomElement in which to store the attribute table's properties.
* @param doc QDomDocument for the destination xml.
* @see readXML
*/
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
/**Reads the properties specific to an attribute table from xml.
* @param itemElem a QDomElement holding the attribute table's desired properties.
* @param doc QDomDocument for the source xml.
* @see writeXML
*/
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
virtual void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
/**Sets the vector layer from which to display feature attributes
* @param layer Vector layer for attribute table
* @see vectorLayer
*/
void setVectorLayer( QgsVectorLayer* layer );
/**Returns the vector layer the attribute table is currently using
* @returns attribute table's current vector layer
* @see setVectorLayer
*/
QgsVectorLayer* vectorLayer() const;
/**Resets the attribute table's columns to match the vector layer's fields
* @see setVectorLayer
*/
void resetColumns();
/**Sets the composer map to use to limit the extent of features shown in the
* attribute table. This setting only has an effect if setDisplayOnlyVisibleFeatures is
* set to true. Changing the composer map forces the table to refetch features from its
* vector layer, and may result in the table changing size to accommodate the new displayed
* feature attributes.
* @param map QgsComposerMap which drives the extents of the table's features
* @see composerMap
* @see setDisplayOnlyVisibleFeatures
*/
void setComposerMap( const QgsComposerMap* map );
/**Returns the composer map whose extents are controlling the features shown in the
* table. The extents of the map are only used if displayOnlyVisibleFeatures() is true.
* @returns composer map controlling the attribute table
* @see setComposerMap
* @see displayOnlyVisibleFeatures
*/
const QgsComposerMap* composerMap() const;
/**Sets the maximum number of features shown by the table. Changing this setting may result
* in the attribute table changing its size to accommodate the new number of rows, and requires
* the table to refetch features from its vector layer.
* @param features maximum number of features to show in the table
* @see maximumNumberOfFeatures
*/
void setMaximumNumberOfFeatures( int features );
/**Returns the maximum number of features to be shown by the table.
* @returns maximum number of features
* @see setMaximumNumberOfFeatures
*/
int maximumNumberOfFeatures() const;
/**Sets attribute table to only show features which are visible in a composer map item. Changing
* this setting forces the table to refetch features from its vector layer, and may result in
* the table changing size to accommodate the new displayed feature attributes.
* @param visibleOnly set to true to show only visible features
* @see displayOnlyVisibleFeatures
* @see setComposerMap
*/
void setDisplayOnlyVisibleFeatures( bool visibleOnly );
/**Returns true if the table is set to show only features visible on a corresponding
* composer map item.
* @returns true if table only shows visible features
* @see composerMap
* @see setDisplayOnlyVisibleFeatures
*/
bool displayOnlyVisibleFeatures() const;
/**Returns true if a feature filter is active on the attribute table
* @returns bool state of the feature filter
* @see setFilterFeatures
* @see featureFilter
*/
bool filterFeatures() const;
/**Sets whether the feature filter is active for the attribute table. Changing
* this setting forces the table to refetch features from its vector layer, and may result in
* the table changing size to accommodate the new displayed feature attributes.
* @param filter Set to true to enable the feature filter
* @see filterFeatures
* @see setFeatureFilter
*/
void setFilterFeatures( bool filter );
/**Returns the current expression used to filter features for the table. The filter is only
* active if filterFeatures() is true.
* @returns feature filter expression
* @see setFeatureFilter
* @see filterFeatures
*/
QString featureFilter() const;
/**Sets the expression used for filtering features in the table. The filter is only
* active if filterFeatures() is set to true. Changing this setting forces the table
* to refetch features from its vector layer, and may result in
* the table changing size to accommodate the new displayed feature attributes.
* @param expression filter to use for selecting which features to display in the table
* @see featureFilter
* @see setFilterFeatures
*/
void setFeatureFilter( const QString& expression );
/**Sets the attributes to display in the table.
* @param attr QSet of integer values refering to the attributes from the vector layer to show.
* Set to an empty QSet to show all feature attributes.
* @param refresh set to true to force the table to refetch features from its vector layer
* and immediately update the display of the table. This may result in the table changing size
* to accommodate the new displayed feature attributes.
* @see displayAttributes
*/
void setDisplayAttributes( const QSet<int>& attr, bool refresh = true );
/**Returns the attributes used to sort the table's features.
* @returns a QList of integer/bool pairs, where the integer refers to the attribute index and
* the bool to the sort order for the attribute. If true the attribute is sorted ascending,
* if false, the attribute is sorted in descending order.
* @note not available in python bindings
*/
//QList<QPair<int, bool> > sortAttributes() const;
/**Queries the attribute table's vector layer for attributes to show in the table.
* @param attributeMaps list of QgsAttributeMaps where the fetched feature attributes will be stored
* @returns true if attributes were successfully fetched
* @note not available in python bindings
*/
bool getTableContents( QgsComposerTableContents &contents );
};

View File

@ -1,4 +1,4 @@
/**Frame item for a composer multiframe item*/
class QgsComposerFrame: QgsComposerItem
{
%TypeHeaderCode
@ -9,24 +9,37 @@ class QgsComposerFrame: QgsComposerItem
QgsComposerFrame( QgsComposition* c, QgsComposerMultiFrame* mf, qreal x, qreal y, qreal width, qreal height );
~QgsComposerFrame();
/**Sets the part of this frame (relative to the total multiframe extent in mm)*/
/**Sets the visible part of the multiframe's content which is visible within
* this frame (relative to the total multiframe extent in mm).
* @param section visible portion of content
* @see extent
*/
void setContentSection( const QRectF& section );
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
void beginItemCommand( const QString& text );
void endItemCommand();
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
int type() const;
/**Returns the parent multiframe for the frame.
* @returns parent multiframe
*/
QgsComposerMultiFrame* multiFrame() const;
//Overriden to allow multiframe to set display name
virtual QString displayName() const;
//Overriden to handle fixed frame sizes set by multi frame
void setSceneRect( const QRectF& rectangle );
void setSceneRect( const QRectF& rectangle );
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
void beginItemCommand( const QString& text );
void endItemCommand();
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
int type() const;
/**Returns the visible portion of the multi frame's content which
* is shown in this frame.
* @returns extent of visible portion
* @note added in QGIS 2.5
* @see setContentSection
*/
QRectF extent() const;
};

View File

@ -94,18 +94,6 @@ class QgsComposerHtml: QgsComposerMultiFrame
*/
void setEvaluateExpressions( bool evaluateExpressions );
QSizeF totalSize() const;
void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
//overriden to break frames without dividing lines of text
double findNearbyPageBreak( double yPos );
/**Returns whether html item is using smart breaks. Smart breaks prevent
* the html frame contents from breaking mid-way though a line of text.
* @returns true if html item is using smart breaks
@ -184,6 +172,13 @@ class QgsComposerHtml: QgsComposerMultiFrame
bool userStylesheetEnabled() const;
virtual QString displayName() const;
QSizeF totalSize() const;
void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
//overriden to break frames without dividing lines of text
double findNearbyPageBreak( double yPos );
public slots:

View File

@ -1,5 +1,11 @@
/**Abstract base class for composer entries with the ability to distribute the content to several frames (items)*/
/**
* \ingroup composer
* \class QgsComposerMultiFrame
* Abstract base class for composer items with the ability to distribute the content to several frames
* (QgsComposerFrame items).
*/
class QgsComposerMultiFrame: QgsComposerObject
{
%TypeHeaderCode
@ -8,64 +14,182 @@ class QgsComposerMultiFrame: QgsComposerObject
public:
/*! Specifies the behaviour for creating new frames to fit the multiframe's content
*/
enum ResizeMode
{
UseExistingFrames,
ExtendToNextPage, //uses the next page(s) until the content has been printed
RepeatOnEveryPage, //repeats the same frame on every page
RepeatUntilFinished //duplicates last frame to next page to fit the total size
UseExistingFrames, /*!< don't automatically create new frames, just use existing frames */
ExtendToNextPage, /*!< creates new full page frames on the following page(s) until the entire multiframe content is visible */
RepeatOnEveryPage, /*!< repeats the same frame on every page */
RepeatUntilFinished /*!< creates new frames with the same position and dimensions as the existing frame on the following page(s),
until the entire multiframe content is visible */
};
/**Construct a new multiframe item.
* @param c parent composition
* @param createUndoCommands
*/
QgsComposerMultiFrame( QgsComposition* c, bool createUndoCommands );
virtual ~QgsComposerMultiFrame();
/**Returns the total size of the multiframe's content.
* @returns total size required for content
*/
virtual QSizeF totalSize() const = 0;
/**Returns a fixed size for the frames, if desired.
* @returns fixed size for frames. If the size has a width or height of 0, then
/**Returns the fixed size for a frame, if desired. If the fixed frame size changes,
* the sizes of all frames can be recalculated by calling recalculateFrameRects().
* @param frameIndex frame number
* @returns fixed size for frame. If the size has a width or height of 0, then
* the frame size is not fixed in that direction and frames can have variable width
* or height accordingly.
* @note added in version 2.5
* @see minFrameSize
* @see recalculateFrameRects
*/
virtual QSizeF fixedFrameSize() const;
virtual QSizeF fixedFrameSize( const int frameIndex = -1 ) const;
virtual void render( QPainter* p, const QRectF& renderExtent );
virtual void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
/**Returns the minimum size for a frames, if desired. If the minimum
* size changes, the sizes of all frames can be recalculated by calling
* recalculateFrameRects().
* @param frameIndex frame number
* @returns minimum size for frame. If the size has a width or height of 0, then
* the frame size has no minimum in that direction.
* @note added in version 2.5
* @see fixedFrameSize
* @see recalculateFrameRects
*/
virtual QSizeF minFrameSize( const int frameIndex = -1 ) const;
/**Renders a portion of the multiframe's content into a painter.
* @param p destination painter
* @param renderExtent visible extent of content to render into the painter.
* @deprecated use render( QPainter* painter, const QRectF& renderExtent, const int frameIndex ) instead
*/
virtual void render( QPainter* p, const QRectF& renderExtent ) /Deprecated/;
/**Renders a portion of the multiframe's content into a painter.
* @param painter destination painter
* @param renderExtent visible extent of content to render into the painter.
* @param frameIndex frame number for content
* @note added in version 2.5
*/
virtual void render( QPainter* painter, const QRectF& renderExtent, const int frameIndex );
/**Adds a frame to the multiframe.
* @param frame frame to add
* @param recalcFrameSizes set to true to force recalculation of all existing frame sizes
* @see removeFrame
*/
virtual void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true ) = 0;
/**Finds the optimal position to break a frame at.
* @param yPos maximum vertical position for break
* @returns the optimal breakable position which occurs in the multi frame close
* to and before the specified yPos
* @note added in version 2.3*/
* @note added in version 2.3
*/
virtual double findNearbyPageBreak( double yPos );
/**Removes a frame from the multiframe. This method automatically removes the frame from the
* composition.
* @param i index of frame to remove
* @see addFrame
* @see deleteFrames
*/
void removeFrame( int i );
void update();
void setResizeMode( ResizeMode mode );
ResizeMode resizeMode() const;
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const = 0;
bool _writeXML( QDomElement& elem, QDomDocument& doc, bool ignoreFrames = false ) const;
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false ) = 0;
bool _readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
QgsComposition* composition();
bool createUndoCommands() const;
void setCreateUndoCommands( bool enabled );
/**Removes and deletes all frames from mComposition*/
/**Removes and deletes all child frames.
* @see removeFrame
*/
void deleteFrames();
/** Return the number of frames associated with this multiframeset.
@note added in 2.0, replaces nFrames
/**Sets the resize mode for the multiframe, and recalculates frame sizes to match.
* @param mode resize mode
* @see resizeMode
*/
void setResizeMode( ResizeMode mode );
/**Returns the resize mode for the multiframe.
* @returns resize mode
* @see setResizeMode
*/
ResizeMode resizeMode() const;
/**Stores state information about multiframe in DOM element. Implementations of writeXML
* should also call the _writeXML method to save general multiframe properties.
* @param elem is DOM element
* @param doc is the DOM document
* @param ignoreFrames set to false to avoid writing state information about child frames into DOM
* @see _writeXML
*/
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const = 0;
/**Stores state information about base multiframe object in DOM element. Implementations of writeXML
* should call this method.
* @param elem is DOM element
* @param doc is the DOM document
* @param ignoreFrames set to false to avoid writing state information about child frames into DOM
* @see writeXML
*/
bool _writeXML( QDomElement& elem, QDomDocument& doc, bool ignoreFrames = false ) const;
/**Reads multiframe state information from a DOM element. Implementations of readXML
* should also call the _readXML method to restore general multiframe properties.
* @param itemElem is DOM element
* @param doc is the DOM document
* @param ignoreFrames set to false to avoid read state information about child frames from DOM
* @see _readXML
*/
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false ) = 0;
/**Restores state information about base multiframe object from a DOM element. Implementations of readXML
* should call this method.
* @param itemElem is DOM element
* @param doc is the DOM document
* @param ignoreFrames set to false to avoid reading state information about child frames from DOM
* @see readXML
*/
bool _readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
/**Returns the parent composition for the multiframe.
* @returns composition
*/
QgsComposition* composition();
/**Returns whether undo commands should be created for interactions with the multiframe.
* @returns true if undo commands should be created
* @see setCreateUndoCommands
*/
bool createUndoCommands() const;
/**Sets whether undo commands should be created for interactions with the multiframe.
* @param enabled set to true if undo commands should be created
* @see createUndoCommands
*/
void setCreateUndoCommands( bool enabled );
/**Returns the number of frames associated with this multiframe.
* @returns number of child frames
* @note added in QGIS 2.0, replaces nFrames
**/
int frameCount() const;
/**Returns a child frame from the multiframe.
* @param i index of frame
* @returns child frame if found
* @see frameIndex
*/
QgsComposerFrame* frame( int i );
/**Returns the index of a frame within the multiframe
* @param frame frame to find index of
* @returns index for frame if found, -1 if frame not found in multiframe
* @note added in version 2.5
* @see frame
*/
int frameIndex( QgsComposerFrame *frame ) const;
/**Creates a new frame and adds it to the multi frame and composition.
* @param currentFrame an existing QgsComposerFrame from which to copy the size
@ -85,24 +209,49 @@ class QgsComposerMultiFrame: QgsComposerObject
public slots:
/**Forces a redraw of all child frames.
*/
void update();
/**Recalculates the portion of the multiframe item which is shown in each of it's
* component frames. If the resize mode is set to anything but UseExistingFrames then
* this may cause new frames to be added or frames to be removed, in order to fit
* the current size of the multiframe's content.
* @see recalculateFrameRects
*/
void recalculateFrameSizes();
virtual void recalculateFrameSizes();
protected slots:
/**Called before a frame is going to be removed (update frame list)*/
void handleFrameRemoval( QgsComposerItem* item );
/**Adapts to changed number of pages if resize type is RepeatOnEveryPage*/
void handlePageChange();
/**Forces a recalculation of all the associated frame's scene rectangles. This
* method is useful for multiframes which implement a minFrameSize() or
* fixedFrameSize() method.
* @note added in version 2.5
* @see minFrameSize()
* @see fixedFrameSize()
* @see recalculateFrameSizes
*/
void recalculateFrameRects();
signals:
/**Emitted when the properties of a multi frame have changed, and the GUI item widget
* must be updated.
*/
void changed();
/**Emitted when the contents of the multi frame have changed and the frames
* must be redrawn.
*/
void contentsChanged();
protected slots:
/**Called before a frame is going to be removed. Updates frame list and recalculates
* content of remaining frames.
*/
void handleFrameRemoval( QgsComposerItem* item );
/**Adapts to changed number of composition pages if resize type is RepeatOnEveryPage.
*/
void handlePageChange();
};

View File

@ -45,7 +45,11 @@ class QgsComposerMultiFrameMergeCommand: QgsComposerMultiFrameCommand
//composer html
HtmlSource,
HtmlStylesheet,
HtmlBreakDistance
HtmlBreakDistance,
//attribute table
TableMaximumFeatures,
TableMargin,
TableGridStrokeWidth
};
QgsComposerMultiFrameMergeCommand( Context c, QgsComposerMultiFrame* multiFrame, const QString& text );

View File

@ -0,0 +1,314 @@
/**List of QVariants, representing a the contents of a single row in
* a QgsComposerTable
* \note Added in version 2.5
*/
typedef QList< QVariant > QgsComposerTableRow;
/**List of QgsComposerTableRows, representing rows and column cell contents
* for a QgsComposerTable
* \note Added in version 2.5
*/
typedef QList< QgsComposerTableRow > QgsComposerTableContents;
/**List of column definitions for a QgsComposerTable
* \note Added in version 2.5
*/
typedef QList<QgsComposerTableColumn*> QgsComposerTableColumns;
/**A class to display a table in the print composer, and allow
* the table to span over multiple frames
* @note added in QGIS 2.5
*/
class QgsComposerTableV2: QgsComposerMultiFrame
{
%TypeHeaderCode
#include <qgscomposertablev2.h>
%End
public:
/*! Controls how headers are horizontally aligned in a table
*/
enum HeaderHAlignment
{
FollowColumn, /*!< header uses the same alignment as the column */
HeaderLeft, /*!< align headers left */
HeaderCenter, /*!< align headers to center */
HeaderRight /*!< align headers right */
};
/*! Controls where headers are shown in the table
*/
enum HeaderMode
{
FirstFrame, /*!< header shown on first frame only */
AllFrames, /*!< headers shown on all frames */
NoHeaders /*!< no headers shown for table */
};
QgsComposerTableV2( QgsComposition* composition, bool createUndoCommands );
QgsComposerTableV2();
virtual ~QgsComposerTableV2();
/**Sets the margin distance between cell borders and their contents.
* @param margin margin for cell contents
* @see cellMargin
*/
void setCellMargin( const double margin );
/**Returns the margin distance between cell borders and their contents.
* @returns margin for cell contents
* @see setCellMargin
*/
double cellMargin() const;
/**Sets the font used to draw header text in the table.
* @param font font for header cells
* @see headerFont
* @see setContentFont
*/
void setHeaderFont( const QFont& font );
/**Returns the font used to draw header text in the table.
* @returns font for header cells
* @see setHeaderFont
* @see contentFont
*/
QFont headerFont() const;
/**Sets the color used to draw header text in the table.
* @param color header text color
* @see headerFontColor
* @see setHeaderFont
* @see setContentFontColor
*/
void setHeaderFontColor( const QColor& color );
/**Returns the color used to draw header text in the table.
* @returns color for header text
* @see setHeaderFontColor
* @see headerFont
* @see contentFontColor
*/
QColor headerFontColor() const;
/**Sets the horizontal alignment for table headers
* @param alignment Horizontal alignment for table header cells
* @see headerHAlignment
*/
void setHeaderHAlignment( const HeaderHAlignment alignment );
/**Returns the horizontal alignment for table headers
* @returns Horizontal alignment for table header cells
* @see setHeaderHAlignment
*/
HeaderHAlignment headerHAlignment() const;
/**Sets the display mode for headers in the table. This property controls
* if and where headers are shown in the table.
* @param mode display mode for headers
* @see headerMode
*/
void setHeaderMode( const HeaderMode mode );
/**Returns the display mode for headers in the table. This property controls
* if and where headers are shown in the table.
* @returns display mode for headers
* @see setHeaderMode
*/
HeaderMode headerMode() const;
/**Sets the font used to draw text in table body cells.
* @param font font for table cells
* @see contentFont
* @see setHeaderFont
*/
void setContentFont( const QFont& font );
/**Returns the font used to draw text in table body cells.
* @returns font for table cells
* @see setContentFont
* @see headerFont
*/
QFont contentFont() const;
/**Sets the color used to draw text in table body cells.
* @param color table cell text color
* @see contentFontColor
* @see setContentFont
* @see setHeaderFontColor
*/
void setContentFontColor( const QColor& color );
/**Returns the color used to draw text in table body cells.
* @returns text color for table cells
* @see setContentFontColor
* @see contentFont
* @see headerFontColor
*/
QColor contentFontColor() const;
/**Sets whether grid lines should be drawn in the table
* @param showGrid set to true to show grid lines
* @see showGrid
* @see setGridStrokeWidth
* @see setGridColor
*/
void setShowGrid( const bool showGrid );
/**Returns whether grid lines are drawn in the table
* @returns true if grid lines are shown
* @see setShowGrid
* @see gridStrokeWidth
* @see gridColor
*/
bool showGrid() const;
/**Sets the width for grid lines in the table.
* @param width grid line width
* @see gridStrokeWidth
* @see setShowGrid
* @see setGridColor
*/
void setGridStrokeWidth( const double width );
/**Returns the width of grid lines in the table.
* @returns grid line width
* @see setGridStrokeWidth
* @see showGrid
* @see gridColor
*/
double gridStrokeWidth() const;
/**Sets color used for grid lines in the table.
* @param color grid line color
* @see gridColor
* @see setShowGrid
* @see setGridStrokeWidth
*/
void setGridColor( const QColor& color );
/**Returns the color used for grid lines in the table.
* @returns grid line color
* @see setGridColor
* @see showGrid
* @see gridStrokeWidth
*/
QColor gridColor() const;
/**Returns a pointer to the list of QgsComposerTableColumns shown in the table
* @returns pointer to list of columns in table
* @see setColumns
*/
QgsComposerTableColumns* columns();
/**Replaces the columns in the table with a specified list of QgsComposerTableColumns.
* @param columns list of QgsComposerTableColumns to show in table
* @see columns
*/
void setColumns( QgsComposerTableColumns columns );
/**Returns the text used in the column headers for the table.
* @returns QMap of int to QString, where the int is the column index (starting at 0),
* and the string is the text to use for the column's header
* @note not available in python bindings
*/
virtual QMap<int, QString> headerLabels() const;
/**Fetches the contents used for the cells in the table.
* @returns true if table contents were successfully retrieved.
* @param contents QgsComposerTableContents to store retrieved row data in
* @note not available in python bindings
*/
virtual bool getTableContents( QgsComposerTableContents &contents ) = 0;
//reimplemented to return fixed table width
virtual QSizeF fixedFrameSize( const int frameIndex = -1 ) const;
//reimplemented to return min frame height
virtual QSizeF minFrameSize( const int frameIndex = -1 ) const;
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
virtual QSizeF totalSize() const;
virtual void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
public slots:
/**Refreshes the contents shown in the table by querying for new data.
* This also causes the column widths and size of the table to change to accommodate the
* new data.
* @see adjustFrameToSize
*/
virtual void refreshAttributes();
void recalculateFrameSizes();
protected:
/**Calculates the maximum width of text shown in columns.
*/
virtual bool calculateMaxColumnWidths();
/**Returns total width of table contents.
* @returns table width
* @see totalHeight
*/
//not const, as needs to call calculateMaxColumnWidths()
double totalWidth();
/**Returns total height of table contents.
* @returns total height
* @see totalWidth
*/
double totalHeight() const;
/**Calculates how many content rows are visible within a given frame
* @param frameIndex index number for frame
* @returns number of visible content rows (excludes header rows)
*/
int rowsVisible( const int frameIndex ) const;
/**Calculates how many content rows would be visible within a specified
* height.
* @param frameHeight height of frame
* @param includeHeader set to true if frame would include a header row
* @returns number of visible content rows (excluding header row)
*/
int rowsVisible( const double frameHeight, const bool includeHeader ) const;
/**Calculates a range of rows which should be visible in a given
* frame extent.
* @param extent visible extent
* @param frameIndex index number for frame
* @returns row range
*/
QPair<int, int> rowRange( const QRectF extent, const int frameIndex ) const;
/**Draws the horizontal grid lines for the table.
* @param painter destination painter for grid lines
* @param rows number of rows shown in table
* @param drawHeaderLines set to true to include for the table header
* @see drawVerticalGridLines
*/
void drawHorizontalGridLines( QPainter* painter, const int rows, const bool drawHeaderLines ) const;
/**Draws the vertical grid lines for the table.
* @param painter destination painter for grid lines
* @param maxWidthMap QMap of int to double, where the int contains the column number and the double is the
* maximum width of text present in the column.
* @param numberRows number of rows of content in table frame
* @param hasHeader set to true if table frame includes header cells
* @note not available in python bindings
* @see drawVerticalGridLines
* @see calculateMaxColumnWidths
* @note not available in python bindings
*/
//void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, const int numberRows, const bool hasHeader ) const;
/**Recalculates and updates the size of the table and all table frames.
*/
void recalculateTableSize();
};

View File

@ -400,6 +400,8 @@ class QgsComposition : QGraphicsScene
void beginMultiFrameCommand( QgsComposerMultiFrame* multiFrame, const QString& text, const QgsComposerMultiFrameMergeCommand::Context c = QgsComposerMultiFrameMergeCommand::Unknown );
void endMultiFrameCommand();
/**Deletes current multi frame command*/
void cancelMultiFrameCommand();
/**Adds multiframe. The object is owned by QgsComposition until removeMultiFrame is called*/
void addMultiFrame( QgsComposerMultiFrame* multiFrame );
@ -422,8 +424,10 @@ class QgsComposition : QGraphicsScene
void addComposerShape( QgsComposerShape* shape );
/**Adds a composer table to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerTable( QgsComposerAttributeTable* table );
/**Adds composer html frame and advices composer to create a widget for it (through signal)*/
/**Adds composer html frame and advises composer to create a widget for it (through signal)*/
void addComposerHtmlFrame( QgsComposerHtml* html /Transfer/, QgsComposerFrame* frame /Transfer/);
/**Adds composer tablev2 frame and advises composer to create a widget for it (through signal)*/
void addComposerTableFrame( QgsComposerAttributeTableV2* table /Transfer/, QgsComposerFrame* frame /Transfer/);
/**Remove item from the graphics scene. Additionally to QGraphicsScene::removeItem, this function considers undo/redo command*/
void removeComposerItem( QgsComposerItem* item, const bool createCommand = true, const bool removeGroupItems = true );
@ -589,6 +593,8 @@ class QgsComposition : QGraphicsScene
void composerShapeAdded( QgsComposerShape* shape );
/**Is emitted when a new composer table has been added*/
void composerTableAdded( QgsComposerAttributeTable* table );
/**Is emitted when a new composer table frame has been added to the view*/
void composerTableFrameAdded( QgsComposerAttributeTableV2* table, QgsComposerFrame* frame );
/**Is emitted when a composer item has been removed from the scene*/
void itemRemoved( QgsComposerItem* );

View File

@ -121,6 +121,8 @@
%Include composer/qgscomposerarrow.sip
%Include composer/qgscomposerattributetable.sip
%Include composer/qgscomposerattributetablemodel.sip
%Include composer/qgscomposerattributetablemodelv2.sip
%Include composer/qgscomposerattributetablev2.sip
%Include composer/qgscomposerframe.sip
%Include composer/qgscomposerhtml.sip
%Include composer/qgscomposerobject.sip
@ -139,6 +141,7 @@
%Include composer/qgscomposershape.sip
%Include composer/qgscomposertable.sip
%Include composer/qgscomposertablecolumn.sip
%Include composer/qgscomposertablev2.sip
%Include composer/qgscomposerutils.sip
%Include composer/qgscomposition.sip
%Include composer/qgscomposermodel.sip

View File

@ -35,6 +35,7 @@ class QgsComposerView : QGraphicsView
AddEllipse,
AddTriangle,
AddTable, // add attribute table
AddAttributeTable,
MoveItemContent, // move content of item (e.g. content of map)
Pan,
Zoom

View File

@ -51,13 +51,13 @@ QgsComposerAttributeTableWidget::QgsComposerAttributeTableWidget( QgsComposerAtt
refreshMapComboBox();
mHeaderFontColorButton->setColorDialogTitle( tr( "Select header font color" ) );
mHeaderFontColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
mHeaderFontColorButton->setAllowAlpha( true );
mHeaderFontColorButton->setContext( "composer" );
mContentFontColorButton->setColorDialogTitle( tr( "Select content font color" ) );
mContentFontColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
mContentFontColorButton->setAllowAlpha( true );
mContentFontColorButton->setContext( "composer" );
mGridColorButton->setColorDialogTitle( tr( "Select grid color" ) );
mGridColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
mGridColorButton->setAllowAlpha( true );
mGridColorButton->setContext( "composer" );
updateGuiElements();

View File

@ -172,7 +172,6 @@ class CORE_EXPORT QgsComposerTableSortColumnsProxyModelV2: public QSortFilterPro
*/
QgsComposerTableColumn* columnFromIndex( const QModelIndex & index ) const;
/**Returns the QgsComposerTableColumn corresponding to an index from the source
* QgsComposerAttributeTableColumnModel model.
* @returns QgsComposerTableColumn for specified index from QgsComposerAttributeTableColumnModel

View File

@ -424,7 +424,7 @@ bool QgsComposerAttributeTableV2::getTableContents( QgsComposerTableContents &co
qStableSort( contents.begin(), contents.end(), c );
}
adjustFrameToSize();
recalculateTableSize();
return true;
}

View File

@ -47,10 +47,11 @@ class CORE_EXPORT QgsComposerAttributeTableCompareV2
};
/**A table class that displays a vector attribute table*/
/**A table that displays attributes from a vector layer*/
class CORE_EXPORT QgsComposerAttributeTableV2: public QgsComposerTableV2
{
Q_OBJECT
public:
QgsComposerAttributeTableV2( QgsComposition* composition, bool createUndoCommands );
~QgsComposerAttributeTableV2();

View File

@ -21,26 +21,26 @@
class QgsComposition;
class QgsComposerMultiFrame;
/**Frame for html, table, text which can be divided onto several frames*/
/**Frame item for a composer multiframe item*/
class CORE_EXPORT QgsComposerFrame: public QgsComposerItem
{
public:
QgsComposerFrame( QgsComposition* c, QgsComposerMultiFrame* mf, qreal x, qreal y, qreal width, qreal height );
~QgsComposerFrame();
/**Sets the part of this frame (relative to the total multiframe extent in mm)*/
/**Sets the visible part of the multiframe's content which is visible within
* this frame (relative to the total multiframe extent in mm).
* @param section visible portion of content
* @see extent
*/
void setContentSection( const QRectF& section ) { mSection = section; }
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
void beginItemCommand( const QString& text );
void endItemCommand();
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
int type() const { return ComposerFrame; }
/**Returns the parent multiframe for the frame.
* @returns parent multiframe
*/
QgsComposerMultiFrame* multiFrame() const { return mMultiFrame; }
//Overriden to allow multiframe to set display name
@ -49,10 +49,18 @@ class CORE_EXPORT QgsComposerFrame: public QgsComposerItem
//Overriden to handle fixed frame sizes set by multi frame
void setSceneRect( const QRectF& rectangle );
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
void beginItemCommand( const QString& text );
void endItemCommand();
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
int type() const { return ComposerFrame; }
/**Returns the visible portion of the multi frame's content which
* is shown in this frame.
* @returns extent of visible portion
* @note added in QGIS 2.5
* @see setContentSection
*/
QRectF extent() const { return mSection; }

View File

@ -117,17 +117,6 @@ class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
*/
void setEvaluateExpressions( bool evaluateExpressions );
QSizeF totalSize() const;
void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
//overriden to break frames without dividing lines of text
double findNearbyPageBreak( double yPos );
/**Returns whether html item is using smart breaks. Smart breaks prevent
* the html frame contents from breaking mid-way though a line of text.
* @returns true if html item is using smart breaks
@ -206,6 +195,13 @@ class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
bool userStylesheetEnabled() const { return mEnableUserStylesheet; }
virtual QString displayName() const;
QSizeF totalSize() const;
void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
//overriden to break frames without dividing lines of text
double findNearbyPageBreak( double yPos );
public slots:

View File

@ -47,12 +47,12 @@ void QgsComposerMultiFrame::render( QPainter *p, const QRectF &renderExtent )
Q_UNUSED( renderExtent );
}
void QgsComposerMultiFrame::render( QPainter *p, const QRectF &renderExtent, const int frameIndex )
void QgsComposerMultiFrame::render( QPainter *painter, const QRectF &renderExtent, const int frameIndex )
{
Q_UNUSED( frameIndex );
//base implementation ignores frameIndex
Q_NOWARN_DEPRECATED_PUSH
render( p, renderExtent );
render( painter, renderExtent );
Q_NOWARN_DEPRECATED_POP
}

View File

@ -29,28 +29,47 @@ class QDomElement;
class QRectF;
class QPainter;
/**Abstract base class for composer entries with the ability to distribute the content to several frames (items)*/
/**
* \ingroup composer
* \class QgsComposerMultiFrame
* Abstract base class for composer items with the ability to distribute the content to several frames
* (QgsComposerFrame items).
*/
class CORE_EXPORT QgsComposerMultiFrame: public QgsComposerObject
{
Q_OBJECT
public:
/*! Specifies the behaviour for creating new frames to fit the multiframe's content
*/
enum ResizeMode
{
UseExistingFrames = 0,
ExtendToNextPage, //uses the next page(s) until the content has been printed
RepeatOnEveryPage, //repeats the same frame on every page
RepeatUntilFinished //duplicates last frame to next page to fit the total size
UseExistingFrames = 0, /*!< don't automatically create new frames, just use existing frames */
ExtendToNextPage, /*!< creates new full page frames on the following page(s) until the entire multiframe content is visible */
RepeatOnEveryPage, /*!< repeats the same frame on every page */
RepeatUntilFinished /*!< creates new frames with the same position and dimensions as the existing frame on the following page(s),
until the entire multiframe content is visible */
};
/**Construct a new multiframe item.
* @param c parent composition
* @param createUndoCommands
*/
QgsComposerMultiFrame( QgsComposition* c, bool createUndoCommands );
virtual ~QgsComposerMultiFrame();
/**Returns the total size of the multiframe's content.
* @returns total size required for content
*/
virtual QSizeF totalSize() const = 0;
/**Returns a fixed size for the frames, if desired. If the fixed frame size changes,
/**Returns the fixed size for a frame, if desired. If the fixed frame size changes,
* the sizes of all frames can be recalculated by calling recalculateFrameRects().
* @param frameIndex frame number
* @returns fixed size for frames. If the size has a width or height of 0, then
* @returns fixed size for frame. If the size has a width or height of 0, then
* the frame size is not fixed in that direction and frames can have variable width
* or height accordingly.
* @note added in version 2.5
@ -59,11 +78,11 @@ class CORE_EXPORT QgsComposerMultiFrame: public QgsComposerObject
*/
virtual QSizeF fixedFrameSize( const int frameIndex = -1 ) const { Q_UNUSED( frameIndex ); return QSizeF( 0, 0 ); }
/**Returns the minimum size size for the frames, if desired. If the minimum
/**Returns the minimum size for a frames, if desired. If the minimum
* size changes, the sizes of all frames can be recalculated by calling
* recalculateFrameRects().
* @param frameIndex frame number
* @returns minimum size for frames. If the size has a width or height of 0, then
* @returns minimum size for frame. If the size has a width or height of 0, then
* the frame size has no minimum in that direction.
* @note added in version 2.5
* @see fixedFrameSize
@ -71,51 +90,132 @@ class CORE_EXPORT QgsComposerMultiFrame: public QgsComposerObject
*/
virtual QSizeF minFrameSize( const int frameIndex = -1 ) const { Q_UNUSED( frameIndex ); return QSizeF( 0, 0 ); }
/**Renders a portion of the multiframe's content into a painter.
* @param p destination painter
* @param renderExtent visible extent of content to render into the painter.
* @deprecated use render( QPainter* painter, const QRectF& renderExtent, const int frameIndex ) instead
*/
Q_DECL_DEPRECATED virtual void render( QPainter* p, const QRectF& renderExtent );
virtual void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
/**Renders a portion of the multiframe's content into a painter.
* @param painter destination painter
* @param renderExtent visible extent of content to render into the painter.
* @param frameIndex frame number for content
* @note added in version 2.5
*/
virtual void render( QPainter* painter, const QRectF& renderExtent, const int frameIndex );
/**Adds a frame to the multiframe.
* @param frame frame to add
* @param recalcFrameSizes set to true to force recalculation of all existing frame sizes
* @see removeFrame
*/
virtual void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true ) = 0;
/**Finds the optimal position to break a frame at.
* @param yPos maximum vertical position for break
* @returns the optimal breakable position which occurs in the multi frame close
* to and before the specified yPos
* @note added in version 2.3*/
* @note added in version 2.3
*/
virtual double findNearbyPageBreak( double yPos ) { return yPos; }
/**Removes a frame from the multiframe. This method automatically removes the frame from the
* composition.
* @param i index of frame to remove
* @see addFrame
* @see deleteFrames
*/
void removeFrame( int i );
void update();
void setResizeMode( ResizeMode mode );
ResizeMode resizeMode() const { return mResizeMode; }
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const = 0;
bool _writeXML( QDomElement& elem, QDomDocument& doc, bool ignoreFrames = false ) const;
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false ) = 0;
bool _readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
QgsComposition* composition() { return mComposition; }
bool createUndoCommands() const { return mCreateUndoCommands; }
void setCreateUndoCommands( bool enabled ) { mCreateUndoCommands = enabled; }
/**Removes and deletes all frames from mComposition*/
/**Removes and deletes all child frames.
* @see removeFrame
*/
void deleteFrames();
/** Return the number of frames associated with this multiframeset.
@note added in 2.0, replaces nFrames
/**Sets the resize mode for the multiframe, and recalculates frame sizes to match.
* @param mode resize mode
* @see resizeMode
*/
void setResizeMode( ResizeMode mode );
/**Returns the resize mode for the multiframe.
* @returns resize mode
* @see setResizeMode
*/
ResizeMode resizeMode() const { return mResizeMode; }
/**Stores state information about multiframe in DOM element. Implementations of writeXML
* should also call the _writeXML method to save general multiframe properties.
* @param elem is DOM element
* @param doc is the DOM document
* @param ignoreFrames set to false to avoid writing state information about child frames into DOM
* @see _writeXML
*/
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const = 0;
/**Stores state information about base multiframe object in DOM element. Implementations of writeXML
* should call this method.
* @param elem is DOM element
* @param doc is the DOM document
* @param ignoreFrames set to false to avoid writing state information about child frames into DOM
* @see writeXML
*/
bool _writeXML( QDomElement& elem, QDomDocument& doc, bool ignoreFrames = false ) const;
/**Reads multiframe state information from a DOM element. Implementations of readXML
* should also call the _readXML method to restore general multiframe properties.
* @param itemElem is DOM element
* @param doc is the DOM document
* @param ignoreFrames set to false to avoid read state information about child frames from DOM
* @see _readXML
*/
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false ) = 0;
/**Restores state information about base multiframe object from a DOM element. Implementations of readXML
* should call this method.
* @param itemElem is DOM element
* @param doc is the DOM document
* @param ignoreFrames set to false to avoid reading state information about child frames from DOM
* @see readXML
*/
bool _readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
/**Returns the parent composition for the multiframe.
* @returns composition
*/
QgsComposition* composition() { return mComposition; }
/**Returns whether undo commands should be created for interactions with the multiframe.
* @returns true if undo commands should be created
* @see setCreateUndoCommands
*/
bool createUndoCommands() const { return mCreateUndoCommands; }
/**Sets whether undo commands should be created for interactions with the multiframe.
* @param enabled set to true if undo commands should be created
* @see createUndoCommands
*/
void setCreateUndoCommands( bool enabled ) { mCreateUndoCommands = enabled; }
/**Returns the number of frames associated with this multiframe.
* @returns number of child frames
* @note added in QGIS 2.0, replaces nFrames
**/
int frameCount() const { return mFrameItems.size(); }
/**Returns a child frame from the multiframe.
* @param i index of frame
* @returns child frame if found
* @see frameIndex
*/
QgsComposerFrame* frame( int i ) const;
/**Returns the index of a frame within the multiframe
* @param frame frame to find index of
* @returns index for frame if found, -1 if frame not found in multiframe
* @note added in version 2.5
* @see frame
*/
int frameIndex( QgsComposerFrame *frame ) const;
@ -137,10 +237,15 @@ class CORE_EXPORT QgsComposerMultiFrame: public QgsComposerObject
public slots:
/**Forces a redraw of all child frames.
*/
void update();
/**Recalculates the portion of the multiframe item which is shown in each of it's
* component frames. If the resize mode is set to anything but UseExistingFrames then
* this may cause new frames to be added or frames to be removed, in order to fit
* the current size of the multiframe's content.
* @see recalculateFrameRects
*/
virtual void recalculateFrameSizes();
@ -150,19 +255,40 @@ class CORE_EXPORT QgsComposerMultiFrame: public QgsComposerObject
* @note added in version 2.5
* @see minFrameSize()
* @see fixedFrameSize()
* @see recalculateFrameSizes
*/
void recalculateFrameRects();
signals:
/**Emitted when the properties of a multi frame have changed, and the GUI item widget
* must be updated.
*/
void changed();
/**Emitted when the contents of the multi frame have changed and the frames
* must be redrawn.
*/
void contentsChanged();
protected:
QList<QgsComposerFrame*> mFrameItems;
ResizeMode mResizeMode;
/**True: creates QgsMultiFrameCommands on internal changes (e.g. changing frames )*/
bool mCreateUndoCommands;
protected slots:
/**Called before a frame is going to be removed (update frame list)*/
/**Called before a frame is going to be removed. Updates frame list and recalculates
* content of remaining frames.
*/
void handleFrameRemoval( QgsComposerItem* item );
/**Adapts to changed number of pages if resize type is RepeatOnEveryPage*/
/**Adapts to changed number of composition pages if resize type is RepeatOnEveryPage.
*/
void handlePageChange();
private:
@ -170,13 +296,6 @@ class CORE_EXPORT QgsComposerMultiFrame: public QgsComposerObject
bool mIsRecalculatingSize;
signals:
void changed();
/**Emitted when the contents of the multi frame have changed and the frames
* must be redrawn.
*/
void contentsChanged();
};
#endif // QGSCOMPOSERMULTIFRAME_H

View File

@ -342,7 +342,7 @@ void QgsComposerTableV2::setCellMargin( const double margin )
mCellMargin = margin;
//since spacing has changed, we need to recalculate the table size
adjustFrameToSize();
recalculateTableSize();
emit changed();
}
@ -356,7 +356,7 @@ void QgsComposerTableV2::setHeaderFont( const QFont &font )
mHeaderFont = font;
//since font attributes have changed, we need to recalculate the table size
adjustFrameToSize();
recalculateTableSize();
emit changed();
}
@ -395,7 +395,7 @@ void QgsComposerTableV2::setHeaderMode( const QgsComposerTableV2::HeaderMode mod
}
mHeaderMode = mode;
adjustFrameToSize();
recalculateTableSize();
emit changed();
}
@ -409,7 +409,7 @@ void QgsComposerTableV2::setContentFont( const QFont &font )
mContentFont = font;
//since font attributes have changed, we need to recalculate the table size
adjustFrameToSize();
recalculateTableSize();
emit changed();
}
@ -436,7 +436,7 @@ void QgsComposerTableV2::setShowGrid( const bool showGrid )
mShowGrid = showGrid;
//since grid spacing has changed, we need to recalculate the table size
adjustFrameToSize();
recalculateTableSize();
emit changed();
}
@ -450,7 +450,7 @@ void QgsComposerTableV2::setGridStrokeWidth( const double width )
mGridStrokeWidth = width;
//since grid spacing has changed, we need to recalculate the table size
adjustFrameToSize();
recalculateTableSize();
emit changed();
}
@ -695,7 +695,7 @@ void QgsComposerTableV2::drawVerticalGridLines( QPainter *painter, const QMap<in
}
}
void QgsComposerTableV2::adjustFrameToSize()
void QgsComposerTableV2::recalculateTableSize()
{
recalculateFrameSizes();

View File

@ -42,7 +42,7 @@ typedef QList< QgsComposerTableRow > QgsComposerTableContents;
*/
typedef QList<QgsComposerTableColumn*> QgsComposerTableColumns;
/**A class to display feature attributes in the print composer, and allow
/**A class to display a table in the print composer, and allow
* the table to span over multiple frames
* @note added in QGIS 2.5
*/
@ -76,15 +76,6 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
virtual ~QgsComposerTableV2();
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
virtual QSizeF totalSize() const;
virtual void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
/**Sets the margin distance between cell borders and their contents.
* @param margin margin for cell contents
* @see cellMargin
@ -263,6 +254,11 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
//reimplemented to return min frame height
virtual QSizeF minFrameSize( const int frameIndex = -1 ) const;
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
virtual QSizeF totalSize() const;
virtual void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
public slots:
/**Refreshes the contents shown in the table by querying for new data.
@ -320,9 +316,17 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
*/
virtual bool calculateMaxColumnWidths();
//not const
/**Returns total width of table contents.
* @returns table width
* @see totalHeight
*/
//not const, as needs to call calculateMaxColumnWidths()
double totalWidth();
/**Returns total height of table contents.
* @returns total height
* @see totalWidth
*/
double totalHeight() const;
/**Calculates how many content rows are visible within a given frame
@ -331,10 +335,16 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
*/
int rowsVisible( const int frameIndex ) const;
/**Calculates how many content rows would be visible within a specified
* height.
* @param frameHeight height of frame
* @param includeHeader set to true if frame would include a header row
* @returns number of visible content rows (excluding header row)
*/
int rowsVisible( const double frameHeight, const bool includeHeader ) const;
/**Calculates a range of rows which should be visible in a given
* rectangle.
* frame extent.
* @param extent visible extent
* @param frameIndex index number for frame
* @returns row range
@ -358,10 +368,13 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
* @note not available in python bindings
* @see drawVerticalGridLines
* @see calculateMaxColumnWidths
* @note not available in python bindings
*/
void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, const int numberRows, const bool hasHeader ) const;
void adjustFrameToSize();
/**Recalculates and updates the size of the table and all table frames.
*/
void recalculateTableSize();
};
#endif // QGSCOMPOSERTABLEV2_H