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/multigraphs/australia.png | Bin 0 -> 414991 bytes tests/manual/multigraphs/data.cpp | 329 +++++++++++++++++++++++++++++++ tests/manual/multigraphs/data.h | 101 ++++++++++ tests/manual/multigraphs/main.cpp | 159 +++++++++++++++ tests/manual/multigraphs/multigraphs.pro | 12 ++ tests/manual/multigraphs/multigraphs.qrc | 5 + 6 files changed, 606 insertions(+) create mode 100644 tests/manual/multigraphs/australia.png create mode 100644 tests/manual/multigraphs/data.cpp create mode 100644 tests/manual/multigraphs/data.h create mode 100644 tests/manual/multigraphs/main.cpp create mode 100644 tests/manual/multigraphs/multigraphs.pro create mode 100644 tests/manual/multigraphs/multigraphs.qrc (limited to 'tests/manual/multigraphs') diff --git a/tests/manual/multigraphs/australia.png b/tests/manual/multigraphs/australia.png new file mode 100644 index 00000000..a839b6b9 Binary files /dev/null and b/tests/manual/multigraphs/australia.png differ diff --git a/tests/manual/multigraphs/data.cpp b/tests/manual/multigraphs/data.cpp new file mode 100644 index 00000000..783deaf1 --- /dev/null +++ b/tests/manual/multigraphs/data.cpp @@ -0,0 +1,329 @@ +/****************************************************************************** +** +** 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$ +** +******************************************************************************/ + +#define NOMINMAX + +#include "data.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace QtDataVisualization; + +Data::Data(Q3DSurface *surface, Q3DScatter *scatter, Q3DBars *bars, + QTextEdit *statusArea, QWidget *widget) : + m_surface(surface), + m_scatter(scatter), + m_bars(bars), + m_statusArea(statusArea), + m_widget(widget), + m_resize(true), + m_resolution(QSize(300, 300)), + m_resolutionLevel(0), + m_mode(Surface), + m_scatterDataArray(0), + m_barDataArray(0), + m_started(false) +{ + // Initialize surface + m_surface->activeTheme()->setType(Q3DTheme::ThemeIsabelle); + QLinearGradient gradient; + gradient.setColorAt(0.0, Qt::black); + gradient.setColorAt(0.33, Qt::blue); + gradient.setColorAt(0.67, Qt::red); + gradient.setColorAt(1.0, Qt::yellow); + m_surface->setSelectionMode(QAbstract3DGraph::SelectionNone); + m_surface->activeTheme()->setGridEnabled(false); + m_surface->activeTheme()->setBackgroundEnabled(false); + m_surface->scene()->activeCamera()->setCameraPosition(0.0, 90.0, 150.0); + QSurface3DSeries *series1 = new QSurface3DSeries(new QHeightMapSurfaceDataProxy()); + series1->setFlatShadingEnabled(true); + series1->setDrawMode(QSurface3DSeries::DrawSurface); + series1->setColorStyle(Q3DTheme::ColorStyleRangeGradient); + series1->setBaseGradient(gradient); + m_surface->addSeries(series1); + + // Initialize scatter + m_scatter->activeTheme()->setType(Q3DTheme::ThemeStoneMoss); + m_scatter->setSelectionMode(QAbstract3DGraph::SelectionNone); + m_scatter->activeTheme()->setGridEnabled(false); + m_scatter->setShadowQuality(QAbstract3DGraph::ShadowQualitySoftLow); + m_scatter->scene()->activeCamera()->setCameraPosition(0.0, 85.0, 150.0); + QScatter3DSeries *series2 = new QScatter3DSeries; + series2->setMesh(QAbstract3DSeries::MeshPoint); + m_scatter->addSeries(series2); + + // Initialize bars + m_bars->activeTheme()->setType(Q3DTheme::ThemeQt); + m_bars->setSelectionMode(QAbstract3DGraph::SelectionItemAndRow | QAbstract3DGraph::SelectionSlice); + m_bars->activeTheme()->setGridEnabled(false); + m_bars->setShadowQuality(QAbstract3DGraph::ShadowQualityLow); + m_bars->setBarSpacing(QSizeF(0.0, 0.0)); + m_bars->scene()->activeCamera()->setCameraPosition(0.0, 75.0, 150.0); + QBar3DSeries *series3 = new QBar3DSeries; + series3->setMesh(QAbstract3DSeries::MeshBar); + m_bars->addSeries(series3); + + // Hide scroll bar + m_statusArea->verticalScrollBar()->setVisible(false); +} + +Data::~Data() +{ + delete m_bars; + delete m_surface; + delete m_scatter; + delete m_widget; + delete m_scatterDataArray; // only portion of this array is set to graph +} + +void Data::updateData() +{ + if (!m_started) { + m_statusArea->append(QStringLiteral("We are stopped. The changes will take effect once started.")); + return; + } + QImage depthMap = QImage(":/australia.png"); + if (m_resize) // Resize for better performance + depthMap = depthMap.scaled(m_resolution); + if (m_mode != Surface) + setData(depthMap); + else + static_cast(m_surface->seriesList().at(0)->dataProxy())->setHeightMap( + depthMap); +} + +void Data::clearData() +{ + m_bars->seriesList().at(0)->dataProxy()->resetArray(0); + m_scatter->seriesList().at(0)->dataProxy()->resetArray(0); + m_surface->seriesList().at(0)->dataProxy()->resetArray(0); +} + +void Data::setResolution(int selection) +{ + m_resolutionLevel = selection; + switch (selection) { + case 0: { + m_resize = true; + m_resolution = QSize(300, 300); + break; + } + case 1: { + m_resize = true; + m_resolution = QSize(600, 600); + break; + } + case 2: { + m_resize = true; + m_resolution = QSize(800, 800); + break; + } + case 3: { + m_resize = false; + m_resolution = QSize(1020, 1020); // image size + break; + } + }; + if (m_mode == Scatter) { + m_resize = true; + m_resolution /= 3; + delete m_scatterDataArray; + m_scatterDataArray = new QScatterDataArray; + m_scatterDataArray->resize(m_resolution.width() * m_resolution.height()); + } else if (m_mode == Bars) { + m_resize = true; + m_resolution /= 6; + m_barDataArray = new QBarDataArray; + m_barDataArray->reserve(m_resolution.height()); + for (int i = 0; i < m_resolution.height(); i++) { + QBarDataRow *newProxyRow = new QBarDataRow(m_resolution.width()); + m_barDataArray->append(newProxyRow); + } + } + + m_statusArea->append(QString(QStringLiteral("Resolution: %1 x %2")).arg( + m_resolution.width()).arg(m_resolution.height())); + + updateData(); +} + +void Data::scrollDown() +{ + QScrollBar *scrollbar = m_statusArea->verticalScrollBar(); + scrollbar->setValue(scrollbar->maximum()); +} + +void Data::useGradientOne() +{ + m_surface->activeTheme()->setType(Q3DTheme::ThemeIsabelle); + QLinearGradient gradient; + gradient.setColorAt(0.0, Qt::black); + gradient.setColorAt(0.33, Qt::blue); + gradient.setColorAt(0.67, Qt::red); + gradient.setColorAt(1.0, Qt::yellow); + m_surface->seriesList().at(0)->setBaseGradient(gradient); + m_surface->seriesList().at(0)->setColorStyle(Q3DTheme::ColorStyleRangeGradient); + m_statusArea->append(QStringLiteral("Colors: Thermal image imitation")); +} + +void Data::useGradientTwo() +{ + m_surface->activeTheme()->setType(Q3DTheme::ThemeQt); + QLinearGradient gradient; + gradient.setColorAt(0.0, Qt::white); + gradient.setColorAt(0.8, Qt::red); + gradient.setColorAt(1.0, Qt::green); + m_surface->seriesList().at(0)->setBaseGradient(gradient); + m_surface->seriesList().at(0)->setColorStyle(Q3DTheme::ColorStyleRangeGradient); + m_statusArea->append(QStringLiteral("Colors: Highlight foreground")); +} + +void Data::setData(const QImage &image) +{ + QImage heightImage = image; + + uchar *bits = heightImage.bits(); + + int imageHeight = heightImage.height(); + int imageWidth = heightImage.width(); + int bitCount = imageWidth * 4 * (imageHeight - 1); + int widthBits = imageWidth * 4; + + if (m_mode == Scatter) { + QScatterDataItem *ptrToDataArray = &m_scatterDataArray->first(); + + int limitsX = imageWidth / 2; + int limitsZ = imageHeight / 2; + float height = 0; + int count = 0; + + for (int i = -limitsZ; i < limitsZ; i++, bitCount -= widthBits) { + for (int j = -limitsX; j < limitsX; j++) { + height = float(bits[bitCount + ((j + limitsX) * 4)]) - 128.0; + if (height > -128) { + ptrToDataArray->setPosition(QVector3D(float(j), height, float(i))); + ptrToDataArray++; + count++; + } + } + } + + QScatterDataArray *dataArray = new QScatterDataArray(m_scatterDataArray->mid(0, count)); + m_scatter->seriesList().at(0)->dataProxy()->resetArray(dataArray); + } else { + QBarDataArray *dataArray = m_barDataArray; + for (int i = 0; i < imageHeight; i++, bitCount -= widthBits) { + QBarDataRow &newRow = *dataArray->at(i); + for (int j = 0; j < imageWidth; j++) + newRow[j] = float(bits[bitCount + (j * 4)]); + } + + m_bars->seriesList().at(0)->dataProxy()->resetArray(dataArray); + } +} + +void Data::changeMode(int mode) +{ + m_mode = VisualizationMode(mode); + switch (m_mode) { + case Surface: { + m_statusArea->append(QStringLiteral("Visualization Type: Surface")); + break; + } + case Scatter: { + m_statusArea->append(QStringLiteral("Visualization Type: Scatter")); + break; + } + default: { + m_statusArea->append(QStringLiteral("Visualization Type: Bars")); + break; + } + } + // Reset resolution after mode change + setResolution(m_resolutionLevel); +} + +void Data::start() +{ + m_started = true; + // Reset resolution before starting (otherwise restart will crash due to empty data) + setResolution(m_resolutionLevel); + updateData(); + m_statusArea->append(QStringLiteral("Started<\b>")); +} + +void Data::stop() +{ + m_started = false; + clearData(); + m_statusArea->append(QStringLiteral("Stopped<\b>")); +} + +ContainerChanger::ContainerChanger(QWidget *surface, QWidget *scatter, QWidget *bars, + QWidget *buttonOne, QWidget *buttonTwo) + : m_surface(surface), + m_scatter(scatter), + m_bars(bars), + m_button1(buttonOne), + m_button2(buttonTwo) +{ +} + +ContainerChanger::~ContainerChanger() +{ +} + +void ContainerChanger::changeContainer(int container) +{ + switch (container) { + case 0: { + m_scatter->setVisible(false); + m_bars->setVisible(false); + m_surface->setVisible(true); + m_button1->setEnabled(true); + m_button2->setEnabled(true); + break; + } + case 1: { + m_surface->setVisible(false); + m_bars->setVisible(false); + m_scatter->setVisible(true); + m_button1->setEnabled(false); + m_button2->setEnabled(false); + break; + } + case 2: { + m_surface->setVisible(false); + m_scatter->setVisible(false); + m_bars->setVisible(true); + m_button1->setEnabled(false); + m_button2->setEnabled(false); + break; + } + } +} diff --git a/tests/manual/multigraphs/data.h b/tests/manual/multigraphs/data.h new file mode 100644 index 00000000..63f5beff --- /dev/null +++ b/tests/manual/multigraphs/data.h @@ -0,0 +1,101 @@ +/****************************************************************************** +** +** 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 DATA_H +#define DATA_H + +#include +#include +#include +#include +#include +#include +#include + +using namespace QtDataVisualization; + +class Data : public QObject +{ + Q_OBJECT + +public: + explicit Data(Q3DSurface *surface, Q3DScatter *scatter, Q3DBars *bars, + QTextEdit *statusLabel, QWidget *widget); + ~Data(); + + void start(); + void stop(); + + void updateData(); + void clearData(); + + void scrollDown(); + void setData(const QImage &image); + void useGradientOne(); + void useGradientTwo(); + +public: + enum VisualizationMode { + Surface = 0, + Scatter, + Bars + }; + +public Q_SLOTS: + void setResolution(int selection); + void changeMode(int mode); + +private: + Q3DSurface *m_surface; + Q3DScatter *m_scatter; + Q3DBars *m_bars; + QTextEdit *m_statusArea; + QWidget *m_widget; + bool m_resize; + QSize m_resolution; + int m_resolutionLevel; + VisualizationMode m_mode; + QScatterDataArray *m_scatterDataArray; + QBarDataArray *m_barDataArray; + bool m_started; +}; + +class ContainerChanger : public QObject +{ + Q_OBJECT + +public: + explicit ContainerChanger(QWidget *surface, QWidget *scatter, QWidget *bars, + QWidget *buttonOne, QWidget *buttonTwo); + ~ContainerChanger(); + +public Q_SLOTS: + void changeContainer(int container); + +private: + QWidget *m_surface; + QWidget *m_scatter; + QWidget *m_bars; + QWidget *m_button1; + QWidget *m_button2; +}; + +#endif diff --git a/tests/manual/multigraphs/main.cpp b/tests/manual/multigraphs/main.cpp new file mode 100644 index 00000000..2c539d1f --- /dev/null +++ b/tests/manual/multigraphs/main.cpp @@ -0,0 +1,159 @@ +/****************************************************************************** +** +** 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 "data.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + QWidget *widget = new QWidget(); + QHBoxLayout *hLayout = new QHBoxLayout(widget); + QVBoxLayout *vLayout = new QVBoxLayout(); + + Q3DSurface *surface = new Q3DSurface(); + Q3DScatter *scatter = new Q3DScatter(); + Q3DBars *bars = new Q3DBars(); + + QSize screenSize = surface->screen()->size(); + + QWidget *containerSurface = QWidget::createWindowContainer(surface); + containerSurface->setMinimumSize(QSize(screenSize.height() / 1.2, screenSize.height() / 1.2)); + containerSurface->setMaximumSize(screenSize); + containerSurface->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + containerSurface->setFocusPolicy(Qt::StrongFocus); + + QWidget *containerScatter = QWidget::createWindowContainer(scatter); + containerScatter->setMinimumSize(QSize(screenSize.height() / 1.2, screenSize.height() / 1.2)); + containerScatter->setMaximumSize(screenSize); + containerScatter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + containerScatter->setFocusPolicy(Qt::StrongFocus); + containerScatter->setVisible(false); + + QWidget *containerBars = QWidget::createWindowContainer(bars); + containerBars->setMinimumSize(QSize(screenSize.height() / 1.2, screenSize.height() / 1.2)); + containerBars->setMaximumSize(screenSize); + containerBars->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + containerBars->setFocusPolicy(Qt::StrongFocus); + containerBars->setVisible(false); + + widget->setWindowTitle(QStringLiteral("Test switching graphs on the fly")); + + hLayout->addWidget(containerSurface, 1); + hLayout->addWidget(containerScatter, 1); + hLayout->addWidget(containerBars, 1); + hLayout->addLayout(vLayout); + + QPushButton *startButton = new QPushButton(widget); + startButton->setText(QStringLiteral("Start")); + + QPushButton *stopButton = new QPushButton(widget); + stopButton->setText(QStringLiteral("Stop")); + + QComboBox *resolutionBox = new QComboBox(widget); + resolutionBox->addItem(QStringLiteral("Low")); + resolutionBox->addItem(QStringLiteral("Medium")); + resolutionBox->addItem(QStringLiteral("High")); + resolutionBox->addItem(QStringLiteral("Max")); // Comment this out if demo machine is low-perf + resolutionBox->setCurrentIndex(0); + + QComboBox *modeBox = new QComboBox(widget); + modeBox->addItem(QStringLiteral("Surface Plot")); + modeBox->addItem(QStringLiteral("Scatter Chart")); + modeBox->addItem(QStringLiteral("Bar Chart")); + modeBox->setCurrentIndex(0); + + QLinearGradient gradientOne(0, 0, 200, 1); + gradientOne.setColorAt(0.0, Qt::black); + gradientOne.setColorAt(0.33, Qt::blue); + gradientOne.setColorAt(0.67, Qt::red); + gradientOne.setColorAt(1.0, Qt::yellow); + + QPixmap pm(200, 24); + QPainter pmp(&pm); + pmp.setBrush(QBrush(gradientOne)); + pmp.setPen(Qt::NoPen); + pmp.drawRect(0, 0, 200, 24); + + QPushButton *gradientOneButton = new QPushButton(widget); + gradientOneButton->setIcon(QIcon(pm)); + gradientOneButton->setIconSize(QSize(200, 24)); + gradientOneButton->setToolTip(QStringLiteral("Colors: Thermal Imitation")); + + QLinearGradient gradientTwo(0, 0, 200, 1); + gradientTwo.setColorAt(0.0, Qt::white); + gradientTwo.setColorAt(0.8, Qt::red); + gradientTwo.setColorAt(1.0, Qt::green); + + pmp.setBrush(QBrush(gradientTwo)); + pmp.setPen(Qt::NoPen); + pmp.drawRect(0, 0, 200, 24); + + QPushButton *gradientTwoButton = new QPushButton(widget); + gradientTwoButton->setIcon(QIcon(pm)); + gradientTwoButton->setIconSize(QSize(200, 24)); + gradientTwoButton->setToolTip(QStringLiteral("Colors: Highlight Foreground")); + + QTextEdit *status = new QTextEdit(QStringLiteral("Ready
"), widget); + status->setReadOnly(true); + + vLayout->addWidget(startButton); + vLayout->addWidget(stopButton); + vLayout->addWidget(new QLabel(QStringLiteral("Change resolution"))); + vLayout->addWidget(resolutionBox); + vLayout->addWidget(new QLabel(QStringLiteral("Change visualization type"))); + vLayout->addWidget(modeBox); + vLayout->addWidget(new QLabel(QStringLiteral("Change color scheme"))); + vLayout->addWidget(gradientOneButton); + vLayout->addWidget(gradientTwoButton); + vLayout->addWidget(status, 1, Qt::AlignBottom); + + widget->show(); + + Data datagen(surface, scatter, bars, status, widget); + ContainerChanger changer(containerSurface, containerScatter, containerBars, + gradientOneButton, gradientTwoButton); + + QObject::connect(startButton, &QPushButton::clicked, &datagen, &Data::start); + QObject::connect(stopButton, &QPushButton::clicked, &datagen, &Data::stop); + QObject::connect(resolutionBox, SIGNAL(activated(int)), &datagen, SLOT(setResolution(int))); + QObject::connect(modeBox, SIGNAL(activated(int)), &changer, SLOT(changeContainer(int))); + QObject::connect(modeBox, SIGNAL(activated(int)), &datagen, SLOT(changeMode(int))); + QObject::connect(status, &QTextEdit::textChanged, &datagen, &Data::scrollDown); + QObject::connect(gradientOneButton, &QPushButton::clicked, &datagen, + &Data::useGradientOne); + QObject::connect(gradientTwoButton, &QPushButton::clicked, &datagen, + &Data::useGradientTwo); + + return app.exec(); +} diff --git a/tests/manual/multigraphs/multigraphs.pro b/tests/manual/multigraphs/multigraphs.pro new file mode 100644 index 00000000..f1a7cffe --- /dev/null +++ b/tests/manual/multigraphs/multigraphs.pro @@ -0,0 +1,12 @@ +!include( ../tests.pri ) { + error( "Couldn't find the tests.pri file!" ) +} + +SOURCES += main.cpp \ + data.cpp +HEADERS += data.h + +QT += widgets + +RESOURCES += \ + multigraphs.qrc diff --git a/tests/manual/multigraphs/multigraphs.qrc b/tests/manual/multigraphs/multigraphs.qrc new file mode 100644 index 00000000..bd924255 --- /dev/null +++ b/tests/manual/multigraphs/multigraphs.qrc @@ -0,0 +1,5 @@ + + + australia.png + + -- cgit v1.2.3