diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-05-12 17:42:55 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-05-12 17:42:55 (GMT) |
commit | 161e4c77b35a7cc4dda5b83b212fedaa02c46cdf (patch) | |
tree | 3728674860306f7a1ae0c4e75f35352af5f49ca9 /tests | |
parent | 47760d59d57f548d5816ae43e456c86e01146491 (diff) | |
parent | 770a2428357f030d4efad8c64ceb381ce50c9fb9 (diff) | |
download | Qt-161e4c77b35a7cc4dda5b83b212fedaa02c46cdf.zip Qt-161e4c77b35a7cc4dda5b83b212fedaa02c46cdf.tar.gz Qt-161e4c77b35a7cc4dda5b83b212fedaa02c46cdf.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-2: (33 commits)
Compile fix on Windows.
Remove an unnecessary assert.
Documentation for the Pad Navigator Example.
New Pad Nagivator example implementation.
Skip definition of wintab functions in case of QT_NO_TABLETEVENT.
Made curve tesselation be dynamically adjusted based on transform.
Modified QPainter and QPixmap benchmarks to use raster pixmaps.
Stabilize tst_QWidgetAction::visibilityUpdate
Fix compiler warning in QT_REQUIRE_VERSION
Stabilize tst_QColumnView::parentCurrentIndex
Really fix tst_QDockWidget::taskQTBUG_9758_undockedGeometry on Linux
Fix typos in Elastic Nodes example documentation.
Made paint engine texture drawing work in GL ES 2 and updated docs.
Opt out of visual-config size checks with extension
Fix off-by-one in text layouts and widget size hints on Mac
Stabilize tst_QDockWidget::taskQTBUG_9758_undockedGeometry
Mark QFileDialog::Options as a Q_FLAGS
fix tst_QDockWidget::taskQTBUG_9758_undockedGeometry on Linux
Fixed scrolling bugs in widget graphics effect backend.
Fixed source pixmap bug in widget graphics effect backend.
...
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qbuffer/tst_qbuffer.cpp | 26 | ||||
-rw-r--r-- | tests/auto/qcolumnview/tst_qcolumnview.cpp | 10 | ||||
-rw-r--r-- | tests/auto/qdockwidget/tst_qdockwidget.cpp | 24 | ||||
-rw-r--r-- | tests/auto/qfiledialog/tst_qfiledialog.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 57 | ||||
-rw-r--r-- | tests/auto/qimagereader/tst_qimagereader.cpp | 63 | ||||
-rw-r--r-- | tests/auto/qmessagebox/tst_qmessagebox.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp | 61 | ||||
-rw-r--r-- | tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp | 31 | ||||
-rw-r--r-- | tests/auto/qwidgetaction/tst_qwidgetaction.cpp | 6 | ||||
-rw-r--r-- | tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp | 38 | ||||
-rw-r--r-- | tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp | 79 |
12 files changed, 358 insertions, 43 deletions
diff --git a/tests/auto/qbuffer/tst_qbuffer.cpp b/tests/auto/qbuffer/tst_qbuffer.cpp index fcef6a3..dd5ca91 100644 --- a/tests/auto/qbuffer/tst_qbuffer.cpp +++ b/tests/auto/qbuffer/tst_qbuffer.cpp @@ -76,6 +76,7 @@ private slots: void atEnd(); void readLineBoundaries(); void writeAfterQByteArrayResize(); + void read_null(); protected slots: void readyReadSlot(); @@ -529,5 +530,30 @@ void tst_QBuffer::writeAfterQByteArrayResize() QCOMPARE(buffer.buffer().size(), 1000); } +void tst_QBuffer::read_null() +{ + QByteArray buffer; + buffer.resize(32000); + for (int i = 0; i < buffer.size(); ++i) + buffer[i] = char(i & 0xff); + + QBuffer in(&buffer); + in.open(QIODevice::ReadOnly); + + QByteArray chunk; + + chunk.resize(16380); + in.read(chunk.data(), 16380); + + QCOMPARE(chunk, buffer.mid(0, chunk.size())); + + in.read(chunk.data(), 0); + + chunk.resize(8); + in.read(chunk.data(), chunk.size()); + + QCOMPARE(chunk, buffer.mid(16380, chunk.size())); +} + QTEST_MAIN(tst_QBuffer) #include "tst_qbuffer.moc" diff --git a/tests/auto/qcolumnview/tst_qcolumnview.cpp b/tests/auto/qcolumnview/tst_qcolumnview.cpp index 90f499d..1da8c5d 100644 --- a/tests/auto/qcolumnview/tst_qcolumnview.cpp +++ b/tests/auto/qcolumnview/tst_qcolumnview.cpp @@ -596,11 +596,11 @@ void tst_QColumnView::clicked() QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, localPoint); QCOMPARE(clickedSpy.count(), 1); qApp->processEvents(); - + if (sizeof(qreal) != sizeof(double)) { QSKIP("Skipped due to rounding errors", SkipAll); } - + for (int i = 0; i < view.createdColumns.count(); ++i) { QAbstractItemView *column = view.createdColumns.at(i); if (column && column->selectionModel() && (column->rootIndex() == home)) @@ -961,9 +961,9 @@ void tst_QColumnView::parentCurrentIndex() QVERIFY(third.isValid()); view.setCurrentIndex(third); QTest::qWait(ANIMATION_DELAY); - QCOMPARE(view.createdColumns[0]->currentIndex(), first); - QCOMPARE(view.createdColumns[1]->currentIndex(), second); - QCOMPARE(view.createdColumns[2]->currentIndex(), third); + QTRY_COMPARE(view.createdColumns[0]->currentIndex(), first); + QTRY_COMPARE(view.createdColumns[1]->currentIndex(), second); + QTRY_COMPARE(view.createdColumns[2]->currentIndex(), third); first = model.index(0, 0, QModelIndex()); second = model.index(secondRow, 0, first); diff --git a/tests/auto/qdockwidget/tst_qdockwidget.cpp b/tests/auto/qdockwidget/tst_qdockwidget.cpp index a734985..2059101 100644 --- a/tests/auto/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/qdockwidget/tst_qdockwidget.cpp @@ -96,6 +96,7 @@ private slots: void task248604_infiniteResize(); void task258459_visibilityChanged(); void taskQTBUG_1665_closableChanged(); + void taskQTBUG_9758_undockedGeometry(); }; // Testing get/set functions @@ -653,7 +654,7 @@ void tst_QDockWidget::dockLocationChanged() QCOMPARE(qvariant_cast<Qt::DockWidgetArea>(spy.at(0).at(0)), Qt::TopDockWidgetArea); spy.clear(); - + dw.setFloating(true); QTest::qWait(100); dw.setFloating(false); @@ -878,6 +879,27 @@ void tst_QDockWidget::taskQTBUG_1665_closableChanged() QVERIFY(!(dock.windowFlags() & Qt::WindowCloseButtonHint)); } +void tst_QDockWidget::taskQTBUG_9758_undockedGeometry() +{ + QMainWindow window; + QDockWidget dock1(&window); + QDockWidget dock2(&window); + window.addDockWidget(Qt::RightDockWidgetArea, &dock1); + window.addDockWidget(Qt::RightDockWidgetArea, &dock2); + window.tabifyDockWidget(&dock1, &dock2); + dock1.hide(); + dock2.hide(); + window.show(); + QTest::qWaitForWindowShown(&window); + dock1.setFloating(true); + dock1.show(); + QTest::qWaitForWindowShown(&dock1); + + QVERIFY(dock1.x() >= 0); + QVERIFY(dock1.y() >= 0); +} + + QTEST_MAIN(tst_QDockWidget) #include "tst_qdockwidget.moc" diff --git a/tests/auto/qfiledialog/tst_qfiledialog.cpp b/tests/auto/qfiledialog/tst_qfiledialog.cpp index 38a1ee7..ca7c445 100644 --- a/tests/auto/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/qfiledialog/tst_qfiledialog.cpp @@ -529,10 +529,6 @@ void tst_QFiledialog::completer() #endif ++expected; } -#if !defined(Q_OS_WIN) - if (inputStartsWithRootPath) - expected++; -#endif } QTest::qWait(1000); diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index 1df9a37..b8df7f6 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -218,6 +218,7 @@ private slots: void update(); void update2_data(); void update2(); + void update_ancestorClipsChildrenToShape(); void inputMethodSensitivity(); void inputContextReset(); void indirectPainting(); @@ -3758,6 +3759,62 @@ void tst_QGraphicsView::update2() #endif } +void tst_QGraphicsView::update_ancestorClipsChildrenToShape() +{ + QGraphicsScene scene(-150, -150, 300, 300); + + /* + Add three rects: + + +------------------+ + | child | + | +--------------+ | + | | parent | | + | | +-----------+ | + | | |grandParent| | + | | +-----------+ | + | +--------------+ | + +------------------+ + + ... where both the parent and the grand parent clips children to shape. + */ + QApplication::processEvents(); // Get rid of pending update. + + QGraphicsRectItem *grandParent = static_cast<QGraphicsRectItem *>(scene.addRect(0, 0, 50, 50)); + grandParent->setBrush(Qt::black); + grandParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape); + + QGraphicsRectItem *parent = static_cast<QGraphicsRectItem *>(scene.addRect(-50, -50, 100, 100)); + parent->setBrush(QColor(0, 0, 255, 125)); + parent->setParentItem(grandParent); + parent->setFlag(QGraphicsItem::ItemClipsChildrenToShape); + + QGraphicsRectItem *child = static_cast<QGraphicsRectItem *>(scene.addRect(-100, -100, 200, 200)); + child->setBrush(QColor(255, 0, 0, 125)); + child->setParentItem(parent); + + CustomView view(&scene); + view.show(); + QTest::qWaitForWindowShown(&view); + QTRY_VERIFY(view.painted); + + view.lastUpdateRegions.clear(); + view.painted = false; + + // Call child->update() and make sure the updated area is within the ancestors' clip. + QRectF expected = child->deviceTransform(view.viewportTransform()).mapRect(child->boundingRect()); + expected &= grandParent->deviceTransform(view.viewportTransform()).mapRect(grandParent->boundingRect()); + + child->update(); + QTRY_VERIFY(view.painted); + +#ifndef QT_MAC_USE_COCOA //cocoa doesn't support drawing regions + QTRY_VERIFY(view.painted); + QCOMPARE(view.lastUpdateRegions.size(), 1); + QCOMPARE(view.lastUpdateRegions.at(0), QRegion(expected.toAlignedRect())); +#endif +} + class FocusItem : public QGraphicsRectItem { public: diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp index 1b4c502..aadee5b 100644 --- a/tests/auto/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/qimagereader/tst_qimagereader.cpp @@ -114,6 +114,9 @@ private slots: void readFromFileAfterJunk_data(); void readFromFileAfterJunk(); + void devicePosition_data(); + void devicePosition(); + void setBackgroundColor_data(); void setBackgroundColor(); @@ -1117,7 +1120,7 @@ void tst_QImageReader::readFromFileAfterJunk() QByteArray imageData = imageFile.readAll(); QVERIFY(!imageData.isNull()); - int iterations = 10; + int iterations = 3; if (format == "ppm" || format == "pbm" || format == "pgm" || format == "svg" || format == "svgz") iterations = 1; @@ -1147,6 +1150,64 @@ void tst_QImageReader::readFromFileAfterJunk() } } +void tst_QImageReader::devicePosition_data() +{ + QTest::addColumn<QString>("fileName"); + QTest::addColumn<QByteArray>("format"); + + QTest::newRow("pbm") << QString("image.pbm") << QByteArray("pbm"); + QTest::newRow("pgm") << QString("image.pgm") << QByteArray("pgm"); + QTest::newRow("ppm-1") << QString("image.ppm") << QByteArray("ppm"); +#ifdef QTEST_HAVE_JPEG + QTest::newRow("jpeg-1") << QString("beavis.jpg") << QByteArray("jpeg"); + QTest::newRow("jpeg-2") << QString("YCbCr_cmyk.jpg") << QByteArray("jpeg"); + QTest::newRow("jpeg-3") << QString("YCbCr_rgb.jpg") << QByteArray("jpeg"); +#endif +#if defined QTEST_HAVE_GIF + QTest::newRow("gif-1") << QString("earth.gif") << QByteArray("gif"); +#endif + QTest::newRow("xbm") << QString("gnus.xbm") << QByteArray("xbm"); + QTest::newRow("xpm") << QString("marble.xpm") << QByteArray("xpm"); + QTest::newRow("bmp-1") << QString("colorful.bmp") << QByteArray("bmp"); + QTest::newRow("bmp-2") << QString("font.bmp") << QByteArray("bmp"); + QTest::newRow("png") << QString("kollada.png") << QByteArray("png"); +// QTest::newRow("mng-1") << QString("images/ball.mng") << QByteArray("mng"); +// QTest::newRow("mng-2") << QString("images/fire.mng") << QByteArray("mng"); +#if defined QTEST_HAVE_SVG + QTest::newRow("svg") << QString("rect.svg") << QByteArray("svg"); + QTest::newRow("svgz") << QString("rect.svgz") << QByteArray("svgz"); +#endif +} + +void tst_QImageReader::devicePosition() +{ + QFETCH(QString, fileName); + QFETCH(QByteArray, format); + + QImage expected(prefix + fileName); + QVERIFY(!expected.isNull()); + + QFile imageFile(prefix + fileName); + QVERIFY(imageFile.open(QFile::ReadOnly)); + QByteArray imageData = imageFile.readAll(); + QVERIFY(!imageData.isNull()); + int imageDataSize = imageData.size(); + + const char *preStr = "prebeef\n"; + int preLen = qstrlen(preStr); + imageData.prepend(preStr); + if (format != "svg" && format != "svgz") // Doesn't handle trailing data + imageData.append("\npostbeef"); + QBuffer buf(&imageData); + buf.open(QIODevice::ReadOnly); + buf.seek(preLen); + QImageReader reader(&buf, format); + QCOMPARE(expected, reader.read()); + if (format != "ppm" && format != "gif") // Known not to work + QCOMPARE(buf.pos(), qint64(preLen+imageDataSize)); +} + + void tst_QImageReader::description_data() { QTest::addColumn<QString>("fileName"); diff --git a/tests/auto/qmessagebox/tst_qmessagebox.cpp b/tests/auto/qmessagebox/tst_qmessagebox.cpp index 2de1c52..d4ca064 100644 --- a/tests/auto/qmessagebox/tst_qmessagebox.cpp +++ b/tests/auto/qmessagebox/tst_qmessagebox.cpp @@ -140,6 +140,8 @@ private: tst_QMessageBox::tst_QMessageBox() : keyToSend(-1) { + int argc = qApp->argc(); + QT_REQUIRE_VERSION(argc, qApp->argv(), "4.6.2") } int tst_QMessageBox::exec(QMessageBox *msgBox, int key) diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 2339b21..992c95e 100644 --- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -138,6 +138,7 @@ private slots: void taskQTBUG_6205_doubleProxySelectionSetSourceModel(); void taskQTBUG_7537_appearsAndSort(); void taskQTBUG_7716_unnecessaryDynamicSorting(); + void taskQTBUG_10287_unnecessaryMapCreation(); void testMultipleProxiesWithSelection(); @@ -3038,5 +3039,65 @@ void tst_QSortFilterProxyModel::testMultipleProxiesWithSelection() } +class Model10287 : public QStandardItemModel +{ + Q_OBJECT + +public: + Model10287(QObject *parent = 0) + : QStandardItemModel(0, 1, parent) + { + parentItem = new QStandardItem("parent"); + parentItem->setData(false, Qt::UserRole); + appendRow(parentItem); + + childItem = new QStandardItem("child"); + childItem->setData(true, Qt::UserRole); + parentItem->appendRow(childItem); + + childItem2 = new QStandardItem("child2"); + childItem2->setData(true, Qt::UserRole); + parentItem->appendRow(childItem2); + } + + void removeChild() + { + childItem2->setData(false, Qt::UserRole); + parentItem->removeRow(0); + } + +private: + QStandardItem *parentItem, *childItem, *childItem2; +}; + +class Proxy10287 : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + Proxy10287(QAbstractItemModel *model, QObject *parent = 0) + : QSortFilterProxyModel(parent) + { + setSourceModel(model); + setDynamicSortFilter(true); + } + +protected: + virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const + { + // Filter based on UserRole in model + QModelIndex i = sourceModel()->index(source_row, 0, source_parent); + return i.data(Qt::UserRole).toBool(); + } +}; + +void tst_QSortFilterProxyModel::taskQTBUG_10287_unnecessaryMapCreation() +{ + Model10287 m; + Proxy10287 p(&m); + m.removeChild(); + // No assert failure, it passes. +} + QTEST_MAIN(tst_QSortFilterProxyModel) #include "tst_qsortfilterproxymodel.moc" diff --git a/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp index e0512a9..e370309 100644 --- a/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -98,6 +98,7 @@ private slots: void complexWidgetFocus(); void task188195_baseBackground(); void task232085_spinBoxLineEditBg(); + void changeStyleInChangeEvent(); //at the end because it mess with the style. void widgetStyle(); @@ -1256,7 +1257,7 @@ void tst_QStyleSheetStyle::proxyStyle() QStyleOptionViewItemV4 opt; opt.initFrom(w); opt.features |= QStyleOptionViewItemV2::HasCheckIndicator; - QVERIFY(pb5->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, + QVERIFY(pb5->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &opt, pb5).width() == 3); delete w; delete proxy; @@ -1579,6 +1580,34 @@ void tst_QStyleSheetStyle::task232085_spinBoxLineEditBg() .toLocal8Bit().constData()); } +class ChangeEventWidget : public QWidget +{ public: + void changeEvent(QEvent * event) + { + if(event->type() == QEvent::StyleChange) { + static bool recurse = false; + if (!recurse) { + recurse = true; + QStyle *style = new QMotifStyle; + style->setParent(this); + setStyle(style); + recurse = false; + } + } + QWidget::changeEvent(event); + } +}; + +void tst_QStyleSheetStyle::changeStyleInChangeEvent() +{ //must not crash; + ChangeEventWidget wid; + wid.ensurePolished(); + wid.setStyleSheet(" /* */ "); + wid.ensurePolished(); + wid.setStyleSheet(" /* ** */ "); + wid.ensurePolished(); +} + QTEST_MAIN(tst_QStyleSheetStyle) #include "tst_qstylesheetstyle.moc" diff --git a/tests/auto/qwidgetaction/tst_qwidgetaction.cpp b/tests/auto/qwidgetaction/tst_qwidgetaction.cpp index 5dfcd43..53dc4b5 100644 --- a/tests/auto/qwidgetaction/tst_qwidgetaction.cpp +++ b/tests/auto/qwidgetaction/tst_qwidgetaction.cpp @@ -51,6 +51,8 @@ #include <qmainwindow.h> #include <qmenubar.h> +#include "../../shared/util.h" + //TESTED_CLASS= //TESTED_FILES= @@ -190,8 +192,8 @@ void tst_QWidgetAction::visibilityUpdate() QVERIFY(action->isVisible()); action->setVisible(false); - QTest::qWait(100); //the call to hide is delayed by the toolbar layout - QVERIFY(!combo->isVisible()); + qApp->processEvents(); //the call to hide is delayed by the toolbar layout + QTRY_VERIFY(!combo->isVisible()); delete action; // action also deletes combo diff --git a/tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp b/tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp index 9ffbefb..8e9de4a 100644 --- a/tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp @@ -43,6 +43,7 @@ #include <QPixmap> #include <QBitmap> #include <QPainter> +#include <private/qpixmap_raster_p.h> class tst_QPixmap : public QObject { @@ -67,6 +68,31 @@ Q_DECLARE_METATYPE(QImage::Format) Q_DECLARE_METATYPE(Qt::AspectRatioMode) Q_DECLARE_METATYPE(Qt::TransformationMode) +QPixmap rasterPixmap(int width, int height) +{ + QPixmapData *data = + new QRasterPixmapData(QPixmapData::PixmapType); + + data->resize(width, height); + + return QPixmap(data); +} + +QPixmap rasterPixmap(const QSize &size) +{ + return rasterPixmap(size.width(), size.height()); +} + +QPixmap rasterPixmap(const QImage &image) +{ + QPixmapData *data = + new QRasterPixmapData(QPixmapData::PixmapType); + + data->fromImage(image, Qt::AutoColor); + + return QPixmap(data); +} + tst_QPixmap::tst_QPixmap() { } @@ -90,7 +116,7 @@ void tst_QPixmap::fill() QFETCH(int, height); const QColor color = opaque ? QColor(255, 0, 0) : QColor(255, 0, 0, 200); - QPixmap pixmap(width, height); + QPixmap pixmap = rasterPixmap(width, height); QBENCHMARK { pixmap.fill(color); @@ -126,8 +152,8 @@ void tst_QPixmap::scaled() QFETCH(Qt::AspectRatioMode, ratioMode); QFETCH(Qt::TransformationMode, transformMode); - QPixmap opaque(size); - QPixmap transparent(size); + QPixmap opaque = rasterPixmap(size); + QPixmap transparent = rasterPixmap(size); opaque.fill(QColor(255, 0, 0)); transparent.fill(QColor(255, 0, 0, 200)); @@ -180,8 +206,8 @@ void tst_QPixmap::transformed() QFETCH(QTransform, transform); QFETCH(Qt::TransformationMode, transformMode); - QPixmap opaque(size); - QPixmap transparent(size); + QPixmap opaque = rasterPixmap(size); + QPixmap transparent = rasterPixmap(size); opaque.fill(QColor(255, 0, 0)); transparent.fill(QColor(255, 0, 0, 200)); @@ -209,7 +235,7 @@ void tst_QPixmap::mask() { QFETCH(QSize, size); - QPixmap src(size); + QPixmap src = rasterPixmap(size); src.fill(Qt::transparent); { QPainter p(&src); diff --git a/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp b/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp index d570bb3..318b671 100644 --- a/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp @@ -50,6 +50,8 @@ #define M_PI 3.14159265358979323846 #endif +#include <private/qpixmap_raster_p.h> + Q_DECLARE_METATYPE(QLine) Q_DECLARE_METATYPE(QRect) Q_DECLARE_METATYPE(QSize) @@ -125,6 +127,32 @@ struct PrimitiveSet { }; +QPixmap rasterPixmap(int width, int height) +{ + QPixmapData *data = + new QRasterPixmapData(QPixmapData::PixmapType); + + data->resize(width, height); + + return QPixmap(data); +} + +QPixmap rasterPixmap(const QSize &size) +{ + return rasterPixmap(size.width(), size.height()); +} + +QPixmap rasterPixmap(const QImage &image) +{ + QPixmapData *data = + new QRasterPixmapData(QPixmapData::PixmapType); + + data->fromImage(image, Qt::AutoColor); + + return QPixmap(data); +} + + class tst_QPainter : public QObject { Q_OBJECT @@ -222,7 +250,8 @@ private: QPaintDevice *surface() { - return new QPixmap(1024, 1024); + m_pixmap = rasterPixmap(1024, 1024); + return &m_pixmap; } @@ -233,6 +262,7 @@ private: PrimitiveSet m_primitives_100; PrimitiveSet m_primitives_1000; + QPixmap m_pixmap; QPaintDevice *m_surface; QPainter m_painter; @@ -490,7 +520,7 @@ void tst_QPainter::setupBrushes() void tst_QPainter::beginAndEnd() { - QPixmap pixmap(100, 100); + QPixmap pixmap = rasterPixmap(100, 100); QBENCHMARK { QPainter p; @@ -505,10 +535,11 @@ void tst_QPainter::drawLine() QFETCH(QPen, pen); const int offset = 5; - QPixmap pixmapUnclipped(qMin(line.x1(), line.x2()) - + 2*offset + qAbs(line.dx()), - qMin(line.y1(), line.y2()) - + 2*offset + qAbs(line.dy())); + QPixmap pixmapUnclipped = + rasterPixmap(qMin(line.x1(), line.x2()) + + 2*offset + qAbs(line.dx()), + qMin(line.y1(), line.y2()) + + 2*offset + qAbs(line.dy())); pixmapUnclipped.fill(Qt::white); QPainter p(&pixmapUnclipped); @@ -535,10 +566,11 @@ void tst_QPainter::drawLine_clipped() QFETCH(QPen, pen); const int offset = 5; - QPixmap pixmapClipped(qMin(line.x1(), line.x2()) - + 2*offset + qAbs(line.dx()), - qMin(line.y1(), line.y2()) - + 2*offset + qAbs(line.dy())); + QPixmap pixmapClipped + = rasterPixmap(qMin(line.x1(), line.x2()) + + 2*offset + qAbs(line.dx()), + qMin(line.y1(), line.y2()) + + 2*offset + qAbs(line.dy())); const QRect clip = QRect(line.p1(), line.p2()).normalized(); @@ -569,10 +601,11 @@ void tst_QPainter::drawLine_antialiased_clipped() QFETCH(QPen, pen); const int offset = 5; - QPixmap pixmapClipped(qMin(line.x1(), line.x2()) - + 2*offset + qAbs(line.dx()), - qMin(line.y1(), line.y2()) - + 2*offset + qAbs(line.dy())); + QPixmap pixmapClipped + = rasterPixmap(qMin(line.x1(), line.x2()) + + 2*offset + qAbs(line.dx()), + qMin(line.y1(), line.y2()) + + 2*offset + qAbs(line.dy())); const QRect clip = QRect(line.p1(), line.p2()).normalized(); @@ -696,8 +729,8 @@ void tst_QPainter::drawPixmap() QImage sourceImage = createImage(type, size).convertToFormat(sourceFormat); QImage targetImage(size, targetFormat); - QPixmap sourcePixmap = QPixmap::fromImage(sourceImage); - QPixmap targetPixmap = QPixmap::fromImage(targetImage); + QPixmap sourcePixmap = rasterPixmap(sourceImage); + QPixmap targetPixmap = rasterPixmap(targetImage); QPainter p(&targetPixmap); @@ -759,10 +792,10 @@ void tst_QPainter::compositionModes() QFETCH(QSize, size); QFETCH(QColor, color); - QPixmap src(size); + QPixmap src = rasterPixmap(size); src.fill(color); - QPixmap dest(size); + QPixmap dest = rasterPixmap(size); if (mode < QPainter::RasterOp_SourceOrDestination) color.setAlpha(127); // porter-duff needs an alpha channel dest.fill(color); @@ -844,11 +877,11 @@ void tst_QPainter::drawTiledPixmap() QFETCH(QColor, color); QFETCH(QPainter::RenderHint, renderHint); - QPixmap src(srcSize); + QPixmap src = rasterPixmap(srcSize); src.fill(color); const QRect dstRect = transform.mapRect(QRect(QPoint(), dstSize)); - QPixmap dst(dstRect.right() + 5, dstRect.bottom() + 5); + QPixmap dst = rasterPixmap(dstRect.right() + 5, dstRect.bottom() + 5); QPainter p(&dst); p.setTransform(transform); p.setRenderHint(renderHint); @@ -1411,7 +1444,7 @@ void tst_QPainter::drawBorderPixmapRoundedRect() rp.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, rectImage.width()-(pw+1), rectImage.height()-(pw+1)), radius, radius); else rp.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, rectImage.width()-pw, rectImage.height()-pw), radius, radius); - QPixmap rectPixmap = QPixmap::fromImage(rectImage); + QPixmap rectPixmap = rasterPixmap(rectImage); //setup surface QImage surface(100, 100, QImage::Format_RGB16); @@ -1466,7 +1499,7 @@ void tst_QPainter::drawScaledBorderPixmapRoundedRect() else rp.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, rectImage.width()-pw, rectImage.height()-pw), radius, radius); - QPixmap rectPixmap = QPixmap::fromImage(rectImage); + QPixmap rectPixmap = rasterPixmap(rectImage); //setup surface QImage surface(400, 400, QImage::Format_RGB16); @@ -1522,7 +1555,7 @@ void tst_QPainter::drawTransformedBorderPixmapRoundedRect() else rp.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, rectImage.width()-pw, rectImage.height()-pw), radius, radius); - QPixmap rectPixmap = QPixmap::fromImage(rectImage); + QPixmap rectPixmap = rasterPixmap(rectImage); //setup surface QImage surface(400, 400, QImage::Format_RGB16); |