From 6e4fb232702fa128b5efa3eef5dfaff4870a9fd0 Mon Sep 17 00:00:00 2001 From: Mika Salmela Date: Fri, 4 Jul 2014 09:58:12 +0300 Subject: Texture to surface API for setting a texture to surface. Task-number: QTRD-3232 Change-Id: Icd9de61882b54b9c1fc84a742e49980926ca681d Reviewed-by: Miikka Heikkinen --- src/datavisualization/data/qsurface3dseries.cpp | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'src/datavisualization/data/qsurface3dseries.cpp') diff --git a/src/datavisualization/data/qsurface3dseries.cpp b/src/datavisualization/data/qsurface3dseries.cpp index 1107d721..bcfc4042 100644 --- a/src/datavisualization/data/qsurface3dseries.cpp +++ b/src/datavisualization/data/qsurface3dseries.cpp @@ -299,6 +299,54 @@ QSurface3DSeries::DrawFlags QSurface3DSeries::drawMode() const return dptrc()->m_drawMode; } +/*! + * Set the \a texture as a QImage for the surface. To clear the texture, set empty + * QImage as texture. + */ +void QSurface3DSeries::setTexture(const QImage &texture) +{ + if (dptr()->m_texture != texture) { + dptr()->setTexture(texture); + + emit textureChanged(texture); + dptr()->m_textureFile.clear(); + } +} + +QImage QSurface3DSeries::texture() const +{ + return dptrc()->m_texture; +} + +/*! \property QSurface3DSeries::textureFile + * + * Holds the texture file name for the surface texture. To clear the texture, set empty + * file name. + */ +void QSurface3DSeries::setTextureFile(const QString &filename) +{ + if (dptr()->m_textureFile != filename) { + if (filename.isEmpty()) { + setTexture(QImage()); + } else { + QImage image(filename); + if (image.isNull()) { + qWarning() << "Warning: Tried to set invalid image file as surface texture."; + return; + } + setTexture(image); + } + + dptr()->m_textureFile = filename; + emit textureFileChanged(filename); + } +} + +QString QSurface3DSeries::textureFile() const +{ + return dptrc()->m_textureFile; +} + /*! * \internal */ @@ -445,4 +493,11 @@ void QSurface3DSeriesPrivate::setDrawMode(QSurface3DSeries::DrawFlags mode) } } +void QSurface3DSeriesPrivate::setTexture(const QImage &texture) +{ + m_texture = texture; + if (static_cast(m_controller)) + static_cast(m_controller)->updateSurfaceTexture(qptr()); +} + QT_END_NAMESPACE_DATAVISUALIZATION -- cgit v1.2.3