diff options
author | Thomas Zander <thomas.zander@trolltech.com> | 2009-05-20 13:14:34 +0200 |
---|---|---|
committer | Thomas Zander <thomas.zander@trolltech.com> | 2009-05-20 13:14:34 +0200 |
commit | 7f429adf7dc0dafecdbfd659d98a91535f854028 (patch) | |
tree | ba596cfe5e79934d57f89c05e69ebb2b084701ec | |
parent | 52269753203cdcd3f214223009cbbe83dda21d70 (diff) |
Do an experiment; copy the header data and apply on our print view.
-rw-r--r-- | src/qgraphicsheader.cpp | 12 | ||||
-rw-r--r-- | src/qgraphicsheader.h | 2 | ||||
-rw-r--r-- | src/qprintertableview.cpp | 36 |
3 files changed, 47 insertions, 3 deletions
diff --git a/src/qgraphicsheader.cpp b/src/qgraphicsheader.cpp index 4bd5869..0d1cc38 100644 --- a/src/qgraphicsheader.cpp +++ b/src/qgraphicsheader.cpp @@ -1550,4 +1550,16 @@ void QtGraphicsHeader::copyStyleOptionState(const QStyleOptionGraphicsItem *sour } } +void QtGraphicsHeader::setSectionsState(const QtGraphicsHeader &other) +{ + Q_D(QtGraphicsHeader); + d->cachedDataIndex = -1; + setSectionCount(other.sectionCount()); + d->sectionSizeSpans = other.d_ptr->sectionSizeSpans; + d->sectionModeSpans = other.d_ptr->sectionModeSpans; + d->sectionMovableSpans = other.d_ptr->sectionMovableSpans; + d->sectionClickableSpans = other.d_ptr->sectionClickableSpans; + d->sectionSelectedSpans = other.d_ptr->sectionSelectedSpans; +} + #include "moc_qgraphicsheader.cpp" diff --git a/src/qgraphicsheader.h b/src/qgraphicsheader.h index 694d6d6..cd0997e 100644 --- a/src/qgraphicsheader.h +++ b/src/qgraphicsheader.h @@ -105,6 +105,8 @@ public: //virtual void autoResizeSections(); void copyStyleOptionState(const QStyleOptionGraphicsItem *source, QStyleOptionHeader *dest); + void setSectionsState(const QtGraphicsHeader &other); + public Q_SLOTS: void setOffset(qreal offset); void setSectionCount(int count); diff --git a/src/qprintertableview.cpp b/src/qprintertableview.cpp index 67cb717..bf1fb54 100644 --- a/src/qprintertableview.cpp +++ b/src/qprintertableview.cpp @@ -28,8 +28,8 @@ #include "qgraphicstableview.h" #include "qtablemodelinterface.h" +#include "qgraphicsheader.h" -//#include <qstyleoption.h> #include <qgraphicsscene.h> #include <qpainter.h> #include <qtextdocument.h> @@ -200,8 +200,38 @@ bool QtPrinterTableView::print() QtGraphicsTableView view; scene.addItem(&view); view.setModel(d->model); - view.setHorizontalHeader(d->horizontalHeader); - view.setVerticalHeader(d->verticalHeader); + + + class QTableHeaderDataProvider2 : public QtGraphicsHeaderDataProvider + { + public: + QTableHeaderDataProvider2(QtTableModelInterface *model_) : model(model_) {} + QHash<int,QVariant> data(int logicalIndex, const QList<int> &roles) const + { + // ### call the model - temporary implementation + QHash<int,QVariant> hash; + for (int i = 0; i < roles.count(); ++i) + if (roles.at(i) == Qt::DisplayRole) + hash.insert(Qt::DisplayRole, logicalIndex + 1); + return hash; + } + QtTableModelInterface *model; + }; + + if (d->horizontalHeader) { + QtGraphicsHeader *header = new QtGraphicsHeader(Qt::Horizontal, &view); + header->setDataProvider(new QTableHeaderDataProvider2(d->model)); + header->setSectionsState(*d->horizontalHeader); + + + view.setHorizontalHeader(header); + } + if (d->verticalHeader) { + QtGraphicsHeader *header = new QtGraphicsHeader(Qt::Vertical, &view); + header->setDataProvider(new QTableHeaderDataProvider2(d->model)); + header->setSectionsState(*d->verticalHeader); + view.setVerticalHeader(header); + } QPainter painter; if (!painter.begin(d->printer)) { |