Commit aa806ada authored by schultezub's avatar schultezub
Browse files

* Introducing DataContainerInspectorWidget (compiles but still crashes...)

 * added DataContainer::getDataHandlesCopy()


git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@263 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent fac4d6b3
......@@ -8,16 +8,20 @@ FILE(GLOB TUMVIS_APPLICATION_SOURCES
*.cpp
gui/*.cpp
gui/properties/*.cpp
tools/*.cpp
)
FILE(GLOB TUMVIS_APPLICATION_HEADERS
*.h
gui/*.h
gui/properties/*.h
tools/*.h
)
SET(TUMVIS_APPLICATION_TO_BE_MOCCED
gui/mainwindow.h
gui/datacontainerinspectorwidget.h
gui/datacontainertreewidget.h
gui/pipelinetreewidget.h
gui/qtcolortools.h
gui/properties/abstractpropertywidget.h
......
// ================================================================================================
//
// 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 Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, 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.
//
// ================================================================================================
#include "datacontainerinspectorwidget.h"
#include "tgt/assert.h"
#include "core/datastructures/datacontainer.h"
#include "core/datastructures/datahandle.h"
#include "application/gui/datacontainertreewidget.h"
namespace TUMVis {
DataContainerInspectorWidget::DataContainerInspectorWidget(QWidget* parent)
: QWidget(parent)
, _dataContainer(0)
, _selectedDataHandle(0)
, _dctWidget(0)
, _canvas(0)
, _mainLayout(0)
, _infoWidget(0)
, _infoWidgetLayout(0)
{
setupGUI();
}
DataContainerInspectorWidget::~DataContainerInspectorWidget() {
delete _selectedDataHandle;
}
void DataContainerInspectorWidget::setDataContainer(DataContainer* dataContainer) {
if (_dataContainer != 0) {
_dataContainer->s_changed.disconnect(this);
}
_dataContainer = dataContainer;
_dctWidget->update(dataContainer);
if (_dataContainer != 0) {
_dataContainer->s_changed.connect(this, &DataContainerInspectorWidget::onDataContainerChanged);
}
}
void DataContainerInspectorWidget::onDataContainerChanged() {
}
QSize DataContainerInspectorWidget::sizeHint() const {
return QSize(640, 480);
}
void DataContainerInspectorWidget::onDCTWidgetItemClicked(const QModelIndex& index) {
if (index.isValid()) {
// Yak, this is so ugly - another reason why GUI programming sucks...
QVariant item = index.data(Qt::UserRole);
DataHandle* ptr = static_cast<DataHandle*>(item.value<void*>());
_lblTimestamp->setText("Timestamp: " + QString::number(ptr->getTimestamp()));
// QModelIndex idxName(index.row(), 0, index.data(), index.model());
// QVariant name = idxName.data(Qt::DisplayRole);
// _lblName->setText("Name: " + name.toString());
}
}
void DataContainerInspectorWidget::setupGUI() {
_mainLayout = new QHBoxLayout();
_mainLayout->setSpacing(4);
setLayout(_mainLayout);
_dctWidget = new DataContainerTreeWidget(this);
_mainLayout->addWidget(_dctWidget);
_infoWidget = new QWidget(this);
_infoWidgetLayout = new QVBoxLayout();
_infoWidgetLayout->setSpacing(4);
_infoWidget->setLayout(_infoWidgetLayout);
_lblName = new QLabel(QString("Name: "), _infoWidget);
_infoWidgetLayout->addWidget(_lblName);
_lblTimestamp = new QLabel("Timestamp: ", _infoWidget);
_infoWidgetLayout->addWidget(_lblTimestamp);
_canvas = CtxtMgr.createContext("DataContainerInspector", "", tgt::ivec2(128, 128), tgt::GLCanvas::RGBA, _infoWidget);
_infoWidgetLayout->addWidget(_canvas);
_mainLayout->addWidget(_infoWidget);
connect(
_dctWidget, SIGNAL(clicked(const QModelIndex&)),
this, SLOT(onDCTWidgetItemClicked(const QModelIndex&)));
}
void DataContainerInspectorWidget::updateInfoWidget() {
}
}
\ No newline at end of file
// ================================================================================================
//
// 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 Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, 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 DATACONTAINERINSPECTORWIDGET_H__
#define DATACONTAINERINSPECTORWIDGET_H__
#include "sigslot/sigslot.h"
#include "tgt/painter.h"
#include "tgt/qt/qtcontextmanager.h"
#include "tgt/qt/qtthreadedcanvas.h"
#include "core/tools/opengljobprocessor.h"
#include <QLabel>
#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
class QModelIndex;
namespace TUMVis {
class DataContainer;
class DataContainerTreeWidget;
class DataHandle;
class DataContainerInspectorWidget : public QWidget, public sigslot::has_slots<> {
Q_OBJECT;
public:
/**
* Creates a new DataContainerInspectorWidget.
* \param parent Parent Qt widget, may be 0 (default)
*/
DataContainerInspectorWidget(QWidget* parent = 0);
/**
* Destructor.
*/
~DataContainerInspectorWidget();
/**
* Set the DataContainer this widget is inspecting.
* \param dataContainer The DataContainer this widget shall inspect, may be 0.
*/
void setDataContainer(DataContainer* dataContainer);
/**
* Slot called when _dataContainer has changed and emitted the s_changed signal.
*/
void onDataContainerChanged();
/**
* Size hint for the default window size
* \return QSize(640, 480)
*/
QSize sizeHint() const;
private slots:
/**
* Slot to be called by the DataContainerTreeWidget when the selected item changes.
* \param index Index of the selected item
*/
void onDCTWidgetItemClicked(const QModelIndex& index);
protected:
/**
* Setup the GUI stuff
*/
void setupGUI();
/**
* Updates _infoWidget
*/
void updateInfoWidget();
DataContainer* _dataContainer; ///< The DataContainer this widget is inspecting
const DataHandle* _selectedDataHandle; ///< The currently selected DataHandle
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
QVBoxLayout* _infoWidgetLayout; ///< Layout for the _infoWidget
QLabel* _lblName;
QLabel* _lblTimestamp;
};
}
#endif // DATACONTAINERINSPECTORWIDGET_H__
#include "datacontainertreewidget.h"
#include "tgt/assert.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"
#include "core/datastructures/imagedatarendertarget.h"
#include "core/datastructures/imagedatagl.h"
#include <QHeaderView>
#include <QStringList>
namespace TUMVis {
namespace {
const int COLUMN_NAME = 0;
const int COLUMN_TYPE = 1;
}
// = TreeModel items ==============================================================================
DataContainerTreeRootItem::DataContainerTreeRootItem(TreeItem* parent /*= 0*/)
: TreeItem(parent)
{}
QVariant DataContainerTreeRootItem::getData(int column, int role) const {
if (role == Qt::DisplayRole) {
if (column == COLUMN_NAME)
return QVariant(QString("Name"));
else if (column == COLUMN_TYPE)
return QVariant(QString("Data Type"));
}
return QVariant();
}
DataContainerTreeRootItem::~DataContainerTreeRootItem() {
}
// ================================================================================================
DataHandleTreeItem::DataHandleTreeItem(const DataHandle* dataHandle, const std::string& name, TreeItem* parent)
: TreeItem(parent)
, _dataHandle(dataHandle)
, _name(name)
{
tgtAssert(_dataHandle != 0, "DataHandle must not be 0.");
}
QVariant DataHandleTreeItem::getData(int column, int role) const {
switch (role) {
case Qt::DisplayRole:
if (column == COLUMN_NAME)
return QVariant(QString::fromStdString(_name));
else if (column == COLUMN_TYPE) {
const AbstractData* data = _dataHandle->getData();
tgtAssert(data != 0, "WTF - DataHandle with empty data?");
if (const ImageDataDisk* tester = dynamic_cast<const ImageDataDisk*>(data)) {
return QVariant(QString("ImageData on disk"));
}
else if (const ImageDataLocal* tester = dynamic_cast<const ImageDataLocal*>(data)) {
return QVariant(QString("ImageData in local memory"));
}
else if (const ImageDataGL* tester = dynamic_cast<const ImageDataGL*>(data)) {
return QVariant(QString("ImageData in OpenGL texture."));
}
else if (const ImageDataRenderTarget* tester = dynamic_cast<const ImageDataRenderTarget*>(data)) {
return QVariant(QString("RenderTarget"));
}
}
else
return QVariant();
case Qt::UserRole:
// const cast ist ugly, same as GUI programming...
return qVariantFromValue(const_cast<void*>(static_cast<const void*>(_dataHandle)));
default:
return QVariant();
}
}
DataHandleTreeItem::~DataHandleTreeItem() {
delete _dataHandle;
}
// = DataContainerTreeModel ============================================================================
DataContainerTreeModel::DataContainerTreeModel(QObject *parent /*= 0*/)
: QAbstractItemModel(parent)
, _rootItem(new DataContainerTreeRootItem(0))
{
}
DataContainerTreeModel::~DataContainerTreeModel() {
delete _rootItem;
}
QVariant DataContainerTreeModel::data(const QModelIndex &index, int role) const {
if (!index.isValid())
return QVariant();
TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
return item->getData(index.column(), role);
}
bool DataContainerTreeModel::setData(const QModelIndex& index, const QVariant& value, int role) {
if (!index.isValid())
return false;
TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
return item->setData(index.column(), role, value);
}
Qt::ItemFlags DataContainerTreeModel::flags(const QModelIndex &index) const {
if (!index.isValid())
return 0;
switch (index.column()) {
case COLUMN_TYPE:
return QAbstractItemModel::flags(index) | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
case COLUMN_NAME:
return QAbstractItemModel::flags(index) | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
return 0;
}
QVariant DataContainerTreeModel::headerData(int section, Qt::Orientation orientation, int role /*= Qt::DisplayRole*/) const {
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return _rootItem->getData(section, role);
return QVariant();
}
QModelIndex DataContainerTreeModel::index(int row, int column, const QModelIndex &parent /*= QModelIndex()*/) const {
if (!hasIndex(row, column, parent))
return QModelIndex();
TreeItem* parentItem;
if (!parent.isValid())
parentItem = _rootItem;
else
parentItem = static_cast<TreeItem*>(parent.internalPointer());
TreeItem* childItem = parentItem->getChild(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
QModelIndex DataContainerTreeModel::parent(const QModelIndex &index) const {
if (!index.isValid())
return QModelIndex();
TreeItem* childItem = static_cast<TreeItem*>(index.internalPointer());
TreeItem* parentItem = childItem->getParent();
if (parentItem == _rootItem)
return QModelIndex();
return createIndex(parentItem->getRow(), 0, parentItem);
}
int DataContainerTreeModel::rowCount(const QModelIndex &parent /*= QModelIndex()*/) const {
TreeItem* parentItem;
if (parent.column() > 0)
return 0;
if (!parent.isValid())
parentItem = _rootItem;
else
parentItem = static_cast<TreeItem*>(parent.internalPointer());
return parentItem->getChildCount();
}
int DataContainerTreeModel::columnCount(const QModelIndex &parent /*= QModelIndex()*/) const {
return 2;
}
void DataContainerTreeModel::setData(const DataContainer* dataContainer) {
delete _rootItem;
_rootItem = new DataContainerTreeRootItem();
std::vector< std::pair< std::string, const DataHandle*> > handlesCopy = dataContainer->getDataHandlesCopy();
for (std::vector< std::pair< std::string, const DataHandle*> >::iterator it = handlesCopy.begin(); it != handlesCopy.end(); ++it) {
DataHandleTreeItem* dhti = new DataHandleTreeItem(it->second, it->first, _rootItem);
}
}
// = DataContainerTreeWidget ===========================================================================
DataContainerTreeWidget::DataContainerTreeWidget(QWidget* parent /*= 0*/)
: QTreeView(parent)
{
setupWidget();
}
DataContainerTreeWidget::~DataContainerTreeWidget() {
}
void DataContainerTreeWidget::update(const DataContainer* dataContainer) {
_treeModel->setData(dataContainer);
expandAll();
resizeColumnToContents(0);
resizeColumnToContents(1);
}
void DataContainerTreeWidget::setupWidget() {
_treeModel = new DataContainerTreeModel(this);
tgtAssert(_treeModel != 0, "Failed creating TreeViewWidget model.");
setModel(_treeModel);
}
}
\ No newline at end of file
// ================================================================================================
//
// 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 Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, 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 DATACONTAINERTREEWIDGET_H__
#define DATACONTAINERTREEWIDGET_H__
#include <QAbstractItemModel>
#include <QTreeWidget>
#include <QList>
#include <QVariant>
#include "application/tools/treeitem.h"
namespace TUMVis {
class DataContainer;
class DataHandle;
// = TreeModel items ==============================================================================
/**
* Specialization for root TreeItems.
*/
class DataContainerTreeRootItem : public TreeItem {
public:
DataContainerTreeRootItem(TreeItem* parent = 0);
virtual ~DataContainerTreeRootItem();
/// \see TreeItem::getData()
virtual QVariant getData(int column, int role) const;
};
/**
* Specialization for TreeItems hosting an AbstractProcessor.
*/
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
* \param parent Parent TreeItem
*/
DataHandleTreeItem(const DataHandle* dataHandle, const std::string& name, TreeItem* parent);
/**
* Destructor, deletes the DataHandle
*/
virtual ~DataHandleTreeItem();
/// \see TreeItem::getData()
virtual QVariant getData(int column, int role) const;
private:
const DataHandle* _dataHandle; ///< Base DataHandle
std::string _name; ///< Name of that DataHandle
};
// = TreeModel ====================================================================================
/**
* QItemModel for displaying a list of pipelines and their processors in the DataContainerTreeWidget.
*/
class DataContainerTreeModel : public QAbstractItemModel {
Q_OBJECT
public:
DataContainerTreeModel(QObject *parent = 0);
~DataContainerTreeModel();
void setData(const DataContainer* dataContainer);
QVariant data(const QModelIndex &index, int role) const;
/**
* Sets the data at index \a index to \a value.
* \param index position where to set data
* \param value new data
* \param role edit role
**/
bool setData(const QModelIndex& index, const QVariant& value, int role);
Qt::ItemFlags flags(const QModelIndex &index) const;