From 31f9c57bc50ae053cfaf039a1dfdb128e2494458 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 20 Oct 2015 13:18:59 +0300 Subject: Fix issues with COIN builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -Fix miscellaneous compile errors -Move manual tests to manual folder and enable export of autotests -Added widgets requirement -Fixed autotests -Fixed renderer and controller synchronization in QML case -Treat fallback Mesa as ES2 similar to setting AA_UseSoftwareOpenGL Change-Id: If6619733725d079e339bef16262e5ea1450ab20f Reviewed-by: Tomi Korpipää --- tests/manual/directional/directional.pro | 8 + tests/manual/directional/main.cpp | 166 +++++++++++++++++ tests/manual/directional/scatterdatamodifier.cpp | 220 +++++++++++++++++++++++ tests/manual/directional/scatterdatamodifier.h | 72 ++++++++ 4 files changed, 466 insertions(+) create mode 100644 tests/manual/directional/directional.pro create mode 100644 tests/manual/directional/main.cpp create mode 100644 tests/manual/directional/scatterdatamodifier.cpp create mode 100644 tests/manual/directional/scatterdatamodifier.h (limited to 'tests/manual/directional') diff --git a/tests/manual/directional/directional.pro b/tests/manual/directional/directional.pro new file mode 100644 index 00000000..25b2a1f6 --- /dev/null +++ b/tests/manual/directional/directional.pro @@ -0,0 +1,8 @@ +!include( ../tests.pri ) { + error( "Couldn't find the tests.pri file!" ) +} + +SOURCES += main.cpp scatterdatamodifier.cpp +HEADERS += scatterdatamodifier.h + +QT += widgets diff --git a/tests/manual/directional/main.cpp b/tests/manual/directional/main.cpp new file mode 100644 index 00000000..0eed202d --- /dev/null +++ b/tests/manual/directional/main.cpp @@ -0,0 +1,166 @@ +/****************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Data Visualization module. +** +** $QT_BEGIN_LICENSE:COMM$ +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** $QT_END_LICENSE$ +** +******************************************************************************/ + +#include "scatterdatamodifier.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + Q3DScatter *graph = new Q3DScatter(); + QWidget *container = QWidget::createWindowContainer(graph); + + QSize screenSize = graph->screen()->size(); + container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.5)); + container->setMaximumSize(screenSize); + container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + container->setFocusPolicy(Qt::StrongFocus); + + QWidget *widget = new QWidget; + QHBoxLayout *hLayout = new QHBoxLayout(widget); + QVBoxLayout *vLayout = new QVBoxLayout(); + hLayout->addWidget(container, 1); + hLayout->addLayout(vLayout); + + widget->setWindowTitle(QStringLiteral("Directional scatter")); + + QComboBox *themeList = new QComboBox(widget); + themeList->addItem(QStringLiteral("Qt")); + themeList->addItem(QStringLiteral("Primary Colors")); + themeList->addItem(QStringLiteral("Digia")); + themeList->addItem(QStringLiteral("Stone Moss")); + themeList->addItem(QStringLiteral("Army Blue")); + themeList->addItem(QStringLiteral("Retro")); + themeList->addItem(QStringLiteral("Ebony")); + themeList->addItem(QStringLiteral("Isabelle")); + themeList->setCurrentIndex(6); + + QPushButton *labelButton = new QPushButton(widget); + labelButton->setText(QStringLiteral("Change label style")); + + QComboBox *itemStyleList = new QComboBox(widget); + itemStyleList->addItem(QStringLiteral("Arrow"), int(QAbstract3DSeries::MeshArrow)); + itemStyleList->addItem(QStringLiteral("Cube"), int(QAbstract3DSeries::MeshCube)); + itemStyleList->addItem(QStringLiteral("Minimal"), int(QAbstract3DSeries::MeshMinimal)); + itemStyleList->setCurrentIndex(-1); + + QPushButton *cameraButton = new QPushButton(widget); + cameraButton->setText(QStringLiteral("Change camera preset")); + + QPushButton *toggleRotationButton = new QPushButton(widget); + toggleRotationButton->setText(QStringLiteral("Toggle animation")); + + QCheckBox *backgroundCheckBox = new QCheckBox(widget); + backgroundCheckBox->setText(QStringLiteral("Show background")); + backgroundCheckBox->setChecked(true); + + QCheckBox *optimizationCheckBox = new QCheckBox(widget); + optimizationCheckBox->setText(QStringLiteral("Optimization static")); + + QCheckBox *gridCheckBox = new QCheckBox(widget); + gridCheckBox->setText(QStringLiteral("Show grid")); + gridCheckBox->setChecked(true); + + QComboBox *shadowQuality = new QComboBox(widget); + shadowQuality->addItem(QStringLiteral("None")); + shadowQuality->addItem(QStringLiteral("Low")); + shadowQuality->addItem(QStringLiteral("Medium")); + shadowQuality->addItem(QStringLiteral("High")); + shadowQuality->addItem(QStringLiteral("Low Soft")); + shadowQuality->addItem(QStringLiteral("Medium Soft")); + shadowQuality->addItem(QStringLiteral("High Soft")); + shadowQuality->setCurrentIndex(4); + + QFontComboBox *fontList = new QFontComboBox(widget); + fontList->setCurrentFont(QFont("Arial")); + + vLayout->addWidget(labelButton, 0, Qt::AlignTop); + vLayout->addWidget(cameraButton, 0, Qt::AlignTop); + vLayout->addWidget(toggleRotationButton, 0, Qt::AlignTop); + vLayout->addWidget(optimizationCheckBox); + vLayout->addWidget(backgroundCheckBox); + vLayout->addWidget(gridCheckBox); + vLayout->addWidget(new QLabel(QStringLiteral("Change dot style"))); + vLayout->addWidget(itemStyleList); + vLayout->addWidget(new QLabel(QStringLiteral("Change theme"))); + vLayout->addWidget(themeList); + vLayout->addWidget(new QLabel(QStringLiteral("Adjust shadow quality"))); + vLayout->addWidget(shadowQuality); + vLayout->addWidget(new QLabel(QStringLiteral("Change font"))); + vLayout->addWidget(fontList, 1, Qt::AlignTop); + + ScatterDataModifier *modifier = new ScatterDataModifier(graph); + + QObject::connect(cameraButton, &QPushButton::clicked, modifier, + &ScatterDataModifier::changePresetCamera); + QObject::connect(toggleRotationButton, &QPushButton::clicked, modifier, + &ScatterDataModifier::toggleRotation); + QObject::connect(labelButton, &QPushButton::clicked, modifier, + &ScatterDataModifier::changeLabelStyle); + + QObject::connect(backgroundCheckBox, &QCheckBox::stateChanged, modifier, + &ScatterDataModifier::setBackgroundEnabled); + QObject::connect(gridCheckBox, &QCheckBox::stateChanged, modifier, + &ScatterDataModifier::setGridEnabled); + + QObject::connect(modifier, &ScatterDataModifier::backgroundEnabledChanged, + backgroundCheckBox, &QCheckBox::setChecked); + QObject::connect(optimizationCheckBox, &QCheckBox::stateChanged, + modifier, &ScatterDataModifier::enableOptimization); + QObject::connect(modifier, &ScatterDataModifier::gridEnabledChanged, + gridCheckBox, &QCheckBox::setChecked); + QObject::connect(itemStyleList, SIGNAL(currentIndexChanged(int)), modifier, + SLOT(changeStyle(int))); + + QObject::connect(themeList, SIGNAL(currentIndexChanged(int)), modifier, + SLOT(changeTheme(int))); + + QObject::connect(shadowQuality, SIGNAL(currentIndexChanged(int)), modifier, + SLOT(changeShadowQuality(int))); + + QObject::connect(modifier, &ScatterDataModifier::shadowQualityChanged, shadowQuality, + &QComboBox::setCurrentIndex); + QObject::connect(graph, &Q3DScatter::shadowQualityChanged, modifier, + &ScatterDataModifier::shadowQualityUpdatedByVisual); + + QObject::connect(fontList, &QFontComboBox::currentFontChanged, modifier, + &ScatterDataModifier::changeFont); + + QObject::connect(modifier, &ScatterDataModifier::fontChanged, fontList, + &QFontComboBox::setCurrentFont); + + itemStyleList->setCurrentIndex(0); + optimizationCheckBox->setChecked(true); + + widget->show(); + return app.exec(); +} diff --git a/tests/manual/directional/scatterdatamodifier.cpp b/tests/manual/directional/scatterdatamodifier.cpp new file mode 100644 index 00000000..2746bdf1 --- /dev/null +++ b/tests/manual/directional/scatterdatamodifier.cpp @@ -0,0 +1,220 @@ +/****************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Data Visualization module. +** +** $QT_BEGIN_LICENSE:COMM$ +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** $QT_END_LICENSE$ +** +******************************************************************************/ + +#include "scatterdatamodifier.h" +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace QtDataVisualization; + +const int numberOfCols = 8; +const int numberOfRows = 8; +const float limit = 8.0f; +const float PI = 3.14159f; +#define HEDGEHOG + +ScatterDataModifier::ScatterDataModifier(Q3DScatter *scatter) + : m_graph(scatter), + m_fontSize(40.0f), + m_style(QAbstract3DSeries::MeshUserDefined), + m_smooth(true) +{ + m_graph->activeTheme()->setType(Q3DTheme::ThemeEbony); + QFont font = m_graph->activeTheme()->font(); + font.setPointSize(m_fontSize); + m_graph->activeTheme()->setFont(font); + m_graph->setShadowQuality(QAbstract3DGraph::ShadowQualitySoftLow); + m_graph->scene()->activeCamera()->setCameraPreset(Q3DCamera::CameraPresetFront); + + m_graph->setAxisX(new QValue3DAxis); + m_graph->setAxisY(new QValue3DAxis); + m_graph->setAxisZ(new QValue3DAxis); + + QScatterDataProxy *proxy = new QScatterDataProxy; + QScatter3DSeries *series = new QScatter3DSeries(proxy); + series->setItemLabelFormat("@xTitle: @xLabel @yTitle: @yLabel @zTitle: @zLabel"); + m_graph->addSeries(series); + + QObject::connect(&m_rotationTimer, &QTimer::timeout, this, + &ScatterDataModifier::triggerRotation); + + addData(); +} + +ScatterDataModifier::~ScatterDataModifier() +{ + delete m_graph; +} + +void ScatterDataModifier::addData() +{ + // Configure the axes according to the data + m_graph->axisX()->setTitle("X"); + m_graph->axisY()->setTitle("Y"); + m_graph->axisZ()->setTitle("Z"); + m_graph->axisX()->setRange(-limit, limit); + m_graph->axisY()->setRange(-1.0f, 1.0f); + m_graph->axisZ()->setRange(-limit, limit); + + QScatterDataArray *dataArray = new QScatterDataArray; + dataArray->resize(numberOfCols * numberOfRows); + QScatterDataItem *ptrToDataArray = &dataArray->first(); + + float angleStep = 360.0f / float(numberOfCols); + float latAngleStep = 100.0f / float(numberOfRows); + + for (float i = 0; i < numberOfRows; i++) { + float latAngle = float(i) * latAngleStep + 40.0f; + float radius = qSin(latAngle * PI / 180.0f) * limit; + float y = qCos(latAngle * PI / 180.0f) * 1.0f; +#ifdef HEDGEHOG + float angleZ = (qAtan((y * limit / 2.0f) / radius) * 180.0f / PI); + QQuaternion rotationZ = QQuaternion::fromAxisAndAngle(QVector3D(0.0f, 0.0f, 1.0f), angleZ - 90.0f); +#endif + for (float j = 0; j < numberOfCols; j++) { + float angle = float(j) * angleStep; + float x = qCos(angle * PI / 180.0f) * radius; + float z = qSin(angle * PI / 180.0f) * radius; + + float angleY = (qAtan(z / x) * 180.0f / PI); + if (x < 0) + angleY = 180.0f + angleY; + if (x > 0 && z < 0) + angleY = 360.0f + angleY; +#ifdef HEDGEHOG + QQuaternion rotationY = QQuaternion::fromAxisAndAngle(QVector3D(0.0f, 1.0f, 0.0f), angleY); + QQuaternion rotation = rotationY * rotationZ; +#else + QQuaternion rotation = QQuaternion::fromAxisAndAngle(QVector3D(0.0f, 1.0f, 0.0f), angleY) * + QQuaternion::fromAxisAndAngle(QVector3D(1.0f, 0.0f, 0.0f), -90.0f); +#endif + + ptrToDataArray->setPosition(QVector3D(x, y, z)); + ptrToDataArray->setRotation(rotation); + ptrToDataArray++; + } + } + + m_graph->seriesList().at(0)->dataProxy()->resetArray(dataArray); +} + +void ScatterDataModifier::enableOptimization(int enabled) +{ + if (enabled) + m_graph->setOptimizationHints(QAbstract3DGraph::OptimizationStatic); + else + m_graph->setOptimizationHints(QAbstract3DGraph::OptimizationDefault); +} + +void ScatterDataModifier::changeStyle(int style) +{ + QComboBox *comboBox = qobject_cast(sender()); + if (comboBox) { + m_style = QAbstract3DSeries::Mesh(comboBox->itemData(style).toInt()); + if (m_graph->seriesList().size()) + m_graph->seriesList().at(0)->setMesh(m_style); + } +} + +void ScatterDataModifier::changeTheme(int theme) +{ + Q3DTheme *currentTheme = m_graph->activeTheme(); + currentTheme->setType(Q3DTheme::Theme(theme)); + emit backgroundEnabledChanged(currentTheme->isBackgroundEnabled()); + emit gridEnabledChanged(currentTheme->isGridEnabled()); + emit fontChanged(currentTheme->font()); +} + +void ScatterDataModifier::changePresetCamera() +{ + static int preset = Q3DCamera::CameraPresetFrontLow; + + m_graph->scene()->activeCamera()->setCameraPreset((Q3DCamera::CameraPreset)preset); + + if (++preset > Q3DCamera::CameraPresetDirectlyBelow) + preset = Q3DCamera::CameraPresetFrontLow; +} + +void ScatterDataModifier::changeLabelStyle() +{ + m_graph->activeTheme()->setLabelBackgroundEnabled(!m_graph->activeTheme()->isLabelBackgroundEnabled()); +} + +void ScatterDataModifier::changeFont(const QFont &font) +{ + QFont newFont = font; + newFont.setPointSizeF(m_fontSize); + m_graph->activeTheme()->setFont(newFont); +} + +void ScatterDataModifier::shadowQualityUpdatedByVisual(QAbstract3DGraph::ShadowQuality sq) +{ + int quality = int(sq); + emit shadowQualityChanged(quality); // connected to a checkbox in main.cpp +} + +void ScatterDataModifier::triggerRotation() +{ + if (m_graph->seriesList().size()) { + int selectedIndex = m_graph->seriesList().at(0)->selectedItem(); + if (selectedIndex != QScatter3DSeries::invalidSelectionIndex()) { + static float itemAngle = 0.0f; + QScatterDataItem item(*(m_graph->seriesList().at(0)->dataProxy()->itemAt(selectedIndex))); + QQuaternion itemRotation = QQuaternion::fromAxisAndAngle(0.0f, 0.0f, 1.0f, itemAngle++); + item.setRotation(itemRotation); + m_graph->seriesList().at(0)->dataProxy()->setItem(selectedIndex, item); + } else { + static float seriesAngle = 0.0f; + QQuaternion rotation = QQuaternion::fromAxisAndAngle(1.0f, 1.0f, 1.0f, seriesAngle++); + m_graph->seriesList().at(0)->setMeshRotation(rotation); + } + } +} + +void ScatterDataModifier::changeShadowQuality(int quality) +{ + QAbstract3DGraph::ShadowQuality sq = QAbstract3DGraph::ShadowQuality(quality); + m_graph->setShadowQuality(sq); +} + +void ScatterDataModifier::setBackgroundEnabled(int enabled) +{ + m_graph->activeTheme()->setBackgroundEnabled((bool)enabled); +} + +void ScatterDataModifier::setGridEnabled(int enabled) +{ + m_graph->activeTheme()->setGridEnabled((bool)enabled); +} + +void ScatterDataModifier::toggleRotation() +{ + if (m_rotationTimer.isActive()) + m_rotationTimer.stop(); + else + m_rotationTimer.start(20); +} diff --git a/tests/manual/directional/scatterdatamodifier.h b/tests/manual/directional/scatterdatamodifier.h new file mode 100644 index 00000000..ca4dc4a3 --- /dev/null +++ b/tests/manual/directional/scatterdatamodifier.h @@ -0,0 +1,72 @@ +/****************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Data Visualization module. +** +** $QT_BEGIN_LICENSE:COMM$ +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** $QT_END_LICENSE$ +** +******************************************************************************/ + +#ifndef SCATTERDATAMODIFIER_H +#define SCATTERDATAMODIFIER_H + +#include +#include +#include +#include + +using namespace QtDataVisualization; + +class ScatterDataModifier : public QObject +{ + Q_OBJECT +public: + explicit ScatterDataModifier(Q3DScatter *scatter); + ~ScatterDataModifier(); + + void addData(); + void changeStyle(); + void changePresetCamera(); + void changeLabelStyle(); + void changeFont(const QFont &font); + void changeFontSize(int fontsize); + void enableOptimization(int enabled); + void setBackgroundEnabled(int enabled); + void setGridEnabled(int enabled); + void toggleRotation(); + void start(); + +public Q_SLOTS: + void changeStyle(int style); + void changeTheme(int theme); + void changeShadowQuality(int quality); + void shadowQualityUpdatedByVisual(QAbstract3DGraph::ShadowQuality shadowQuality); + void triggerRotation(); + +Q_SIGNALS: + void backgroundEnabledChanged(bool enabled); + void gridEnabledChanged(bool enabled); + void shadowQualityChanged(int quality); + void fontChanged(QFont font); + +private: + Q3DScatter *m_graph; + int m_fontSize; + QAbstract3DSeries::Mesh m_style; + bool m_smooth; + QTimer m_rotationTimer; +}; + +#endif -- cgit v1.2.3