27 , mEmptyTableMode( HeadersOnly )
28 , mShowEmptyRows( false )
29 , mHeaderFontColor( Qt::black )
30 , mHeaderHAlignment( FollowColumn )
31 , mHeaderMode( FirstFrame )
32 , mContentFontColor( Qt::black )
34 , mGridStrokeWidth( 0.5 )
35 , mGridColor( Qt::black )
36 , mBackgroundColor( Qt::white )
46 QString defaultFontString = settings.value(
"/Composer/defaultFont" ).toString();
47 if ( !defaultFontString.isEmpty() )
79 elem.setAttribute(
"cellMargin", QString::number(
mCellMargin ) );
80 elem.setAttribute(
"emptyTableMode", QString::number((
int )
mEmptyTableMode ) );
83 elem.setAttribute(
"headerFont",
mHeaderFont.toString() );
85 elem.setAttribute(
"headerHAlignment", QString::number((
int )
mHeaderHAlignment ) );
86 elem.setAttribute(
"headerMode", QString::number((
int )
mHeaderMode ) );
87 elem.setAttribute(
"contentFont",
mContentFont.toString() );
91 elem.setAttribute(
"showGrid",
mShowGrid );
95 QDomElement displayColumnsElem = doc.createElement(
"displayColumns" );
96 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
97 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
99 QDomElement columnElem = doc.createElement(
"column" );
100 ( *columnIt )->writeXML( columnElem, doc );
101 displayColumnsElem.appendChild( columnElem );
103 elem.appendChild( displayColumnsElem );
105 bool state =
_writeXML( elem, doc, ignoreFrames );
114 if ( !
_readXML( itemElem, doc, ignoreFrames ) )
119 if ( itemElem.isNull() )
126 mShowEmptyRows = itemElem.attribute(
"showEmptyRows",
"0" ).toInt();
127 mHeaderFont.fromString( itemElem.attribute(
"headerFont",
"" ) );
131 mContentFont.fromString( itemElem.attribute(
"contentFont",
"" ) );
133 mCellMargin = itemElem.attribute(
"cellMargin",
"1.0" ).toDouble();
134 mGridStrokeWidth = itemElem.attribute(
"gridStrokeWidth",
"0.5" ).toDouble();
135 mShowGrid = itemElem.attribute(
"showGrid",
"1" ).toInt();
142 QDomNodeList columnsList = itemElem.elementsByTagName(
"displayColumns" );
143 if ( columnsList.size() > 0 )
145 QDomElement columnsElem = columnsList.at( 0 ).toElement();
146 QDomNodeList columnEntryList = columnsElem.elementsByTagName(
"column" );
147 for (
int i = 0; i < columnEntryList.size(); ++i )
149 QDomElement columnElem = columnEntryList.at( i ).toElement();
171 QRectF frameExtent =
frame( frameIndex )->
extent();
173 bool includeHeader =
false;
177 includeHeader =
true;
179 return rowsVisible( frameExtent.height(), includeHeader );
185 double headerHeight = 0;
198 double contentHeight = frameHeight - headerHeight;
202 return qMax( floor( contentHeight / rowHeight ), 0.0 );
211 return qMakePair( 0, 0 );
216 int rowsAlreadyShown = 0;
222 double headerHeight = 0;
235 double contentHeight = extent.height() - headerHeight;
239 int firstVisible = qMin( rowsAlreadyShown,
mTableContents.length() );
240 int rowsVisible = qMax( floor( contentHeight / rowHeight ), 0.0 );
241 int lastVisible = qMin( firstVisible + rowsVisible,
mTableContents.length() );
243 return qMakePair( firstVisible, lastVisible );
262 QPair< int, int > rowsToShow =
rowRange( renderExtent, frameIndex );
273 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
286 int numberRowsToDraw = rowsToShow.second - rowsToShow.first;
291 bool mergeCells =
false;
301 p->setRenderHint( QPainter::Antialiasing,
true );
307 p->setPen( Qt::NoPen );
309 double totalHeight = ( drawHeader || ( numberRowsToDraw > 0 ) ? gridSize : 0 ) +
310 ( drawHeader ? cellHeaderHeight + gridSize : 0.0 ) +
311 ( drawContents ? numberRowsToDraw : 1 ) * ( cellBodyHeight + gridSize );
313 if ( totalHeight > 0 )
316 p->drawRect( backgroundRect );
322 double currentX = gridSize;
324 p->setPen( Qt::SolidLine );
325 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
330 Qt::TextFlag textFlag = ( Qt::TextFlag )0;
331 if (( *columnIt )->width() <= 0 )
336 textFlag = Qt::TextDontClip;
345 Qt::AlignmentFlag headerAlign = Qt::AlignLeft;
349 headerAlign = ( *columnIt )->hAlignment();
352 headerAlign = Qt::AlignLeft;
355 headerAlign = Qt::AlignHCenter;
358 headerAlign = Qt::AlignRight;
364 currentY += cellHeaderHeight;
365 currentY += gridSize;
371 for (
int row = rowsToShow.first; row < rowsToShow.second; ++row )
376 QString str = cellContents.toString();
380 currentY += cellBodyHeight;
381 currentY += gridSize;
387 currentX += gridSize;
397 gridPen.setJoinStyle( Qt::MiterJoin );
398 p->setPen( gridPen );
407 double messageY = gridSize + ( drawHeader ? cellHeaderHeight + gridSize : 0 );
408 cell = QRectF( messageX, messageY,
mTableSize.width() - messageX, cellBodyHeight );
618 QMap<int, QString> headers;
620 QgsComposerTableColumns::const_iterator columnIt =
mColumns.constBegin();
622 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
624 headers.insert( col, ( *columnIt )->heading() );
632 Q_UNUSED( frameIndex );
645 return QSizeF( 0, height );
671 QgsComposerTableColumns::const_iterator columnIt =
mColumns.constBegin();
673 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
676 if (( *columnIt )->width() > 0 )
679 width = ( *columnIt )->width();
691 QgsComposerTableContents::const_iterator rowIt =
mTableContents.constBegin();
692 double currentCellTextWidth;
695 QgsComposerTableRow::const_iterator colIt = rowIt->constBegin();
696 int columnNumber = 0;
697 for ( ; colIt != rowIt->constEnd(); ++colIt )
699 if (
mColumns.at( columnNumber )->width() <= 0 )
703 mMaxColumnWidthMap[ columnNumber ] = qMax( currentCellTextWidth, mMaxColumnWidthMap[ columnNumber ] );
725 totalWidth += maxColWidthIt.value();
739 int rowsAlreadyShown = 0;
741 int rowsVisibleInLastFrame = 0;
742 double heightOfLastFrame = 0;
743 for (
int idx = 0; idx < numberExistingFrames; ++idx )
747 heightOfLastFrame =
frame( idx )->rect().height();
748 rowsVisibleInLastFrame =
rowsVisible( heightOfLastFrame, hasHeader );
749 rowsAlreadyShown += rowsVisibleInLastFrame;
750 height += heightOfLastFrame;
763 rowsVisibleInLastFrame =
rowsVisible( heightOfLastFrame, hasHeader );
769 if ( remainingRows <= 0 )
775 if ( rowsVisibleInLastFrame < 1 )
784 int numberFramesMissing = ceil((
double )remainingRows / (
double )rowsVisibleInLastFrame );
785 height += heightOfLastFrame * numberFramesMissing;
792 if ( rows < 1 && !drawHeaderLines )
799 currentY = halfGridStrokeWidth;
800 if ( drawHeaderLines )
802 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
806 for (
int row = 0; row < rows; ++row )
808 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
812 painter->drawLine( QPointF( halfGridStrokeWidth, currentY ), QPointF(
mTableSize.width() - halfGridStrokeWidth, currentY ) );
818 if ( numberRows < 1 && !hasHeader )
824 double tableHeight = 0;
830 double headerHeight = tableHeight;
834 double currentX = halfGridStrokeWidth;
835 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
837 QMap<int, double>::const_iterator maxColWidthIt = maxWidthMap.constBegin();
839 for ( ; maxColWidthIt != maxWidthMap.constEnd(); ++maxColWidthIt )
841 currentX += ( maxColWidthIt.value() + 2 *
mCellMargin );
842 if ( col == maxWidthMap.size() || !mergeCells )
844 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
846 else if ( hasHeader )
848 painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, headerHeight - halfGridStrokeWidth ) );
867 if ( contents.indexOf( row ) >= 0 )
QColor mContentFontColor
Table contents font color.
QFont mContentFont
Table contents font.
double totalWidth()
Returns total width of table contents.
virtual void recalculateFrameSizes()
Recalculates the portion of the multiframe item which is shown in each of it's component frames...
virtual QMap< int, QString > headerLabels() const
Returns the text used in the column headers for the table.
virtual QSizeF minFrameSize(const int frameIndex=-1) const override
Returns the minimum size for a frames, if desired.
void setShowGrid(const bool showGrid)
Sets whether grid lines should be drawn in the table.
bool mShowGrid
True if grid should be shown.
void setGridStrokeWidth(const double width)
Sets the width for grid lines in the table.
double mGridStrokeWidth
Width of grid lines.
void setGridColor(const QColor &color)
Sets color used for grid lines in the table.
A item that forms part of a map composition.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const override
Stores state information about multiframe in DOM element.
QFont mHeaderFont
Header font.
static void drawText(QPainter *painter, const QPointF &pos, const QString &text, const QFont &font, const QColor &color=QColor())
Draws text on a painter at a specific position, taking care of composer specific issues (calculation ...
void setEmptyTableBehaviour(const EmptyTableMode mode)
Sets the behaviour for empty tables with no content rows.
static QColor decodeColor(QString str)
static double fontAscentMM(const QFont &font)
Calculate font ascent in millimeters, including workarounds for QT font rendering issues...
virtual void render(QPainter *p, const QRectF &renderExtent, const int frameIndex) override
Renders a portion of the multiframe's content into a painter.
void setShowEmptyRows(const bool showEmpty)
Sets whether empty rows should be drawn.
void recalculateTableSize()
Recalculates and updates the size of the table and all table frames.
EmptyTableMode mEmptyTableMode
Behaviour for empty tables.
QColor mHeaderFontColor
Header font color.
double mCellMargin
Margin between cell borders and cell text.
void setColumns(QgsComposerTableColumns columns)
Replaces the columns in the table with a specified list of QgsComposerTableColumns.
static QString encodeColor(QColor color)
HeaderMode mHeaderMode
Header display mode.
void drawVerticalGridLines(QPainter *painter, const QMap< int, double > &maxWidthMap, const int numberRows, const bool hasHeader, const bool mergeCells=false) const
Draws the vertical grid lines for the table.
QList< QgsComposerTableRow > QgsComposerTableContents
List of QgsComposerTableRows, representing rows and column cell contents for a QgsComposerTable.
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false)
Restores state information about base multiframe object from a DOM element.
void setContentFontColor(const QColor &color)
Sets the color used to draw text in table body cells.
bool mShowEmptyRows
True if empty rows should be shown in the table.
bool contentsContainsRow(const QgsComposerTableContents &contents, const QgsComposerTableRow &row) const
Checks whether a table contents contains a given row.
void recalculateFrameRects()
Forces a recalculation of all the associated frame's scene rectangles.
virtual QSizeF fixedFrameSize(const int frameIndex=-1) const override
Returns the fixed size for a frame, if desired.
QPair< int, int > rowRange(const QRectF &extent, const int frameIndex) const
Calculates a range of rows which should be visible in a given frame extent.
double totalHeight() const
Returns total height of table contents.
Abstract base class for composer items with the ability to distribute the content to several frames (...
bool _writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const
Stores state information about base multiframe object in DOM element.
HeaderHAlignment mHeaderHAlignment
Alignment for table headers.
void setEmptyTableMessage(const QString message)
Sets the message for empty tables with no content rows.
void recalculateFrameSizes() override
QMap< int, double > mMaxColumnWidthMap
Map of maximum width for each column.
int frameCount() const
Returns the number of frames associated with this multiframe.
Stores properties of a column in a QgsComposerTable.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false) override
Reads multiframe state information from a DOM element.
virtual bool calculateMaxColumnWidths()
Calculates the maximum width of text shown in columns.
Graphics scene for map printing.
void setHeaderMode(const HeaderMode mode)
Sets the display mode for headers in the table.
void setBackgroundColor(const QColor &color)
Sets color used for background of table.
QColor mGridColor
Color for grid lines.
void setHeaderHAlignment(const HeaderHAlignment alignment)
Sets the horizontal alignment for table headers.
QgsComposerTableContents mTableContents
Contents to show in table.
QString mEmptyTableMessage
String to show in empty tables.
static double textWidthMM(const QFont &font, const QString &text)
Calculate font width in millimeters for a string, including workarounds for QT font rendering issues...
QgsComposition * mComposition
void deleteFrames()
Removes and deletes all child frames.
QgsComposerTableColumns mColumns
Columns to show in table.
void setHeaderFontColor(const QColor &color)
Sets the color used to draw header text in the table.
void setHeaderFont(const QFont &font)
Sets the font used to draw header text in the table.
QRectF extent() const
Returns the visible portion of the multi frame's content which is shown in this frame.
virtual void refreshAttributes()
Refreshes the contents shown in the table by querying for new data.
double paperHeight() const
Height of paper item.
QList< QgsComposerTableColumn * > QgsComposerTableColumns
List of column definitions for a QgsComposerTable.
void drawHorizontalGridLines(QPainter *painter, const int rows, const bool drawHeaderLines) const
Draws the horizontal grid lines for the table.
virtual ~QgsComposerTableV2()
QgsComposerTableColumns * columns()
Returns a pointer to the list of QgsComposerTableColumns shown in the table.
void setCellMargin(const double margin)
Sets the margin distance between cell borders and their contents.
bool showGrid() const
Returns whether grid lines are drawn in the table.
int frameIndex(QgsComposerFrame *frame) const
Returns the index of a frame within the multiframe.
virtual bool getTableContents(QgsComposerTableContents &contents)=0
Fetches the contents used for the cells in the table.
int rowsVisible(const int frameIndex) const
Calculates how many content rows are visible within a given frame.
QgsComposerFrame * frame(int i) const
Returns a child frame from the multiframe.
virtual bool readXML(const QDomElement &columnElem)
Reads the column's properties from xml.
void update()
Forces a redraw of all child frames.
QList< QVariant > QgsComposerTableRow
List of QVariants, representing a the contents of a single row in a QgsComposerTable.
void setContentFont(const QFont &font)
Sets the font used to draw text in table body cells.
QColor mBackgroundColor
Color for table background.
QgsComposition::PlotStyle plotStyle() const
QgsComposerTableContents * contents()
Returns the current contents of the table.
void handleFrameRemoval(QgsComposerItem *item)
Called before a frame is going to be removed.
virtual QSizeF totalSize() const override
Returns the total size of the multiframe's content.
void changed()
Emitted when the properties of a multi frame have changed, and the GUI item widget must be updated...