summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/datavisualization/customitems/customitemgraph.cpp40
-rw-r--r--src/datavisualization/data/customrenderitem_p.h6
-rw-r--r--src/datavisualization/data/data.pri7
-rw-r--r--src/datavisualization/data/qcustom3ditem.cpp34
-rw-r--r--src/datavisualization/data/qcustom3ditem.h2
-rw-r--r--src/datavisualization/data/qcustom3ditem_p.h8
-rw-r--r--src/datavisualization/data/qcustom3dlabel.cpp358
-rw-r--r--src/datavisualization/data/qcustom3dlabel.h93
-rw-r--r--src/datavisualization/data/qcustom3dlabel_p.h73
-rw-r--r--src/datavisualization/engine/abstract3drenderer.cpp100
-rw-r--r--src/datavisualization/engine/bars3drenderer.cpp2
-rw-r--r--src/datavisualizationqml2/datavisualizationqml2_plugin.cpp5
-rw-r--r--src/datavisualizationqml2/datavisualizationqml2_plugin.h2
-rw-r--r--tests/qmlcamera/qml/qmlcamera/main.qml11
14 files changed, 705 insertions, 36 deletions
diff --git a/examples/datavisualization/customitems/customitemgraph.cpp b/examples/datavisualization/customitems/customitemgraph.cpp
index ca6a46ef..07ee1b9a 100644
--- a/examples/datavisualization/customitems/customitemgraph.cpp
+++ b/examples/datavisualization/customitems/customitemgraph.cpp
@@ -20,6 +20,7 @@
#include <QtDataVisualization/Q3DTheme>
#include <QtDataVisualization/QCustom3DItem>
+#include <QtDataVisualization/QCustom3DLabel>
#include <QtGui/QImage>
using namespace QtDataVisualization;
@@ -97,6 +98,17 @@ CustomItemGraph::CustomItemGraph(Q3DSurface *surface, QLabel *label)
m_selectionAnimation->setPropertyName("scaling");
m_selectionAnimation->setDuration(500);
m_selectionAnimation->setLoopCount(-1);
+
+ QFont titleFont = QFont("Century Gothic", 30);
+ titleFont.setBold(true);
+ QCustom3DLabel *titleLabel = new QCustom3DLabel("Oil Rigs on Imaginary Sea", titleFont,
+ QVector3D(0.0f, 1.2f, 0.0f),
+ QVector3D(1.0f, 1.0f, 0.0f),
+ QQuaternion());
+ titleLabel->setPositionAbsolute(true);
+ titleLabel->setFacingCamera(true);
+ titleLabel->setBackgroundColor(QColor(0x66cdaa));
+ m_graph->addCustomItem(titleLabel);
}
CustomItemGraph::~CustomItemGraph()
@@ -110,6 +122,7 @@ void CustomItemGraph::toggleItemOne(bool show)
QVector3D positionOne = QVector3D(39.0f, 77.0f, 19.2f);
//! [1]
QVector3D positionOnePipe = QVector3D(39.0f, 45.0f, 19.2f);
+ QVector3D positionOneLabel = QVector3D(39.0f, 107.0f, 19.2f);
if (show) {
//! [0]
QImage color = QImage(2, 2, QImage::Format_RGB32);
@@ -130,12 +143,19 @@ void CustomItemGraph::toggleItemOne(bool show)
color);
item->setShadowCasting(false);
m_graph->addCustomItem(item);
+
+ QCustom3DLabel *label = new QCustom3DLabel();
+ label->setText("Oil Rig One");
+ label->setPosition(positionOneLabel);
+ label->setScaling(QVector3D(1.0f, 1.0f, 1.0f));
+ m_graph->addCustomItem(label);
} else {
resetSelection();
//! [4]
m_graph->removeCustomItemAt(positionOne);
//! [4]
m_graph->removeCustomItemAt(positionOnePipe);
+ m_graph->removeCustomItemAt(positionOneLabel);
}
}
@@ -143,6 +163,7 @@ void CustomItemGraph::toggleItemTwo(bool show)
{
QVector3D positionTwo = QVector3D(34.5f, 77.0f, 23.4f);
QVector3D positionTwoPipe = QVector3D(34.5f, 45.0f, 23.4f);
+ QVector3D positionTwoLabel = QVector3D(34.5f, 107.0f, 23.4f);
if (show) {
QImage color = QImage(2, 2, QImage::Format_RGB32);
color.fill(Qt::red);
@@ -159,16 +180,24 @@ void CustomItemGraph::toggleItemTwo(bool show)
color);
item->setShadowCasting(false);
m_graph->addCustomItem(item);
+
+ QCustom3DLabel *label = new QCustom3DLabel();
+ label->setText("Oil Rig Two");
+ label->setPosition(positionTwoLabel);
+ label->setScaling(QVector3D(1.0f, 1.0f, 1.0f));
+ m_graph->addCustomItem(label);
} else {
resetSelection();
m_graph->removeCustomItemAt(positionTwo);
m_graph->removeCustomItemAt(positionTwoPipe);
+ m_graph->removeCustomItemAt(positionTwoLabel);
}
}
void CustomItemGraph::toggleItemThree(bool show)
{
QVector3D positionThree = QVector3D(34.5f, 86.0f, 19.1f);
+ QVector3D positionThreeLabel = QVector3D(34.5f, 116.0f, 19.1f);
if (show) {
QImage color = QImage(2, 2, QImage::Format_RGB32);
color.fill(Qt::darkMagenta);
@@ -179,9 +208,16 @@ void CustomItemGraph::toggleItemThree(bool show)
item->setRotation(QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 75.0f));
item->setTextureImage(color);
m_graph->addCustomItem(item);
+
+ QCustom3DLabel *label = new QCustom3DLabel();
+ label->setText("Refinery");
+ label->setPosition(positionThreeLabel);
+ label->setScaling(QVector3D(1.0f, 1.0f, 1.0f));
+ m_graph->addCustomItem(label);
} else {
resetSelection();
m_graph->removeCustomItemAt(positionThree);
+ m_graph->removeCustomItemAt(positionThreeLabel);
}
}
@@ -225,14 +261,14 @@ void CustomItemGraph::handleElementSelected(QAbstract3DGraph::ElementType type)
if (type == QAbstract3DGraph::ElementCustomItem) {
int index = m_graph->selectedCustomItemIndex();
QCustom3DItem *item = m_graph->selectedCustomItem();
- m_previouslyAnimatedItem = item;
- m_previousScaling = item->scaling();
QString text;
text.setNum(index);
text.append(": ");
QStringList split = item->meshFile().split("/");
text.append(split.last());
m_textField->setText(text);
+ m_previouslyAnimatedItem = item;
+ m_previousScaling = item->scaling();
m_selectionAnimation->setTargetObject(item);
m_selectionAnimation->setStartValue(item->scaling());
m_selectionAnimation->setEndValue(item->scaling() * 1.5f);
diff --git a/src/datavisualization/data/customrenderitem_p.h b/src/datavisualization/data/customrenderitem_p.h
index 17195f7b..4fb94276 100644
--- a/src/datavisualization/data/customrenderitem_p.h
+++ b/src/datavisualization/data/customrenderitem_p.h
@@ -65,6 +65,8 @@ public:
inline int index() const { return m_index; }
inline void setShadowCasting(bool shadowCasting) { m_shadowCasting = shadowCasting; }
inline bool isShadowCasting() const { return m_shadowCasting; }
+ inline void setFacingCamera(bool facing) { m_isFacingCamera = facing; }
+ inline bool isFacingCamera() const { return m_isFacingCamera; }
inline void setRenderer(Abstract3DRenderer *renderer) { m_renderer = renderer; }
private:
@@ -80,10 +82,10 @@ private:
bool m_valid;
int m_index;
bool m_shadowCasting;
+ bool m_isFacingCamera;
QCustom3DItem *m_item;
Abstract3DRenderer *m_renderer;
-
- };
+};
typedef QHash<QCustom3DItem *, CustomRenderItem *> CustomRenderItemArray;
QT_END_NAMESPACE_DATAVISUALIZATION
diff --git a/src/datavisualization/data/data.pri b/src/datavisualization/data/data.pri
index ca139984..73f398bf 100644
--- a/src/datavisualization/data/data.pri
+++ b/src/datavisualization/data/data.pri
@@ -39,7 +39,9 @@ HEADERS += \
$$PWD/qsurface3dseries_p.h \
$$PWD/customrenderitem_p.h \
$$PWD/qcustom3ditem.h \
- $$PWD/qcustom3ditem_p.h
+ $$PWD/qcustom3ditem_p.h \
+ $$PWD/qcustom3dlabel.h \
+ $$PWD/qcustom3dlabel_p.h
SOURCES += \
$$PWD/labelitem.cpp \
@@ -66,4 +68,5 @@ SOURCES += \
$$PWD/qscatter3dseries.cpp \
$$PWD/qsurface3dseries.cpp \
$$PWD/customrenderitem.cpp \
- $$PWD/qcustom3ditem.cpp
+ $$PWD/qcustom3ditem.cpp \
+ $$PWD/qcustom3dlabel.cpp
diff --git a/src/datavisualization/data/qcustom3ditem.cpp b/src/datavisualization/data/qcustom3ditem.cpp
index f1307d7a..17d17502 100644
--- a/src/datavisualization/data/qcustom3ditem.cpp
+++ b/src/datavisualization/data/qcustom3ditem.cpp
@@ -17,8 +17,6 @@
****************************************************************************/
#include "qcustom3ditem_p.h"
-#include "objecthelper_p.h"
-#include "texturehelper_p.h"
QT_BEGIN_NAMESPACE_DATAVISUALIZATION
@@ -76,7 +74,7 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
/*! \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,
+ * coordinates. Defaults to \c{false}. Items with absolute coordinates will always be rendered,
* whereas items with data coordinates are only rendered if they are within axis ranges.
*
* \sa position
@@ -118,7 +116,18 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
* Constructs QCustom3DItem with given \a parent.
*/
QCustom3DItem::QCustom3DItem(QObject *parent) :
- d_ptr(new QCustom3DItemPrivate(this, parent))
+ QObject(parent),
+ d_ptr(new QCustom3DItemPrivate(this))
+{
+ setTextureImage(QImage());
+}
+
+/*!
+ * \internal
+ */
+QCustom3DItem::QCustom3DItem(QCustom3DItemPrivate *d, QObject *parent) :
+ QObject(parent),
+ d_ptr(d)
{
setTextureImage(QImage());
}
@@ -130,7 +139,8 @@ QCustom3DItem::QCustom3DItem(QObject *parent) :
QCustom3DItem::QCustom3DItem(const QString &meshFile, const QVector3D &position,
const QVector3D &scaling, const QQuaternion &rotation,
const QImage &texture, QObject *parent) :
- d_ptr(new QCustom3DItemPrivate(this, meshFile, position, scaling, rotation, parent))
+ QObject(parent),
+ d_ptr(new QCustom3DItemPrivate(this, meshFile, position, scaling, rotation))
{
setTextureImage(texture);
}
@@ -192,7 +202,7 @@ QVector3D QCustom3DItem::position() const
/*! \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,
+ * coordinates. Defaults to \c{false}. Items with absolute coordinates will always be rendered,
* whereas items with data coordinates are only rendered if they are within axis ranges.
*
* \sa position
@@ -355,22 +365,21 @@ QString QCustom3DItem::textureFile() const
return d_ptr->m_textureFile;
}
-QCustom3DItemPrivate::QCustom3DItemPrivate(QCustom3DItem *q, QObject *parent) :
- QObject(parent),
+QCustom3DItemPrivate::QCustom3DItemPrivate(QCustom3DItem *q) :
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),
- m_shadowCasting(true)
+ m_shadowCasting(true),
+ m_isLabelItem(false)
{
}
QCustom3DItemPrivate::QCustom3DItemPrivate(QCustom3DItem *q, const QString &meshFile,
const QVector3D &position, const QVector3D &scaling,
- const QQuaternion &rotation, QObject *parent) :
- QObject(parent),
+ const QQuaternion &rotation) :
q_ptr(q),
m_meshFile(meshFile),
m_position(position),
@@ -378,7 +387,8 @@ QCustom3DItemPrivate::QCustom3DItemPrivate(QCustom3DItem *q, const QString &mesh
m_scaling(scaling),
m_rotation(rotation),
m_visible(true),
- m_shadowCasting(true)
+ m_shadowCasting(true),
+ m_isLabelItem(false)
{
}
diff --git a/src/datavisualization/data/qcustom3ditem.h b/src/datavisualization/data/qcustom3ditem.h
index 53ec0bcf..2f7f37cf 100644
--- a/src/datavisualization/data/qcustom3ditem.h
+++ b/src/datavisualization/data/qcustom3ditem.h
@@ -86,6 +86,8 @@ signals:
void shadowCastingChanged(bool shadowCasting);
protected:
+ QCustom3DItem(QCustom3DItemPrivate *d, QObject *parent = 0);
+
QScopedPointer<QCustom3DItemPrivate> d_ptr;
private:
diff --git a/src/datavisualization/data/qcustom3ditem_p.h b/src/datavisualization/data/qcustom3ditem_p.h
index 3e807df3..c1ce5996 100644
--- a/src/datavisualization/data/qcustom3ditem_p.h
+++ b/src/datavisualization/data/qcustom3ditem_p.h
@@ -60,9 +60,9 @@ class QCustom3DItemPrivate : public QObject
{
Q_OBJECT
public:
- QCustom3DItemPrivate(QCustom3DItem *q, QObject *parent);
+ QCustom3DItemPrivate(QCustom3DItem *q);
QCustom3DItemPrivate(QCustom3DItem *q, const QString &meshFile, const QVector3D &position,
- const QVector3D &scaling, const QQuaternion &rotation, QObject *parent);
+ const QVector3D &scaling, const QQuaternion &rotation);
virtual ~QCustom3DItemPrivate();
QImage textureImage();
@@ -81,12 +81,16 @@ public:
bool m_visible;
bool m_shadowCasting;
+ bool m_isLabelItem;
+
QCustomItemDirtyBitField m_dirtyBits;
signals:
void needUpdate();
private:
+ QCustom3DItemPrivate(QCustom3DItemPrivate *d);
+
friend class QCustom3DItem;
};
diff --git a/src/datavisualization/data/qcustom3dlabel.cpp b/src/datavisualization/data/qcustom3dlabel.cpp
new file mode 100644
index 00000000..585f4f35
--- /dev/null
+++ b/src/datavisualization/data/qcustom3dlabel.cpp
@@ -0,0 +1,358 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+#include "qcustom3dlabel_p.h"
+#include "utils_p.h"
+
+QT_BEGIN_NAMESPACE_DATAVISUALIZATION
+
+/*!
+ * \class QCustom3DLabel
+ * \inmodule QtDataVisualization
+ * \brief The QCustom3DLabel class is for creating custom labels to be added to a graph.
+ * \since Qt Data Visualization 1.1
+ *
+ * This class is for creating custom labels to be added to a graph. You can set text, font,
+ * position, scaling, rotation, and colors. You can also toggle borders and background for the
+ * label. Colors, borders and background are used from active theme unless any of them is set
+ * explicitly.
+ *
+ * \note In scaling, z has no effect. Setting the same x and y retains the original
+ * font dimensions.
+ *
+ * \sa QAbstract3DGraph::addCustomItem()
+ */
+
+/*!
+ * \qmltype Custom3DLabel
+ * \inqmlmodule QtDataVisualization
+ * \since QtDataVisualization 1.1
+ * \ingroup datavisualization_qml
+ * \instantiates QCustom3DLabel
+ * \brief The Custom3DLabel type is for creating custom labels to be added to a graph.
+ *
+ * This type is for creating custom labels to be added to a graph. You can set text, font,
+ * position, scaling, rotation, and colors. You can also toggle borders and background for the
+ * label. Colors, borders and background are used from active theme unless any of them is set
+ * explicitly.
+ *
+ * \note In scaling, z has no effect. Setting the same x and y retains the original
+ * font dimensions.
+ */
+
+/*! \qmlproperty string Custom3DLabel::text
+ *
+ * The text for the label. Rich text is not supported.
+ */
+
+/*! \qmlproperty font Custom3DLabel::font
+ *
+ * The font to be used for the label. Defaults to \c{Font {family: "Arial"; pointSize: 20}}.
+ * Special formatting (for example outlined) is not supported.
+ */
+
+/*! \qmlproperty color Custom3DLabel::textColor
+ *
+ * Color for the label text. Also affects label border, if enabled. Defaults to \c{"white"}.
+ *
+ * \sa borderEnabled
+ */
+
+/*! \qmlproperty color Custom3DLabel::backgroundColor
+ *
+ * Color for the label background, if enabled. Defaults to \c{"gray"}.
+ *
+ * \sa backgroundEnabled
+ */
+
+/*! \qmlproperty bool Custom3DLabel::backgroundEnabled
+ *
+ * Enable label background. If set to \c{false}, backgroundColor has no effect. Defaults
+ * to \c{true}.
+ */
+
+/*! \qmlproperty bool Custom3DLabel::borderEnabled
+ *
+ * Enable label borders. Defaults to \c{true}.
+ */
+
+/*! \qmlproperty bool Custom3DLabel::facingCamera
+ *
+ * Forces the label to face camera always. Defaults to \c{false}. If set to \c{true}, rotation()
+ * has no effect.
+ */
+
+/*!
+ * Constructs QCustom3DLabel with given \a parent.
+ */
+QCustom3DLabel::QCustom3DLabel(QObject *parent) :
+ QCustom3DItem(new QCustom3DLabelPrivate(this), parent)
+{
+}
+
+/*!
+ * Constructs QCustom3DLabel with given \a text, \a font, \a position, \a scaling,
+ * \a rotation, and optional \a parent.
+ *
+ * \note Setting the same x and y for \a scaling retains the original font dimensions.
+ */
+QCustom3DLabel::QCustom3DLabel(const QString &text, const QFont &font,
+ const QVector3D &position, const QVector3D &scaling,
+ const QQuaternion &rotation, QObject *parent) :
+ QCustom3DItem(new QCustom3DLabelPrivate(this, text, font, position, scaling, rotation),
+ parent)
+{
+}
+
+/*!
+ * Destroys QCustom3DLabel.
+ */
+QCustom3DLabel::~QCustom3DLabel()
+{
+}
+
+/*! \property QCustom3DLabel::text
+ *
+ * The text for the label. Rich text is not supported.
+ */
+void QCustom3DLabel::setText(const QString &text)
+{
+ if (dptr()->m_text != text) {
+ dptr()->m_text = text;
+ dptr()->handleTextureChange();
+ emit textChanged(text);
+ emit dptr()->needUpdate();
+ }
+}
+
+QString QCustom3DLabel::text() const
+{
+ return dptrc()->m_text;
+}
+
+/*! \property QCustom3DLabel::font
+ *
+ * The font to be used for the label. Defaults to \c{QFont("Arial", 20)}. Special formatting
+ * (for example outlined) is not supported.
+ */
+void QCustom3DLabel::setFont(const QFont &font)
+{
+ if (dptr()->m_font != font) {
+ dptr()->m_font = font;
+ dptr()->handleTextureChange();
+ emit fontChanged(font);
+ emit dptr()->needUpdate();
+ }
+}
+
+QFont QCustom3DLabel::font() const
+{
+ return dptrc()->m_font;
+}
+
+/*! \property QCustom3DLabel::textColor
+ *
+ * Color for the label text. Also affects label border, if enabled. Defaults to \c{Qt::white}.
+ *
+ * \sa borderEnabled
+ */
+void QCustom3DLabel::setTextColor(const QColor &color)
+{
+ if (dptr()->m_txtColor != color) {
+ dptr()->m_txtColor = color;
+ dptr()->m_customVisuals = true;
+ dptr()->handleTextureChange();
+ emit textColorChanged(color);
+ emit dptr()->needUpdate();
+ }
+}
+
+QColor QCustom3DLabel::textColor() const
+{
+ return dptrc()->m_txtColor;
+}
+
+/*! \property QCustom3DLabel::backgroundColor
+ *
+ * Color for the label background, if enabled. Defaults to \c{Qt::gray}.
+ *
+ * \sa backgroundEnabled
+ */
+void QCustom3DLabel::setBackgroundColor(const QColor &color)
+{
+ if (dptr()->m_bgrColor != color) {
+ dptr()->m_bgrColor = color;
+ dptr()->m_customVisuals = true;
+ dptr()->handleTextureChange();
+ emit backgroundColorChanged(color);
+ emit dptr()->needUpdate();
+ }
+}
+
+QColor QCustom3DLabel::backgroundColor() const
+{
+ return dptrc()->m_bgrColor;
+}
+
+/*! \property QCustom3DLabel::borderEnabled
+ *
+ * Enable label borders. Defaults to \c{true}.
+ */
+void QCustom3DLabel::setBorderEnabled(bool enabled)
+{
+ if (dptr()->m_borders != enabled) {
+ dptr()->m_borders = enabled;
+ dptr()->m_customVisuals = true;
+ dptr()->handleTextureChange();
+ emit borderEnabledChanged(enabled);
+ emit dptr()->needUpdate();
+ }
+}
+
+bool QCustom3DLabel::isBorderEnabled() const
+{
+ return dptrc()->m_borders;
+}
+
+/*! \property QCustom3DLabel::backgroundEnabled
+ *
+ * Enable label background. If set to \c{false}, backgroundColor() has no effect. Defaults
+ * to \c{true}.
+ */
+void QCustom3DLabel::setBackgroundEnabled(bool enabled)
+{
+ if (dptr()->m_background != enabled) {
+ dptr()->m_background = enabled;
+ dptr()->m_customVisuals = true;
+ dptr()->handleTextureChange();
+ emit backgroundEnabledChanged(enabled);
+ emit dptr()->needUpdate();
+ }
+}
+
+bool QCustom3DLabel::isBackgroundEnabled() const
+{
+ return dptrc()->m_background;
+}
+
+/*! \property QCustom3DLabel::facingCamera
+ *
+ * Forces the label to face camera always. Defaults to \c{false}. If set to \c{true}, rotation()
+ * has no effect.
+ */
+void QCustom3DLabel::setFacingCamera(bool enabled)
+{
+ if (dptr()->m_facingCamera != enabled) {
+ dptr()->m_facingCamera = enabled;
+ dptr()->m_facingCameraDirty = true;
+ emit facingCameraChanged(enabled);
+ emit dptr()->needUpdate();
+ }
+}
+
+bool QCustom3DLabel::isFacingCamera() const
+{
+ return dptrc()->m_facingCamera;
+}
+
+/*!
+ * \internal
+ */
+QCustom3DLabelPrivate *QCustom3DLabel::dptr()
+{
+ return static_cast<QCustom3DLabelPrivate *>(d_ptr.data());
+}
+
+/*!
+ * \internal
+ */
+const QCustom3DLabelPrivate *QCustom3DLabel::dptrc() const
+{
+ return static_cast<const QCustom3DLabelPrivate *>(d_ptr.data());
+}
+
+QCustom3DLabelPrivate::QCustom3DLabelPrivate(QCustom3DLabel *q) :
+ QCustom3DItemPrivate(q),
+ m_font(QFont(QStringLiteral("Arial"), 20)),
+ m_bgrColor(Qt::gray),
+ m_txtColor(Qt::white),
+ m_background(true),
+ m_borders(true),
+ m_facingCamera(false),
+ m_customVisuals(false),
+ m_facingCameraDirty(false)
+{
+ m_isLabelItem = true;
+ m_shadowCasting = false;
+ m_meshFile = QStringLiteral(":/defaultMeshes/plane");
+ createTextureImage();
+}
+
+QCustom3DLabelPrivate::QCustom3DLabelPrivate(QCustom3DLabel *q, const QString &text,
+ const QFont &font, const QVector3D &position,
+ const QVector3D &scaling,
+ const QQuaternion &rotation) :
+ QCustom3DItemPrivate(q, QStringLiteral(":/defaultMeshes/plane"), position, scaling, rotation),
+ m_text(text),
+ m_font(font),
+ m_bgrColor(Qt::gray),
+ m_txtColor(Qt::white),
+ m_background(true),
+ m_borders(true),
+ m_facingCamera(false),
+ m_customVisuals(false),
+ m_facingCameraDirty(false)
+{
+ m_isLabelItem = true;
+ m_shadowCasting = false;
+ createTextureImage();
+}
+
+QCustom3DLabelPrivate::~QCustom3DLabelPrivate()
+{
+}
+
+void QCustom3DLabelPrivate::resetDirtyBits()
+{
+ QCustom3DItemPrivate::resetDirtyBits();
+ m_facingCameraDirty = false;
+}
+
+void QCustom3DLabelPrivate::createTextureImage()
+{
+ createTextureImage(m_bgrColor, m_txtColor, m_background, m_borders);
+}
+
+void QCustom3DLabelPrivate::createTextureImage(const QColor &bgrColor, const QColor &txtColor,
+ bool background, bool borders)
+{
+ m_textureImage = Utils::printTextToImage(m_font, m_text, bgrColor, txtColor, background,
+ borders, 0);
+}
+
+void QCustom3DLabelPrivate::handleTextureChange()
+{
+ createTextureImage();
+ m_dirtyBits.textureDirty = true;
+ if (!m_textureFile.isEmpty()) {
+ m_textureFile.clear();
+ emit q_ptr->textureFileChanged(m_textureFile);
+ }
+}
+
+QT_END_NAMESPACE_DATAVISUALIZATION
diff --git a/src/datavisualization/data/qcustom3dlabel.h b/src/datavisualization/data/qcustom3dlabel.h
new file mode 100644
index 00000000..f42ee378
--- /dev/null
+++ b/src/datavisualization/data/qcustom3dlabel.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+#ifndef QCUSTOMLABELITEM_H
+#define QCUSTOMLABELITEM_H
+
+#include <QtDataVisualization/qdatavisualizationglobal.h>
+#include <QtDataVisualization/QCustom3DItem>
+#include <QtGui/QVector3D>
+#include <QtGui/QQuaternion>
+#include <QtGui/QFont>
+#include <QtGui/QColor>
+
+QT_BEGIN_NAMESPACE_DATAVISUALIZATION
+
+class QCustom3DLabelPrivate;
+
+class QT_DATAVISUALIZATION_EXPORT QCustom3DLabel : public QCustom3DItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
+ Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
+ Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY textColorChanged)
+ Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
+ Q_PROPERTY(bool borderEnabled READ isBorderEnabled WRITE setBorderEnabled NOTIFY borderEnabledChanged)
+ Q_PROPERTY(bool backgroundEnabled READ isBackgroundEnabled WRITE setBackgroundEnabled NOTIFY backgroundEnabledChanged)
+ Q_PROPERTY(bool facingCamera READ isFacingCamera WRITE setFacingCamera NOTIFY facingCameraChanged)
+
+public:
+ explicit QCustom3DLabel(QObject *parent = 0);
+ explicit QCustom3DLabel(const QString &text, const QFont &font, const QVector3D &position,
+ const QVector3D &scaling, const QQuaternion &rotation,
+ QObject *parent = 0);
+ virtual ~QCustom3DLabel();
+
+ void setText(const QString &text);
+ QString text() const;
+
+ void setFont(const QFont &font);
+ QFont font() const;
+
+ void setTextColor(const QColor &color);
+ QColor textColor() const;
+
+ void setBackgroundColor(const QColor &color);
+ QColor backgroundColor() const;
+
+ void setBorderEnabled(bool enabled);
+ bool isBorderEnabled() const;
+
+ void setBackgroundEnabled(bool enabled);
+ bool isBackgroundEnabled() const;
+
+ void setFacingCamera(bool enabled);
+ bool isFacingCamera() const;
+
+signals:
+ void textChanged(const QString &text);
+ void fontChanged(const QFont &font);
+ void textColorChanged(const QColor &color);
+ void backgroundColorChanged(const QColor &color);
+ void borderEnabledChanged(bool enabled);
+ void backgroundEnabledChanged(bool enabled);
+ void facingCameraChanged(bool enabled);
+
+protected:
+ QCustom3DLabelPrivate *dptr();
+ const QCustom3DLabelPrivate *dptrc() const;
+
+private:
+ Q_DISABLE_COPY(QCustom3DLabel)
+
+ friend class Abstract3DRenderer;
+};
+
+QT_END_NAMESPACE_DATAVISUALIZATION
+
+#endif
diff --git a/src/datavisualization/data/qcustom3dlabel_p.h b/src/datavisualization/data/qcustom3dlabel_p.h
new file mode 100644
index 00000000..0bb0e017
--- /dev/null
+++ b/src/datavisualization/data/qcustom3dlabel_p.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the QtDataVisualization API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef QCUSTOMLABELITEM_P_H
+#define QCUSTOMLABELITEM_P_H
+
+#include "qcustom3dlabel.h"
+#include "qcustom3ditem_p.h"
+
+QT_BEGIN_NAMESPACE_DATAVISUALIZATION
+
+class QCustom3DLabelPrivate : public QCustom3DItemPrivate
+{
+ Q_OBJECT
+
+public:
+ QCustom3DLabelPrivate(QCustom3DLabel *q);
+ QCustom3DLabelPrivate(QCustom3DLabel *q, const QString &text, const QFont &font,
+ const QVector3D &position, const QVector3D &scaling,
+ const QQuaternion &rotation);
+ virtual ~QCustom3DLabelPrivate();
+
+ void resetDirtyBits();
+ void createTextureImage();
+ void createTextureImage(const QColor &bgrColor, const QColor &txtColor, bool background,
+ bool borders);
+ void handleTextureChange();
+
+public:
+ QString m_text;
+ QFont m_font;
+ QColor m_bgrColor;
+ QColor m_txtColor;
+ bool m_background;
+ bool m_borders;
+ bool m_facingCamera;
+
+ bool m_customVisuals;
+
+ bool m_facingCameraDirty;
+
+private:
+ friend class QCustom3DLabel;
+};
+
+QT_END_NAMESPACE_DATAVISUALIZATION
+
+#endif
diff --git a/src/datavisualization/engine/abstract3drenderer.cpp b/src/datavisualization/engine/abstract3drenderer.cpp
index cd03073d..0f9109db 100644
--- a/src/datavisualization/engine/abstract3drenderer.cpp
+++ b/src/datavisualization/engine/abstract3drenderer.cpp
@@ -29,6 +29,7 @@
#include "qvalue3daxisformatter_p.h"
#include "shaderhelper_p.h"
#include "qcustom3ditem_p.h"
+#include "qcustom3dlabel_p.h"
QT_BEGIN_NAMESPACE_DATAVISUALIZATION
@@ -315,7 +316,7 @@ void Abstract3DRenderer::calculateZoomLevel()
GLfloat zoomAdjustment;
div = qMin(m_primarySubViewport.width(), m_primarySubViewport.height());
zoomAdjustment = 2.0f * defaultRatio * ((m_primarySubViewport.width() / div)
- / (m_primarySubViewport.height() / div)) / m_graphAspectRatio;
+ / (m_primarySubViewport.height() / div)) / m_graphAspectRatio;
m_autoScaleAdjustment = qMin(zoomAdjustment, 1.0f); // clamp to 1.0f
}
@@ -844,11 +845,33 @@ CustomRenderItem *Abstract3DRenderer::addCustomItem(QCustom3DItem *item)
newItem->setRenderer(this);
newItem->setItemPointer(item); // Store pointer for render item updates
newItem->setMesh(item->meshFile());
- newItem->setScaling(item->scaling());
+ QVector3D scaling = item->scaling();
+ QImage textureImage = item->d_ptr->textureImage();
+ bool facingCamera = false;
+ if (item->d_ptr->m_isLabelItem) {
+ QCustom3DLabel *labelItem = static_cast<QCustom3DLabel *>(item);
+ float pointSize = labelItem->font().pointSizeF();
+ // Check do we have custom visuals or need to use theme
+ if (!labelItem->dptr()->m_customVisuals) {
+ // Recreate texture using theme
+ labelItem->dptr()->createTextureImage(m_cachedTheme->labelBackgroundColor(),
+ m_cachedTheme->labelTextColor(),
+ m_cachedTheme->isLabelBackgroundEnabled(),
+ m_cachedTheme->isLabelBorderEnabled());
+ pointSize = m_cachedTheme->font().pointSizeF();
+ textureImage = item->d_ptr->textureImage();
+ }
+ // Calculate scaling based on text (texture size), font size and asked scaling
+ float scaledFontSize = (0.05f + pointSize / 500.0f) / float(textureImage.height());
+ scaling.setX(scaling.x() * textureImage.width() * scaledFontSize);
+ scaling.setY(scaling.y() * textureImage.height() * scaledFontSize);
+ // Check if facing camera
+ facingCamera = labelItem->isFacingCamera();
+ }
+ newItem->setScaling(scaling);
+ newItem->setRotation(item->rotation());
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);
@@ -858,6 +881,7 @@ CustomRenderItem *Abstract3DRenderer::addCustomItem(QCustom3DItem *item)
newItem->setTranslation(translation);
newItem->setVisible(item->isVisible());
newItem->setShadowCasting(item->isShadowCasting());
+ newItem->setFacingCamera(facingCamera);
m_customRenderCache.insert(item, newItem);
return newItem;
}
@@ -870,7 +894,31 @@ void Abstract3DRenderer::updateCustomItem(CustomRenderItem *renderItem)
item->d_ptr->m_dirtyBits.meshDirty = false;
}
if (item->d_ptr->m_dirtyBits.scalingDirty) {
- renderItem->setScaling(item->scaling());
+ QVector3D scaling = item->scaling();
+ // In case we have label item, we need to recreate texture for scaling adjustment
+ if (item->d_ptr->m_isLabelItem) {
+ QCustom3DLabel *labelItem = static_cast<QCustom3DLabel *>(item);
+ float pointSize = labelItem->font().pointSizeF();
+ // Check do we have custom visuals or need to use theme
+ if (labelItem->dptr()->m_customVisuals) {
+ // Recreate texture
+ labelItem->dptr()->createTextureImage();
+ } else {
+ // Recreate texture using theme
+ labelItem->dptr()->createTextureImage(m_cachedTheme->labelBackgroundColor(),
+ m_cachedTheme->labelTextColor(),
+ m_cachedTheme->isLabelBackgroundEnabled(),
+ m_cachedTheme->isLabelBorderEnabled());
+ pointSize = m_cachedTheme->font().pointSizeF();
+ }
+ QImage textureImage = item->d_ptr->textureImage();
+ // Calculate scaling based on text (texture size), font size and asked scaling
+ float scaledFontSize = (0.05f + pointSize / 500.0f) / float(textureImage.height());
+ scaling.setX(scaling.x() * textureImage.width() * scaledFontSize);
+ scaling.setY(scaling.y() * textureImage.height() * scaledFontSize);
+ item->d_ptr->clearTextureImage();
+ }
+ renderItem->setScaling(scaling);
item->d_ptr->m_dirtyBits.scalingDirty = false;
}
if (item->d_ptr->m_dirtyBits.rotationDirty) {
@@ -879,6 +927,18 @@ void Abstract3DRenderer::updateCustomItem(CustomRenderItem *renderItem)
}
if (item->d_ptr->m_dirtyBits.textureDirty) {
QImage textureImage = item->d_ptr->textureImage();
+ if (item->d_ptr->m_isLabelItem) {
+ QCustom3DLabel *labelItem = static_cast<QCustom3DLabel *>(item);
+ // Check do we have custom visuals or need to use theme
+ if (!labelItem->dptr()->m_customVisuals) {
+ // Recreate texture using theme
+ labelItem->dptr()->createTextureImage(m_cachedTheme->labelBackgroundColor(),
+ m_cachedTheme->labelTextColor(),
+ m_cachedTheme->isLabelBackgroundEnabled(),
+ m_cachedTheme->isLabelBorderEnabled());
+ textureImage = item->d_ptr->textureImage();
+ }
+ }
renderItem->setBlendNeeded(textureImage.hasAlphaChannel());
GLuint oldTexture = renderItem->texture();
m_textureHelper->deleteTexture(&oldTexture);
@@ -904,15 +964,21 @@ void Abstract3DRenderer::updateCustomItem(CustomRenderItem *renderItem)
renderItem->setShadowCasting(item->isShadowCasting());
item->d_ptr->m_dirtyBits.shadowCastingDirty = false;
}
+ if (item->d_ptr->m_isLabelItem) {
+ QCustom3DLabel *labelItem = static_cast<QCustom3DLabel *>(item);
+ if (labelItem->dptr()->m_facingCameraDirty) {
+ renderItem->setFacingCamera(labelItem->isFacingCamera());
+ labelItem->dptr()->m_facingCameraDirty = false;
+ }
+ }
}
void Abstract3DRenderer::updateCustomItemPositions()
{
foreach (CustomRenderItem *renderItem, m_customRenderCache) {
- if (!renderItem->isPositionAbsolute()) {
- QVector3D translation = convertPositionToTranslation(renderItem->position(), false);
- renderItem->setTranslation(translation);
- }
+ QVector3D translation = convertPositionToTranslation(renderItem->position(),
+ renderItem->isPositionAbsolute());
+ renderItem->setTranslation(translation);
}
}
@@ -959,11 +1025,21 @@ void Abstract3DRenderer::drawCustomItems(RenderingState state,
QMatrix4x4 itModelMatrix;
QMatrix4x4 MVPMatrix;
+ QQuaternion rotation = item->rotation();
+ // Check if the (label) item should be facing camera, and adjust rotation accordingly
+ if (item->isFacingCamera()) {
+ float camRotationX = m_cachedScene->activeCamera()->xRotation();
+ float camRotationY = m_cachedScene->activeCamera()->yRotation();
+ rotation = QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, -camRotationX)
+ * QQuaternion::fromAxisAndAngle(1.0f, 0.0f, 0.0f, -camRotationY);
+ }
+
modelMatrix.translate(item->translation());
- modelMatrix.rotate(item->rotation());
+ modelMatrix.rotate(rotation);
modelMatrix.scale(item->scaling());
- itModelMatrix.rotate(item->rotation());
- itModelMatrix.scale(item->scaling());
+ itModelMatrix.rotate(rotation);
+ if (!item->isFacingCamera())
+ itModelMatrix.scale(item->scaling());
MVPMatrix = projectionViewMatrix * modelMatrix;
if (RenderingNormal == state) {
diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp
index 87fecbf2..73a2eb3a 100644
--- a/src/datavisualization/engine/bars3drenderer.cpp
+++ b/src/datavisualization/engine/bars3drenderer.cpp
@@ -2640,7 +2640,7 @@ QVector3D Bars3DRenderer::convertPositionToTranslation(const QVector3D &position
yTrans = m_axisCacheY.positionAt(position.y());
} else {
xTrans = position.x() * m_scaleX;
- yTrans = position.y();
+ yTrans = position.y() + m_backgroundAdjustment;
zTrans = position.z() * m_scaleZ;
}
return QVector3D(xTrans, yTrans, zTrans);
diff --git a/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp b/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp
index fd45bdca..6893a286 100644
--- a/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp
+++ b/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp
@@ -88,11 +88,11 @@ void QtDataVisualizationQml2Plugin::registerTypes(const char *uri)
// New revisions
qmlRegisterUncreatableType<QAbstract3DAxis, 1>(uri, 1, 1, "AbstractAxis3D",
- QLatin1String("Trying to create uncreatable: AbstractAxis."));
+ QLatin1String("Trying to create uncreatable: AbstractAxis."));
qmlRegisterUncreatableType<QAbstract3DSeries, 1>(uri, 1, 1, "Abstract3DSeries",
QLatin1String("Trying to create uncreatable: Abstract3DSeries."));
qmlRegisterUncreatableType<AbstractDeclarative, 1>(uri, 1, 1, "AbstractGraph3D",
- QLatin1String("Trying to create uncreatable: AbstractGraph3D."));
+ QLatin1String("Trying to create uncreatable: AbstractGraph3D."));
qmlRegisterType<QValue3DAxis, 1>(uri, 1, 1, "ValueAxis3D");
qmlRegisterType<QItemModelBarDataProxy, 1>(uri, 1, 1, "ItemModelBarDataProxy");
qmlRegisterType<QItemModelSurfaceDataProxy, 1>(uri, 1, 1, "ItemModelSurfaceDataProxy");
@@ -102,6 +102,7 @@ void QtDataVisualizationQml2Plugin::registerTypes(const char *uri)
qmlRegisterType<QValue3DAxisFormatter>(uri, 1, 1, "ValueAxis3DFormatter");
qmlRegisterType<QLogValue3DAxisFormatter>(uri, 1, 1, "LogValueAxis3DFormatter");
qmlRegisterType<QCustom3DItem>(uri, 1, 1, "Custom3DItem");
+ qmlRegisterType<QCustom3DLabel>(uri, 1, 1, "Custom3DLabel");
// New metatypes
qRegisterMetaType<QAbstract3DGraph::ElementType>("QAbstract3DGraph::ElementType");
diff --git a/src/datavisualizationqml2/datavisualizationqml2_plugin.h b/src/datavisualizationqml2/datavisualizationqml2_plugin.h
index fcc0bcde..1e566ac1 100644
--- a/src/datavisualizationqml2/datavisualizationqml2_plugin.h
+++ b/src/datavisualizationqml2/datavisualizationqml2_plugin.h
@@ -46,6 +46,7 @@
#include "declarativecolor_p.h"
#include "declarativescene_p.h"
#include "qcustom3ditem.h"
+#include "qcustom3dlabel.h"
#include <QtQml/QQmlExtensionPlugin>
@@ -98,6 +99,7 @@ QML_DECLARE_TYPE(DeclarativeTheme3D)
QML_DECLARE_TYPE(QAbstract3DInputHandler)
QML_DECLARE_TYPE(QCustom3DItem)
+QML_DECLARE_TYPE(QCustom3DLabel)
QT_BEGIN_NAMESPACE_DATAVISUALIZATION
diff --git a/tests/qmlcamera/qml/qmlcamera/main.qml b/tests/qmlcamera/qml/qmlcamera/main.qml
index c357accf..444e175c 100644
--- a/tests/qmlcamera/qml/qmlcamera/main.qml
+++ b/tests/qmlcamera/qml/qmlcamera/main.qml
@@ -67,7 +67,7 @@ Rectangle {
scene.activeCamera.zoomLevel: zoomSlider.value
inputHandler: null
- customItemList: [shuttleItem]
+ customItemList: [shuttleItem, labelItem]
}
Custom3DItem {
@@ -78,6 +78,15 @@ Rectangle {
scaling: Qt.vector3d(0.2,0.2,0.2)
}
+ Custom3DLabel {
+ id: labelItem
+ facingCamera: true
+ positionAbsolute: true
+ position: Qt.vector3d(0.0,1.5,0.0)
+ scaling: Qt.vector3d(1.0,1.0,1.0)
+ text: "Qt Shuttle"
+ }
+
MouseArea {
id: inputArea
anchors.fill: parent