summaryrefslogtreecommitdiffstats
path: root/src/datavisualization
diff options
context:
space:
mode:
Diffstat (limited to 'src/datavisualization')
-rw-r--r--src/datavisualization/data/customrenderitem_p.h3
-rw-r--r--src/datavisualization/data/qcustom3ditem.cpp61
-rw-r--r--src/datavisualization/data/qcustom3ditem.h5
-rw-r--r--src/datavisualization/data/qcustom3ditem_p.h3
-rw-r--r--src/datavisualization/engine/abstract3drenderer.cpp32
-rw-r--r--src/datavisualization/engine/abstract3drenderer_p.h3
-rw-r--r--src/datavisualization/engine/bars3drenderer.cpp24
-rw-r--r--src/datavisualization/engine/bars3drenderer_p.h2
-rw-r--r--src/datavisualization/engine/scatter3drenderer.cpp19
-rw-r--r--src/datavisualization/engine/scatter3drenderer_p.h2
-rw-r--r--src/datavisualization/engine/surface3drenderer.cpp21
-rw-r--r--src/datavisualization/engine/surface3drenderer_p.h2
12 files changed, 140 insertions, 37 deletions
diff --git a/src/datavisualization/data/customrenderitem_p.h b/src/datavisualization/data/customrenderitem_p.h
index 81a78144..f05540d0 100644
--- a/src/datavisualization/data/customrenderitem_p.h
+++ b/src/datavisualization/data/customrenderitem_p.h
@@ -51,6 +51,8 @@ public:
inline QVector3D scaling() const { return m_scaling; }
inline void setPosition(const QVector3D &position) { m_position = position; }
inline QVector3D position() const { return m_position; }
+ inline void setPositionAbsolute(bool absolute) { m_absolute = absolute; }
+ inline bool isPositionAbsolute() const { return m_absolute; }
inline void setBlendNeeded(bool blend) { m_needBlend = blend; }
inline bool isBlendNeeded() const { return m_needBlend; }
inline void setVisible(bool visible) { m_visible = visible; }
@@ -68,6 +70,7 @@ private:
GLuint m_texture;
QVector3D m_scaling;
QVector3D m_position;
+ bool m_absolute;
ObjectHelper *m_object;
bool m_needBlend;
bool m_visible;
diff --git a/src/datavisualization/data/qcustom3ditem.cpp b/src/datavisualization/data/qcustom3ditem.cpp
index f39a0478..f1307d7a 100644
--- a/src/datavisualization/data/qcustom3ditem.cpp
+++ b/src/datavisualization/data/qcustom3ditem.cpp
@@ -62,15 +62,31 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
/*! \qmlproperty vector3d Custom3DItem::position
*
- * Holds the item \a position as a vector3d. Item position is in data coordinates. Defaults to
- * \c {vector3d(0.0, 0.0, 0.0)}.
+ * Holds the item \a position as a vector3d. Defaults to \c {vector3d(0.0, 0.0, 0.0)}.
*
- * \note Items positioned outside axis ranges are not rendered.
+ * Item position is either in data coordinates or in absolute coordinates, depending on
+ * positionAbsolute property. When using absolute coordinates, values between \c{-1.0...1.0} are
+ * within axis ranges.
+ *
+ * \note Items positioned outside any axis range are not rendered if positionAbsolute is \c{false}.
+ *
+ * \sa positionAbsolute
+ */
+
+/*! \qmlproperty bool Custom3DItem::positionAbsolute
+ *
+ * This property dictates if item position is to be handled in data coordinates or in absolute
+ * coordinates. Defaults to \c{false}. Items with absolute cooridnates will always be rendered,
+ * whereas items with data coordinates are only rendered if they are within axis ranges.
+ *
+ * \sa position
*/
/*! \qmlproperty vector3d Custom3DItem::scaling
*
* Holds the item \a scaling as a vector3d. Defaults to \c {vector3d(0.1, 0.1, 0.1)}.
+ * The default value sets the item to 10% of the height of the graph, provided the item size is
+ * normalized.
*/
/*! \qmlproperty quaternion Custom3DItem::rotation
@@ -148,10 +164,15 @@ QString QCustom3DItem::meshFile() const
/*! \property QCustom3DItem::position
*
- * Holds the item \a position as a QVector3D. Item position is in data coordinates. Defaults to
- * \c {QVector3D(0.0, 0.0, 0.0)}.
+ * Holds the item \a position as a QVector3D. Defaults to \c {QVector3D(0.0, 0.0, 0.0)}.
+ *
+ * Item position is either in data coordinates or in absolute coordinates, depending on
+ * positionAbsolute property. When using absolute coordinates, values between \c{-1.0...1.0} are
+ * within axis ranges.
+ *
+ * \note Items positioned outside any axis range are not rendered if positionAbsolute is \c{false}.
*
- * \note Items positioned outside axis ranges are not rendered.
+ * \sa positionAbsolute
*/
void QCustom3DItem::setPosition(const QVector3D &position)
{
@@ -168,9 +189,34 @@ QVector3D QCustom3DItem::position() const
return d_ptr->m_position;
}
+/*! \property QCustom3DItem::positionAbsolute
+ *
+ * This property dictates if item position is to be handled in data coordinates or in absolute
+ * coordinates. Defaults to \c{false}. Items with absolute cooridnates will always be rendered,
+ * whereas items with data coordinates are only rendered if they are within axis ranges.
+ *
+ * \sa position
+ */
+void QCustom3DItem::setPositionAbsolute(bool positionAbsolute)
+{
+ if (d_ptr->m_positionAbsolute != positionAbsolute) {
+ d_ptr->m_positionAbsolute = positionAbsolute;
+ d_ptr->m_dirtyBits.positionAbsoluteDirty = true;
+ emit positionAbsoluteChanged(positionAbsolute);
+ emit d_ptr->needUpdate();
+ }
+}
+
+bool QCustom3DItem::isPositionAbsolute() const
+{
+ return d_ptr->m_positionAbsolute;
+}
+
/*! \property QCustom3DItem::scaling
*
* Holds the item \a scaling as a QVector3D. Defaults to \c {QVector3D(0.1, 0.1, 0.1)}.
+ * The default value sets the item to 10% of the height of the graph, provided the item size is
+ * normalized.
*/
void QCustom3DItem::setScaling(const QVector3D &scaling)
{
@@ -313,6 +359,7 @@ QCustom3DItemPrivate::QCustom3DItemPrivate(QCustom3DItem *q, QObject *parent) :
QObject(parent),
q_ptr(q),
m_position(QVector3D(0.0f, 0.0f, 0.0f)),
+ m_positionAbsolute(false),
m_scaling(QVector3D(0.1f, 0.1f, 0.1f)),
m_rotation(QQuaternion(0.0f, 0.0f, 0.0f, 0.0f)),
m_visible(true),
@@ -327,6 +374,7 @@ QCustom3DItemPrivate::QCustom3DItemPrivate(QCustom3DItem *q, const QString &mesh
q_ptr(q),
m_meshFile(meshFile),
m_position(position),
+ m_positionAbsolute(false),
m_scaling(scaling),
m_rotation(rotation),
m_visible(true),
@@ -354,6 +402,7 @@ void QCustom3DItemPrivate::resetDirtyBits()
m_dirtyBits.textureDirty = false;
m_dirtyBits.meshDirty = false;
m_dirtyBits.positionDirty = false;
+ m_dirtyBits.positionAbsoluteDirty = false;
m_dirtyBits.scalingDirty = false;
m_dirtyBits.rotationDirty = false;
m_dirtyBits.visibleDirty = false;
diff --git a/src/datavisualization/data/qcustom3ditem.h b/src/datavisualization/data/qcustom3ditem.h
index 72aad604..53ec0bcf 100644
--- a/src/datavisualization/data/qcustom3ditem.h
+++ b/src/datavisualization/data/qcustom3ditem.h
@@ -34,6 +34,7 @@ class QT_DATAVISUALIZATION_EXPORT QCustom3DItem : public QObject
Q_PROPERTY(QString meshFile READ meshFile WRITE setMeshFile NOTIFY meshFileChanged)
Q_PROPERTY(QString textureFile READ textureFile WRITE setTextureFile NOTIFY textureFileChanged)
Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
+ Q_PROPERTY(bool positionAbsolute READ isPositionAbsolute WRITE setPositionAbsolute NOTIFY positionAbsoluteChanged)
Q_PROPERTY(QVector3D scaling READ scaling WRITE setScaling NOTIFY scalingChanged)
Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
@@ -55,6 +56,9 @@ public:
void setPosition(const QVector3D &position);
QVector3D position() const;
+ void setPositionAbsolute(bool positionAbsolute);
+ bool isPositionAbsolute() const;
+
void setScaling(const QVector3D &scaling);
QVector3D scaling() const;
@@ -75,6 +79,7 @@ signals:
void meshFileChanged(const QString &meshFile);
void textureFileChanged(const QString &textureFile);
void positionChanged(const QVector3D &position);
+ void positionAbsoluteChanged(bool positionAbsolute);
void scalingChanged(const QVector3D &scaling);
void rotationChanged(const QQuaternion &rotation);
void visibleChanged(bool visible);
diff --git a/src/datavisualization/data/qcustom3ditem_p.h b/src/datavisualization/data/qcustom3ditem_p.h
index 2523abd4..3e807df3 100644
--- a/src/datavisualization/data/qcustom3ditem_p.h
+++ b/src/datavisualization/data/qcustom3ditem_p.h
@@ -37,6 +37,7 @@ struct QCustomItemDirtyBitField {
bool textureDirty : 1;
bool meshDirty : 1;
bool positionDirty : 1;
+ bool positionAbsoluteDirty : 1;
bool scalingDirty : 1;
bool rotationDirty : 1;
bool visibleDirty : 1;
@@ -46,6 +47,7 @@ struct QCustomItemDirtyBitField {
: textureDirty(false),
meshDirty(false),
positionDirty(false),
+ positionAbsoluteDirty(false),
scalingDirty(false),
rotationDirty(false),
visibleDirty(false),
@@ -73,6 +75,7 @@ public:
QString m_textureFile;
QString m_meshFile;
QVector3D m_position;
+ bool m_positionAbsolute;
QVector3D m_scaling;
QQuaternion m_rotation;
bool m_visible;
diff --git a/src/datavisualization/engine/abstract3drenderer.cpp b/src/datavisualization/engine/abstract3drenderer.cpp
index 684db1a5..988ea21e 100644
--- a/src/datavisualization/engine/abstract3drenderer.cpp
+++ b/src/datavisualization/engine/abstract3drenderer.cpp
@@ -574,13 +574,15 @@ CustomRenderItem *Abstract3DRenderer::addCustomItem(QCustom3DItem *item)
newItem->setMesh(item->meshFile());
newItem->setScaling(item->scaling());
newItem->setPosition(item->position());
+ newItem->setPositionAbsolute(item->isPositionAbsolute());
newItem->setRotation(item->rotation());
QImage textureImage = item->d_ptr->textureImage();
newItem->setBlendNeeded(textureImage.hasAlphaChannel());
GLuint texture = m_textureHelper->create2DTexture(textureImage, true, true, true);
newItem->setTexture(texture);
item->d_ptr->clearTextureImage();
- QVector3D translation = convertPositionToTranslation(item->position());
+ QVector3D translation = convertPositionToTranslation(item->position(),
+ item->isPositionAbsolute());
newItem->setTranslation(translation);
newItem->setVisible(item->isVisible());
newItem->setShadowCasting(item->isShadowCasting());
@@ -613,11 +615,14 @@ void Abstract3DRenderer::updateCustomItem(CustomRenderItem *renderItem)
item->d_ptr->clearTextureImage();
item->d_ptr->m_dirtyBits.textureDirty = false;
}
- if (item->d_ptr->m_dirtyBits.positionDirty) {
- QVector3D translation = convertPositionToTranslation(item->position());
+ if (item->d_ptr->m_dirtyBits.positionDirty || item->d_ptr->m_dirtyBits.positionAbsoluteDirty) {
renderItem->setPosition(item->position());
+ renderItem->setPositionAbsolute(item->isPositionAbsolute());
+ QVector3D translation = convertPositionToTranslation(item->position(),
+ item->isPositionAbsolute());
renderItem->setTranslation(translation);
item->d_ptr->m_dirtyBits.positionDirty = false;
+ item->d_ptr->m_dirtyBits.positionAbsoluteDirty = false;
}
if (item->d_ptr->m_dirtyBits.visibleDirty) {
renderItem->setVisible(item->isVisible());
@@ -653,16 +658,21 @@ void Abstract3DRenderer::drawCustomItems(RenderingState state,
// Draw custom items
foreach (CustomRenderItem *item, m_customRenderCache) {
- // Check that the render item is visible and within axis ranges, and skip drawing if not
- if (!item->isVisible()
- || item->position().x() < m_axisCacheX.min()
- || item->position().x() > m_axisCacheX.max()
- || item->position().z() < m_axisCacheZ.min()
- || item->position().z() > m_axisCacheZ.max()
- || item->position().y() < m_axisCacheY.min()
- || item->position().y() > m_axisCacheY.max())
+ // Check that the render item is visible, and skip drawing if not
+ if (!item->isVisible())
continue;
+ // Check if the render item is in data coordinates and not within axis ranges, and skip drawing if it is
+ if (!item->isPositionAbsolute()
+ && (item->position().x() < m_axisCacheX.min()
+ || item->position().x() > m_axisCacheX.max()
+ || item->position().z() < m_axisCacheZ.min()
+ || item->position().z() > m_axisCacheZ.max()
+ || item->position().y() < m_axisCacheY.min()
+ || item->position().y() > m_axisCacheY.max())) {
+ continue;
+ }
+
QMatrix4x4 modelMatrix;
QMatrix4x4 itModelMatrix;
QMatrix4x4 MVPMatrix;
diff --git a/src/datavisualization/engine/abstract3drenderer_p.h b/src/datavisualization/engine/abstract3drenderer_p.h
index ebe473b9..f5bf0ff4 100644
--- a/src/datavisualization/engine/abstract3drenderer_p.h
+++ b/src/datavisualization/engine/abstract3drenderer_p.h
@@ -117,7 +117,8 @@ public:
virtual CustomRenderItem *addCustomItem(QCustom3DItem *item);
virtual void updateCustomItem(CustomRenderItem *renderItem);
- virtual QVector3D convertPositionToTranslation(const QVector3D &position) = 0;
+ virtual QVector3D convertPositionToTranslation(const QVector3D &position,
+ bool isAbsolute) = 0;
void generateBaseColorTexture(const QColor &color, GLuint *texture);
void fixGradientAndGenerateTexture(QLinearGradient *gradient, GLuint *gradientTexture);
diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp
index bc49e7ed..4dcf296f 100644
--- a/src/datavisualization/engine/bars3drenderer.cpp
+++ b/src/datavisualization/engine/bars3drenderer.cpp
@@ -2604,13 +2604,23 @@ void Bars3DRenderer::initLabelShaders(const QString &vertexShader, const QString
m_labelShader->initialize();
}
-QVector3D Bars3DRenderer::convertPositionToTranslation(const QVector3D &position) {
- // Convert row and column to translation on graph
- float xTrans = (((position.x() + 0.5f) * m_cachedBarSpacing.width()) - m_rowWidth)
- / m_scaleFactor;
- float zTrans = (m_columnDepth - ((position.z() + 0.5f) * m_cachedBarSpacing.height()))
- / m_scaleFactor;
- float yTrans = m_axisCacheY.positionAt(position.y());
+QVector3D Bars3DRenderer::convertPositionToTranslation(const QVector3D &position, bool isAbsolute)
+{
+ float xTrans = 0.0f;
+ float yTrans = 0.0f;
+ float zTrans = 0.0f;
+ if (!isAbsolute) {
+ // Convert row and column to translation on graph
+ xTrans = (((position.x() + 0.5f) * m_cachedBarSpacing.width()) - m_rowWidth)
+ / m_scaleFactor;
+ zTrans = (m_columnDepth - ((position.z() + 0.5f) * m_cachedBarSpacing.height()))
+ / m_scaleFactor;
+ yTrans = m_axisCacheY.positionAt(position.y());
+ } else {
+ xTrans = position.x() * m_scaleX;
+ yTrans = position.y();
+ zTrans = position.z() * m_scaleZ;
+ }
return QVector3D(xTrans, yTrans, zTrans);
}
diff --git a/src/datavisualization/engine/bars3drenderer_p.h b/src/datavisualization/engine/bars3drenderer_p.h
index 68848673..2e9ec0de 100644
--- a/src/datavisualization/engine/bars3drenderer_p.h
+++ b/src/datavisualization/engine/bars3drenderer_p.h
@@ -122,7 +122,7 @@ public:
void updateScene(Q3DScene *scene);
void render(GLuint defaultFboHandle = 0);
- QVector3D convertPositionToTranslation(const QVector3D &position);
+ QVector3D convertPositionToTranslation(const QVector3D &position, bool isAbsolute);
protected:
virtual void initializeOpenGL();
diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp
index 3cf91833..acdd3cb8 100644
--- a/src/datavisualization/engine/scatter3drenderer.cpp
+++ b/src/datavisualization/engine/scatter3drenderer.cpp
@@ -1967,10 +1967,21 @@ void Scatter3DRenderer::updateRenderItem(const QScatterDataItem &dataItem, Scatt
}
}
-QVector3D Scatter3DRenderer::convertPositionToTranslation(const QVector3D &position) {
- float xTrans = m_axisCacheX.positionAt(position.x());
- float yTrans = m_axisCacheY.positionAt(position.y());
- float zTrans = m_axisCacheZ.positionAt(position.z());
+QVector3D Scatter3DRenderer::convertPositionToTranslation(const QVector3D &position,
+ bool isAbsolute)
+{
+ float xTrans = 0.0f;
+ float yTrans = 0.0f;
+ float zTrans = 0.0f;
+ if (!isAbsolute) {
+ xTrans = m_axisCacheX.positionAt(position.x());
+ yTrans = m_axisCacheY.positionAt(position.y());
+ zTrans = m_axisCacheZ.positionAt(position.z());
+ } else {
+ xTrans = position.x() * m_axisCacheX.scale() / 2.0f;
+ yTrans = position.y();
+ zTrans = position.z() * m_axisCacheZ.scale() / 2.0f;
+ }
return QVector3D(xTrans, yTrans, zTrans);
}
diff --git a/src/datavisualization/engine/scatter3drenderer_p.h b/src/datavisualization/engine/scatter3drenderer_p.h
index 09b8dace..0b58102b 100644
--- a/src/datavisualization/engine/scatter3drenderer_p.h
+++ b/src/datavisualization/engine/scatter3drenderer_p.h
@@ -108,7 +108,7 @@ public:
void updateItems(const QVector<Scatter3DController::ChangeItem> &items);
void updateScene(Q3DScene *scene);
- QVector3D convertPositionToTranslation(const QVector3D &position);
+ QVector3D convertPositionToTranslation(const QVector3D &position, bool isAbsolute);
inline int clickedIndex() const { return m_clickedIndex; }
void resetClickedStatus();
diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp
index cc4cf788..4b5464d5 100644
--- a/src/datavisualization/engine/surface3drenderer.cpp
+++ b/src/datavisualization/engine/surface3drenderer.cpp
@@ -1212,7 +1212,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
// Draw selection buffer
if (!m_cachedIsSlicingActivated && (!m_renderCacheList.isEmpty()
- || !m_customRenderCache.isEmpty())
+ || !m_customRenderCache.isEmpty())
&& m_selectionState == SelectOnScene
&& m_cachedSelectionMode > QAbstract3DGraph::SelectionNone) {
m_selectionShader->bind();
@@ -2682,10 +2682,21 @@ void Surface3DRenderer::updateDepthBuffer()
}
#endif
-QVector3D Surface3DRenderer::convertPositionToTranslation(const QVector3D &position) {
- float xTrans = m_axisCacheX.positionAt(position.x());
- float yTrans = m_axisCacheY.positionAt(position.y());
- float zTrans = m_axisCacheZ.positionAt(position.z());
+QVector3D Surface3DRenderer::convertPositionToTranslation(const QVector3D &position,
+ bool isAbsolute)
+{
+ float xTrans = 0.0f;
+ float yTrans = 0.0f;
+ float zTrans = 0.0f;
+ if (!isAbsolute) {
+ xTrans = m_axisCacheX.positionAt(position.x());
+ yTrans = m_axisCacheY.positionAt(position.y());
+ zTrans = m_axisCacheZ.positionAt(position.z());
+ } else {
+ xTrans = position.x() * m_scaleX;
+ yTrans = position.y();
+ zTrans = position.z() * m_scaleZ;
+ }
return QVector3D(xTrans, yTrans, zTrans);
}
diff --git a/src/datavisualization/engine/surface3drenderer_p.h b/src/datavisualization/engine/surface3drenderer_p.h
index db46a17b..7c3e461d 100644
--- a/src/datavisualization/engine/surface3drenderer_p.h
+++ b/src/datavisualization/engine/surface3drenderer_p.h
@@ -116,7 +116,7 @@ public:
void updateSelectedPoint(const QPoint &position, QSurface3DSeries *series);
inline QPoint clickedPosition() const { return m_clickedPosition; }
void resetClickedStatus();
- QVector3D convertPositionToTranslation(const QVector3D &position);
+ QVector3D convertPositionToTranslation(const QVector3D &position, bool isAbsolute);
void render(GLuint defaultFboHandle = 0);