diff options
9 files changed, 80 insertions, 2 deletions
diff --git a/examples/datavisualization/qmlsurface/qml/qmlsurface/main.qml b/examples/datavisualization/qmlsurface/qml/qmlsurface/main.qml index 2124346a..f128ac45 100644 --- a/examples/datavisualization/qmlsurface/qml/qmlsurface/main.qml +++ b/examples/datavisualization/qmlsurface/qml/qmlsurface/main.qml @@ -155,6 +155,26 @@ Rectangle { } Button { + id: surfaceGridColor + Layout.fillWidth: true + Layout.fillHeight: true + text: "Red surface grid color" + onClicked: { + if (Qt.colorEqual(surfaceSeries.wireFrameColor, "#000000") + && Qt.colorEqual(heightSeries.wireFrameColor, "#000000")) { + surfaceSeries.wireFrameColor = "red" + heightSeries.wireFrameColor = "red" + text = "Black surface grid color" + } + else { + surfaceSeries.wireFrameColor = "black" + heightSeries.wireFrameColor = "black" + text = "Red surface grid color" + } + } + } + + Button { id: surfaceToggle Layout.fillWidth: true Layout.fillHeight: true diff --git a/src/datavisualization/data/qsurface3dseries.cpp b/src/datavisualization/data/qsurface3dseries.cpp index 94241dbc..f3e8e1fa 100644 --- a/src/datavisualization/data/qsurface3dseries.cpp +++ b/src/datavisualization/data/qsurface3dseries.cpp @@ -165,6 +165,12 @@ QT_BEGIN_NAMESPACE * file name is set. */ +/*! + * \qmlproperty color Surface3DSeries::wireFrameColor + * \since 6.3 + * + * The color used to draw the gridlines of the surface wireframe. + */ /*! * \enum QSurface3DSeries::DrawFlag @@ -399,6 +405,24 @@ QString QSurface3DSeries::textureFile() const } /*! + * \property QSurface3DSeries::wireFrameColor + * \since 6.3 + * + * \brief The color for the surface wireframe. + */ +void QSurface3DSeries::setWireFrameColor(const QColor &color) +{ + if (dptr()->m_wireFrameColor != color) { + dptr()->setWireFrameColor(color); + emit wireFrameColorChanged(color); + } +} + +QColor QSurface3DSeries::wireFrameColor() const +{ + return dptrc()->m_wireFrameColor; +} +/*! * \internal */ QSurface3DSeriesPrivate *QSurface3DSeries::dptr() @@ -420,7 +444,8 @@ QSurface3DSeriesPrivate::QSurface3DSeriesPrivate(QSurface3DSeries *q) : QAbstract3DSeriesPrivate(q, QAbstract3DSeries::SeriesTypeSurface), m_selectedPoint(Surface3DController::invalidSelectionPosition()), m_flatShadingEnabled(true), - m_drawMode(QSurface3DSeries::DrawSurfaceAndWireframe) + m_drawMode(QSurface3DSeries::DrawSurfaceAndWireframe), + m_wireFrameColor(Qt::black) { m_itemLabelFormat = QStringLiteral("@xLabel, @yLabel, @zLabel"); m_mesh = QAbstract3DSeries::MeshSphere; @@ -553,4 +578,11 @@ void QSurface3DSeriesPrivate::setTexture(const QImage &texture) static_cast<Surface3DController *>(m_controller)->updateSurfaceTexture(qptr()); } +void QSurface3DSeriesPrivate::setWireFrameColor(const QColor &color) +{ + m_wireFrameColor = color; + if (m_controller) + m_controller->markSeriesVisualsDirty(); +} + QT_END_NAMESPACE diff --git a/src/datavisualization/data/qsurface3dseries.h b/src/datavisualization/data/qsurface3dseries.h index eadc6622..7f02e491 100644 --- a/src/datavisualization/data/qsurface3dseries.h +++ b/src/datavisualization/data/qsurface3dseries.h @@ -48,6 +48,7 @@ class QT_DATAVISUALIZATION_EXPORT QSurface3DSeries : public QAbstract3DSeries Q_PROPERTY(DrawFlags drawMode READ drawMode WRITE setDrawMode NOTIFY drawModeChanged) Q_PROPERTY(QImage texture READ texture WRITE setTexture NOTIFY textureChanged) Q_PROPERTY(QString textureFile READ textureFile WRITE setTextureFile NOTIFY textureFileChanged) + Q_PROPERTY(QColor wireFrameColor READ wireFrameColor WRITE setWireFrameColor NOTIFY wireFrameColorChanged) public: enum DrawFlag { @@ -81,6 +82,9 @@ public: void setTextureFile(const QString &filename); QString textureFile() const; + void setWireFrameColor(const QColor &color); + QColor wireFrameColor() const; + Q_SIGNALS: void dataProxyChanged(QSurfaceDataProxy *proxy); void selectedPointChanged(const QPoint &position); @@ -89,6 +93,7 @@ Q_SIGNALS: void drawModeChanged(QSurface3DSeries::DrawFlags mode); void textureChanged(const QImage &image); void textureFileChanged(const QString &filename); + void wireFrameColorChanged(const QColor &color); protected: explicit QSurface3DSeries(QSurface3DSeriesPrivate *d, QObject *parent = nullptr); diff --git a/src/datavisualization/data/qsurface3dseries_p.h b/src/datavisualization/data/qsurface3dseries_p.h index 16a8cb23..3b35cd22 100644 --- a/src/datavisualization/data/qsurface3dseries_p.h +++ b/src/datavisualization/data/qsurface3dseries_p.h @@ -60,6 +60,7 @@ public: void setFlatShadingEnabled(bool enabled); void setDrawMode(QSurface3DSeries::DrawFlags mode); void setTexture(const QImage &texture); + void setWireFrameColor(const QColor &color); private: QSurface3DSeries *qptr(); @@ -69,6 +70,7 @@ private: QSurface3DSeries::DrawFlags m_drawMode; QImage m_texture; QString m_textureFile; + QColor m_wireFrameColor; private: friend class QSurface3DSeries; diff --git a/src/datavisualization/engine/drawer.cpp b/src/datavisualization/engine/drawer.cpp index e83a1715..853e800b 100644 --- a/src/datavisualization/engine/drawer.cpp +++ b/src/datavisualization/engine/drawer.cpp @@ -197,6 +197,10 @@ void Drawer::drawSelectionObject(ShaderHelper *shader, AbstractObjectHelper *obj void Drawer::drawSurfaceGrid(ShaderHelper *shader, SurfaceObject *object) { + // Get grid line color + QVector4D lineColor = Utils::vectorFromColor(object->wireFrameColor()); + shader->setUniformValue(shader->color(), lineColor); + // 1st attribute buffer : vertices glEnableVertexAttribArray(shader->posAtt()); glBindBuffer(GL_ARRAY_BUFFER, object->vertexBuf()); diff --git a/src/datavisualization/engine/surfaceseriesrendercache.cpp b/src/datavisualization/engine/surfaceseriesrendercache.cpp index 918d0fb6..545cee7e 100644 --- a/src/datavisualization/engine/surfaceseriesrendercache.cpp +++ b/src/datavisualization/engine/surfaceseriesrendercache.cpp @@ -66,6 +66,10 @@ void SurfaceSeriesRenderCache::populate(bool newSeries) QSurface3DSeries::DrawFlags drawMode = series()->drawMode(); m_surfaceVisible = drawMode.testFlag(QSurface3DSeries::DrawSurface); m_surfaceGridVisible = drawMode.testFlag(QSurface3DSeries::DrawWireframe); + QColor lineColor = series()->wireFrameColor(); + m_surfaceObj->setLineColor(lineColor); + m_sliceSurfaceObj->setLineColor(lineColor); + if (m_flatChangeAllowed && m_surfaceFlatShading != series()->isFlatShadingEnabled()) { m_surfaceFlatShading = series()->isFlatShadingEnabled(); m_flatStatusDirty = true; diff --git a/src/datavisualization/utils/surfaceobject_p.h b/src/datavisualization/utils/surfaceobject_p.h index 4532a671..9e317bb2 100644 --- a/src/datavisualization/utils/surfaceobject_p.h +++ b/src/datavisualization/utils/surfaceobject_p.h @@ -45,6 +45,7 @@ #include "qsurfacedataproxy.h" #include <QtCore/QRect> +#include <QtGui/QColor> QT_BEGIN_NAMESPACE @@ -95,6 +96,8 @@ public: float minYValue() const { return m_minY; } float maxYValue() const { return m_maxY; } inline void activateSurfaceTexture(bool value) { m_returnTextureBuffer = value; } + inline void setLineColor(const QColor &color) { m_wireFrameColor = color; } + inline const QColor &wireFrameColor() const { return m_wireFrameColor; } private: void createCoarseIndices(GLint *indices, int &p, int row, int upperRow, int j); @@ -129,6 +132,7 @@ private: bool m_returnTextureBuffer = false; SurfaceObject::DataDimensions m_dataDimension; SurfaceObject::DataDimensions m_oldDataDimension = DataDimensions(-1); + QColor m_wireFrameColor; }; QT_END_NAMESPACE diff --git a/tests/auto/cpptest/q3dsurface-series/tst_series.cpp b/tests/auto/cpptest/q3dsurface-series/tst_series.cpp index 23f86dd5..9a097d6e 100644 --- a/tests/auto/cpptest/q3dsurface-series/tst_series.cpp +++ b/tests/auto/cpptest/q3dsurface-series/tst_series.cpp @@ -92,7 +92,7 @@ void tst_series::initialProperties() QCOMPARE(m_series->isFlatShadingEnabled(), true); QCOMPARE(m_series->isFlatShadingSupported(), true); QCOMPARE(m_series->selectedPoint(), m_series->invalidSelectionPosition()); - + QCOMPARE(m_series->wireFrameColor(), QColor(Qt::black)); // Common properties. The ones identical between different series are tested in QBar3DSeries tests QCOMPARE(m_series->itemLabelFormat(), QString("@xLabel, @yLabel, @zLabel")); QCOMPARE(m_series->mesh(), QAbstract3DSeries::MeshSphere); @@ -107,10 +107,12 @@ void tst_series::initializeProperties() m_series->setDrawMode(QSurface3DSeries::DrawWireframe); m_series->setFlatShadingEnabled(false); m_series->setSelectedPoint(QPoint(0, 0)); + m_series->setWireFrameColor(QColor(Qt::red)); QCOMPARE(m_series->drawMode(), QSurface3DSeries::DrawWireframe); QCOMPARE(m_series->isFlatShadingEnabled(), false); QCOMPARE(m_series->selectedPoint(), QPoint(0, 0)); + QCOMPARE(m_series->wireFrameColor(), QColor(Qt::red)); // Common properties. The ones identical between different series are tested in QBar3DSeries tests m_series->setMesh(QAbstract3DSeries::MeshPyramid); diff --git a/tests/auto/qmltest/surface3d/tst_surfaceseries.qml b/tests/auto/qmltest/surface3d/tst_surfaceseries.qml index a4593c94..0428ab53 100644 --- a/tests/auto/qmltest/surface3d/tst_surfaceseries.qml +++ b/tests/auto/qmltest/surface3d/tst_surfaceseries.qml @@ -79,6 +79,7 @@ Item { flatShadingEnabled: false selectedPoint: Qt.point(0, 0) textureFile: ":\customtexture.jpg" + wireFrameColor: "red" baseColor: "blue" baseGradient: gradient1 @@ -123,6 +124,7 @@ Item { compare(initial.flatShadingEnabled, true) compare(initial.flatShadingSupported, true) compare(initial.selectedPoint, Qt.point(-1, -1)) + compare(initial.wireFrameColor, "#000000") } function test_2_initial_common() { @@ -156,6 +158,7 @@ Item { compare(initialized.flatShadingEnabled, false) compare(initialized.selectedPoint, Qt.point(0, 0)) compare(initialized.textureFile, ":\customtexture.jpg") + compare(initialized.wireFrameColor, "#ff0000") } function test_2_initialized_common() { @@ -187,6 +190,7 @@ Item { change.flatShadingEnabled = false change.selectedPoint = Qt.point(0, 0) change.textureFile = ":\customtexture.jpg" + change.wireFrameColor = "green" } function test_2_test_change() { @@ -196,6 +200,7 @@ Item { compare(change.flatShadingEnabled, false) compare(change.selectedPoint, Qt.point(0, 0)) compare(change.textureFile, ":\customtexture.jpg") + compare(change.wireFrameColor, "#008000") } function test_3_change_common() { |