diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-11-23 19:17:25 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2015-11-23 19:17:25 +0000 |
commit | 746f54c6df0b6c08126b02ddc19e9e3010cb0d2d (patch) | |
tree | 0b50efabfdc1ea8acd61521fa6d2234effe3a1a9 /tests | |
parent | 550fbf96b06bc9194388ccdae1a9e6116d959599 (diff) | |
parent | 1ed7a67a4cef8350103e4ea33b4bbd084f5d4c2d (diff) |
Merge "Merge remote-tracking branch 'origin/5.6' into dev" into refs/staging/dev
Diffstat (limited to 'tests')
11 files changed, 462 insertions, 40 deletions
diff --git a/tests/auto/gui/image/qimagereader/images/longcomment.pgm b/tests/auto/gui/image/qimagereader/images/longcomment.pgm new file mode 100644 index 0000000000..a5624b6c73 --- /dev/null +++ b/tests/auto/gui/image/qimagereader/images/longcomment.pgm @@ -0,0 +1,12 @@ +P2 +# A short comment +# A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment +24 7 +15 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0 +0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0 +0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0 +0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0 +0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 diff --git a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp index 2eb9b4fc2d..1425ce3c2f 100644 --- a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp @@ -224,6 +224,7 @@ void tst_QImageReader::readImage_data() QTest::newRow("PPM: runners") << QString("runners.ppm") << true << QByteArray("ppm"); QTest::newRow("PPM: test") << QString("test.ppm") << true << QByteArray("ppm"); QTest::newRow("XBM: gnus") << QString("gnus.xbm") << true << QByteArray("xbm"); + QTest::newRow("PGM: longcomment") << QString("longcomment.pgm") << true << QByteArray("pgm"); QTest::newRow("JPEG: beavis") << QString("beavis.jpg") << true << QByteArray("jpeg"); QTest::newRow("JPEG: qtbug13653") << QString("qtbug13653-no_eoi.jpg") << true << QByteArray("jpeg"); diff --git a/tests/auto/other/compiler/tst_compiler.cpp b/tests/auto/other/compiler/tst_compiler.cpp index 2c95002cb2..af0fa4682d 100644 --- a/tests/auto/other/compiler/tst_compiler.cpp +++ b/tests/auto/other/compiler/tst_compiler.cpp @@ -979,6 +979,20 @@ void tst_Compiler::cxx11_nullptr() #endif } +namespace SomeNamespace { +class AdlOnly { + QVector<int> v; +public: + AdlOnly() : v(5) { std::fill_n(v.begin(), v.size(), 42); } + +private: + friend QVector<int>::const_iterator begin(const AdlOnly &x) { return x.v.begin(); } + friend QVector<int>::const_iterator end(const AdlOnly &x) { return x.v.end(); } + friend QVector<int>::iterator begin(AdlOnly &x) { return x.v.begin(); } + friend QVector<int>::iterator end(AdlOnly &x) { return x.v.end(); } +}; +} + void tst_Compiler::cxx11_range_for() { #ifndef Q_COMPILER_RANGE_FOR @@ -998,6 +1012,85 @@ void tst_Compiler::cxx11_range_for() l << 2; for (int i : ll) QCOMPARE(i, 2); + + { + const int array[] = { 0, 1, 2, 3, 4 }; + int i = 0; + for (const int &e : array) + QCOMPARE(e, array[i++]); + i = 0; + for (int e : array) + QCOMPARE(e, array[i++]); + i = 0; + for (const int e : array) + QCOMPARE(e, array[i++]); +#ifdef Q_COMPILER_AUTO_TYPE + i = 0; + for (const auto &e : array) + QCOMPARE(e, array[i++]); + i = 0; + for (auto &e : array) // auto deducing const + QCOMPARE(e, array[i++]); + i = 0; + for (auto e : array) + QCOMPARE(e, array[i++]); + i = 0; + for (const auto e : array) + QCOMPARE(e, array[i++]); +#endif + } + + { + int array[] = { 0, 1, 2, 3, 4 }; + const int array2[] = { 10, 11, 12, 13, 14 }; + int i = 0; + for (const int &e : array) + QCOMPARE(e, array[i++]); + i = 0; + for (int &e : array) + QCOMPARE(e, array[i++]); + i = 0; + for (int e : array) + QCOMPARE(e, array[i++]); + i = 0; + for (const int e : array) + QCOMPARE(e, array[i++]); +#ifdef Q_COMPILER_AUTO_TYPE + i = 0; + for (const auto &e : array) + QCOMPARE(e, array[i++]); + i = 0; + for (auto &e : array) + QCOMPARE(e, array[i++]); + i = 0; + for (auto e : array) + QCOMPARE(e, array[i++]); + i = 0; + for (const auto e : array) + QCOMPARE(e, array[i++]); +#endif + for (int &e : array) + e += 10; + i = 0; + for (const int &e : array) + QCOMPARE(e, array2[i++]); + } + + { + const SomeNamespace::AdlOnly x; + for (const int &e : x) + QCOMPARE(e, 42); + } + + { + SomeNamespace::AdlOnly x; + for (const int &e : x) + QCOMPARE(e, 42); + for (int &e : x) + e += 10; + for (const int &e : x) + QCOMPARE(e, 52); + } #endif } @@ -1035,24 +1128,88 @@ void tst_Compiler::cxx11_ref_qualifiers() #endif } +class MoveDefinedQString { + QString s; +public: + MoveDefinedQString() : s() {} + explicit MoveDefinedQString(const QString &s) : s(s) {} + MoveDefinedQString(const MoveDefinedQString &other) : s(other.s) {} +#ifdef Q_COMPILER_RVALUE_REFS + MoveDefinedQString(MoveDefinedQString &&other) : s(std::move(other.s)) { other.s.clear(); } + MoveDefinedQString &operator=(MoveDefinedQString &&other) + { s = std::move(other.s); other.s.clear(); return *this; } +#endif + MoveDefinedQString &operator=(const MoveDefinedQString &other) { s = other.s; return *this; } + +private: + friend bool operator==(const MoveDefinedQString &lhs, const MoveDefinedQString &rhs) + { return lhs.s == rhs.s; } + friend bool operator!=(const MoveDefinedQString &lhs, const MoveDefinedQString &rhs) + { return !operator==(lhs, rhs); } + friend char* toString(const MoveDefinedQString &mds) + { using namespace QTest; return toString(mds.s); } +}; + void tst_Compiler::cxx11_rvalue_refs() { #ifndef Q_COMPILER_RVALUE_REFS QSKIP("Compiler does not support C++11 feature"); #else - int i = 1; - i = std::move(i); - - QString s = "Hello"; - QString t = std::move(s); - QCOMPARE(t, QString("Hello")); + // we require std::move: + { + int i = 1; + i = std::move(i); + + MoveDefinedQString s("Hello"); + MoveDefinedQString t = std::move(s); + QCOMPARE(t, MoveDefinedQString("Hello")); + QCOMPARE(s, MoveDefinedQString()); + + s = t; + t = std::move(s); + QCOMPARE(t, MoveDefinedQString("Hello")); + QCOMPARE(s, MoveDefinedQString()); + + MoveDefinedQString &&r = std::move(t); // no actual move! + QCOMPARE(r, MoveDefinedQString("Hello")); + QCOMPARE(t, MoveDefinedQString("Hello")); // so 't' is unchanged + } - s = t; - t = std::move(s); - QCOMPARE(t, QString("Hello")); + // we require std::forward: + { + MoveDefinedQString s("Hello"); + MoveDefinedQString s2 = std::forward<MoveDefinedQString>(s); // forward as rvalue + QCOMPARE(s2, MoveDefinedQString("Hello")); + QCOMPARE(s, MoveDefinedQString()); + + MoveDefinedQString s3 = std::forward<MoveDefinedQString&>(s2); // forward as lvalue + QCOMPARE(s2, MoveDefinedQString("Hello")); + QCOMPARE(s3, MoveDefinedQString("Hello")); + } - QString &&r = std::move(s); - QCOMPARE(r, QString("Hello")); + // supported by MSVC only from November 2013 CTP, but only check for VC2015: +# if !defined(Q_CC_MSVC) || defined(Q_CC_INTEL) || _MSC_VER >= 1900 // VS14 == VC2015 + // we require automatic generation of move special member functions: + { + struct M { MoveDefinedQString s1, s2; }; + M m1 = { MoveDefinedQString("Hello"), MoveDefinedQString("World") }; + QCOMPARE(m1.s1, MoveDefinedQString("Hello")); + QCOMPARE(m1.s2, MoveDefinedQString("World")); + M m2 = std::move(m1); + QCOMPARE(m1.s1, MoveDefinedQString()); + QCOMPARE(m1.s2, MoveDefinedQString()); + QCOMPARE(m2.s1, MoveDefinedQString("Hello")); + QCOMPARE(m2.s2, MoveDefinedQString("World")); + M m3; + QCOMPARE(m3.s1, MoveDefinedQString()); + QCOMPARE(m3.s2, MoveDefinedQString()); + m3 = std::move(m2); + QCOMPARE(m2.s1, MoveDefinedQString()); + QCOMPARE(m2.s2, MoveDefinedQString()); + QCOMPARE(m3.s1, MoveDefinedQString("Hello")); + QCOMPARE(m3.s2, MoveDefinedQString("World")); + } +# endif // MSVC < 2015 #endif } @@ -1265,9 +1422,11 @@ void tst_Compiler::cxx14_decltype_auto() } #if __cpp_return_type_deduction >= 201304 -auto returnTypeDeduction() +auto returnTypeDeduction(bool choice) { - return 1U; + if (choice) + return 1U; + return returnTypeDeduction(!choice); } #endif @@ -1276,7 +1435,7 @@ void tst_Compiler::cxx14_return_type_deduction() #if __cpp_return_type_deduction-0 < 201304 QSKIP("Compiler does not support this C++14 feature"); #else - QCOMPARE(returnTypeDeduction(), 1U); + QCOMPARE(returnTypeDeduction(false), 1U); #endif } diff --git a/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp b/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp index ae2f8dde5f..52baa0070b 100644 --- a/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp +++ b/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp @@ -593,7 +593,7 @@ public: connect(this, SIGNAL(modelReset()), this, SLOT(modelResetSlot())); } - void testme() + void testNested() { // Only the outermost beginResetModel/endResetModel should // emit signals. @@ -618,6 +618,14 @@ public: QCOMPARE(gotReset, true); } + void testClear() // QTBUG-49404: Basic test whether clear() emits signals. + { + gotAboutToBeReset = gotReset = false; + clear(); + QVERIFY(gotAboutToBeReset); + QVERIFY(gotReset); + } + private slots: void modelAboutToBeResetSlot() { gotAboutToBeReset = true; } void modelResetSlot() { gotReset = true; } @@ -634,7 +642,8 @@ void tst_QSqlQueryModel::nestedResets() CHECK_DATABASE(db); NestedResetsTest t; - t.testme(); + t.testClear(); + t.testNested(); } // For task 180617 diff --git a/tests/auto/tools/qmake/testdata/findDeps/findDeps.pro b/tests/auto/tools/qmake/testdata/findDeps/findDeps.pro index 442c9c767f..2713296f5b 100644 --- a/tests/auto/tools/qmake/testdata/findDeps/findDeps.pro +++ b/tests/auto/tools/qmake/testdata/findDeps/findDeps.pro @@ -9,4 +9,4 @@ HEADERS += object1.h \ object7.h \ object8.h \ object9.h -SOURCES += main.cpp +SOURCES += main.cpp needed.cpp diff --git a/tests/auto/tools/qmake/testdata/findDeps/main.cpp b/tests/auto/tools/qmake/testdata/findDeps/main.cpp index e4aa5c6251..0df3f9b7c3 100644 --- a/tests/auto/tools/qmake/testdata/findDeps/main.cpp +++ b/tests/auto/tools/qmake/testdata/findDeps/main.cpp @@ -31,6 +31,9 @@ ** ****************************************************************************/ +#define spurious \ + / #include "needed.cpp" +// if not ignored, symbol needed() won't be available ... #include <moc_object1.cpp> /**/ #include <moc_object2.cpp> @@ -49,5 +52,7 @@ static void function2(); /**/ static void function3(); // #include <moc_object9.cpp> -int main () {} - +int main () { + extern int needed(void); + return needed(); +} diff --git a/tests/auto/tools/qmake/testdata/findDeps/needed.cpp b/tests/auto/tools/qmake/testdata/findDeps/needed.cpp new file mode 100644 index 0000000000..698d0aaa12 --- /dev/null +++ b/tests/auto/tools/qmake/testdata/findDeps/needed.cpp @@ -0,0 +1 @@ +extern int needed(void) { return 1; } diff --git a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp index 638fad6206..a4a0045265 100644 --- a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp +++ b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp @@ -57,6 +57,8 @@ private slots: void asViewport(); void requestUpdate(); void fboRedirect(); + void showHide(); + void nativeWindow(); }; void tst_QOpenGLWidget::create() @@ -81,7 +83,8 @@ public: : QOpenGLWidget(parent), m_initCalled(false), m_paintCalled(false), m_resizeCalled(false), m_resizeOk(false), - m_w(expectedWidth), m_h(expectedHeight) { } + m_w(expectedWidth), m_h(expectedHeight), + r(1.0f), g(0.0f), b(0.0f) { } void initializeGL() Q_DECL_OVERRIDE { m_initCalled = true; @@ -89,13 +92,16 @@ public: } void paintGL() Q_DECL_OVERRIDE { m_paintCalled = true; - glClearColor(1.0f, 0.0f, 0.0f, 1.0f); + glClearColor(r, g, b, 1.0f); glClear(GL_COLOR_BUFFER_BIT); } void resizeGL(int w, int h) Q_DECL_OVERRIDE { m_resizeCalled = true; m_resizeOk = w == m_w && h == m_h; } + void setClearColor(float r, float g, float b) { + this->r = r; this->g = g; this->b = b; + } bool m_initCalled; bool m_paintCalled; @@ -103,6 +109,7 @@ public: bool m_resizeOk; int m_w; int m_h; + float r, g, b; }; void tst_QOpenGLWidget::clearAndGrab() @@ -355,6 +362,69 @@ void tst_QOpenGLWidget::fboRedirect() QVERIFY(reportedDefaultFbo != widgetFbo); } +void tst_QOpenGLWidget::showHide() +{ + QScopedPointer<ClearWidget> w(new ClearWidget(0, 800, 600)); + w->resize(800, 600); + w->show(); + QTest::qWaitForWindowExposed(w.data()); + + w->hide(); + + QImage image = w->grabFramebuffer(); + QVERIFY(!image.isNull()); + QCOMPARE(image.width(), w->width()); + QCOMPARE(image.height(), w->height()); + QVERIFY(image.pixel(30, 40) == qRgb(255, 0, 0)); + + w->setClearColor(0, 0, 1); + w->show(); + QTest::qWaitForWindowExposed(w.data()); + + image = w->grabFramebuffer(); + QVERIFY(!image.isNull()); + QCOMPARE(image.width(), w->width()); + QCOMPARE(image.height(), w->height()); + QVERIFY(image.pixel(30, 40) == qRgb(0, 0, 255)); +} + +void tst_QOpenGLWidget::nativeWindow() +{ + QScopedPointer<ClearWidget> w(new ClearWidget(0, 800, 600)); + w->resize(800, 600); + w->show(); + w->winId(); + QTest::qWaitForWindowExposed(w.data()); + + QImage image = w->grabFramebuffer(); + QVERIFY(!image.isNull()); + QCOMPARE(image.width(), w->width()); + QCOMPARE(image.height(), w->height()); + QVERIFY(image.pixel(30, 40) == qRgb(255, 0, 0)); + QVERIFY(w->internalWinId()); + + // Now as a native child. + QWidget nativeParent; + nativeParent.resize(800, 600); + nativeParent.setAttribute(Qt::WA_NativeWindow); + ClearWidget *child = new ClearWidget(0, 800, 600); + child->setClearColor(0, 1, 0); + child->setParent(&nativeParent); + child->resize(400, 400); + child->move(23, 34); + nativeParent.show(); + QTest::qWaitForWindowExposed(&nativeParent); + + QVERIFY(nativeParent.internalWinId()); + QVERIFY(!child->internalWinId()); + + image = child->grabFramebuffer(); + QVERIFY(!image.isNull()); + QCOMPARE(image.width(), child->width()); + QCOMPARE(image.height(), child->height()); + QVERIFY(image.pixel(30, 40) == qRgb(0, 255, 0)); +} + QTEST_MAIN(tst_QOpenGLWidget) #include "tst_qopenglwidget.moc" diff --git a/tests/manual/qopenglwidget/openglwidget/main.cpp b/tests/manual/qopenglwidget/openglwidget/main.cpp index aaa48ea60a..a56cea1dfe 100644 --- a/tests/manual/qopenglwidget/openglwidget/main.cpp +++ b/tests/manual/qopenglwidget/openglwidget/main.cpp @@ -35,13 +35,108 @@ #include <QApplication> #include <QPushButton> #include <QMdiArea> +#include <QMdiSubWindow> +#include <QMenu> +#include <QMenuBar> +#include <QMainWindow> #include <QLCDNumber> +#include <QScrollArea> +#include <QScrollBar> +#include <QTabWidget> +#include <QLabel> #include <QTimer> #include <QSurfaceFormat> #include <QDebug> +#include <private/qwindow_p.h> + +class Tools : public QObject +{ + Q_OBJECT + +public: + Tools(QWidget *root, QWidget *widgetToTurn, const QVector<QWidget *> glwidgets) + : m_root(root), m_widgetToTurn(widgetToTurn), m_glWidgets(glwidgets) { } + void dump(); + +private slots: + void turnNative(); + void hideShowAllGL(); + void dumpCompositingStatus(); + +signals: + void aboutToShowGLWidgets(); + +private: + void dumpWidget(QWidget *w, int indent = 0); + + QWidget *m_root; + QWidget *m_widgetToTurn; + QVector<QWidget *> m_glWidgets; +}; + +void Tools::turnNative() +{ + qDebug("Turning into native"); + m_widgetToTurn->winId(); + dump(); +} + +void Tools::hideShowAllGL() +{ + if (m_glWidgets[0]->isVisible()) { + qDebug("Hiding all render-to-texture widgets"); + foreach (QWidget *w, m_glWidgets) + w->hide(); + } else { + qDebug("Showing all render-to-texture widgets"); + emit aboutToShowGLWidgets(); + foreach (QWidget *w, m_glWidgets) + w->show(); + } +} + +void Tools::dump() +{ + qDebug() << "Widget hierarchy"; + dumpWidget(m_root); + qDebug() << "========"; +} + +void Tools::dumpWidget(QWidget *w, int indent) +{ + QString indentStr; + indentStr.fill(' ', indent); + qDebug().noquote() << indentStr << w << "winId =" << w->internalWinId(); + foreach (QObject *obj, w->children()) { + if (QWidget *cw = qobject_cast<QWidget *>(obj)) + dumpWidget(cw, indent + 4); + } +} + +void Tools::dumpCompositingStatus() +{ + QWindow *w = m_root->window()->windowHandle(); + qDebug() << "Compositing status for" << w << m_root->window() << "is" << QWindowPrivate::get(w)->compositing; +} + +class TabWidgetResetter : public QObject +{ + Q_OBJECT +public: + TabWidgetResetter(QTabWidget *tw) : m_tw(tw) { } +public slots: + void reset() { m_tw->setCurrentIndex(0); } +private: + QTabWidget *m_tw; +}; int main(int argc, char *argv[]) { + if (argc > 1 && !strcmp(argv[1], "--sharecontext")) { + qDebug("Requesting all contexts to share"); + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); + } + QApplication a(argc, argv); QSurfaceFormat format; @@ -53,28 +148,86 @@ int main(int argc, char *argv[]) } qDebug() << "Requesting" << format; - QMdiArea w; - w.resize(400,400); + QMainWindow wnd; + wnd.setObjectName("Main Window"); + wnd.resize(1024, 768); + + QMdiArea *w = new QMdiArea; + w->setObjectName("MDI area"); + w->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + wnd.setCentralWidget(w); - OpenGLWidget *glw = new OpenGLWidget; + OpenGLWidget *glw = new OpenGLWidget(33, QVector3D(0, 0, 1)); + glw->setObjectName("First GL Widget with 33 ms timer"); glw->setFormat(format); - w.addSubWindow(glw); - glw->setMinimumSize(100,100); + glw->setMinimumSize(100, 100); + QMdiSubWindow *sw = w->addSubWindow(glw); + sw->setObjectName("First MDI Sub-Window"); + sw->setWindowTitle("33 ms timer"); - OpenGLWidget *glw2 = new OpenGLWidget; + OpenGLWidget *glw2 = new OpenGLWidget(16); + glw2->setObjectName("Second GL Widget with 16 ms timer"); glw2->setFormat(format); - glw2->setMinimumSize(100,100); - w.addSubWindow(glw2); + glw2->setMinimumSize(100, 100); + QOpenGLWidget *glw22 = new OpenGLWidget(16); + glw22->setObjectName("Second #2 GLWidget"); + glw22->setParent(glw2); + glw22->resize(40, 40); + sw = w->addSubWindow(glw2); + sw->setObjectName("Second MDI Sub-Window"); + sw->setWindowTitle("16 ms timer"); + + OpenGLWidget *glw3 = new OpenGLWidget(0); // trigger updates continuously, no timer + glw3->setObjectName("GL widget in scroll area (possibly native)"); + glw3->setFormat(format); + glw3->setFixedSize(600, 600); + QScrollArea *sa = new QScrollArea; + sa->setWidget(glw3); + sa->setMinimumSize(100, 100); + sa->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + sw = w->addSubWindow(sa); + sw->setObjectName("MDI Sub-Window for scroll area"); + sw->setWindowTitle("Cont. update"); + sw->resize(300, 300); + sa->verticalScrollBar()->setValue(300); QLCDNumber *lcd = new QLCDNumber; lcd->display(1337); - lcd->setMinimumSize(300,100); - w.addSubWindow(lcd); + lcd->setMinimumSize(300, 100); + sw = w->addSubWindow(lcd); + sw->setObjectName("MDI Sub-Window for LCD widget"); + sw->setWindowTitle("Ordinary widget"); + + QTabWidget *tw = new QTabWidget; + QOpenGLWidget *glw4 = new OpenGLWidget(16, QVector3D(1, 0, 0)); + glw4->setObjectName("GL widget in tab widget"); + tw->addTab(glw4, "OpenGL"); + QLabel *label = new QLabel("Another tab"); + tw->addTab(label, "Not OpenGL"); + tw->setMinimumSize(100, 100); + sw = w->addSubWindow(tw); + sw->setObjectName("MDI Sub-Window for tab widget"); + sw->setWindowTitle("Tabs"); - w.show(); + TabWidgetResetter twr(tw); + Tools t(&wnd, glw3, QVector<QWidget *>() << glw << glw2 << glw3 << glw4); + QObject::connect(&t, SIGNAL(aboutToShowGLWidgets()), &twr, SLOT(reset())); + QMenu *toolsMenu = wnd.menuBar()->addMenu("&Tools"); + toolsMenu->addAction("&Turn widgets (or some parent) into native", &t, SLOT(turnNative())); + toolsMenu->addAction("&Hide/show all OpenGL widgets", &t, SLOT(hideShowAllGL())); + + QTimer compStatusDumpTimer; + QObject::connect(&compStatusDumpTimer, SIGNAL(timeout()), &t, SLOT(dumpCompositingStatus())); + compStatusDumpTimer.start(5000); + + wnd.show(); if (glw->isValid()) qDebug() << "Got" << glw->format(); + t.dump(); + return a.exec(); } + +#include "main.moc" diff --git a/tests/manual/qopenglwidget/openglwidget/openglwidget.cpp b/tests/manual/qopenglwidget/openglwidget/openglwidget.cpp index d47e12edc8..4d2463b84d 100644 --- a/tests/manual/qopenglwidget/openglwidget/openglwidget.cpp +++ b/tests/manual/qopenglwidget/openglwidget/openglwidget.cpp @@ -75,16 +75,23 @@ public: int w,h; QWidget *q; + + int m_interval; + QVector3D m_rotAxis; }; -OpenGLWidget::OpenGLWidget(QWidget *parent) +OpenGLWidget::OpenGLWidget(int interval, const QVector3D &rotAxis, QWidget *parent) : QOpenGLWidget(parent) { - d = new OpenGLWidgetPrivate(this); - QTimer *timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(update())); - timer->start(30); + d.reset(new OpenGLWidgetPrivate(this)); + d->m_interval = interval; + d->m_rotAxis = rotAxis; + if (interval > 0) { + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(update())); + timer->start(interval); + } } OpenGLWidget::~OpenGLWidget() @@ -152,7 +159,8 @@ void OpenGLWidgetPrivate::render() QMatrix4x4 matrix; matrix.perspective(60.0f, 4.0f/3.0f, 0.1f, 100.0f); matrix.translate(0, 0, -2); - matrix.rotate(100.0f * m_frame / 30/*screen()->refreshRate()*/, 0, 1, 0); + const qreal angle = 100.0f * m_frame / 30; + matrix.rotate(angle, m_rotAxis); m_program->setUniformValue(m_matrixUniform, matrix); @@ -182,4 +190,7 @@ void OpenGLWidgetPrivate::render() m_program->release(); ++m_frame; + + if (m_interval <= 0) + q->update(); } diff --git a/tests/manual/qopenglwidget/openglwidget/openglwidget.h b/tests/manual/qopenglwidget/openglwidget/openglwidget.h index 4dc5fde067..a1d5490845 100644 --- a/tests/manual/qopenglwidget/openglwidget/openglwidget.h +++ b/tests/manual/qopenglwidget/openglwidget/openglwidget.h @@ -35,13 +35,14 @@ #define OPENGLWIDGET_H #include <QtWidgets/QOpenGLWidget> +#include <QtGui/QVector3D> class OpenGLWidgetPrivate; class OpenGLWidget : public QOpenGLWidget { Q_OBJECT public: - OpenGLWidget(QWidget *parent = 0); + OpenGLWidget(int interval = 30, const QVector3D &rotAxis = QVector3D(0, 1, 0), QWidget *parent = 0); ~OpenGLWidget(); void initializeGL(); @@ -49,7 +50,7 @@ public: void paintGL(); private: - OpenGLWidgetPrivate *d; + QScopedPointer<OpenGLWidgetPrivate> d; }; #endif // OPENGLWIDGET_H |