本文整理汇总了C++中QAbstractItemModel::span方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemModel::span方法的具体用法?C++ QAbstractItemModel::span怎么用?C++ QAbstractItemModel::span使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemModel
的用法示例。
在下文中一共展示了QAbstractItemModel::span方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cellRect
void KDReports::SpreadsheetReportLayout::paintPageContent(int pageNumber, QPainter &painter)
{
//qDebug() << "painting with" << m_tableLayout.scaledFont();
QAbstractItemModel* model = m_tableLayout.m_model;
const qreal padding = m_tableLayout.scaledCellPadding();
const QRect cellCoords = m_pageRects[pageNumber];
//qDebug() << "painting page" << pageNumber << "cellCoords=" << cellCoords;
qreal y = 0 /*m_topMargin*/; // in pixels
const qreal rowHeight = m_tableLayout.rowHeight();
if ( m_tableLayout.m_horizontalHeaderVisible ) {
qreal x = 0 /*m_leftMargin*/;
if ( m_tableLayout.m_verticalHeaderVisible ) {
x += m_tableLayout.vHeaderWidth();
}
for ( int col = cellCoords.left(); col <= cellCoords.right(); ++col )
{
const QRectF cellRect( x, y, m_tableLayout.m_columnWidths[ col ], m_tableLayout.hHeaderHeight() );
paintTableHorizontalHeader( cellRect, painter, col );
x += cellRect.width();
}
y += m_tableLayout.hHeaderHeight();
}
const int firstRow = cellCoords.top();
const int firstColumn = cellCoords.left();
const int numRows = cellCoords.height();
const int numColumns = cellCoords.width();
// This won't work across page breaks....
QVector<QBitArray> coveredCells;
coveredCells.resize( numRows );
for ( int row = firstRow; row <= cellCoords.bottom(); ++row )
coveredCells[row - firstRow].resize( numColumns );
for ( int row = firstRow; row <= cellCoords.bottom(); ++row )
{
qreal x = 0 /*m_leftMargin*/;
if ( m_tableLayout.m_verticalHeaderVisible ) {
x = paintTableVerticalHeader( x, y, painter, row );
}
painter.setFont( m_tableLayout.scaledFont() );
for ( int col = cellCoords.left(); col <= cellCoords.right(); ++col )
{
if (coveredCells[row - firstRow].testBit(col - firstColumn)) {
x += m_tableLayout.m_columnWidths[ col ];
continue;
}
const QModelIndex index = model->index( row, col );
const QSize span = model->span( index );
if (span.isValid()) {
for (int r = row; r < row + span.height() && r < numRows; ++r) {
for (int c = col; c < col + span.width() && c < numColumns; ++c) {
coveredCells[r - firstRow].setBit(c - firstColumn);
}
}
}
const QRectF cellRect( x, y, cellWidth( col, span.width() ), qMax(1, span.height()) * rowHeight );
const QRectF cellContentsRect = cellRect.adjusted( padding, padding, -padding, -padding );
//qDebug() << "cell" << row << col << "rect=" << cellRect;
const QString cellText = model->data( index, Qt::DisplayRole ).toString();
const QColor foreground = qvariant_cast<QColor>( model->data( index, Qt::ForegroundRole ) );
const QColor background = qvariant_cast<QColor>( model->data( index, Qt::BackgroundRole ) );
const Qt::Alignment alignment( model->data( index, Qt::TextAlignmentRole ).toInt() );
const QVariant decorationAlignment( model->data( index, KDReports::AutoTableElement::DecorationAlignmentRole ) );
const QVariant cellDecoration( model->data( index, Qt::DecorationRole ) );
if ( background.isValid() ) {
painter.fillRect( cellRect, QBrush( background ) );
} else if ( span.isValid() ) {
painter.fillRect( cellRect, Qt::white );
}
drawBorder(cellRect, painter);
// Per-cell font is not supported, on purpose. All rows use the same font,
// otherwise the calculations for making things fit into a number of pages
// become quite complex and slow.
//const QVariant cellFont = model->data( index, Qt::FontRole );
//if ( cellFont.isValid() )
// painter.setFont( qvariant_cast<QFont>( cellFont ) );
//else
// painter.setFont( scaledFont );
if ( foreground.isValid() )
painter.setPen( foreground );
paintTextAndIcon( painter, cellContentsRect, cellText, cellDecoration, decorationAlignment, alignment );
if ( foreground.isValid() )
painter.setPen( Qt::black );
x += m_tableLayout.m_columnWidths[ col ];
}
y += rowHeight;
}
}