2010-11-26 10:30:19 +00:00
|
|
|
/**A class to display feature attributes in the print composer*/
|
|
|
|
class QgsComposerTable: QgsComposerItem
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgscomposertable.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
2014-05-15 12:06:25 +10:00
|
|
|
|
|
|
|
/*! 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 */
|
|
|
|
};
|
|
|
|
|
2010-11-26 10:30:19 +00:00
|
|
|
QgsComposerTable( QgsComposition* composition /TransferThis/ );
|
|
|
|
virtual ~QgsComposerTable();
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
/** return correct graphics item type. Added in v1.7 */
|
|
|
|
virtual int type() const;
|
|
|
|
|
2010-11-26 10:30:19 +00:00
|
|
|
/** \brief Reimplementation of QCanvasItem::paint*/
|
|
|
|
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
|
|
|
|
|
|
|
|
virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) const = 0;
|
|
|
|
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) = 0;
|
|
|
|
|
2014-05-15 12:06:25 +10:00
|
|
|
/**Sets the margin distance between cell borders and their contents.
|
|
|
|
* @param d margin for cell contents
|
|
|
|
* @see lineTextDistance
|
|
|
|
*/
|
2010-11-26 10:30:19 +00:00
|
|
|
void setLineTextDistance( double d );
|
2014-05-15 12:06:25 +10:00
|
|
|
|
|
|
|
/**Returns the margin distance between cell borders and their contents.
|
|
|
|
* @returns margin for cell contents
|
|
|
|
* @see setLineTextDistance
|
|
|
|
*/
|
2010-11-26 10:30:19 +00:00
|
|
|
double lineTextDistance() const;
|
|
|
|
|
2014-05-15 12:06:25 +10:00
|
|
|
/**Sets the font used to draw header text in the table.
|
|
|
|
* @param f font for header cells
|
|
|
|
* @see headerFont
|
|
|
|
* @see setContentFont
|
|
|
|
*/
|
2010-11-26 10:30:19 +00:00
|
|
|
void setHeaderFont( const QFont& f );
|
2014-05-15 12:06:25 +10:00
|
|
|
|
|
|
|
/**Returns the font used to draw header text in the table.
|
|
|
|
* @returns font for header cells
|
|
|
|
* @see setHeaderFont
|
|
|
|
* @see contentFont
|
|
|
|
*/
|
2010-11-26 10:30:19 +00:00
|
|
|
QFont headerFont() const;
|
2014-05-15 12:06:25 +10:00
|
|
|
|
|
|
|
/**Sets the horizontal alignment for table headers
|
|
|
|
* @param alignment Horizontal alignment for table header cells
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see headerHAlignment
|
|
|
|
*/
|
|
|
|
void setHeaderHAlignment( const HeaderHAlignment alignment );
|
2010-11-26 10:30:19 +00:00
|
|
|
|
2014-05-15 12:06:25 +10:00
|
|
|
/**Returns the horizontal alignment for table headers
|
|
|
|
* @returns Horizontal alignment for table header cells
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see setHeaderHAlignment
|
|
|
|
*/
|
|
|
|
HeaderHAlignment headerHAlignment() const;
|
|
|
|
|
|
|
|
/**Sets the font used to draw text in table body cells.
|
|
|
|
* @param f font for table cells
|
|
|
|
* @see contentFont
|
|
|
|
* @see setHeaderFont
|
|
|
|
*/
|
2010-11-26 10:30:19 +00:00
|
|
|
void setContentFont( const QFont& f );
|
2014-05-15 12:06:25 +10:00
|
|
|
|
|
|
|
/**Returns the font used to draw text in table body cells.
|
|
|
|
* @returns font for table cells
|
|
|
|
* @see setContentFont
|
|
|
|
* @see headerFont
|
|
|
|
*/
|
2010-11-26 10:30:19 +00:00
|
|
|
QFont contentFont() const;
|
|
|
|
|
2014-05-15 12:06:25 +10:00
|
|
|
/**Sets whether grid lines should be drawn in the table
|
|
|
|
* @param show set to true to show grid lines
|
|
|
|
* @see showGrid
|
|
|
|
* @see setGridStrokeWidth
|
|
|
|
* @see setGridColor
|
|
|
|
*/
|
2010-11-26 10:30:19 +00:00
|
|
|
void setShowGrid( bool show );
|
2014-05-15 12:06:25 +10:00
|
|
|
|
|
|
|
/**Returns whether grid lines are drawn in the table
|
|
|
|
* @returns true if grid lines are shown
|
|
|
|
* @see setShowGrid
|
|
|
|
* @see gridStrokeWidth
|
|
|
|
* @see gridColor
|
|
|
|
*/
|
2010-11-26 10:30:19 +00:00
|
|
|
bool showGrid() const;
|
|
|
|
|
2014-05-15 12:06:25 +10:00
|
|
|
/**Sets the width for grid lines in the table.
|
|
|
|
* @param w grid line width
|
|
|
|
* @see gridStrokeWidth
|
|
|
|
* @see setShowGrid
|
|
|
|
* @see setGridColor
|
|
|
|
*/
|
2010-11-26 10:30:19 +00:00
|
|
|
void setGridStrokeWidth( double w );
|
2014-05-15 12:06:25 +10:00
|
|
|
|
|
|
|
/**Returns the width of grid lines in the table.
|
|
|
|
* @returns grid line width
|
|
|
|
* @see setGridStrokeWidth
|
|
|
|
* @see showGrid
|
|
|
|
* @see gridColor
|
|
|
|
*/
|
2010-11-26 10:30:19 +00:00
|
|
|
double gridStrokeWidth() const;
|
|
|
|
|
2014-05-15 12:06:25 +10:00
|
|
|
/**Sets color used for grid lines in the table.
|
|
|
|
* @param c grid line color
|
|
|
|
* @see gridColor
|
|
|
|
* @see setShowGrid
|
|
|
|
* @see setGridStrokeWidth
|
|
|
|
*/
|
2010-11-26 10:30:19 +00:00
|
|
|
void setGridColor( const QColor& c );
|
2014-05-15 12:06:25 +10:00
|
|
|
|
|
|
|
/**Returns the color used for grid lines in the table.
|
|
|
|
* @returns grid line color
|
|
|
|
* @see setGridColor
|
|
|
|
* @see showGrid
|
|
|
|
* @see gridStrokeWidth
|
|
|
|
*/
|
2010-11-26 10:30:19 +00:00
|
|
|
QColor gridColor() const;
|
2014-04-23 06:28:56 +10:00
|
|
|
|
2014-05-15 12:06:25 +10:00
|
|
|
/**Returns a pointer to the list of QgsComposerTableColumns shown in the table
|
|
|
|
* @returns pointer to list of columns in table
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see setColumns
|
|
|
|
*/
|
|
|
|
QList<QgsComposerTableColumn*>* columns();
|
|
|
|
|
|
|
|
/**Replaces the columns in the table with a specified list of QgsComposerTableColumns.
|
|
|
|
* @param columns list of QgsComposerTableColumns to show in table
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see columns
|
|
|
|
*/
|
|
|
|
void setColumns( QList<QgsComposerTableColumn*> columns );
|
|
|
|
|
2014-04-23 06:28:56 +10:00
|
|
|
public slots:
|
2010-11-26 10:30:19 +00:00
|
|
|
|
2014-04-23 06:28:56 +10:00
|
|
|
/**Refreshes the attributes shown in the table by querying the vector layer for new data.
|
|
|
|
* This also causes the column widths and size of the table to change to accomodate the
|
|
|
|
* new data.
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see adjustFrameToSize
|
|
|
|
*/
|
|
|
|
virtual void refreshAttributes();
|
|
|
|
|
|
|
|
/**Adapts the size of the frame to match the content. First, the optimal width of the columns
|
|
|
|
* is recalculated by checking the maximum width of attributes shown in the table. Then, the
|
|
|
|
* table is resized to fit its contents. This slot utilises the table's attribute cache so
|
|
|
|
* that a re-query of the vector layer is not required.
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see refreshAttributes
|
|
|
|
*/
|
|
|
|
virtual void adjustFrameToSize();
|
2010-11-26 10:30:19 +00:00
|
|
|
|
|
|
|
protected:
|
2012-09-24 02:28:15 +02:00
|
|
|
/**Retrieves feature attributes*/
|
2013-07-08 21:49:00 +02:00
|
|
|
// virtual bool getFeatureAttributes( QList<QgsAttributeMap>& attributeMaps );
|
2014-04-28 19:00:42 +10:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
/**Calculate the maximum width values of the vector attributes*/
|
2013-07-08 21:49:00 +02:00
|
|
|
// virtual bool calculateMaxColumnWidths( QMap<int, double>& maxWidthMap, const QList< QMap<int, QVariant> >& attributeMaps ) const;
|
2012-09-24 02:28:15 +02:00
|
|
|
/**Adapts the size of the item frame to match the content*/
|
2013-07-08 21:49:00 +02:00
|
|
|
// void adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList< QMap<int, QVariant> >& attributeMaps );
|
2014-05-15 12:06:25 +10:00
|
|
|
|
|
|
|
/**Draws the horizontal grid lines for the table.
|
|
|
|
* @param p destination painter for grid lines
|
|
|
|
* @param nAttributes number of attribute rows shown in table
|
|
|
|
* @see drawVerticalGridLines
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void drawHorizontalGridLines( QPainter* p, int nAttributes );
|
2014-05-15 12:06:25 +10:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
// void drawVerticalGridLines( QPainter* p, const QMap<int, double>& maxWidthMap );
|
|
|
|
|
2014-05-15 12:06:25 +10:00
|
|
|
/**Writes common table properties to xml for storage.
|
|
|
|
* @param itemElem an existing QDomElement in which to store the table's properties.
|
|
|
|
* @param doc QDomDocument for the destination xml.
|
|
|
|
* @see tableReadXML
|
|
|
|
* @see writeXML
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
bool tableWriteXML( QDomElement& itemElem, QDomDocument& doc ) const;
|
2014-05-15 12:06:25 +10:00
|
|
|
|
|
|
|
/**Reads the table's common properties from xml.
|
|
|
|
* @param itemElem a QDomElement holding the table's desired properties.
|
|
|
|
* @param doc QDomDocument for the source xml.
|
|
|
|
* @see tableWriteXML
|
|
|
|
* @see readXML
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
bool tableReadXML( const QDomElement& itemElem, const QDomDocument& doc );
|
2010-11-26 10:30:19 +00:00
|
|
|
};
|