bool QgsComposerTableV2::calculateMaxColumnWidths() { mMaxColumnWidthMap.clear(); //total number of cells (rows + 1 for header) int cols = mColumns.count(); int cells = cols * ( mTableContents.count() + 1 ); QVector< double > widths( cells ); //first, go through all the column headers and calculate the sizes QgsComposerTableColumns::const_iterator columnIt = mColumns.constBegin(); int col = 0; for ( ; columnIt != mColumns.constEnd(); ++columnIt ) { if (( *columnIt )->width() > 0 ) { //column has manually specified width widths[col] = ( *columnIt )->width(); } else if ( mHeaderMode != QgsComposerTableV2::NoHeaders ) { widths[col] = QgsComposerUtils::textWidthMM( mHeaderFont, ( *columnIt )->heading() ); } else { widths[col] = 0.0; } col++; } //next, go through all the table contents and calculate the sizes QgsComposerTableContents::const_iterator rowIt = mTableContents.constBegin(); double currentCellTextWidth; int row = 1; for ( ; rowIt != mTableContents.constEnd(); ++rowIt ) { QgsComposerTableRow::const_iterator colIt = rowIt->constBegin(); col = 0; for ( ; colIt != rowIt->constEnd(); ++colIt ) { if ( mColumns.at( col )->width() <= 0 ) { //column width set to automatic, so check content size QStringList multiLineSplit = ( *colIt ).toString().split( "\n" ); currentCellTextWidth = 0; Q_FOREACH ( QString line, multiLineSplit ) { currentCellTextWidth = qMax( currentCellTextWidth, QgsComposerUtils::textWidthMM( mContentFont, line ) ); } widths[ row * cols + col ] = currentCellTextWidth; } else {
bool QgsComposerTableV2::calculateMaxColumnWidths() { mMaxColumnWidthMap.clear(); //first, go through all the column headers and calculate the max width values QgsComposerTableColumns::const_iterator columnIt = mColumns.constBegin(); int col = 0; for ( ; columnIt != mColumns.constEnd(); ++columnIt ) { double width = 0; if (( *columnIt )->width() > 0 ) { //column has manually specified width width = ( *columnIt )->width(); } else if ( mHeaderMode != QgsComposerTableV2::NoHeaders ) { width = QgsComposerUtils::textWidthMM( mHeaderFont, ( *columnIt )->heading() ); } mMaxColumnWidthMap.insert( col, width ); col++; } //next, go through all the table contents and calculate the max width values QgsComposerTableContents::const_iterator rowIt = mTableContents.constBegin(); double currentCellTextWidth; for ( ; rowIt != mTableContents.constEnd(); ++rowIt ) { QgsComposerTableRow::const_iterator colIt = rowIt->constBegin(); int columnNumber = 0; for ( ; colIt != rowIt->constEnd(); ++colIt ) { if ( mColumns.at( columnNumber )->width() <= 0 ) { //column width set to automatic, so check content size currentCellTextWidth = QgsComposerUtils::textWidthMM( mContentFont, ( *colIt ).toString() ); mMaxColumnWidthMap[ columnNumber ] = qMax( currentCellTextWidth, mMaxColumnWidthMap[ columnNumber ] ); } columnNumber++; } } return true; }