Skip to content

Commit 372534e

Browse files
committed
[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
1 parent 29cc064 commit 372534e

File tree

6 files changed

+452
-94
lines changed

6 files changed

+452
-94
lines changed

python/core/composer/qgscomposertablev2.sip

Lines changed: 84 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ class QgsComposerTableV2: QgsComposerMultiFrame
322322
*/
323323
virtual bool calculateMaxColumnWidths();
324324

325+
/** Calculates the maximum height of text shown in rows.
326+
* @note added in QGIS 2.12
327+
*/
328+
virtual bool calculateMaxRowHeights();
329+
325330
/** Returns total width of table contents.
326331
* @returns table width
327332
* @see totalHeight
@@ -333,37 +338,110 @@ class QgsComposerTableV2: QgsComposerMultiFrame
333338
* @returns total height
334339
* @see totalWidth
335340
*/
336-
double totalHeight() const;
341+
//not const, as needs to call calculateMaxRowHeights()
342+
double totalHeight();
343+
344+
/** Calculates how many content rows would be visible within a frame of the specified
345+
* height.
346+
* @param frameHeight height of frame
347+
* @param firstRow index of first row visible in frame (where 0 = first row in table)
348+
* @param includeHeader set to true if frame would include a header row
349+
* @param includeEmptyRows set to true to also include rows which would be empty in the returned count. For instance,
350+
* if the frame would include all table content rows and have space left for extra rows then setting this parameter
351+
* to true would also include a count of these extra blank rows.
352+
* @returns number of visible content rows (excluding header row)
353+
* @note added in QGIS 2.12
354+
*/
355+
int rowsVisible( double frameHeight, int firstRow, bool includeHeader, bool includeEmptyRows ) const;
356+
357+
/** Calculates how many content rows are visible within a given frame.
358+
* @param frameIndex index number for frame
359+
* @param firstRow index of first row visible in frame (where 0 = first row in table)
360+
* @param includeEmptyRows set to true to also include rows which would be empty in the returned count. For instance,
361+
* if the frame would include all table content rows and have space left for extra rows then setting this parameter
362+
* to true would also include a count of these extra blank rows.
363+
* @returns number of visible content rows (excludes header rows)
364+
* @note added in QGIS 2.12
365+
*/
366+
int rowsVisible( int frameIndex, int firstRow, bool includeEmptyRows ) const;
367+
368+
/** Calculates a range of rows which should be visible in a given frame.
369+
* @param frameIndex index number for frame
370+
* @returns row range
371+
* @note added in QGIS 2.12
372+
*/
373+
QPair<int, int> rowRange( int frameIndex ) const;
374+
375+
/** Draws the horizontal grid lines for the table.
376+
* @param painter destination painter for grid lines
377+
* @param firstRow index corresponding to first row shown in frame
378+
* @param lastRow index corresponding to last row shown in frame. If greater than the number of content rows in the
379+
* table, then the default row height will be used for the remaining rows.
380+
* @param drawHeaderLines set to true to include for the table header
381+
* @see drawVerticalGridLines
382+
* @note added in QGIS 2.12
383+
*/
384+
void drawHorizontalGridLines( QPainter* painter, int firstRow, int lastRow, bool drawHeaderLines ) const;
385+
386+
/** Draws the vertical grid lines for the table.
387+
* @param painter destination painter for grid lines
388+
* @param maxWidthMap QMap of int to double, where the int contains the column number and the double is the
389+
* maximum width of text present in the column.
390+
* @param firstRow index corresponding to first row shown in frame
391+
* @param lastRow index corresponding to last row shown in frame. If greater than the number of content rows in the
392+
* table, then the default row height will be used for the remaining rows.
393+
* @param hasHeader set to true if table frame includes header cells
394+
* @param mergeCells set to true to merge table content cells
395+
* @note not available in python bindings
396+
* @see drawVerticalGridLines
397+
* @see calculateMaxColumnWidths
398+
* @note not available in python bindings
399+
* @note added in QGIS 2.12
400+
*/
401+
//void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, int firstRow, int lastRow, bool hasHeader, bool mergeCells = false ) const;
402+
403+
/** Recalculates and updates the size of the table and all table frames.
404+
*/
405+
void recalculateTableSize();
406+
407+
/** Checks whether a table contents contains a given row
408+
* @param contents table contents to check
409+
* @param row row to check for
410+
* @returns true if contents contains rows
411+
*/
412+
bool contentsContainsRow( const QgsComposerTableContents &contents, const QgsComposerTableRow &row ) const;
413+
414+
//deprecated methods
337415

338416
/** Calculates how many content rows are visible within a given frame
339417
* @param frameIndex index number for frame
340418
* @returns number of visible content rows (excludes header rows)
341419
*/
342-
int rowsVisible( const int frameIndex ) const;
420+
int rowsVisible( const int frameIndex ) const /Deprecated/;
343421

344422
/** Calculates how many content rows would be visible within a specified
345423
* height.
346424
* @param frameHeight height of frame
347425
* @param includeHeader set to true if frame would include a header row
348426
* @returns number of visible content rows (excluding header row)
349427
*/
350-
int rowsVisible( const double frameHeight, const bool includeHeader ) const;
428+
int rowsVisible( const double frameHeight, const bool includeHeader ) const /Deprecated/;
351429

352430
/** Calculates a range of rows which should be visible in a given
353431
* frame extent.
354432
* @param extent visible extent
355433
* @param frameIndex index number for frame
356434
* @returns row range
357435
*/
358-
QPair<int, int> rowRange( const QRectF &extent, const int frameIndex ) const;
436+
QPair<int, int> rowRange( const QRectF &extent, const int frameIndex ) const /Deprecated/;
359437

360438
/** Draws the horizontal grid lines for the table.
361439
* @param painter destination painter for grid lines
362440
* @param rows number of rows shown in table
363441
* @param drawHeaderLines set to true to include for the table header
364442
* @see drawVerticalGridLines
365443
*/
366-
void drawHorizontalGridLines( QPainter* painter, const int rows, const bool drawHeaderLines ) const;
444+
void drawHorizontalGridLines( QPainter* painter, const int rows, const bool drawHeaderLines ) const /Deprecated/;
367445

368446
/** Draws the vertical grid lines for the table.
369447
* @param painter destination painter for grid lines
@@ -377,17 +455,7 @@ class QgsComposerTableV2: QgsComposerMultiFrame
377455
* @see calculateMaxColumnWidths
378456
* @note not available in python bindings
379457
*/
380-
// void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, const int numberRows, const bool hasHeader, const bool mergeCells = false ) const;
381-
382-
/** Recalculates and updates the size of the table and all table frames.
383-
*/
384-
void recalculateTableSize();
458+
// void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, const int numberRows, const bool hasHeader, const bool mergeCells = false ) const /Deprecated/;
385459

386-
/** Checks whether a table contents contains a given row
387-
* @param contents table contents to check
388-
* @param row row to check for
389-
* @returns true if contents contains rows
390-
*/
391-
bool contentsContainsRow( const QgsComposerTableContents &contents, const QgsComposerTableRow &row ) const;
392460

393461
};

0 commit comments

Comments
 (0)