52 , mEmptyTableMode( HeadersOnly )
53 , mShowEmptyRows( false )
54 , mHeaderFontColor(
Qt::black )
55 , mHeaderHAlignment( FollowColumn )
56 , mHeaderMode( FirstFrame )
57 , mContentFontColor(
Qt::black )
59 , mGridStrokeWidth( 0.5 )
60 , mGridColor(
Qt::black )
61 , mBackgroundColor(
Qt::white )
62 , mWrapBehaviour( TruncateText )
73 if ( !defaultFontString.
isEmpty() )
85 , mEmptyTableMode( HeadersOnly )
86 , mShowEmptyRows( false )
87 , mHeaderFontColor(
Qt::black )
88 , mHeaderHAlignment( FollowColumn )
89 , mHeaderMode( FirstFrame )
90 , mContentFontColor(
Qt::black )
92 , mGridStrokeWidth( 0.5 )
93 , mGridColor(
Qt::black )
94 , mBackgroundColor(
Qt::white )
95 , mWrapBehaviour( TruncateText )
133 ( *columnIt )->writeXML( columnElem, doc );
149 bool state =
_writeXML( elem, doc, ignoreFrames );
158 if ( !
_readXML( itemElem, doc, ignoreFrames ) )
194 if ( columnsList.
size() > 0 )
198 for (
int i = 0; i < columnEntryList.
size(); ++i )
209 if ( stylesList.
size() > 0 )
216 if ( styleList.
size() > 0 )
241 bool includeHeader =
false;
245 includeHeader =
true;
255 double headerHeight = 0;
268 double contentHeight = frameHeight - headerHeight;
272 return qMax( floor( contentHeight / rowHeight ), 0.0 );
278 double headerHeight = 0;
291 double contentHeight = frameHeight - headerHeight;
295 int currentRow = firstRow;
299 contentHeight -= currentRowHeight;
303 if ( includeEmptyRows && contentHeight > 0 )
306 currentRow += qMax( floor( contentHeight / rowHeight ), 0.0 );
309 return currentRow - firstRow - 1;
321 bool includeHeader =
false;
325 includeHeader =
true;
327 return rowsVisible( frameExtent.
height(), firstRow, includeHeader, includeEmptyRows );
336 return qMakePair( 0, 0 );
341 int rowsAlreadyShown = 0;
344 rowsAlreadyShown +=
rowsVisible( idx, rowsAlreadyShown,
false );
349 int possibleRowsVisible =
rowsVisible( frameIndex, rowsAlreadyShown,
false );
352 return qMakePair( firstVisible, lastVisible );
398 int numberRowsToDraw = rowsToShow.second - rowsToShow.first;
399 int numberEmptyRows = 0;
402 numberRowsToDraw =
rowsVisible( frameIndex, rowsToShow.first,
true );
403 numberEmptyRows = numberRowsToDraw - rowsToShow.second + rowsToShow.first;
405 bool mergeCells =
false;
419 p->
setPen( Qt::SolidLine );
421 double currentX = gridSize;
422 double currentY = gridSize;
438 Qt::TextFlag textFlag = ( Qt::TextFlag )0;
439 if (( *columnIt )->width() <= 0 )
444 textFlag = Qt::TextDontClip;
450 Qt::AlignmentFlag headerAlign = Qt::AlignLeft;
454 headerAlign = ( *columnIt )->hAlignment();
457 headerAlign = Qt::AlignLeft;
460 headerAlign = Qt::AlignHCenter;
463 headerAlign = Qt::AlignRight;
471 currentX += gridSize;
475 currentY += cellHeaderHeight;
476 currentY += gridSize;
484 for (
int row = rowsToShow.first; row < rowsToShow.second; ++row )
509 Qt::TextFlag textFlag = ( Qt::TextFlag )0;
515 textFlag = Qt::TextDontClip;
517 else if ( textRequiresWrapping( str, ( *columnIt )->width(),
mContentFont ) )
519 str = wrappedText( str, ( *columnIt )->width(),
mContentFont );
527 currentX += gridSize;
530 currentY += rowHeight;
531 currentY += gridSize;
535 if ( numberRowsToDraw > rowsDrawn )
541 for (
int row = rowsDrawn; row < numberRowsToDraw; ++row )
563 currentX += gridSize;
567 currentY += cellBodyHeight + gridSize;
588 double messageY = gridSize + ( drawHeader ? cellHeaderHeight + gridSize : 0 );
834 headers.
insert( col, ( *columnIt )->heading() );
842 Q_UNUSED( frameIndex );
855 return QSizeF( 0, height );
877 void QgsComposerTableV2::initStyles()
914 if (( *columnIt )->width() > 0 )
917 widths[col] = ( *columnIt )->width();
932 double currentCellTextWidth;
938 for ( ; colIt != rowIt->constEnd(); ++colIt )
944 currentCellTextWidth = 0;
945 Q_FOREACH (
const QString& line, multiLineSplit )
949 widths[ row * cols + col ] = currentCellTextWidth;
953 widths[ row * cols + col ] = 0;
962 for (
int col = 0; col < cols; ++col )
964 double maxColWidth = 0;
967 maxColWidth = qMax( widths[ row * cols + col ], maxColWidth );
1001 for ( ; colIt != rowIt->constEnd(); ++colIt )
1021 double maxRowHeight = 0;
1022 for (
int col = 0; col < cols; ++col )
1024 maxRowHeight = qMax( heights[ row * cols + col ], maxRowHeight );
1045 totalWidth += maxColWidthIt.
value();
1065 int rowsAlreadyShown = 0;
1067 int rowsVisibleInLastFrame = 0;
1068 double heightOfLastFrame = 0;
1069 for (
int idx = 0; idx < numberExistingFrames; ++idx )
1074 rowsVisibleInLastFrame =
rowsVisible( heightOfLastFrame, rowsAlreadyShown, hasHeader,
false );
1075 rowsAlreadyShown += rowsVisibleInLastFrame;
1076 height += heightOfLastFrame;
1087 if ( remainingRows <= 0 )
1101 int numberFramesMissing = 0;
1102 while ( remainingRows > 0 )
1104 numberFramesMissing++;
1106 rowsVisibleInLastFrame =
rowsVisible( heightOfLastFrame, rowsAlreadyShown, hasHeader,
false );
1107 if ( rowsVisibleInLastFrame < 1 )
1114 rowsAlreadyShown += rowsVisibleInLastFrame;
1120 height += heightOfLastFrame * numberFramesMissing;
1133 if ( lastRow - firstRow < 1 && !drawHeaderLines )
1140 double currentY = 0;
1141 currentY = halfGridStrokeWidth;
1142 if ( drawHeaderLines )
1148 for (
int row = firstRow; row < lastRow; ++row )
1164 bool QgsComposerTableV2::textRequiresWrapping(
const QString& text,
double columnWidth,
const QFont &font )
const
1170 double currentTextWidth = 0;
1171 Q_FOREACH (
const QString& line, multiLineSplit )
1176 return ( currentTextWidth > columnWidth );
1179 QString QgsComposerTableV2::wrappedText(
const QString &value,
double columnWidth,
const QFont &font )
const
1183 Q_FOREACH (
const QString& line, lines )
1185 if ( textRequiresWrapping( line, columnWidth, font ) )
1191 Q_FOREACH (
const QString& word, words )
1193 if ( textRequiresWrapping( word, columnWidth, font ) )
1196 if ( !wordsInCurrentLine.
isEmpty() )
1197 linesToProcess << wordsInCurrentLine;
1198 wordsInCurrentLine.
clear();
1199 linesToProcess << word;
1203 if ( !wordsInCurrentLine.
isEmpty() )
1204 wordsInCurrentLine.
append(
" " );
1205 wordsInCurrentLine.
append( word );
1208 if ( !wordsInCurrentLine.
isEmpty() )
1209 linesToProcess << wordsInCurrentLine;
1211 Q_FOREACH (
const QString& line, linesToProcess )
1215 while ( lastPos > -1 )
1217 if ( !textRequiresWrapping( remainingText.
left( lastPos ), columnWidth, font ) )
1219 outLines << remainingText.
left( lastPos );
1220 remainingText = remainingText.
mid( lastPos + 1 );
1223 lastPos = remainingText.
lastIndexOf(
" ", lastPos - 1 );
1225 outLines << remainingText;
1234 return outLines.
join(
"\n" );
1265 if ( lastRow - firstRow < 1 && !hasHeader )
1271 double tableHeight = 0;
1277 double headerHeight = tableHeight;
1280 for (
int row = firstRow; row < lastRow; ++row )
1287 double currentX = halfGridStrokeWidth;
1288 painter->
drawLine(
QPointF( currentX, halfGridStrokeWidth ),
QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
1292 for ( ; maxColWidthIt != maxWidthMap.
constEnd(); ++maxColWidthIt )
1295 if ( col == maxWidthMap.
size() || !mergeCells )
1297 painter->
drawLine(
QPointF( currentX, halfGridStrokeWidth ),
QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
1299 else if ( hasHeader )
1301 painter->
drawLine(
QPointF( currentX, halfGridStrokeWidth ),
QPointF( currentX, headerHeight - halfGridStrokeWidth ) );
1320 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...
QDomNodeList elementsByTagName(const QString &tagname) const
QColor backgroundColor() const
Returns the color used for the background of the table.
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.
WrapBehaviour mWrapBehaviour
void setShowGrid(const bool showGrid)
Sets whether grid lines should be drawn in the table.
QString & append(QChar ch)
bool mShowGrid
True if grid should be shown.
void setGridStrokeWidth(const double width)
Sets the width for grid lines in the table.
bool contains(const Key &key) const
double mGridStrokeWidth
Width of grid lines.
void setRenderHint(RenderHint hint, bool on)
QDomNode appendChild(const QDomNode &newChild)
void setGridColor(const QColor &color)
Sets color used for grid lines in the table.
void drawHorizontalGridLines(QPainter *painter, int firstRow, int lastRow, bool drawHeaderLines) const
Draws the horizontal grid lines for the table.
QString attribute(const QString &name, const QString &defValue) const
double totalHeight()
Returns total height of table contents.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
static QString encodeColor(const QColor &color)
void setEmptyTableMessage(const QString &message)
Sets the message for empty tables with no content rows.
const_iterator constBegin() const
const T & at(int i) const
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.
#define Q_NOWARN_DEPRECATED_PUSH
QMap< CellStyleGroup, QgsComposerTableStyle * > mCellStyles
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.
QPair< int, int > rowRange(const int frameIndex) const
Calculates a range of rows which should be visible in a given frame.
void setJoinStyle(Qt::PenJoinStyle style)
static double fontAscentMM(const QFont &font)
Calculate font ascent in millimeters, including workarounds for QT font rendering issues...
QString join(const QString &separator) const
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 drawLine(const QLineF &line)
void recalculateTableSize()
Recalculates and updates the size of the table and all table frames.
HeaderHAlignment
Controls how headers are horizontally aligned in a table.
double toDouble(bool *ok) const
EmptyTableMode mEmptyTableMode
Behaviour for empty tables.
QColor mHeaderFontColor
Header font color.
QString tr(const char *sourceText, const char *disambiguation, int n)
double mCellMargin
Margin between cell borders and cell text.
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
HeaderMode mHeaderMode
Header display mode.
int indexOf(const T &value, int from) const
bool enabled
Whether the styling option is enabled.
QDomElement toElement() const
QList< Key > keys() const
CellStyleGroup
Row or column groups for cell styling.
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false)
Restores state information about base multiframe object from a DOM element.
void drawRect(const QRectF &rectangle)
void setContentFontColor(const QColor &color)
Sets the color used to draw text in table body cells.
QString number(int n, int base)
EmptyTableMode
Controls how empty tables are displayed.
int count(const T &value) const
void append(const T &value)
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.
bool fromString(const QString &descrip)
virtual QSizeF fixedFrameSize(const int frameIndex=-1) const override
Returns the fixed size for a frame, if desired.
void setPen(const QColor &color)
void setAttribute(const QString &name, const QString &value)
int toInt(bool *ok, int base) const
Abstract base class for composer items with the ability to distribute the content to several frames (...
const_iterator constEnd() const
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.
bool writeXML(QDomElement &styleElem, QDomDocument &doc) const
Writes the style's properties to XML for storage.
void setWidthF(qreal width)
void setBrush(const QBrush &brush)
void recalculateFrameSizes() override
QMap< int, double > mMaxColumnWidthMap
Map of maximum width for each column.
static bool setFromXmlChildNode(QFont &font, const QDomElement &element, const QString &childNode)
Sets the properties of a font to match the properties stored in an XML child node.
WrapBehaviour
Controls how long strings in the table are handled.
int frameCount() const
Returns the number of frames associated with this multiframe.
Stores properties of a column in a QgsComposerTable.
void setColor(const QColor &color)
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.
int rowsVisible(double frameHeight, int firstRow, bool includeHeader, bool includeEmptyRows) const
Calculates how many content rows would be visible within a frame of the specified height...
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.
bool readXML(const QDomElement &styleElem)
Reads the style's properties from XML.
#define Q_NOWARN_DEPRECATED_POP
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.
const QgsComposerTableStyle * cellStyle(CellStyleGroup group) const
Returns the cell style for a cell group.
QgsComposerTableColumns mColumns
Columns to show in table.
QVariant value(const QString &key, const QVariant &defaultValue) const
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.
void setCellStyle(CellStyleGroup group, const QgsComposerTableStyle &style)
Sets the cell style for a cell group.
QString mid(int position, int n) const
virtual void refreshAttributes()
Refreshes the contents shown in the table by querying for new data.
void setFamily(const QString &family)
void setColumns(const QgsComposerTableColumns &columns)
Replaces the columns in the table with a specified list of QgsComposerTableColumns.
static double textHeightMM(const QFont &font, const QString &text, double multiLineHeight=1.0)
Calculate font height in millimeters for a string, including workarounds for QT font rendering issues...
double paperHeight() const
Height of paper item.
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
virtual ~QgsComposerTableV2()
QString left(int n) const
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.
static QColor decodeColor(const QString &str)
iterator insert(const Key &key, const T &value)
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.
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
void setContentFont(const QFont &font)
Sets the font used to draw text in table body cells.
const_iterator constBegin() const
Styling option for a composer table cell.
QColor mBackgroundColor
Color for table background.
QgsComposition::PlotStyle plotStyle() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
HeaderMode
Controls where headers are shown in the table.
void drawVerticalGridLines(QPainter *painter, const QMap< int, double > &maxWidthMap, int firstRow, int lastRow, bool hasHeader, bool mergeCells=false) const
Draws the vertical grid lines for 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 setWrapBehaviour(WrapBehaviour behaviour)
Sets the wrap behaviour for the table, which controls how text within cells is automatically wrapped...
QMap< int, double > mMaxRowHeightMap
Map of maximum height for each row.
virtual bool calculateMaxRowHeights()
Calculates the maximum height of text shown in rows.
void changed()
Emitted when the properties of a multi frame have changed, and the GUI item widget must be updated...
QDomNode at(int index) const
const T value(const Key &key) const
QColor cellBackgroundColor
Cell background color.