diff options
author | Thomas Zander <thomas.zander@trolltech.com> | 2009-05-12 18:57:35 +0200 |
---|---|---|
committer | Thomas Zander <thomas.zander@trolltech.com> | 2009-05-12 18:57:35 +0200 |
commit | 47b25e3e74de782c4a9eff974cb5933cc9e01328 (patch) | |
tree | 63c08a81f043e98099f94ceea68c38dc117e79e7 | |
parent | 0486d9abaaf7b52beb8526d8497a60ebaaef6857 (diff) |
Remove the second paint method since thats useless now. Cells
are painted as items.
-rw-r--r-- | examples/spreadsheet/spreadsheet.cpp | 15 | ||||
-rw-r--r-- | src/qgraphicstableview.cpp | 69 | ||||
-rw-r--r-- | src/qgraphicstableview.h | 18 |
3 files changed, 30 insertions, 72 deletions
diff --git a/examples/spreadsheet/spreadsheet.cpp b/examples/spreadsheet/spreadsheet.cpp index 71dd24e..8a2285c 100644 --- a/examples/spreadsheet/spreadsheet.cpp +++ b/examples/spreadsheet/spreadsheet.cpp @@ -80,15 +80,16 @@ void SpreadSheet::print() const QSizeF visibleSize(rect.width() / scaleX, rect.height() / scaleY); QtTableController *controller = mainwindow.table->controller(); + Q_ASSERT(controller); + QtGraphicsTableView *view = controller->view(); + Q_ASSERT(view); - QtTableOption option; -//option.flags = QtGraphicsTableView::PaintGrid; int row = 0; int column; bool first = true; while (row < controller->model()->rowCount()) { column = 0; - option.firstRow = row; + view->setFirstRow(row); qreal height = visibleSize.height(); while (true) { const qreal rowHeight = controller->view()->rowHeight(row); @@ -104,7 +105,7 @@ void SpreadSheet::print() printer.newPage(); } first = false; - option.firstColumn = column; + view->setFirstColumn(column); qreal width = visibleSize.width(); while (true) { @@ -116,8 +117,10 @@ void SpreadSheet::print() ++column; width -= columnWidth; } - option.section = QRectF(0, 0, visibleSize.width() - width, visibleSize.height() - height); - controller->view()->paintSection(&painter, &option); + painter.setClipRect(QRectF(0, 0, visibleSize.width() - width, visibleSize.height() - height)); + view->doLayout(); + view->paint(&painter, 0); + // paint children } } } diff --git a/src/qgraphicstableview.cpp b/src/qgraphicstableview.cpp index f7937e3..91f6a86 100644 --- a/src/qgraphicstableview.cpp +++ b/src/qgraphicstableview.cpp @@ -39,16 +39,6 @@ #include <qgraphicssceneevent.h> -// QtTableOption - -QtTableOption::QtTableOption(const QStyleOptionGraphicsItem *option) - : graphicsOption(option), - flags(0), - firstRow(0), - firstColumn(0) -{ -} - // QtGraphicsTableViewItem QtGraphicsTableViewItem::QtGraphicsTableViewItem(int row, int column, QtGraphicsTableView *view) @@ -997,71 +987,54 @@ bool QtGraphicsTableView::showGrid() const /*! Paints the table using the given \a painter */ -void QtGraphicsTableView::paint(QPainter *painter, const QStyleOptionGraphicsItem *graphicsOption, QWidget *widget) -{ - Q_UNUSED(widget); - Q_D(const QtGraphicsTableView); - QtTableOption option(graphicsOption); - option.flags = PaintGrid; - option.flags |= PaintBackground; - - if (d->horizontalHeader) - option.firstColumn = d->horizontalHeader->firstSection(); - else if (d->model) - option.firstColumn = d->firstColumn; - - if (d->verticalHeader) - option.firstRow = d->verticalHeader->firstSection(); - else if (d->model) - option.firstRow = d->firstRow; - - if (graphicsOption) { - //painter->translate(graphicsOption->exposedRect.topLeft()); - option.section = graphicsOption->exposedRect; - } else { - option.section = QRectF(QPointF(), size()); - } - - //painter->setClipRect(0, 0, option.section.width(), option.section.height()); - paintSection(painter, &option); -} -/*! - Paints the table using the given \a painter - */ -void QtGraphicsTableView::paintSection(QPainter *painter, const QtTableOption *tableOption) +void QtGraphicsTableView::paint(QPainter *painter, const QStyleOptionGraphicsItem *graphicsOption, QWidget *widget) { Q_D(const QtGraphicsTableView); - Q_ASSERT(tableOption); + Q_UNUSED(widget); int verticalCount = 0; int horizontalCount = 0; qreal verticalOffset = 0; qreal horizontalOffset = 0; QVector<int> verticalMapping; QVector<int> horizontalMapping; - const QStyleOptionGraphicsItem *graphicsOption = tableOption->graphicsOption; - QRectF area = tableOption->section; + QRectF area; + if (graphicsOption) { + area = graphicsOption->exposedRect; + } else if (painter->hasClipping()) { + area = painter->clipRegion().boundingRect(); + } else { + area = QRectF(QPoint(), size()); + } + + int firstRow = 0; + int firstColumn = 0; if (d->horizontalHeader) { horizontalCount = d->horizontalHeader->sectionCount(); horizontalOffset = d->horizontalHeader->offset(); horizontalMapping = d->horizontalHeader->indexMapping(); + firstColumn = d->horizontalHeader->firstSection(); } else if (d->model) { horizontalCount = d->model->columnCount(); horizontalOffset = d->horizontalOffset; + firstColumn = d->firstColumn; } if (d->verticalHeader) { verticalCount = d->verticalHeader->sectionCount(); verticalOffset = d->verticalHeader->offset(); verticalMapping = d->verticalHeader->indexMapping(); + firstRow = d->verticalHeader->firstSection(); } else if (d->model) { verticalCount = d->model->rowCount(); verticalOffset = d->verticalOffset; + firstRow = d->firstRow; } + // paint the contents int row; int column; - int vertical = tableOption->firstRow; int horizontal; + int vertical = firstRow; qreal rowHeight; qreal columnWidth; qreal x; @@ -1078,14 +1051,14 @@ void QtGraphicsTableView::paintSection(QPainter *painter, const QtTableOption *t rowHeight = d->verticalHeader ? d->verticalHeader->sectionSize(row) : d->defaultRowHeight; if (y >= area.top()) { x = 0; - horizontal = tableOption->firstColumn; + horizontal = firstColumn; while (x < area.width() && horizontal < horizontalCount) { column = horizontalMapping.value(horizontal, horizontal); columnWidth = d->horizontalHeader ? d->horizontalHeader->sectionSize(column) : d->defaultColumnWidth; if (x >= area.left()) { QRectF rect(x, y, columnWidth - gridSize, rowHeight - gridSize); // draw grid - if (d->showGrid && (tableOption->flags & PaintGrid)) { + if (d->showGrid) { QPen pen = painter->pen(); painter->setPen(gridPen); painter->drawLine(int(rect.left()), int(rect.bottom()), int(rect.right()), int(rect.bottom())); diff --git a/src/qgraphicstableview.h b/src/qgraphicstableview.h index 1f10a5b..cef611c 100644 --- a/src/qgraphicstableview.h +++ b/src/qgraphicstableview.h @@ -61,12 +61,6 @@ class Q_ITEMVIEWSNG_EXPORT QtGraphicsTableView : public QGraphicsWidget Q_PROPERTY(QtGraphicsHeader* verticalHeader READ verticalHeader WRITE setVerticalHeader) public: - enum PaintingFlag { - PaintGrid = 0x00000001, - PaintBackground = 0x00000002 - }; - Q_DECLARE_FLAGS(PaintingFlags, PaintingFlag) - explicit QtGraphicsTableView(QGraphicsWidget *parent = 0, Qt::WindowFlags wFlags = 0); virtual ~QtGraphicsTableView(); @@ -218,18 +212,6 @@ private: Q_DECLARE_PRIVATE(QtGraphicsTableViewItem) }; -class Q_ITEMVIEWSNG_EXPORT QtTableOption -{ -public: - QtTableOption(const QStyleOptionGraphicsItem *graphicsOption = 0); - - const QStyleOptionGraphicsItem * const graphicsOption; - QtGraphicsTableView::PaintingFlags flags; - int firstRow; - int firstColumn; - QRectF section; -}; - QT_END_NAMESPACE QT_END_HEADER |