summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/engine
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2014-05-12 10:06:27 +0300
committerTomi Korpipää <tomi.korpipaa@digia.com>2014-05-12 10:07:15 +0300
commit6880277f23b47117f7788f08f855ed99b5120f9f (patch)
treede8b9e64ffce03a3ce77c8ffac396f7174e91956 /src/datavisualization/engine
parent590d11726e0708e9f8fad0ec386cc5859dbe5cc8 (diff)
CustomDataItem made into a public class
Task-number: QTRD-3055 Change-Id: I1e449df7c1bcb48fc639dbae579e2e1499c9ef2b Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/engine')
-rw-r--r--src/datavisualization/engine/abstract3dcontroller.cpp60
-rw-r--r--src/datavisualization/engine/abstract3dcontroller_p.h11
-rw-r--r--src/datavisualization/engine/abstract3drenderer.cpp25
-rw-r--r--src/datavisualization/engine/abstract3drenderer_p.h4
-rw-r--r--src/datavisualization/engine/qabstract3dgraph.cpp42
-rw-r--r--src/datavisualization/engine/qabstract3dgraph.h8
6 files changed, 84 insertions, 66 deletions
diff --git a/src/datavisualization/engine/abstract3dcontroller.cpp b/src/datavisualization/engine/abstract3dcontroller.cpp
index 2b566a91..790a0889 100644
--- a/src/datavisualization/engine/abstract3dcontroller.cpp
+++ b/src/datavisualization/engine/abstract3dcontroller.cpp
@@ -88,7 +88,7 @@ Abstract3DController::~Abstract3DController()
destroyRenderer();
delete m_scene;
delete m_themeManager;
- foreach (CustomDataItem *item, m_customItems)
+ foreach (QCustom3DItem *item, m_customItems)
delete item;
m_customItems.clear();
}
@@ -851,46 +851,52 @@ void Abstract3DController::requestRender(QOpenGLFramebufferObject *fbo)
m_renderer->render(fbo->handle());
}
-int Abstract3DController::addCustomItem(const QString &meshFile, const QVector3D &position,
- const QVector3D &scaling, const QQuaternion &rotation,
- const QImage &textureImage)
+int Abstract3DController::addCustomItem(QCustom3DItem *item)
{
- CustomDataItem *newItem = new CustomDataItem();
- newItem->setMeshFile(meshFile);
- newItem->setPosition(position);
- newItem->setScaling(scaling);
- newItem->setRotation(rotation);
- newItem->setTextureImage(textureImage);
- m_customItems.append(newItem);
+ if (!item)
+ return -1;
+
+ int index = m_customItems.indexOf(item);
+
+ if (index != -1)
+ return index;
+
+ item->setParent(this);
+ m_customItems.append(item);
m_isCustomDataDirty = true;
emitNeedRender();
return m_customItems.count() - 1;
}
-void Abstract3DController::deleteCustomItem(int index)
+void Abstract3DController::deleteCustomItems()
{
- if (m_customItems.size() > index) {
- delete m_customItems[index];
- m_customItems.removeAt(index);
- m_isCustomDataDirty = true;
- emitNeedRender();
- }
+ foreach (QCustom3DItem *item, m_customItems)
+ delete item;
+ m_customItems.clear();
+ m_isCustomDataDirty = true;
+ emitNeedRender();
+}
+
+void Abstract3DController::deleteCustomItem(QCustom3DItem *item)
+{
+ if (!item)
+ return;
+
+ m_customItems.removeOne(item);
+ delete item;
+ item = 0;
+ m_isCustomDataDirty = true;
+ emitNeedRender();
}
void Abstract3DController::deleteCustomItem(const QVector3D &position)
{
- int index = -1;
- int counter = 0;
- // Get the index for the item at position
- foreach (CustomDataItem *item, m_customItems) {
+ // Get the item for the position
+ foreach (QCustom3DItem *item, m_customItems) {
if (item->position() == position) {
- index = counter;
- break;
+ deleteCustomItem(item);
}
- counter++;
}
- if (index >= 0)
- deleteCustomItem(index);
}
void Abstract3DController::handleAxisTitleChanged(const QString &title)
diff --git a/src/datavisualization/engine/abstract3dcontroller_p.h b/src/datavisualization/engine/abstract3dcontroller_p.h
index 78c6c81c..53560760 100644
--- a/src/datavisualization/engine/abstract3dcontroller_p.h
+++ b/src/datavisualization/engine/abstract3dcontroller_p.h
@@ -35,7 +35,7 @@
#include "qabstract3dinputhandler.h"
#include "qabstractdataproxy.h"
#include "q3dscene_p.h"
-#include "customdataitem_p.h"
+#include "qcustom3ditem.h"
#include <QtGui/QLinearGradient>
#include <QtCore/QTime>
@@ -175,7 +175,7 @@ protected:
QVector<QAbstract3DSeries *> m_changedSeriesList;
- QList<CustomDataItem *> m_customItems;
+ QList<QCustom3DItem *> m_customItems;
explicit Abstract3DController(QRect initialViewport, Q3DScene *scene, QObject *parent = 0);
@@ -236,9 +236,9 @@ public:
void requestRender(QOpenGLFramebufferObject *fbo);
- int addCustomItem(const QString &meshFile, const QVector3D &position, const QVector3D &scaling,
- const QQuaternion &rotation, const QImage &textureImage);
- void deleteCustomItem(int index);
+ int addCustomItem(QCustom3DItem *item);
+ void deleteCustomItems();
+ void deleteCustomItem(QCustom3DItem *item);
void deleteCustomItem(const QVector3D &position);
void emitNeedRender();
@@ -321,6 +321,7 @@ private:
void setAxisHelper(QAbstract3DAxis::AxisOrientation orientation, QAbstract3DAxis *axis,
QAbstract3DAxis **axisPtr);
+ friend class AbstractDeclarative;
friend class Bars3DController;
friend class QAbstract3DGraphPrivate;
};
diff --git a/src/datavisualization/engine/abstract3drenderer.cpp b/src/datavisualization/engine/abstract3drenderer.cpp
index 95cecbd3..bff24bc7 100644
--- a/src/datavisualization/engine/abstract3drenderer.cpp
+++ b/src/datavisualization/engine/abstract3drenderer.cpp
@@ -28,6 +28,7 @@
#include "objecthelper_p.h"
#include "qvalue3daxisformatter_p.h"
#include "shaderhelper_p.h"
+#include "qcustom3ditem_p.h"
QT_BEGIN_NAMESPACE_DATAVISUALIZATION
@@ -74,6 +75,13 @@ Abstract3DRenderer::~Abstract3DRenderer()
}
m_renderCacheList.clear();
+ foreach (CustomRenderItem *item, m_customRenderCache) {
+ GLuint texture = item->texture();
+ m_textureHelper->deleteTexture(&texture);
+ delete item;
+ }
+ m_customRenderCache.clear();
+
delete m_textureHelper;
}
@@ -402,16 +410,19 @@ void Abstract3DRenderer::updateSeries(const QList<QAbstract3DSeries *> &seriesLi
}
}
-void Abstract3DRenderer::updateCustomData(const QList<CustomDataItem *> &customItems)
+void Abstract3DRenderer::updateCustomData(const QList<QCustom3DItem *> &customItems)
{
if (customItems.isEmpty() && m_customRenderCache.isEmpty())
return;
// There are probably not too many custom items, just recreate the array if something changes
- foreach (CustomRenderItem *item, m_customRenderCache)
+ foreach (CustomRenderItem *item, m_customRenderCache) {
+ GLuint texture = item->texture();
+ m_textureHelper->deleteTexture(&texture);
delete item;
+ }
m_customRenderCache.clear();
- foreach (CustomDataItem *item, customItems)
+ foreach (QCustom3DItem *item, customItems)
addCustomItem(item);
}
@@ -526,12 +537,16 @@ QVector4D Abstract3DRenderer::indexToSelectionColor(GLint index)
return QVector4D(idxRed, idxGreen, idxBlue, 0);
}
-void Abstract3DRenderer::addCustomItem(CustomDataItem *item) {
+void Abstract3DRenderer::addCustomItem(QCustom3DItem *item) {
CustomRenderItem *newItem = new CustomRenderItem();
newItem->setMesh(item->meshFile());
newItem->setScaling(item->scaling());
newItem->setRotation(item->rotation());
- newItem->setTexture(item->texture());
+ GLuint texture = m_textureHelper->create2DTexture(item->d_ptr->textureImage(),
+ true, true, true);
+ newItem->setTexture(texture);
+ // TODO: Uncomment this once custom item render cache handling has been optimized
+ //item->d_ptr->clearTextureImage();
QVector3D translation = convertPositionToTranslation(item->position());
newItem->setTranslation(translation);
m_customRenderCache.append(newItem);
diff --git a/src/datavisualization/engine/abstract3drenderer_p.h b/src/datavisualization/engine/abstract3drenderer_p.h
index 65dcd8f6..ea61ae51 100644
--- a/src/datavisualization/engine/abstract3drenderer_p.h
+++ b/src/datavisualization/engine/abstract3drenderer_p.h
@@ -67,7 +67,7 @@ public:
virtual void updateData() = 0;
virtual void updateSeries(const QList<QAbstract3DSeries *> &seriesList);
- virtual void updateCustomData(const QList<CustomDataItem *> &customItems);
+ virtual void updateCustomData(const QList<QCustom3DItem *> &customItems);
virtual SeriesRenderCache *createNewCache(QAbstract3DSeries *series);
virtual void cleanCache(SeriesRenderCache *cache);
virtual void render(GLuint defaultFboHandle);
@@ -111,7 +111,7 @@ public:
virtual void fixMeshFileName(QString &fileName, QAbstract3DSeries::Mesh mesh);
- virtual void addCustomItem(CustomDataItem *item);
+ virtual void addCustomItem(QCustom3DItem *item);
virtual QVector3D convertPositionToTranslation(const QVector3D &position) = 0;
diff --git a/src/datavisualization/engine/qabstract3dgraph.cpp b/src/datavisualization/engine/qabstract3dgraph.cpp
index e143e756..85ee79c9 100644
--- a/src/datavisualization/engine/qabstract3dgraph.cpp
+++ b/src/datavisualization/engine/qabstract3dgraph.cpp
@@ -382,46 +382,42 @@ void QAbstract3DGraph::clearSelection()
}
/*!
- * Adds a custom mesh item located in \a meshFile to a graph at \a position with \a {scaling},
- * \a rotation and optional \a textureImage. Item must be in Wavefront obj format and include
- * vertices, normals and UVs. It also needs to be in triangles. Item position is given in data
- * coordinates.
+ * Adds a QCustom3DItem \a item to the graph. Graph takes ownership of the added item.
*
- * \return index to the added item.
+ * \return index to the added item if add was successful, -1 if trying to add a null item, and
+ * index of the item if trying to add an already added item.
*
- * \note No validity checks are made for the position of the item, so it is up to the user to
- * provide a valid position. Items positioned outside axis ranges are still rendered.
- *
- * \sa removeCustomItemAt()
+ * \sa removeCustomItems(), removeCustomItem(), removeCustomItemAt()
*
* \since Qt Data Visualization 1.1
*/
-int QAbstract3DGraph::addCustomItem(const QString &meshFile, const QVector3D &position,
- const QVector3D &scaling, const QQuaternion &rotation,
- const QImage &textureImage)
+int QAbstract3DGraph::addCustomItem(QCustom3DItem *item)
{
- return d_ptr->m_visualController->addCustomItem(meshFile, position, scaling, rotation,
- textureImage);
+ return d_ptr->m_visualController->addCustomItem(item);
}
/*!
- * Removes the custom item at \a {index}. Deletes the resources allocated to it.
- *
- * \note The index of the remaining items will change if the item removed is other than
- * the last.
+ * Removes all custom items. Deletes the resources allocated to them.
*
* \since Qt Data Visualization 1.1
*/
-void QAbstract3DGraph::removeCustomItemAt(int index)
+void QAbstract3DGraph::removeCustomItems()
{
- d_ptr->m_visualController->deleteCustomItem(index);
+ d_ptr->m_visualController->deleteCustomItems();
}
/*!
- * Removes the custom item at \a {position}. Deletes the resources allocated to it.
+ * Removes the custom \a {item}. Deletes the resources allocated to it.
*
- * \note The index of the remaining items will change if an item is removed from a position that
- * is not at the last index.
+ * \since Qt Data Visualization 1.1
+ */
+void QAbstract3DGraph::removeCustomItem(QCustom3DItem *item)
+{
+ d_ptr->m_visualController->deleteCustomItem(item);
+}
+
+/*!
+ * Removes all custom items at \a {position}. Deletes the resources allocated to them.
*
* \since Qt Data Visualization 1.1
*/
diff --git a/src/datavisualization/engine/qabstract3dgraph.h b/src/datavisualization/engine/qabstract3dgraph.h
index dc0bf6f0..ae1efacf 100644
--- a/src/datavisualization/engine/qabstract3dgraph.h
+++ b/src/datavisualization/engine/qabstract3dgraph.h
@@ -29,6 +29,7 @@
QT_BEGIN_NAMESPACE_DATAVISUALIZATION
class QAbstract3DGraphPrivate;
+class QCustom3DItem;
class QT_DATAVISUALIZATION_EXPORT QAbstract3DGraph : public QWindow, protected QOpenGLFunctions
{
@@ -107,10 +108,9 @@ public:
void clearSelection();
- int addCustomItem(const QString &meshFile, const QVector3D &position,
- const QVector3D &scaling, const QQuaternion &rotation,
- const QImage &textureImage = QImage());
- void removeCustomItemAt(int index);
+ int addCustomItem(QCustom3DItem *item);
+ void removeCustomItems();
+ void removeCustomItem(QCustom3DItem *item);
void removeCustomItemAt(const QVector3D &position);
QImage renderToImage(int msaaSamples = 0, const QSize &imageSize = QSize());