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() )
133 ( *columnIt )->writeXML( columnElem, doc );
141 for ( ; it != mCellStyleNames.
constEnd(); ++it )
150 bool state =
_writeXML( elem, doc, ignoreFrames );
159 if ( !
_readXML( itemElem, doc, ignoreFrames ) )
199 for (
int i = 0; i < columnEntryList.
size(); ++i )
215 for ( ; it != mCellStyleNames.
constEnd(); ++it )
244 bool includeHeader =
false;
248 includeHeader =
true;
258 double headerHeight = 0;
271 double contentHeight = frameHeight - headerHeight;
275 return qMax( floor( contentHeight / rowHeight ), 0.0 );
281 double headerHeight = 0;
294 double contentHeight = frameHeight - headerHeight;
298 int currentRow = firstRow;
302 contentHeight -= currentRowHeight;
306 if ( includeEmptyRows && contentHeight > 0 )
309 currentRow += qMax( floor( contentHeight / rowHeight ), 0.0 );
312 return currentRow - firstRow - 1;
324 bool includeHeader =
false;
328 includeHeader =
true;
330 return rowsVisible( frameExtent.
height(), firstRow, includeHeader, includeEmptyRows );
339 return qMakePair( 0, 0 );
344 int rowsAlreadyShown = 0;
347 rowsAlreadyShown +=
rowsVisible( idx, rowsAlreadyShown,
false );
352 int possibleRowsVisible =
rowsVisible( frameIndex, rowsAlreadyShown,
false );
355 return qMakePair( firstVisible, lastVisible );
401 int numberRowsToDraw = rowsToShow.second - rowsToShow.first;
402 int numberEmptyRows = 0;
405 numberRowsToDraw =
rowsVisible( frameIndex, rowsToShow.first,
true );
406 numberEmptyRows = numberRowsToDraw - rowsToShow.second + rowsToShow.first;
408 bool mergeCells =
false;
422 p->
setPen( Qt::SolidLine );
424 double currentX = gridSize;
425 double currentY = gridSize;
441 Qt::TextFlag textFlag =
static_cast< Qt::TextFlag
>( 0 );
442 if ( column->
width() <= 0 )
447 textFlag = Qt::TextDontClip;
453 Qt::AlignmentFlag headerAlign = Qt::AlignLeft;
460 headerAlign = Qt::AlignLeft;
463 headerAlign = Qt::AlignHCenter;
466 headerAlign = Qt::AlignRight;
474 currentX += gridSize;
478 currentY += cellHeaderHeight;
479 currentY += gridSize;
487 for (
int row = rowsToShow.first; row < rowsToShow.second; ++row )
512 Qt::TextFlag textFlag =
static_cast< Qt::TextFlag
>( 0 );
518 textFlag = Qt::TextDontClip;
530 currentX += gridSize;
533 currentY += rowHeight;
534 currentY += gridSize;
538 if ( numberRowsToDraw > rowsDrawn )
544 for (
int row = rowsDrawn; row < numberRowsToDraw; ++row )
566 currentX += gridSize;
570 currentY += cellBodyHeight + gridSize;
591 double messageY = gridSize + ( drawHeader ? cellHeaderHeight + gridSize : 0 );
837 headers.
insert( col, ( *columnIt )->heading() );
845 Q_UNUSED( frameIndex );
858 return QSizeF( 0, height );
880 void QgsComposerTableV2::initStyles()
917 if (( *columnIt )->width() > 0 )
920 widths[col] = ( *columnIt )->width();
935 double currentCellTextWidth;
941 for ( ; colIt != rowIt->constEnd(); ++colIt )
947 currentCellTextWidth = 0;
948 Q_FOREACH (
const QString& line, multiLineSplit )
952 widths[ row * cols + col ] = currentCellTextWidth;
956 widths[ row * cols + col ] = 0;
965 for (
int col = 0; col < cols; ++col )
967 double maxColWidth = 0;
970 maxColWidth = qMax( widths[ row * cols + col ], maxColWidth );
1004 for ( ; colIt != rowIt->constEnd(); ++colIt )
1024 double maxRowHeight = 0;
1025 for (
int col = 0; col < cols; ++col )
1027 maxRowHeight = qMax( heights[ row * cols + col ], maxRowHeight );
1048 totalWidth += maxColWidthIt.
value();
1068 int rowsAlreadyShown = 0;
1070 int rowsVisibleInLastFrame = 0;
1071 double heightOfLastFrame = 0;
1072 for (
int idx = 0; idx < numberExistingFrames; ++idx )
1077 rowsVisibleInLastFrame =
rowsVisible( heightOfLastFrame, rowsAlreadyShown, hasHeader,
false );
1078 rowsAlreadyShown += rowsVisibleInLastFrame;
1079 height += heightOfLastFrame;
1090 if ( remainingRows <= 0 )
1104 int numberFramesMissing = 0;
1105 while ( remainingRows > 0 )
1107 numberFramesMissing++;
1109 rowsVisibleInLastFrame =
rowsVisible( heightOfLastFrame, rowsAlreadyShown, hasHeader,
false );
1110 if ( rowsVisibleInLastFrame < 1 )
1117 rowsAlreadyShown += rowsVisibleInLastFrame;
1123 height += heightOfLastFrame * numberFramesMissing;
1136 if ( lastRow - firstRow < 1 && !drawHeaderLines )
1143 double currentY = 0;
1144 currentY = halfGridStrokeWidth;
1145 if ( drawHeaderLines )
1151 for (
int row = firstRow; row < lastRow; ++row )
1167 bool QgsComposerTableV2::textRequiresWrapping(
const QString& text,
double columnWidth,
const QFont &font )
const 1173 double currentTextWidth = 0;
1174 Q_FOREACH (
const QString& line, multiLineSplit )
1179 return ( currentTextWidth > columnWidth );
1182 QString QgsComposerTableV2::wrappedText(
const QString &value,
double columnWidth,
const QFont &font )
const 1186 Q_FOREACH (
const QString& line, lines )
1188 if ( textRequiresWrapping( line, columnWidth, font ) )
1194 Q_FOREACH (
const QString& word, words )
1196 if ( textRequiresWrapping( word, columnWidth, font ) )
1199 if ( !wordsInCurrentLine.
isEmpty() )
1200 linesToProcess << wordsInCurrentLine;
1201 wordsInCurrentLine.
clear();
1202 linesToProcess << word;
1206 if ( !wordsInCurrentLine.
isEmpty() )
1207 wordsInCurrentLine.
append(
' ' );
1208 wordsInCurrentLine.
append( word );
1211 if ( !wordsInCurrentLine.
isEmpty() )
1212 linesToProcess << wordsInCurrentLine;
1214 Q_FOREACH (
const QString& line, linesToProcess )
1218 while ( lastPos > -1 )
1220 if ( !textRequiresWrapping( remainingText.
left( lastPos ), columnWidth, font ) )
1222 outLines << remainingText.
left( lastPos );
1223 remainingText = remainingText.
mid( lastPos + 1 );
1226 lastPos = remainingText.
lastIndexOf(
' ', lastPos - 1 );
1228 outLines << remainingText;
1237 return outLines.
join(
"\n" );
1268 if ( lastRow - firstRow < 1 && !hasHeader )
1274 double tableHeight = 0;
1280 double headerHeight = tableHeight;
1283 for (
int row = firstRow; row < lastRow; ++row )
1290 double currentX = halfGridStrokeWidth;
1291 painter->
drawLine(
QPointF( currentX, halfGridStrokeWidth ),
QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
1295 for ( ; maxColWidthIt != maxWidthMap.
constEnd(); ++maxColWidthIt )
1298 if ( col == maxWidthMap.
size() || !mergeCells )
1300 painter->
drawLine(
QPointF( currentX, halfGridStrokeWidth ),
QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
1302 else if ( hasHeader )
1304 painter->
drawLine(
QPointF( currentX, halfGridStrokeWidth ),
QPointF( currentX, headerHeight - halfGridStrokeWidth ) );
1323 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
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.
bool showGrid() const
Returns whether grid lines are drawn in the table.
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.
Qt::AlignmentFlag hAlignment() const
Returns the horizontal alignment for a column, which controls the alignment used for drawing column v...
Qt::AlignmentFlag vAlignment() const
Returns the vertical alignment for a column, which controls the alignment used for drawing column val...
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
HeaderMode
Controls where headers are shown in the table.
static QString encodeColor(const QColor &color)
void setEmptyTableMessage(const QString &message)
Sets the message for empty tables with no content rows.
const QgsComposerTableStyle * cellStyle(CellStyleGroup group) const
Returns the cell style for a cell group.
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
static void drawText(QPainter *painter, 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 ...
QFont mHeaderFont
Header font.
void setEmptyTableBehaviour(const EmptyTableMode mode)
Sets the behaviour for empty tables with no content rows.
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.
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.
EmptyTableMode
Controls how empty tables are displayed.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
virtual QMap< int, QString > headerLabels() const
Returns the text used in the column headers for the table.
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QgsComposition::PlotStyle plotStyle() 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
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 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.
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 setContentFontColor(const QColor &color)
Sets the color used to draw text in table body cells.
QString number(int n, int base)
QRectF extent() const
Returns the visible portion of the multi frame's content which is shown in this frame.
int count(const T &value) const
void append(const T &value)
bool contentsContainsRow(const QgsComposerTableContents &contents, const QgsComposerTableRow &row) const
Checks whether a table contents contains a given row.
bool mShowEmptyRows
True if empty rows should be shown in the table.
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
HeaderHAlignment mHeaderHAlignment
Alignment for table headers.
WrapBehaviour
Controls how long strings in the table are handled.
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.
Stores properties of a column in a QgsComposerTable.
void setColor(const QColor &color)
double width() const
Returns the width for a column.
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.
QString heading() const
Returns the heading for a column, which is the value displayed in the columns header cell...
HeaderHAlignment
Controls how headers are horizontally aligned in a table.
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
const Key key(const T &value) const
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.
QVariant value(const QString &key, const QVariant &defaultValue) const
CellStyleGroup
Row or column groups for cell styling.
bool writeXML(QDomElement &styleElem, QDomDocument &doc) const
Writes the style's properties to XML for storage.
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.
void setCellStyle(CellStyleGroup group, const QgsComposerTableStyle &style)
Sets the cell style for a cell group.
QString mid(int position, int n) const
int frameCount() const
Returns the number of frames associated with this multiframe.
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...
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
virtual ~QgsComposerTableV2()
QgsComposerTableColumns * columns()
Returns a pointer to the list of QgsComposerTableColumns shown in the table.
QString left(int n) const
void setCellMargin(const double margin)
Sets the margin distance between cell borders and their contents.
int frameIndex(QgsComposerFrame *frame) const
Returns the index of a frame within the multiframe.
double paperHeight() const
Height of paper item.
virtual bool getTableContents(QgsComposerTableContents &contents)=0
Fetches the contents used for the cells in the table.
static QColor decodeColor(const QString &str)
QColor backgroundColor() const
Returns the color used for the background of the table.
iterator insert(const Key &key, const T &value)
QPair< int, int > rowRange(const int frameIndex) const
Calculates a range of rows which should be visible in a given frame.
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.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QgsComposerTableContents * contents()
Returns the current contents of the table.
QgsComposerFrame * frame(int i) const
Returns a child frame from the multiframe.
void handleFrameRemoval(QgsComposerItem *item)
Called before a frame is going to be removed.
void drawHorizontalGridLines(QPainter *painter, int firstRow, int lastRow, bool drawHeaderLines) const
Draws the horizontal grid lines for the table.
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...
bool _writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const
Stores state information about base multiframe object in DOM element.
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.