Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit 5cc0e4b6 authored by schultezub's avatar schultezub
Browse files

introducing QtDataHandle to use DataHandles in QVariants and Qt signals

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@321 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 375e51e0
......@@ -25,6 +25,7 @@ SET(TUMVIS_APPLICATION_TO_BE_MOCCED
gui/datacontainertreewidget.h
gui/pipelinetreewidget.h
gui/qtcolortools.h
gui/qtdatahandle.h
gui/properties/abstractpropertywidget.h
gui/properties/abstracttransferfunctioneditor.h
gui/properties/boolpropertywidget.h
......
......@@ -100,8 +100,9 @@ namespace TUMVis {
{
tbb::mutex::scoped_lock lock(_localMutex);
_dataContainer = dataContainer;
if (_dataContainer != 0)
if (_dataContainer != 0) {
_handles = _dataContainer->getHandlesCopy();
}
}
if (_dataContainer != 0) {
......@@ -123,11 +124,11 @@ namespace TUMVis {
std::map<std::string, DataHandle>::iterator lb = _handles.lower_bound(name);
if (lb == _handles.end() || lb->first != name) {
// not existant -> insert
_handles.insert(std::make_pair(name, dh));
_handles.insert(std::make_pair(name, DataHandle(dh)));
}
else {
// existant -> replace
lb->second = dh;
lb->second = DataHandle(dh);
}
}
......
......@@ -32,6 +32,7 @@
#include "core/datastructures/abstractdata.h"
#include "core/datastructures/datacontainer.h"
#include "application/gui/datacontainertreewidget.h"
#include "application/gui/qtdatahandle.h"
namespace TUMVis {
......@@ -68,8 +69,8 @@ namespace TUMVis {
}
void DataContainerInspectorWidget::onDataContainerDataAdded(const std::string& key, const DataHandle& dh) {
// copy DataHandle because signal will be handled by a different thread an indefinite amount of time later:
emit dataContainerChanged(QString::fromStdString(key), dh);
// copy QtDataHandle because signal will be handled by a different thread an indefinite amount of time later:
emit dataContainerChanged(QString::fromStdString(key), QtDataHandle(dh));
}
QSize DataContainerInspectorWidget::sizeHint() const {
......@@ -81,13 +82,13 @@ namespace TUMVis {
// Yak, this is so ugly - another reason why GUI programming sucks...
QVariant item = index.data(Qt::UserRole);
_selectedDataHandle = DataHandle(*static_cast<DataHandle*>(item.value<void*>()));
_selectedDataHandle = item.value<QtDataHandle>();
QModelIndex idxName = index.sibling(index.row(), 0);
_selectedDataHandleName = idxName.data(Qt::DisplayRole).toString();
}
else {
_selectedDataHandle = DataHandle(0);
_selectedDataHandle = QtDataHandle(0);
_selectedDataHandleName = "";
}
......@@ -124,12 +125,13 @@ namespace TUMVis {
_mainLayout->addWidget(_infoWidget, 1);
qRegisterMetaType<QtDataHandle>("QtDataHandle");
connect(
_dctWidget, SIGNAL(clicked(const QModelIndex&)),
this, SLOT(onDCTWidgetItemClicked(const QModelIndex&)));
connect(
this, SIGNAL(dataContainerChanged(const QString&, const DataHandle&)),
_dctWidget->getTreeModel(), SLOT(onDataContainerChanged(const QString&, const DataHandle&)));
this, SIGNAL(dataContainerChanged(const QString&, QtDataHandle)),
_dctWidget->getTreeModel(), SLOT(onDataContainerChanged(const QString&, QtDataHandle)));
}
void DataContainerInspectorWidget::updateInfoWidget() {
......
......@@ -34,7 +34,7 @@
#include "tgt/qt/qtcontextmanager.h"
#include "tgt/qt/qtthreadedcanvas.h"
#include "core/datastructures/datahandle.h"
#include "application/gui/qtdatahandle.h"
#include "core/tools/opengljobprocessor.h"
#include <QLabel>
......@@ -87,7 +87,7 @@ namespace TUMVis {
QSize sizeHint() const;
signals:
void dataContainerChanged(const QString&, const DataHandle&);
void dataContainerChanged(const QString&, QtDataHandle);
private slots:
/**
......@@ -115,14 +115,14 @@ namespace TUMVis {
QString humanizeBytes(size_t numBytes) const;
DataContainer* _dataContainer; ///< The DataContainer this widget is inspecting
DataHandle _selectedDataHandle; ///< The currently selected DataHandle
QString _selectedDataHandleName; ///< The name of the currently selected DataHandle
QtDataHandle _selectedDataHandle; ///< The currently selected QtDataHandle
QString _selectedDataHandleName; ///< The name of the currently selected QtDataHandle
DataContainerTreeWidget* _dctWidget; ///< The TreeWidget showing the DataHandles in _dataContainer
tgt::QtThreadedCanvas* _canvas; ///< The OpenGL canvas for rendering the DataContainer's contents
QHBoxLayout* _mainLayout; ///< Layout for this widget
QWidget* _infoWidget; ///< Widget showing the information about the selected DataHandle
QWidget* _infoWidget; ///< Widget showing the information about the selected QtDataHandle
QVBoxLayout* _infoWidgetLayout; ///< Layout for the _infoWidget
QLabel* _lblName;
......
......@@ -4,8 +4,8 @@
#include "tgt/assert.h"
#include "application/gui/qtdatahandle.h"
#include "core/datastructures/datacontainer.h"
#include "core/datastructures/datahandle.h"
#include "core/datastructures/abstractdata.h"
#include "core/datastructures/imagedatadisk.h"
#include "core/datastructures/imagedatalocal.h"
......@@ -46,12 +46,12 @@ namespace TUMVis {
// ================================================================================================
DataHandleTreeItem::DataHandleTreeItem(const DataHandle& dataHandle, const std::string& name, TreeItem* parent)
DataHandleTreeItem::DataHandleTreeItem(const QtDataHandle& dataHandle, const std::string& name, TreeItem* parent)
: TreeItem(parent)
, _dataHandle(dataHandle)
, _name(name)
{
tgtAssert(_dataHandle.getData() != 0, "WTF - DataHandle with empty data?");
tgtAssert(_dataHandle.getData() != 0, "WTF - QtDataHandle with empty data?");
}
QVariant DataHandleTreeItem::getData(int column, int role) const {
......@@ -61,7 +61,7 @@ namespace TUMVis {
return QVariant(QString::fromStdString(_name));
else if (column == COLUMN_TYPE) {
const AbstractData* data = _dataHandle.getData();
tgtAssert(data != 0, "WTF - DataHandle with empty data?");
tgtAssert(data != 0, "WTF - QtDataHandle with empty data?");
if (const ImageDataDisk* tester = dynamic_cast<const ImageDataDisk*>(data)) {
return QVariant(QString("ImageData on disk"));
}
......@@ -79,7 +79,7 @@ namespace TUMVis {
return QVariant();
case Qt::UserRole:
// const cast ist ugly, same as GUI programming...
return qVariantFromValue(const_cast<void*>(static_cast<const void*>(&_dataHandle)));
return qVariantFromValue(_dataHandle);
default:
return QVariant();
}
......@@ -88,7 +88,7 @@ namespace TUMVis {
DataHandleTreeItem::~DataHandleTreeItem() {
}
void DataHandleTreeItem::setDataHandle(const DataHandle& dataHandle) {
void DataHandleTreeItem::setDataHandle(const QtDataHandle& dataHandle) {
_dataHandle = dataHandle;
}
......@@ -196,13 +196,13 @@ namespace TUMVis {
std::vector< std::pair< std::string, DataHandle> > handlesCopy = dataContainer->getDataHandlesCopy();
for (std::vector< std::pair< std::string, DataHandle> >::iterator it = handlesCopy.begin(); it != handlesCopy.end(); ++it) {
DataHandleTreeItem* dhti = new DataHandleTreeItem(it->second, it->first, _rootItem);
DataHandleTreeItem* dhti = new DataHandleTreeItem(QtDataHandle(it->second), it->first, _rootItem);
_itemMap.insert(std::make_pair(QString::fromStdString(it->first), dhti));
}
}
void DataContainerTreeModel::onDataContainerChanged(const QString& key, const DataHandle& dh) {
tgtAssert(dh.getData() != 0, "WTF - DataHandle with empty data?");
void DataContainerTreeModel::onDataContainerChanged(const QString& key, QtDataHandle dh) {
tgtAssert(dh.getData() != 0, "WTF - QtDataHandle with empty data?");
std::map<QString, DataHandleTreeItem*>::const_iterator it = _itemMap.lower_bound(key);
if (it == _itemMap.end() || it->first != key) {
......
......@@ -36,7 +36,7 @@
#include <map>
#include "application/tools/treeitem.h"
#include "core/datastructures/datahandle.h"
#include "application/gui/qtdatahandle.h"
namespace TUMVis {
class DataContainer;
......@@ -61,15 +61,15 @@ namespace TUMVis {
class DataHandleTreeItem : public TreeItem {
public:
/**
* Creates a new TreeItem for a DataHandle
* \param dataHandle The DataHandle to wrap around, DataHandleTreeItem takes ownership of this pointer!
* \param name Name of the DataHandle
* Creates a new TreeItem for a QtDataHandle
* \param dataHandle The QtDataHandle to wrap around, DataHandleTreeItem takes ownership of this pointer!
* \param name Name of the QtDataHandle
* \param parent Parent TreeItem
*/
DataHandleTreeItem(const DataHandle& dataHandle, const std::string& name, TreeItem* parent);
DataHandleTreeItem(const QtDataHandle& dataHandle, const std::string& name, TreeItem* parent);
/**
* Destructor, deletes the DataHandle
* Destructor, deletes the QtDataHandle
*/
virtual ~DataHandleTreeItem();
......@@ -77,15 +77,15 @@ namespace TUMVis {
virtual QVariant getData(int column, int role) const;
/**
* Sets the DataHandle for this tree item.
* Sets the QtDataHandle for this tree item.
* \note DataHandleTreeItem takes ownership of this pointer.
* \param dataHandle The DataHandle to wrap around, DataHandleTreeItem takes ownership of this pointer!
* \param dataHandle The QtDataHandle to wrap around, DataHandleTreeItem takes ownership of this pointer!
*/
void setDataHandle(const DataHandle& dataHandle);
void setDataHandle(const QtDataHandle& dataHandle);
private:
DataHandle _dataHandle; ///< Base DataHandle
std::string _name; ///< Name of that DataHandle
QtDataHandle _dataHandle; ///< Base QtDataHandle
std::string _name; ///< Name of that QtDataHandle
};
// = TreeModel ====================================================================================
......@@ -122,15 +122,15 @@ namespace TUMVis {
public slots:
/**
* Slot being called when a DataHandle has been added to the DataContainer.
* \param key Name of the DataHandle
* \param dh The added DataHandle
* Slot being called when a QtDataHandle has been added to the DataContainer.
* \param key Name of the QtDataHandle
* \param dh The added QtDataHandle
*/
void onDataContainerChanged(const QString& key, const DataHandle& dh);
void onDataContainerChanged(const QString& key, QtDataHandle dh);
private:
TreeItem* _rootItem;
std::map<QString, DataHandleTreeItem*> _itemMap; ///< Mapping the DataHandle Keys to the TreeItems
std::map<QString, DataHandleTreeItem*> _itemMap; ///< Mapping the QtDataHandle Keys to the TreeItems
};
// = Widget =======================================================================================
......
......@@ -32,6 +32,7 @@
#include "application/tumvisapplication.h"
#include "application/gui/datacontainerinspectorwidget.h"
#include "application/gui/datacontainerinspectorcanvas.h"
#include "application/gui/qtdatahandle.h"
#include "core/pipeline/abstractpipeline.h"
#include "core/pipeline/abstractprocessor.h"
......@@ -61,6 +62,8 @@ namespace TUMVis {
}
void MainWindow::setup() {
qRegisterMetaType<QtDataHandle>("QtDataHandle");
_dcInspectorCanvas = new DataContainerInspectorCanvas();
_dcInspectorCanvas->show();
......
// ================================================================================================
//
// This file is part of the TUMVis Visualization Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge (christian.szb@in.tum.de)
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#ifndef QTQtDataHandle_H__
#define QTQtDataHandle_H__
#include "core/datastructures/datahandle.h"
#include <QMetaType>
namespace TUMVis {
/**
* Wraps around a DataHandle to make it suitable for QVariant and queued connections.
*/
class QtDataHandle : public DataHandle {
public:
/**
* Creates a new QtDataHandle for the given data.
* \note By passing the data to QtDataHandle you will transfer its ownership to the reference
* counting mechanism. Make sure not to interfere with it or delete \a data yourself!
* \param data Data for the QtDataHandle
*/
QtDataHandle(AbstractData* data = 0)
: DataHandle(data)
{}
/**
* Copy-constructor
* \note If \a rhs is not shareable, this implies a copy of the data!
* \param rhs Source QtDataHandle
*/
QtDataHandle(const QtDataHandle& rhs)
: DataHandle(rhs)
{}
/**
* Copy-constructor
* \note If \a rhs is not shareable, this implies a copy of the data!
* \param rhs Source DataHandle
*/
explicit QtDataHandle(const DataHandle& rhs)
: DataHandle(rhs)
{}
/**
* Assignment operator
* \note If \a rhs is not shareable, this implies a copy of the data!
* \param rhs source QtDataHandle
* \return *this
*/
QtDataHandle& operator=(const QtDataHandle& rhs) {
DataHandle::operator=(rhs);
return *this;
}
/**
* Destructor, decrease the reference count of the managed AbstractData.
*/
virtual ~QtDataHandle() {
}
};
}
Q_DECLARE_METATYPE(TUMVis::QtDataHandle);
#endif // QTQtDataHandle_H__
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment