Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[composer] Add proper handling of multiline text in attribute tables
Previously multi-line text would overflow onto neighbouring cells.
Now rows will be expanded to fit required height of text.
Fix #10273.

Sponsored by City of Uster
  • Loading branch information
nyalldawson committed Aug 18, 2015
1 parent 29cc064 commit 372534e
Show file tree
Hide file tree
Showing 6 changed files with 452 additions and 94 deletions.
100 changes: 84 additions & 16 deletions python/core/composer/qgscomposertablev2.sip
Expand Up @@ -322,6 +322,11 @@ class QgsComposerTableV2: QgsComposerMultiFrame
*/
virtual bool calculateMaxColumnWidths();

/** Calculates the maximum height of text shown in rows.
* @note added in QGIS 2.12
*/
virtual bool calculateMaxRowHeights();

/** Returns total width of table contents.
* @returns table width
* @see totalHeight
Expand All @@ -333,37 +338,110 @@ class QgsComposerTableV2: QgsComposerMultiFrame
* @returns total height
* @see totalWidth
*/
double totalHeight() const;
//not const, as needs to call calculateMaxRowHeights()
double totalHeight();

/** Calculates how many content rows would be visible within a frame of the specified
* height.
* @param frameHeight height of frame
* @param firstRow index of first row visible in frame (where 0 = first row in table)
* @param includeHeader set to true if frame would include a header row
* @param includeEmptyRows set to true to also include rows which would be empty in the returned count. For instance,
* if the frame would include all table content rows and have space left for extra rows then setting this parameter
* to true would also include a count of these extra blank rows.
* @returns number of visible content rows (excluding header row)
* @note added in QGIS 2.12
*/
int rowsVisible( double frameHeight, int firstRow, bool includeHeader, bool includeEmptyRows ) const;

/** Calculates how many content rows are visible within a given frame.
* @param frameIndex index number for frame
* @param firstRow index of first row visible in frame (where 0 = first row in table)
* @param includeEmptyRows set to true to also include rows which would be empty in the returned count. For instance,
* if the frame would include all table content rows and have space left for extra rows then setting this parameter
* to true would also include a count of these extra blank rows.
* @returns number of visible content rows (excludes header rows)
* @note added in QGIS 2.12
*/
int rowsVisible( int frameIndex, int firstRow, bool includeEmptyRows ) const;

/** Calculates a range of rows which should be visible in a given frame.
* @param frameIndex index number for frame
* @returns row range
* @note added in QGIS 2.12
*/
QPair<int, int> rowRange( int frameIndex ) const;

/** Draws the horizontal grid lines for the table.
* @param painter destination painter for grid lines
* @param firstRow index corresponding to first row shown in frame
* @param lastRow index corresponding to last row shown in frame. If greater than the number of content rows in the
* table, then the default row height will be used for the remaining rows.
* @param drawHeaderLines set to true to include for the table header
* @see drawVerticalGridLines
* @note added in QGIS 2.12
*/
void drawHorizontalGridLines( QPainter* painter, int firstRow, int lastRow, 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 firstRow index corresponding to first row shown in frame
* @param lastRow index corresponding to last row shown in frame. If greater than the number of content rows in the
* table, then the default row height will be used for the remaining rows.
* @param hasHeader set to true if table frame includes header cells
* @param mergeCells set to true to merge table content cells
* @note not available in python bindings
* @see drawVerticalGridLines
* @see calculateMaxColumnWidths
* @note not available in python bindings
* @note added in QGIS 2.12
*/
//void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, int firstRow, int lastRow, bool hasHeader, bool mergeCells = false ) const;

/** Recalculates and updates the size of the table and all table frames.
*/
void recalculateTableSize();

/** Checks whether a table contents contains a given row
* @param contents table contents to check
* @param row row to check for
* @returns true if contents contains rows
*/
bool contentsContainsRow( const QgsComposerTableContents &contents, const QgsComposerTableRow &row ) const;

//deprecated methods

/** 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;
int rowsVisible( const int frameIndex ) const /Deprecated/;

/** 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;
int rowsVisible( const double frameHeight, const bool includeHeader ) const /Deprecated/;

/** 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;
QPair<int, int> rowRange( const QRectF &extent, const int frameIndex ) const /Deprecated/;

/** 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;
void drawHorizontalGridLines( QPainter* painter, const int rows, const bool drawHeaderLines ) const /Deprecated/;

/** Draws the vertical grid lines for the table.
* @param painter destination painter for grid lines
Expand All @@ -377,17 +455,7 @@ class QgsComposerTableV2: QgsComposerMultiFrame
* @see calculateMaxColumnWidths
* @note not available in python bindings
*/
// void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, const int numberRows, const bool hasHeader, const bool mergeCells = false ) const;

/** Recalculates and updates the size of the table and all table frames.
*/
void recalculateTableSize();
// void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, const int numberRows, const bool hasHeader, const bool mergeCells = false ) const /Deprecated/;

/** Checks whether a table contents contains a given row
* @param contents table contents to check
* @param row row to check for
* @returns true if contents contains rows
*/
bool contentsContainsRow( const QgsComposerTableContents &contents, const QgsComposerTableRow &row ) const;

};

1 comment on commit 372534e

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 372534e Aug 19, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's the jumping-up-and-down emoji when we need it! 👍

Please sign in to comment.