diff --git a/CoreUI/Qmitk/QmitkDataStorageTreeModel.cpp b/CoreUI/Qmitk/QmitkDataStorageTreeModel.cpp index f376f19ffd..ab86eaa4c7 100644 --- a/CoreUI/Qmitk/QmitkDataStorageTreeModel.cpp +++ b/CoreUI/Qmitk/QmitkDataStorageTreeModel.cpp @@ -1,862 +1,862 @@ /*========================================================================= Program: MITK Language: C++ Date: $Date: 2008-08-13 16:56:36 +0200 (Mi, 13 Aug 2008) $ Version: $Revision: 14972 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include #include #include #include #include #include #include #include #include #include "QmitkDataStorageTreeModel.h" #include "QmitkNodeDescriptorManager.h" #include #include #include #include #include #include QmitkDataStorageTreeModel::QmitkDataStorageTreeModel( mitk::DataStorage* _DataStorage , bool _PlaceNewNodesOnTop , bool _ShowHelperObjects , bool _ShowNodesContainingNoData , QObject* parent ) : QAbstractItemModel(parent) , m_DataStorage(0) , m_PlaceNewNodesOnTop(_PlaceNewNodesOnTop) , m_ShowHelperObjects(_ShowHelperObjects) , m_ShowNodesContainingNoData(_ShowNodesContainingNoData) , m_Root(0) { this->UpdateNodeVisibility(); this->SetDataStorage(_DataStorage); } QmitkDataStorageTreeModel::~QmitkDataStorageTreeModel() { // set data storage to 0 = remove all listeners this->SetDataStorage(0); m_Root->Delete(); m_Root = 0; //Removing all observers for ( NodeTagMapType::iterator dataIter = m_HelperObjectObserverTags.begin(); dataIter != m_HelperObjectObserverTags.end(); ++dataIter ) { (*dataIter).first->GetProperty("helper object")->RemoveObserver( (*dataIter).second ); } m_HelperObjectObserverTags.clear(); } mitk::DataNode::Pointer QmitkDataStorageTreeModel::GetNode( const QModelIndex &index ) const { return this->TreeItemFromIndex(index)->GetDataNode(); } const mitk::DataStorage::Pointer QmitkDataStorageTreeModel::GetDataStorage() const { return m_DataStorage.GetPointer(); } QModelIndex QmitkDataStorageTreeModel::index( int row, int column, const QModelIndex & parent ) const { TreeItem* parentItem; if (!parent.isValid()) parentItem = m_Root; else parentItem = static_cast(parent.internalPointer()); TreeItem *childItem = parentItem->GetChild(row); if (childItem) return createIndex(row, column, childItem); else return QModelIndex(); } int QmitkDataStorageTreeModel::rowCount(const QModelIndex &parent) const { TreeItem *parentTreeItem = this->TreeItemFromIndex(parent); return parentTreeItem->GetChildCount(); } Qt::ItemFlags QmitkDataStorageTreeModel::flags( const QModelIndex& index ) const { if (index.isValid()) return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; else return Qt::ItemIsDropEnabled; } int QmitkDataStorageTreeModel::columnCount( const QModelIndex& /* parent = QModelIndex() */ ) const { return 1; } QModelIndex QmitkDataStorageTreeModel::parent(const QModelIndex &index) const { if (!index.isValid()) return QModelIndex(); TreeItem *childItem = this->TreeItemFromIndex(index); TreeItem *parentItem = childItem->GetParent(); if (parentItem == m_Root) return QModelIndex(); return this->createIndex(parentItem->GetIndex(), 0, parentItem); } QmitkDataStorageTreeModel::TreeItem* QmitkDataStorageTreeModel::TreeItemFromIndex( const QModelIndex &index ) const { if (index.isValid()) return static_cast(index.internalPointer()); else return m_Root; } Qt::DropActions QmitkDataStorageTreeModel::supportedDropActions() const { return Qt::CopyAction | Qt::MoveAction; } Qt::DropActions QmitkDataStorageTreeModel::supportedDragActions() const { return Qt::CopyAction | Qt::MoveAction; } bool QmitkDataStorageTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int /*row*/, int /*column*/, const QModelIndex &parent) { // Early exit, returning true, but not actually doing anything (ignoring data). if (action == Qt::IgnoreAction) { return true; } // Note, we are returning true if we handled it, and false otherwise bool returnValue = false; if(data->hasFormat("application/x-qabstractitemmodeldatalist")) { returnValue = true; // First we extract a Qlist of TreeItem* pointers. QString arg = QString(data->data("application/x-qabstractitemmodeldatalist").data()); QStringList listOfTreeItemAddressPointers = arg.split(","); QStringList::iterator slIter; QList listOfItemsToDrop; for(slIter = listOfTreeItemAddressPointers.begin(); slIter != listOfTreeItemAddressPointers.end(); slIter++) { long val = (*slIter).toLong(); listOfItemsToDrop << static_cast((void*)val); } // Retrieve the TreeItem* where we are dropping stuff, and its parent. TreeItem* dropItem = this->TreeItemFromIndex(parent); TreeItem* parentItem = dropItem->GetParent(); // If item was dropped onto empty space, we select the root node if(dropItem == m_Root) { parentItem = m_Root; } // Dragging and Dropping is only allowed within the same parent, so use the first item in list to validate. // (otherwise, you could have a derived image such as a segmentation, and assign it to another image). // NOTE: We are assuming the input list is valid... i.e. when it was dragged, all the items had the same parent. if(listOfItemsToDrop[0] != dropItem && listOfItemsToDrop[0]->GetParent() == parentItem) { // Retrieve the index of where we are dropping stuff. QModelIndex dropItemModelIndex = this->IndexFromTreeItem(dropItem); QModelIndex parentModelIndex = this->IndexFromTreeItem(parentItem); // Iterate through the list of TreeItem (which may be at non-consecutive indexes). QList::iterator diIter; for (diIter = listOfItemsToDrop.begin(); diIter != listOfItemsToDrop.end(); diIter++) { // Here we assume that as you remove items, one at a time, that GetIndex() will be valid. this->beginRemoveRows(parentModelIndex, (*diIter)->GetIndex(), (*diIter)->GetIndex()); parentItem->RemoveChild(*diIter); this->endRemoveRows(); } // Select the target index position, or put it at the end of the list. int dropIndex = dropItemModelIndex.row(); if (dropIndex == -1) { dropIndex = parentItem->GetChildCount(); } // Now insert items again at the drop item position this->beginInsertRows(parentModelIndex, dropIndex, dropIndex + listOfItemsToDrop.size() - 1); for (diIter = listOfItemsToDrop.begin(); diIter != listOfItemsToDrop.end(); diIter++) { parentItem->InsertChild( (*diIter), dropIndex ); dropIndex++; } this->endInsertRows(); // Change Layers to match. this->AdjustLayerProperty(); } } else if(data->hasFormat("application/x-mitk-datanodes")) { returnValue = true; QString arg = QString(data->data("application/x-mitk-datanodes").data()); QStringList listOfDataNodeAddressPointers = arg.split(","); int numberOfNodesDropped = 0; QStringList::iterator slIter; for (slIter = listOfDataNodeAddressPointers.begin(); slIter != listOfDataNodeAddressPointers.end(); slIter++) { long val = (*slIter).toLong(); mitk::DataNode* node = static_cast((void*)val); if(node && m_DataStorage.IsNotNull() && !m_DataStorage->Exists(node)) { m_DataStorage->Add( node ); mitk::BaseData::Pointer basedata = node->GetData(); if (basedata.IsNotNull()) { mitk::RenderingManager::GetInstance()->InitializeViews( basedata->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); numberOfNodesDropped++; } } } // Only do a rendering update, if we actually dropped anything. if (numberOfNodesDropped > 0) { mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } return returnValue; } QStringList QmitkDataStorageTreeModel::mimeTypes() const { QStringList types = QAbstractItemModel::mimeTypes(); types << "application/x-qabstractitemmodeldatalist"; types << "application/x-mitk-datanodes"; return types; } QMimeData * QmitkDataStorageTreeModel::mimeData(const QModelIndexList & indexes) const{ QMimeData * ret = new QMimeData; QString treeItemAddresses(""); QString dataNodeAddresses(""); for (int i = 0; i < indexes.size(); i++) { TreeItem* treeItem = static_cast(indexes.at(i).internalPointer()); long treeItemAddress = reinterpret_cast(treeItem); long dataNodeAddress = reinterpret_cast(treeItem->GetDataNode().GetPointer()); QTextStream(&treeItemAddresses) << treeItemAddress; QTextStream(&dataNodeAddresses) << dataNodeAddress; if (i != indexes.size() - 1) { QTextStream(&treeItemAddresses) << ","; QTextStream(&dataNodeAddresses) << ","; } } ret->setData("application/x-qabstractitemmodeldatalist", QByteArray(treeItemAddresses.toAscii())); ret->setData("application/x-mitk-datanodes", QByteArray(dataNodeAddresses.toAscii())); return ret; } QVariant QmitkDataStorageTreeModel::data( const QModelIndex & index, int role ) const { mitk::DataNode* dataNode = this->TreeItemFromIndex(index)->GetDataNode(); // get name of treeItem (may also be edited) QString nodeName = QString::fromStdString(dataNode->GetName()); if(nodeName.isEmpty()) nodeName = "unnamed"; if (role == Qt::DisplayRole) return nodeName; else if(role == Qt::ToolTipRole) return nodeName; else if(role == Qt::DecorationRole) { QmitkNodeDescriptor* nodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor(dataNode); return nodeDescriptor->GetIcon(); } else if(role == Qt::CheckStateRole) { return dataNode->IsVisible(0); } else if(role == QmitkDataNodeRole) { return QVariant::fromValue(mitk::DataNode::Pointer(dataNode)); } return QVariant(); } QVariant QmitkDataStorageTreeModel::headerData(int /*section*/, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole && m_Root) return QString::fromStdString(m_Root->GetDataNode()->GetName()); return QVariant(); } void QmitkDataStorageTreeModel::SetDataStorage( mitk::DataStorage* _DataStorage ) { if(m_DataStorage != _DataStorage) // dont take the same again { if(m_DataStorage.IsNotNull()) { // remove Listener for the data storage itself m_DataStorage.ObjectDelete.RemoveListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::SetDataStorageDeleted ) ); // remove listeners for the nodes m_DataStorage->AddNodeEvent.RemoveListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::AddNode ) ); m_DataStorage->ChangedNodeEvent.RemoveListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::SetNodeModified ) ); m_DataStorage->RemoveNodeEvent.RemoveListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::RemoveNode ) ); } // take over the new data storage m_DataStorage = _DataStorage; // delete the old root (if necessary, create new) if(m_Root) m_Root->Delete(); mitk::DataNode::Pointer rootDataNode = mitk::DataNode::New(); rootDataNode->SetName("Data Manager"); m_Root = new TreeItem(rootDataNode, 0); this->reset(); if(m_DataStorage.IsNotNull()) { // add Listener for the data storage itself m_DataStorage.ObjectDelete.AddListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::SetDataStorageDeleted ) ); // add listeners for the nodes m_DataStorage->AddNodeEvent.AddListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::AddNode ) ); m_DataStorage->ChangedNodeEvent.AddListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::SetNodeModified ) ); m_DataStorage->RemoveNodeEvent.AddListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::RemoveNode ) ); mitk::DataStorage::SetOfObjects::ConstPointer _NodeSet = m_DataStorage->GetSubset(m_Predicate); // finally add all nodes to the model this->Update(); } } } void QmitkDataStorageTreeModel::SetDataStorageDeleted( const itk::Object* /*_DataStorage*/ ) { this->SetDataStorage(0); } void QmitkDataStorageTreeModel::AddNodeInternal(const mitk::DataNode *node) { if(node == 0 || m_DataStorage.IsNull() || !m_DataStorage->Exists(node) || !m_Predicate->CheckNode(node) || m_Root->Find(node) != 0) return; // find out if we have a root node TreeItem* parentTreeItem = m_Root; QModelIndex index; mitk::DataNode* parentDataNode = this->GetParentNode(node); if(parentDataNode) // no top level data node { parentTreeItem = m_Root->Find(parentDataNode); // find the corresponding tree item if(!parentTreeItem) { this->AddNode(parentDataNode); parentTreeItem = m_Root->Find(parentDataNode); if(!parentTreeItem) return; } // get the index of this parent with the help of the grand parent index = this->createIndex(parentTreeItem->GetIndex(), 0, parentTreeItem); } // add node if(m_PlaceNewNodesOnTop) { // emit beginInsertRows event beginInsertRows(index, 0, 0); parentTreeItem->InsertChild(new TreeItem( const_cast(node)), 0); } else { beginInsertRows(index, parentTreeItem->GetChildCount() , parentTreeItem->GetChildCount()); new TreeItem(const_cast(node), parentTreeItem); } // emit endInsertRows event endInsertRows(); this->AdjustLayerProperty(); } void QmitkDataStorageTreeModel::AddNode( const mitk::DataNode* node ) { if(node == 0 || m_DataStorage.IsNull() || !m_DataStorage->Exists(node) || !m_Predicate->CheckNode(node) || m_Root->Find(node) != 0) return; bool isHelperObject (false); NodeTagMapType::iterator searchIter = m_HelperObjectObserverTags.find( const_cast(node) ); if (node->GetBoolProperty("helper object", isHelperObject) && searchIter == m_HelperObjectObserverTags.end()) { itk::SimpleMemberCommand::Pointer command = itk::SimpleMemberCommand::New(); command->SetCallbackFunction(this, &QmitkDataStorageTreeModel::UpdateNodeVisibility); m_HelperObjectObserverTags.insert( std::pair( const_cast(node), node->GetProperty("helper object")->AddObserver( itk::ModifiedEvent(), command ) ) ); } this->AddNodeInternal(node); } void QmitkDataStorageTreeModel::SetPlaceNewNodesOnTop(bool _PlaceNewNodesOnTop) { m_PlaceNewNodesOnTop = _PlaceNewNodesOnTop; } void QmitkDataStorageTreeModel::RemoveNodeInternal( const mitk::DataNode* node ) { if(!m_Root) return; TreeItem* treeItem = m_Root->Find(node); if(!treeItem) return; // return because there is no treeitem containing this node TreeItem* parentTreeItem = treeItem->GetParent(); QModelIndex parentIndex = this->IndexFromTreeItem(parentTreeItem); // emit beginRemoveRows event (QModelIndex is empty because we dont have a tree model) this->beginRemoveRows(parentIndex, treeItem->GetIndex(), treeItem->GetIndex()); // remove node std::vector children = treeItem->GetChildren(); delete treeItem; // emit endRemoveRows event endRemoveRows(); // move all children of deleted node into its parent for ( std::vector::iterator it = children.begin() ; it != children.end(); it++) { // emit beginInsertRows event beginInsertRows(parentIndex, parentTreeItem->GetChildCount(), parentTreeItem->GetChildCount()); // add nodes again parentTreeItem->AddChild(*it); // emit endInsertRows event endInsertRows(); } this->AdjustLayerProperty(); } void QmitkDataStorageTreeModel::RemoveNode( const mitk::DataNode* node ) { if (node == 0) return; //Removing Observer bool isHelperObject (false); NodeTagMapType::iterator searchIter = m_HelperObjectObserverTags.find( const_cast(node) ); if (node->GetBoolProperty("helper object", isHelperObject) && searchIter != m_HelperObjectObserverTags.end()) { (*searchIter).first->GetProperty("helper object")->RemoveObserver( (*searchIter).second ); m_HelperObjectObserverTags.erase(const_cast(node)); } this->RemoveNodeInternal(node); } void QmitkDataStorageTreeModel::SetNodeModified( const mitk::DataNode* node ) { TreeItem* treeItem = m_Root->Find(node); if(!treeItem) return; TreeItem* parentTreeItem = treeItem->GetParent(); // as the root node should not be removed one should always have a parent item if(!parentTreeItem) return; QModelIndex index = this->createIndex(treeItem->GetIndex(), 0, treeItem); // now emit the dataChanged signal emit dataChanged(index, index); } mitk::DataNode* QmitkDataStorageTreeModel::GetParentNode( const mitk::DataNode* node ) const { mitk::DataNode* dataNode = 0; mitk::DataStorage::SetOfObjects::ConstPointer _Sources = m_DataStorage->GetSources(node); if(_Sources->Size() > 0) dataNode = _Sources->front(); return dataNode; } bool QmitkDataStorageTreeModel::setData( const QModelIndex &index, const QVariant &value, int role ) { mitk::DataNode* dataNode = this->TreeItemFromIndex(index)->GetDataNode(); if(!dataNode) return false; if(role == Qt::EditRole && !value.toString().isEmpty()) { dataNode->SetStringProperty("name", value.toString().toStdString().c_str()); } else if(role == Qt::CheckStateRole) { // Please note: value.toInt() returns 2, independentely from the actual checkstate of the index element. // Therefore the checkstate is being estimated again here. QVariant qcheckstate = index.data(Qt::CheckStateRole); int checkstate = qcheckstate.toInt(); bool isVisible = bool(checkstate); dataNode->SetVisibility(!isVisible); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } // inform listeners about changes emit dataChanged(index, index); return true; } bool QmitkDataStorageTreeModel::setHeaderData( int /*section*/, Qt::Orientation /*orientation*/, const QVariant& /* value */, int /*role = Qt::EditRole*/ ) { return false; } void QmitkDataStorageTreeModel::AdjustLayerProperty() { /// transform the tree into an array and set the layer property descending std::vector vec; this->TreeToVector(m_Root, vec); int i = vec.size()-1; for(std::vector::const_iterator it = vec.begin(); it != vec.end(); ++it) { (*it)->GetDataNode()->SetIntProperty("layer", i); --i; } mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkDataStorageTreeModel::TreeToVector(TreeItem* parent, std::vector& vec) const { TreeItem* current; for(int i = 0; iGetChildCount(); ++i) { current = parent->GetChild(i); this->TreeToVector(current, vec); vec.push_back(current); } } QModelIndex QmitkDataStorageTreeModel::IndexFromTreeItem( TreeItem* item ) const { if(item == m_Root) return QModelIndex(); else return this->createIndex(item->GetIndex(), 0, item); } -std::vector QmitkDataStorageTreeModel::GetNodeSet() const +QList QmitkDataStorageTreeModel::GetNodeSet() const { - std::vector vec; + QList res; if(m_Root) - this->TreeToNodeSet(m_Root, vec); + this->TreeToNodeSet(m_Root, res); - return vec; + return res; } -void QmitkDataStorageTreeModel::TreeToNodeSet( TreeItem* parent, std::vector& vec ) const +void QmitkDataStorageTreeModel::TreeToNodeSet( TreeItem* parent, QList& vec ) const { TreeItem* current; for(int i = 0; iGetChildCount(); ++i) { current = parent->GetChild(i); vec.push_back(current->GetDataNode()); this->TreeToNodeSet(current, vec); } } QModelIndex QmitkDataStorageTreeModel::GetIndex( const mitk::DataNode* node ) const { if(m_Root) { TreeItem* item = m_Root->Find(node); if(item) return this->IndexFromTreeItem(item); } return QModelIndex(); } QmitkDataStorageTreeModel::TreeItem::TreeItem( mitk::DataNode* _DataNode, TreeItem* _Parent ) : m_Parent(_Parent) , m_DataNode(_DataNode) { if(m_Parent) m_Parent->AddChild(this); } QmitkDataStorageTreeModel::TreeItem::~TreeItem() { if(m_Parent) m_Parent->RemoveChild(this); } void QmitkDataStorageTreeModel::TreeItem::Delete() { while(m_Children.size() > 0) delete m_Children.back(); delete this; } QmitkDataStorageTreeModel::TreeItem* QmitkDataStorageTreeModel::TreeItem::Find( const mitk::DataNode* _DataNode ) const { QmitkDataStorageTreeModel::TreeItem* item = 0; if(_DataNode) { if(m_DataNode == _DataNode) item = const_cast(this); else { for(std::vector::const_iterator it = m_Children.begin(); it != m_Children.end(); ++it) { if(item) break; item = (*it)->Find(_DataNode); } } } return item; } int QmitkDataStorageTreeModel::TreeItem::IndexOfChild( const TreeItem* item ) const { std::vector::const_iterator it = std::find(m_Children.begin(), m_Children.end(), item); return it != m_Children.end() ? std::distance(m_Children.begin(), it): -1; } QmitkDataStorageTreeModel::TreeItem* QmitkDataStorageTreeModel::TreeItem::GetChild( int index ) const { return (m_Children.size() > 0 && index >= 0 && index < (int)m_Children.size())? m_Children.at(index): 0; } void QmitkDataStorageTreeModel::TreeItem::AddChild( TreeItem* item ) { this->InsertChild(item); } void QmitkDataStorageTreeModel::TreeItem::RemoveChild( TreeItem* item ) { std::vector::iterator it = std::find(m_Children.begin(), m_Children.end(), item); if(it != m_Children.end()) { m_Children.erase(it); item->SetParent(0); } } int QmitkDataStorageTreeModel::TreeItem::GetChildCount() const { return m_Children.size(); } int QmitkDataStorageTreeModel::TreeItem::GetIndex() const { if (m_Parent) return m_Parent->IndexOfChild(this); return 0; } QmitkDataStorageTreeModel::TreeItem* QmitkDataStorageTreeModel::TreeItem::GetParent() const { return m_Parent; } mitk::DataNode::Pointer QmitkDataStorageTreeModel::TreeItem::GetDataNode() const { return m_DataNode; } void QmitkDataStorageTreeModel::TreeItem::InsertChild( TreeItem* item, int index ) { std::vector::iterator it = std::find(m_Children.begin(), m_Children.end(), item); if(it == m_Children.end()) { if(m_Children.size() > 0 && index >= 0 && index < (int)m_Children.size()) { it = m_Children.begin(); std::advance(it, index); m_Children.insert(it, item); } else m_Children.push_back(item); // add parent if necessary if(item->GetParent() != this) item->SetParent(this); } } std::vector QmitkDataStorageTreeModel::TreeItem::GetChildren() const { return m_Children; } void QmitkDataStorageTreeModel::TreeItem::SetParent( TreeItem* _Parent ) { m_Parent = _Parent; if(m_Parent) m_Parent->AddChild(this); } void QmitkDataStorageTreeModel::SetShowHelperObjects(bool _ShowHelperObjects) { m_ShowHelperObjects = _ShowHelperObjects; this->UpdateNodeVisibility(); } void QmitkDataStorageTreeModel::SetShowNodesContainingNoData(bool _ShowNodesContainingNoData) { m_ShowNodesContainingNoData = _ShowNodesContainingNoData; this->UpdateNodeVisibility(); } void QmitkDataStorageTreeModel::UpdateNodeVisibility() { mitk::NodePredicateData::Pointer dataIsNull = mitk::NodePredicateData::New(0); mitk::NodePredicateNot::Pointer dataIsNotNull = mitk::NodePredicateNot::New(dataIsNull);// Show only nodes that really contain dat if (m_ShowHelperObjects) { if (m_ShowNodesContainingNoData) { // Show every node m_Predicate = mitk::NodePredicateOr::New(dataIsNull, dataIsNotNull); } else { // Show helper objects but not nodes containing no data m_Predicate = dataIsNotNull; } } else { mitk::NodePredicateProperty::Pointer isHelperObject = mitk::NodePredicateProperty::New("helper object", mitk::BoolProperty::New(true)); mitk::NodePredicateNot::Pointer isNotHelperObject = mitk::NodePredicateNot::New(isHelperObject);// Show only nodes that are not helper objects if (m_ShowNodesContainingNoData) { // Don't show helper objects but nodes containing no data m_Predicate = isNotHelperObject; } else { // Don't show helper objects and nodes containing no data m_Predicate = mitk::NodePredicateAnd::New(isNotHelperObject, dataIsNotNull); } } this->Update(); } void QmitkDataStorageTreeModel::Update() { if (m_DataStorage.IsNotNull()) { this->reset(); mitk::DataStorage::SetOfObjects::ConstPointer _NodeSet = m_DataStorage->GetSubset(m_Predicate); for(mitk::DataStorage::SetOfObjects::const_iterator it=_NodeSet->begin(); it!=_NodeSet->end(); it++) { // save node this->AddNodeInternal(*it); } mitk::DataStorage::SetOfObjects::ConstPointer _NotNodeSet = m_DataStorage->GetSubset(mitk::NodePredicateNot::New(m_Predicate)); for(mitk::DataStorage::SetOfObjects::const_iterator it=_NotNodeSet->begin(); it!=_NotNodeSet->end(); it++) { // remove node this->RemoveNodeInternal(*it); } } } diff --git a/CoreUI/Qmitk/QmitkDataStorageTreeModel.h b/CoreUI/Qmitk/QmitkDataStorageTreeModel.h index 0f5cdac06d..0ef751248d 100644 --- a/CoreUI/Qmitk/QmitkDataStorageTreeModel.h +++ b/CoreUI/Qmitk/QmitkDataStorageTreeModel.h @@ -1,289 +1,289 @@ /*========================================================================= Program: MITK Language: C++ Date: $Date: 2008-08-13 16:56:36 +0200 (Mi, 13 Aug 2008) $ Version: $Revision: 14972 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef QMITKDATASTORAGETREEMODEL_H_ #define QMITKDATASTORAGETREEMODEL_H_ #include #include #include #include #include #include "QmitkEnums.h" #include "QmitkCustomVariants.h" #include #include #include class QMITK_EXPORT QmitkDataStorageTreeModel : public QAbstractItemModel { //# CONSTANTS,TYPEDEFS public: static const std::string COLUMN_NAME; static const std::string COLUMN_TYPE; static const std::string COLUMN_VISIBILITY; //# CTORS,DTOR public: QmitkDataStorageTreeModel(mitk::DataStorage* _DataStorage , bool _PlaceNewNodesOnTop=false , bool _ShowHelperObjects=false , bool _ShowNodesContainingNoData=false , QObject* parent = 0); ~QmitkDataStorageTreeModel(); //# GETTER public: typedef std::map NodeTagMapType; /// /// Get node at a specific model index. /// This function is used to get a node from a QModelIndex /// mitk::DataNode::Pointer GetNode(const QModelIndex &index) const; /// /// Returns a copy of the node-vector that is shown by this model /// - virtual std::vector GetNodeSet() const; + virtual QList GetNodeSet() const; /// /// Get the DataStorage. /// const mitk::DataStorage::Pointer GetDataStorage() const; /// /// Get the top placement flag /// bool GetPlaceNewNodesOnTopFlag() { return m_PlaceNewNodesOnTop; } /// /// Get the helper object visibility flag /// bool GetShowHelperObjectsFlag() { return m_ShowHelperObjects; } /// /// Get the visibility flag for showing nodes that contain no data /// bool GetShowNodesContainingNoDataFlag() { return m_ShowNodesContainingNoData; } /// /// Set the top placement flag /// void SetPlaceNewNodesOnTop(bool _PlaceNewNodesOnTop); //# (Re-)implemented from QAbstractItemModel //# Read model Qt::ItemFlags flags(const QModelIndex& index) const; QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; int rowCount ( const QModelIndex & parent = QModelIndex() ) const; int columnCount ( const QModelIndex & parent = QModelIndex() ) const; //# hierarchical model /// /// called whenever the model or the view needs to create a QModelIndex for a particular /// child item (or a top-level item if parent is an invalid QModelIndex) /// QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const; QModelIndex parent ( const QModelIndex & index ) const; //# editable model bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole); bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); Qt::DropActions supportedDropActions() const; Qt::DropActions supportedDragActions() const; QStringList mimeTypes() const; QMimeData * mimeData(const QModelIndexList & indexes) const; //# End of QAbstractItemModel //# SETTER public: /// /// Sets the DataStorage. The whole model will be resetted. /// void SetDataStorage(mitk::DataStorage* _DataStorage); /// /// Notify that the DataStorage was deleted. The whole model will be resetted. /// void SetDataStorageDeleted(const itk::Object* _DataStorage); /// /// Adds a node to this model. /// If a predicate is set (not null) the node will be checked against it.The node has to have a data object (no one wants to see empty nodes). /// virtual void AddNode(const mitk::DataNode* node); /// /// Removes a node from this model. Also removes any event listener from the node. /// virtual void RemoveNode(const mitk::DataNode* node); /// /// Sets a node to modfified. Called by the DataStorage /// virtual void SetNodeModified(const mitk::DataNode* node); /// /// \return an index for the given datatreenode in the tree. If the node is not found /// QModelIndex GetIndex(const mitk::DataNode*) const; /// /// Show or hide helper objects /// void SetShowHelperObjects(bool _ShowHelperObjects); /// /// Show or hide objects that contain no data /// void SetShowNodesContainingNoData(bool _ShowNodesContainingNoData); /// /// Update the visibility of data nodes according to the preference settings /// void UpdateNodeVisibility(); //# MISC protected: /// /// Helper class to represent a tree structure of DataNodes /// class TreeItem { public: /// /// Constructs a new TreeItem with the given DataNode (must not be 0) /// TreeItem(mitk::DataNode* _DataNode, TreeItem* _Parent=0); /// /// Removes itself as child from its parent-> Does not delete its children /// \sa Delete() /// virtual ~TreeItem(); /// /// Find the index of an item /// int IndexOfChild(const TreeItem* item) const; /// /// \child The child at pos index or 0 if it not exists /// TreeItem* GetChild(int index) const; /// /// Find the TreeItem containing a special tree node (recursive tree function) /// TreeItem* Find( const mitk::DataNode* _DataNode) const; /// /// Get the amount of children /// int GetChildCount() const; /// /// \return the index of this node in its parent list /// int GetIndex() const; /// /// \return the parent of this tree item /// TreeItem* GetParent() const; /// /// Return the DataNode associated with this node /// mitk::DataNode::Pointer GetDataNode() const; /// /// Get all children as vector /// std::vector GetChildren() const; /// /// add another item as a child of this (only if not already in that list) /// void AddChild( TreeItem* item); /// /// remove another item as child from this /// void RemoveChild( TreeItem* item); /// /// inserts a child at the given position. if pos is not in range /// the element is added at the end /// void InsertChild( TreeItem* item, int index=-1 ); /// Sets the parent on the treeitem void SetParent(TreeItem* _Parent); /// /// Deletes the whole tree branch /// void Delete(); protected: TreeItem* m_Parent; std::vector m_Children; mitk::DataNode::Pointer m_DataNode; }; /// /// Adjusts the LayerProperty according to the nodes position /// void AdjustLayerProperty(); /// /// invoked after m_DataStorage or m_Predicate changed /// TreeItem* TreeItemFromIndex(const QModelIndex &index) const; /// /// Gives a ModelIndex for the Tree Item /// QModelIndex IndexFromTreeItem(TreeItem*) const; /// /// Returns the first element in the nodes sources list (if available) or 0 /// mitk::DataNode* GetParentNode(const mitk::DataNode* node) const; /// /// Adds all Childs in parent to vec. Before a child is added the function is called recursively /// void TreeToVector(TreeItem* parent, std::vector& vec) const; /// /// Adds all Childs in parent to vec. Before a child is added the function is called recursively /// - void TreeToNodeSet(TreeItem* parent, std::vector& vec) const; + void TreeToNodeSet(TreeItem* parent, QList &vec) const; /// /// Update Tree Model according to predicates /// void Update(); //# ATTRIBUTES protected: mitk::WeakPointer m_DataStorage; mitk::NodePredicateBase::Pointer m_Predicate; bool m_PlaceNewNodesOnTop; bool m_ShowHelperObjects; bool m_ShowNodesContainingNoData; TreeItem* m_Root; NodeTagMapType m_HelperObjectObserverTags; private: void AddNodeInternal(const mitk::DataNode*); void RemoveNodeInternal(const mitk::DataNode*); }; #endif /* QMITKDATASTORAGETREEMODEL_H_ */ diff --git a/CoreUI/Qmitk/QmitkNodeDescriptorManager.cpp b/CoreUI/Qmitk/QmitkNodeDescriptorManager.cpp index 6977c34f79..210b4e204f 100644 --- a/CoreUI/Qmitk/QmitkNodeDescriptorManager.cpp +++ b/CoreUI/Qmitk/QmitkNodeDescriptorManager.cpp @@ -1,175 +1,174 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkNodeDescriptorManager.h" #include #include #include #include #include #include + #include +#include QmitkNodeDescriptorManager* QmitkNodeDescriptorManager::GetInstance() { static QmitkNodeDescriptorManager _Instance; return &_Instance; /* static std::auto_ptr instance; if(instance.get() == 0) { instance.reset(new QmitkNodeDescriptorManager()); instance->Initialize(); } return instance.get();*/ } void QmitkNodeDescriptorManager::Initialize() { // Adding "Images" mitk::NodePredicateDataType::Pointer isImage = mitk::NodePredicateDataType::New("Image"); this->AddDescriptor(new QmitkNodeDescriptor(tr("Image"), QString(":/Qmitk/Images_48.png"), isImage, this)); // Adding "Image Masks" mitk::NodePredicateProperty::Pointer isBinary = mitk::NodePredicateProperty::New("binary", mitk::BoolProperty::New(true)); mitk::NodePredicateAnd::Pointer isBinaryImage = mitk::NodePredicateAnd::New(isBinary, isImage); this->AddDescriptor(new QmitkNodeDescriptor(tr("ImageMask"), QString(":/Qmitk/Binaerbilder_48.png"), isBinaryImage, this)); // Adding "PointSet" mitk::NodePredicateDataType::Pointer isPointSet = mitk::NodePredicateDataType::New("PointSet"); this->AddDescriptor(new QmitkNodeDescriptor(tr("PointSet"), QString(":/Qmitk/PointSet_48.png"), isPointSet, this)); // Adding "Surface" mitk::NodePredicateDataType::Pointer isSurface = mitk::NodePredicateDataType::New("Surface"); this->AddDescriptor(new QmitkNodeDescriptor(tr("Surface"), QString(":/Qmitk/Surface_48.png"), isSurface, this)); // Adding "NoneBinaryImages" mitk::NodePredicateNot::Pointer isNotBinary = mitk::NodePredicateNot::New(isBinary); mitk::NodePredicateAnd::Pointer isNoneBinaryImage = mitk::NodePredicateAnd::New(isImage, isNotBinary); this->AddDescriptor(new QmitkNodeDescriptor(tr("NoneBinaryImage"), QString(":/Qmitk/Images_48.png"), isNoneBinaryImage, this)); } void QmitkNodeDescriptorManager::AddDescriptor( QmitkNodeDescriptor* _Descriptor ) { _Descriptor->setParent(this); m_NodeDescriptors.push_back(_Descriptor); } void QmitkNodeDescriptorManager::RemoveDescriptor( QmitkNodeDescriptor* _Descriptor ) { int index = m_NodeDescriptors.indexOf(_Descriptor); if(index != -1) { m_NodeDescriptors.removeAt(index); _Descriptor->setParent(0); delete _Descriptor; } } QmitkNodeDescriptor* QmitkNodeDescriptorManager::GetDescriptor( const mitk::DataNode* _Node ) const { QmitkNodeDescriptor* _Descriptor = m_UnknownDataNodeDescriptor; for(QList::const_iterator it = m_NodeDescriptors.begin(); it != m_NodeDescriptors.end(); ++it) { if((*it)->CheckNode(_Node)) _Descriptor = *it; } return _Descriptor; } QmitkNodeDescriptor* QmitkNodeDescriptorManager::GetDescriptor( const QString& _ClassName ) const { QmitkNodeDescriptor* _Descriptor = 0; for(QList::const_iterator it = m_NodeDescriptors.begin(); it != m_NodeDescriptors.end(); ++it) { if((*it)->GetClassName() == _ClassName) _Descriptor = *it; } return _Descriptor; } QList QmitkNodeDescriptorManager::GetActions( const mitk::DataNode* _Node ) const { QList actions = m_UnknownDataNodeDescriptor->GetBatchActions(); actions.append(m_UnknownDataNodeDescriptor->GetActions()); QmitkNodeDescriptor* lastDescriptor = m_UnknownDataNodeDescriptor; for(QList::const_iterator it = m_NodeDescriptors.begin(); it != m_NodeDescriptors.end(); ++it) { if((*it)->CheckNode(_Node)) { actions.append(lastDescriptor->GetSeparator()); lastDescriptor = *it; actions.append(lastDescriptor->GetBatchActions()); actions.append(lastDescriptor->GetActions()); } } return actions; } -QList QmitkNodeDescriptorManager::GetActions( const std::vector& _Nodes ) const +QList QmitkNodeDescriptorManager::GetActions( const QList &_Nodes ) const { QList actions = m_UnknownDataNodeDescriptor->GetBatchActions(); - std::vector nodeDescriptors; + QSet nodeDescriptors; QmitkNodeDescriptor* lastDescriptor; // find all descriptors for the nodes (unique) - for( std::vector::const_iterator it = _Nodes.begin() - ; it != _Nodes.end(); ++it) + foreach (mitk::DataNode::Pointer node, _Nodes) { - lastDescriptor = this->GetDescriptor(*it); - if(std::find(nodeDescriptors.begin(), nodeDescriptors.end(), lastDescriptor) == nodeDescriptors.end()) - nodeDescriptors.push_back(lastDescriptor); + lastDescriptor = this->GetDescriptor(node); + nodeDescriptors.insert(lastDescriptor); } // add all actions for the found descriptors lastDescriptor = m_UnknownDataNodeDescriptor; - for( std::vector::const_iterator it = nodeDescriptors.begin() - ; it != nodeDescriptors.end(); ++it) + foreach (QmitkNodeDescriptor* descr, nodeDescriptors) { actions.append(lastDescriptor->GetSeparator()); - lastDescriptor = *it; + lastDescriptor = descr; actions.append(lastDescriptor->GetBatchActions()); } return actions; } QmitkNodeDescriptorManager::QmitkNodeDescriptorManager() : m_UnknownDataNodeDescriptor(new QmitkNodeDescriptor("Unknown", QString(":/Qmitk/DataTypeUnknown_48.png"), 0, this)) { this->Initialize(); } QmitkNodeDescriptorManager::~QmitkNodeDescriptorManager() { //delete m_UnknownDataNodeDescriptor; //qDeleteAll(m_NodeDescriptors); } QmitkNodeDescriptor* QmitkNodeDescriptorManager::GetUnknownDataNodeDescriptor() const { return m_UnknownDataNodeDescriptor; } diff --git a/CoreUI/Qmitk/QmitkNodeDescriptorManager.h b/CoreUI/Qmitk/QmitkNodeDescriptorManager.h index 5506aee32a..a387616f55 100644 --- a/CoreUI/Qmitk/QmitkNodeDescriptorManager.h +++ b/CoreUI/Qmitk/QmitkNodeDescriptorManager.h @@ -1,117 +1,117 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef QmitkNodeDescriptorManager_h #define QmitkNodeDescriptorManager_h #include #include "QmitkNodeDescriptor.h" /// /// \class QmitkNodeDescriptorManager /// \brief QmitkNodeDescriptorManager manages a set of QmitkNodeDescriptors /// /// \sa QmitkNodeDescriptor /// class QMITK_EXPORT QmitkNodeDescriptorManager : public QObject { Q_OBJECT public: /// /// \return the solely instance of QmitkNodeDescriptorManager /// static QmitkNodeDescriptorManager* GetInstance(); /// /// Initializes the QmitkNodeDescriptorManager. /// Adds a few standard Descriptors. /// This Descriptors are added: /// - A QmitkNodeDescriptor for the class of "Image" DataNodes /// - A QmitkNodeDescriptor for the class of "Image Mask" DataNodes /// - A QmitkNodeDescriptor for the class of "Surface" DataNodes /// - A QmitkNodeDescriptor for the class of "PointSet" DataNodes /// virtual void Initialize(); /// /// Adds a new descriptor to the manager. The manager takes the ownership. /// void AddDescriptor(QmitkNodeDescriptor* _Descriptor); /// /// Removes and deletes a descriptor from the manager /// void RemoveDescriptor(QmitkNodeDescriptor* _Descriptor); /// /// Get the last descriptor in the descriptors list that matches the given node. /// *Attention*: More specialized Descriptors should therefore be appended at /// the end of the list, e.g. first add "Image", then add "Image Mask" /// /// \return a QmitkNodeDescriptor for the given node or a QmitkNodeDescriptor describing unknown nodes (never 0) /// \sa AddDescriptor() /// QmitkNodeDescriptor* GetDescriptor(const mitk::DataNode* _Node) const; /// /// Get the last QmitkNodeDescriptor for the given class name /// /// \return a QmitkNodeDescriptor for the given class name or 0 if there is no QmitkNodeDescriptor for _ClassName /// QmitkNodeDescriptor* GetDescriptor(const QString& _ClassName) const; /// /// \return The UnknownDataNodeDescriptor, which is the default Descriptor for all Nodes. /// QmitkNodeDescriptor* GetUnknownDataNodeDescriptor() const; /// /// Returns a list of all actions that are associated with the given node. /// If there are more than one Descriptors for this node all actions /// will be merged together. /// E.g. all actions from the "unknown" DataNodes will be added to /// this list. Generic Actions like Save, Load, etc. are stored there. /// QList GetActions(const mitk::DataNode* _Node) const; /// /// \return a list of actions associated with the given nodes /// - QList GetActions( const std::vector& _Nodes ) const; + QList GetActions( const QList& _Nodes ) const; /// /// Deletes all Descriptors in the list /// virtual ~QmitkNodeDescriptorManager(); protected: /// /// Creates the m_UnknownDataNodeDescriptor /// Calls Initialize /// QmitkNodeDescriptorManager(); protected: /// /// This is the standard QmitkNodeDescriptor matching every node /// QmitkNodeDescriptor* m_UnknownDataNodeDescriptor; /// /// Holds all user defined descriptors /// QList m_NodeDescriptors; }; #endif // QmitkNodeDescriptorManager_h diff --git a/Modules/Bundles/org.mitk.gui.qt.datamanager/manifest_headers.cmake b/Modules/Bundles/org.mitk.gui.qt.datamanager/manifest_headers.cmake index 95f92932a6..bf7062d863 100644 --- a/Modules/Bundles/org.mitk.gui.qt.datamanager/manifest_headers.cmake +++ b/Modules/Bundles/org.mitk.gui.qt.datamanager/manifest_headers.cmake @@ -1,5 +1,5 @@ set(Plugin-Name "MITK Data Manager") set(Plugin-Version "1.0.0") set(Plugin-Vendor "DKFZ, Medical and Biological Informatics") set(Plugin-ContactAddress "http://www.mitk.org") -set(Require-Plugin org.mitk.gui.qt.common.legacy) +set(Require-Plugin org.mitk.gui.qt.common) diff --git a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp index 9e7f3b01e7..b63e0f40d5 100644 --- a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp @@ -1,1037 +1,895 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkDataManagerView.h" #include //# Own Includes //## mitk #include "mitkDataStorageEditorInput.h" #include "mitkIDataStorageReference.h" #include "mitkNodePredicateDataType.h" #include "mitkCoreObjectFactory.h" #include "mitkPACSPlugin.h" #include "mitkDataNodeFactory.h" #include "mitkColorProperty.h" #include "mitkCommon.h" #include "mitkDelegateManager.h" #include "mitkNodePredicateData.h" #include "mitkNodePredicateNot.h" #include "mitkNodePredicateProperty.h" #include "mitkEnumerationProperty.h" #include "mitkProperties.h" #include #include #include +#include //## Qmitk -#include +#include #include #include -#include #include #include #include #include #include "src/internal/QmitkNodeTableViewKeyFilter.h" #include "src/internal/QmitkInfoDialog.h" //## Berry #include #include #include #include //# Toolkit Includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "mitkDataNodeObject.h" #include "mitkIContextMenuAction.h" #include "berryIExtensionPointService.h" const std::string QmitkDataManagerView::VIEW_ID = "org.mitk.views.datamanager"; QmitkDataManagerView::QmitkDataManagerView() { } -QmitkDataManagerView::QmitkDataManagerView(const QmitkDataManagerView& other) -{ - Q_UNUSED(other) - throw std::runtime_error("Copy constructor not implemented"); -} - - QmitkDataManagerView::~QmitkDataManagerView() { - berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); - if(s) - s->RemoveSelectionListener(m_SelectionListener); - berry::IPreferencesService::Pointer prefService - = berry::Platform::GetServiceRegistry() - .GetServiceById(berry::IPreferencesService::ID); - - berry::IBerryPreferences::Pointer prefs - = (prefService->GetSystemPreferences()->Node(VIEW_ID)) - .Cast(); - prefs->OnChanged.RemoveListener( berry::MessageDelegate1( this - , &QmitkDataManagerView::OnPreferencesChanged ) ); } void QmitkDataManagerView::CreateQtPartControl(QWidget* parent) { m_CurrentRowCount = 0; m_Parent = parent; //# Preferences berry::IPreferencesService::Pointer prefService = berry::Platform::GetServiceRegistry() .GetServiceById(berry::IPreferencesService::ID); berry::IBerryPreferences::Pointer prefs = (prefService->GetSystemPreferences()->Node(VIEW_ID)) .Cast(); assert( prefs ); prefs->OnChanged.AddListener( berry::MessageDelegate1( this , &QmitkDataManagerView::OnPreferencesChanged ) ); //# GUI m_NodeTreeModel = new QmitkDataStorageTreeModel(this->GetDataStorage()); m_NodeTreeModel->setParent( parent ); m_NodeTreeModel->SetPlaceNewNodesOnTop( prefs->GetBool("Place new nodes on top", true) ); m_NodeTreeModel->SetShowHelperObjects( prefs->GetBool("Show helper objects", false) ); m_NodeTreeModel->SetShowNodesContainingNoData( prefs->GetBool("Show nodes containing no data", false) ); m_SurfaceDecimation = prefs->GetBool("Use surface decimation", false); //# Tree View (experimental) m_NodeTreeView = new QTreeView; m_NodeTreeView->setSelectionMode( QAbstractItemView::ExtendedSelection ); m_NodeTreeView->setSelectionBehavior( QAbstractItemView::SelectRows ); m_NodeTreeView->setAlternatingRowColors(true); m_NodeTreeView->setDragEnabled(true); m_NodeTreeView->setDropIndicatorShown(true); m_NodeTreeView->setAcceptDrops(true); m_NodeTreeView->setContextMenuPolicy(Qt::CustomContextMenu); m_NodeTreeView->setModel(m_NodeTreeModel); m_NodeTreeView->installEventFilter(new QmitkNodeTableViewKeyFilter(this)); QObject::connect( m_NodeTreeView, SIGNAL(customContextMenuRequested(const QPoint&)) , this, SLOT(NodeTableViewContextMenuRequested(const QPoint&)) ); QObject::connect( m_NodeTreeModel, SIGNAL(rowsInserted (const QModelIndex&, int, int)) , this, SLOT(NodeTreeViewRowsInserted ( const QModelIndex&, int, int )) ); QObject::connect( m_NodeTreeModel, SIGNAL(rowsRemoved (const QModelIndex&, int, int)) , this, SLOT(NodeTreeViewRowsRemoved( const QModelIndex&, int, int )) ); QObject::connect( m_NodeTreeView->selectionModel() , SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection & ) ) , this , SLOT( NodeSelectionChanged ( const QItemSelection &, const QItemSelection & ) ) ); //# m_NodeMenu m_NodeMenu = new QMenu(m_NodeTreeView); - //# m_SelectionProvider - m_SelectionProvider = new QmitkDataNodeSelectionProvider(); - m_SelectionProvider->SetItemSelectionModel(m_NodeTreeView->selectionModel()); - this->GetSite()->SetSelectionProvider(m_SelectionProvider); - // # Actions QmitkNodeDescriptor* unknownDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetUnknownDataNodeDescriptor(); QmitkNodeDescriptor* imageDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Image"); QmitkNodeDescriptor* surfaceDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Surface"); m_GlobalReinitAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Refresh_48.png"), "Global Reinit", this); QObject::connect( m_GlobalReinitAction, SIGNAL( triggered(bool) ) , this, SLOT( GlobalReinit(bool) ) ); unknownDataNodeDescriptor->AddAction(m_GlobalReinitAction); m_SaveAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Save_48.png"), "Save...", this); QObject::connect( m_SaveAction, SIGNAL( triggered(bool) ) , this, SLOT( SaveSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(m_SaveAction); m_RemoveAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Remove_48.png"), "Remove", this); QObject::connect( m_RemoveAction, SIGNAL( triggered(bool) ) , this, SLOT( RemoveSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(m_RemoveAction); m_ReinitAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Refresh_48.png"), "Reinit", this); QObject::connect( m_ReinitAction, SIGNAL( triggered(bool) ) , this, SLOT( ReinitSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(m_ReinitAction); // find contextMenuAction extension points and add them to the node descriptor berry::IExtensionPointService::Pointer extensionPointService = berry::Platform::GetExtensionPointService(); berry::IConfigurationElement::vector cmActions( extensionPointService->GetConfigurationElementsFor("org.mitk.gui.qt.datamanager.contextMenuActions") ); berry::IConfigurationElement::vector::iterator cmActionsIt; std::string cmNodeDescriptorName; std::string cmLabel; std::string cmIcon; std::string cmClass; QmitkNodeDescriptor* tmpDescriptor; QAction* contextMenuAction; QVariant cmActionDataIt; m_ConfElements.clear(); int i=1; for (cmActionsIt = cmActions.begin() ; cmActionsIt != cmActions.end() ; ++cmActionsIt) { cmIcon.erase(); if((*cmActionsIt)->GetAttribute("nodeDescriptorName", cmNodeDescriptorName) && (*cmActionsIt)->GetAttribute("label", cmLabel) && (*cmActionsIt)->GetAttribute("class", cmClass)) { (*cmActionsIt)->GetAttribute("icon", cmIcon); // create context menu entry here tmpDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor(QString::fromStdString(cmNodeDescriptorName)); if(!tmpDescriptor) { MITK_WARN << "cannot add action \"" << cmLabel << "\" because descriptor " << cmNodeDescriptorName << " does not exist"; continue; } contextMenuAction = new QAction( QString::fromStdString(cmLabel), parent); tmpDescriptor->AddAction(contextMenuAction); m_ConfElements[contextMenuAction] = *cmActionsIt; cmActionDataIt.setValue(i); contextMenuAction->setData( cmActionDataIt ); connect( contextMenuAction, SIGNAL( triggered(bool) ) , this, SLOT( ContextMenuActionTriggered(bool) ) ); ++i; } } m_OpacitySlider = new QSlider; m_OpacitySlider->setMinimum(0); m_OpacitySlider->setMaximum(100); m_OpacitySlider->setOrientation(Qt::Horizontal); QObject::connect( m_OpacitySlider, SIGNAL( valueChanged(int) ) , this, SLOT( OpacityChanged(int) ) ); QLabel* _OpacityLabel = new QLabel("Opacity: "); QHBoxLayout* _OpacityWidgetLayout = new QHBoxLayout; _OpacityWidgetLayout->setContentsMargins(4,4,4,4); _OpacityWidgetLayout->addWidget(_OpacityLabel); _OpacityWidgetLayout->addWidget(m_OpacitySlider); QWidget* _OpacityWidget = new QWidget; _OpacityWidget->setLayout(_OpacityWidgetLayout); m_OpacityAction = new QWidgetAction(this); m_OpacityAction->setDefaultWidget(_OpacityWidget); QObject::connect( m_OpacityAction, SIGNAL( changed() ) , this, SLOT( OpacityActionChanged() ) ); unknownDataNodeDescriptor->AddAction(m_OpacityAction, false); m_ColorButton = new QPushButton; m_ColorButton->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum); //m_ColorButton->setText("Change color"); QObject::connect( m_ColorButton, SIGNAL( clicked() ) , this, SLOT( ColorChanged() ) ); QLabel* _ColorLabel = new QLabel("Color: "); _ColorLabel->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); QHBoxLayout* _ColorWidgetLayout = new QHBoxLayout; _ColorWidgetLayout->setContentsMargins(4,4,4,4); _ColorWidgetLayout->addWidget(_ColorLabel); _ColorWidgetLayout->addWidget(m_ColorButton); QWidget* _ColorWidget = new QWidget; _ColorWidget->setLayout(_ColorWidgetLayout); m_ColorAction = new QWidgetAction(this); m_ColorAction->setDefaultWidget(_ColorWidget); QObject::connect( m_ColorAction, SIGNAL( changed() ) , this, SLOT( ColorActionChanged() ) ); unknownDataNodeDescriptor->AddAction(m_ColorAction, false); m_TextureInterpolation = new QAction("Texture Interpolation", this); m_TextureInterpolation->setCheckable ( true ); QObject::connect( m_TextureInterpolation, SIGNAL( changed() ) , this, SLOT( TextureInterpolationChanged() ) ); QObject::connect( m_TextureInterpolation, SIGNAL( toggled(bool) ) , this, SLOT( TextureInterpolationToggled(bool) ) ); imageDataNodeDescriptor->AddAction(m_TextureInterpolation, false); m_SurfaceRepresentation = new QAction("Surface Representation", this); m_SurfaceRepresentation->setMenu(new QMenu); QObject::connect( m_SurfaceRepresentation->menu(), SIGNAL( aboutToShow() ) , this, SLOT( SurfaceRepresentationMenuAboutToShow() ) ); surfaceDataNodeDescriptor->AddAction(m_SurfaceRepresentation, false); m_ShowOnlySelectedNodes = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/ShowSelectedNode_48.png") , "Show only selected nodes", this); QObject::connect( m_ShowOnlySelectedNodes, SIGNAL( triggered(bool) ) , this, SLOT( ShowOnlySelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(m_ShowOnlySelectedNodes); m_ToggleSelectedVisibility = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/InvertShowSelectedNode_48.png") , "Toggle visibility", this); QObject::connect( m_ToggleSelectedVisibility, SIGNAL( triggered(bool) ) , this, SLOT( ToggleVisibilityOfSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(m_ToggleSelectedVisibility); m_ActionShowInfoDialog = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/ShowDataInfo_48.png") , "Details...", this); QObject::connect( m_ActionShowInfoDialog, SIGNAL( triggered(bool) ) , this, SLOT( ShowInfoDialogForSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(m_ActionShowInfoDialog); m_OtsuFilterAction = new QAction("Apply Otsu Filter", this); QObject::connect( m_OtsuFilterAction, SIGNAL( triggered(bool) ) , this, SLOT( OtsuFilter(bool) ) ); // Otsu filter does not work properly, remove it temporarily // imageDataNodeDescriptor->AddAction(m_OtsuFilterAction); QGridLayout* _DndFrameWidgetLayout = new QGridLayout; _DndFrameWidgetLayout->addWidget(m_NodeTreeView, 0, 0); _DndFrameWidgetLayout->setContentsMargins(0,0,0,0); m_DndFrameWidget = new QmitkDnDFrameWidget(m_Parent); m_DndFrameWidget->setLayout(_DndFrameWidgetLayout); QVBoxLayout* layout = new QVBoxLayout(parent); layout->addWidget(m_DndFrameWidget); layout->setContentsMargins(0,0,0,0); m_Parent->setLayout(layout); - - m_SelectionListener = new berry::SelectionChangedAdapter - (this, &QmitkDataManagerView::SelectionChanged); - - berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); - s->AddSelectionListener(m_SelectionListener); - } void QmitkDataManagerView::SetFocus() { } void QmitkDataManagerView::ContextMenuActionTriggered( bool ) { QAction* action = qobject_cast ( sender() ); std::map::iterator it = m_ConfElements.find( action ); if( it == m_ConfElements.end() ) { MITK_WARN << "associated conf element for action " << action->text().toStdString() << " not found"; return; } berry::IConfigurationElement::Pointer confElem = it->second; mitk::IContextMenuAction* contextMenuAction = confElem->CreateExecutableExtension("class"); - if (contextMenuAction == 0) - { - // support legacy BlueBerry extensions - contextMenuAction = confElem->CreateExecutableExtension("class", mitk::IContextMenuAction::GetManifestName()); - } + std::string className; std::string smoothed; confElem->GetAttribute("class", className); confElem->GetAttribute("smoothed", smoothed); if(className == "QmitkThresholdAction") { contextMenuAction->SetDataStorage(this->GetDataStorage()); } - if(className == "QmitkCreatePolygonModelAction") + else if(className == "QmitkCreatePolygonModelAction") { contextMenuAction->SetDataStorage(this->GetDataStorage()); - QmitkStdMultiWidget* activeStdMultiWidget = 0; - berry::IEditorPart::Pointer editor = - this->GetSite()->GetPage()->GetActiveEditor(); - - if (editor.Cast().IsNotNull()) - { - activeStdMultiWidget = editor.Cast()->GetStdMultiWidget(); - } - else - { - mitk::DataStorageEditorInput::Pointer editorInput; - editorInput = new mitk::DataStorageEditorInput(); - // open a new multi-widget editor, but do not give it the focus - berry::IEditorPart::Pointer editor = this->GetSite()->GetPage()->OpenEditor(editorInput, QmitkStdMultiWidgetEditor::EDITOR_ID, false); - activeStdMultiWidget = editor.Cast()->GetStdMultiWidget(); - } - - contextMenuAction->SetStdMultiWidget(activeStdMultiWidget); if(smoothed == "false") { contextMenuAction->SetSmoothed(false); } else { contextMenuAction->SetSmoothed(true); } contextMenuAction->SetDecimated(m_SurfaceDecimation); } - if(className == "QmitkStatisticsAction") + else if(className == "QmitkStatisticsAction") { contextMenuAction->SetFunctionality(this); } - contextMenuAction->Run( this->GetSelectedNodes() ); // run the action -} - -mitk::DataStorage::Pointer QmitkDataManagerView::GetDataStorage() const -{ - mitk::IDataStorageService::Pointer service = - berry::Platform::GetServiceRegistry().GetServiceById(mitk::IDataStorageService::ID); - - if (service.IsNotNull()) - { - return service->GetDefaultDataStorage()->GetDataStorage(); - } - - return 0; + contextMenuAction->Run( this->GetCurrentSelection() ); // run the action } void QmitkDataManagerView::OnPreferencesChanged(const berry::IBerryPreferences* prefs) { if( m_NodeTreeModel->GetPlaceNewNodesOnTopFlag() != prefs->GetBool("Place new nodes on top", true) ) m_NodeTreeModel->SetPlaceNewNodesOnTop( !m_NodeTreeModel->GetPlaceNewNodesOnTopFlag() ); if( m_NodeTreeModel->GetShowHelperObjectsFlag()!= prefs->GetBool("Show helper objects", false) ) m_NodeTreeModel->SetShowHelperObjects( !m_NodeTreeModel->GetShowHelperObjectsFlag() ); if( m_NodeTreeModel->GetShowNodesContainingNoDataFlag()!= prefs->GetBool("Show nodes containing no data", false) ) m_NodeTreeModel->SetShowNodesContainingNoData( !m_NodeTreeModel->GetShowNodesContainingNoDataFlag() ); m_NodeTreeView->expandAll(); m_SurfaceDecimation = prefs->GetBool("Use surface decimation", false); this->GlobalReinit(); } void QmitkDataManagerView::NodeTableViewContextMenuRequested( const QPoint & pos ) { QModelIndex selected = m_NodeTreeView->indexAt ( pos ); mitk::DataNode::Pointer node = m_NodeTreeModel->GetNode(selected); - std::vector selectedNodes = this->GetSelectedNodes(); + QList selectedNodes = this->GetCurrentSelection(); - if(!selectedNodes.empty()) + if(!selectedNodes.isEmpty()) { m_NodeMenu->clear(); QList actions; if(selectedNodes.size() == 1 ) { actions = QmitkNodeDescriptorManager::GetInstance()->GetActions(node); for(QList::iterator it = actions.begin(); it != actions.end(); ++it) { (*it)->setData(QVariant::fromValue(node.GetPointer())); } } else actions = QmitkNodeDescriptorManager::GetInstance()->GetActions(selectedNodes); m_NodeMenu->addActions(actions); m_NodeMenu->popup(QCursor::pos()); } } void QmitkDataManagerView::OpacityChanged(int value) { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { float opacity = static_cast(value)/100.0f; node->SetFloatProperty("opacity", opacity); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } MITK_INFO << "slider changed"; } void QmitkDataManagerView::OpacityActionChanged() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { float opacity = 0.0; if(node->GetFloatProperty("opacity", opacity)) { m_OpacitySlider->setValue(static_cast(opacity*100)); } } MITK_INFO << "changed"; } void QmitkDataManagerView::ColorChanged() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { QColor color = QColorDialog::getColor(); m_ColorButton->setAutoFillBackground(true); node->SetProperty("color",mitk::ColorProperty::New(color.red()/255.0,color.green()/255.0,color.blue()/255.0)); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } MITK_INFO << "slider changed"; } void QmitkDataManagerView::ColorActionChanged() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { mitk::Color color; mitk::ColorProperty::Pointer colorProp; node->GetProperty(colorProp,"color"); if(colorProp.IsNull()) return; color = colorProp->GetValue(); QString styleSheet = "background-color:rgb("; styleSheet.append(QString::number(color[0]*255)); styleSheet.append(","); styleSheet.append(QString::number(color[1]*255)); styleSheet.append(","); styleSheet.append(QString::number(color[2]*255)); styleSheet.append(")"); m_ColorButton->setStyleSheet(styleSheet); } MITK_INFO << "changed"; } void QmitkDataManagerView::TextureInterpolationChanged() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { bool textureInterpolation = false; node->GetBoolProperty("texture interpolation", textureInterpolation); m_TextureInterpolation->setChecked(textureInterpolation); } } void QmitkDataManagerView::TextureInterpolationToggled( bool checked ) { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { node->SetBoolProperty("texture interpolation", checked); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkDataManagerView::SurfaceRepresentationMenuAboutToShow() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(!node) return; mitk::EnumerationProperty* representationProp = dynamic_cast (node->GetProperty("material.representation")); if(!representationProp) return; // clear menu m_SurfaceRepresentation->menu()->clear(); QAction* tmp; // create menu entries for(mitk::EnumerationProperty::EnumConstIterator it=representationProp->Begin(); it!=representationProp->End() ; it++) { tmp = m_SurfaceRepresentation->menu()->addAction(QString::fromStdString(it->second)); tmp->setCheckable(true); if(it->second == representationProp->GetValueAsString()) { tmp->setChecked(true); } QObject::connect( tmp, SIGNAL( triggered(bool) ) , this, SLOT( SurfaceRepresentationActionToggled(bool) ) ); } } void QmitkDataManagerView::SurfaceRepresentationActionToggled( bool /*checked*/ ) { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(!node) return; mitk::EnumerationProperty* representationProp = dynamic_cast (node->GetProperty("material.representation")); if(!representationProp) return; QAction* senderAction = qobject_cast ( QObject::sender() ); if(!senderAction) return; std::string activatedItem = senderAction->text().toStdString(); if ( activatedItem != representationProp->GetValueAsString() ) { if ( representationProp->IsValidEnumerationValue( activatedItem ) ) { representationProp->SetValue( activatedItem ); representationProp->InvokeEvent( itk::ModifiedEvent() ); representationProp->Modified(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } } void QmitkDataManagerView::SaveSelectedNodes( bool ) { QModelIndexList indexesOfSelectedRows = m_NodeTreeView->selectionModel()->selectedRows(); mitk::DataNode* node = 0; unsigned int indexesOfSelectedRowsSize = indexesOfSelectedRows.size(); for (unsigned int i = 0; iGetNode(indexesOfSelectedRows.at(i)); // if node is not defined or if the node contains geometry data do not remove it if ( node != 0 ) { mitk::BaseData::Pointer data = node->GetData(); if (data.IsNotNull()) { QString error; try { CommonFunctionality::SaveBaseData( data.GetPointer(), node->GetName().c_str() ); } catch(std::exception& e) { error = e.what(); } catch(...) { error = "Unknown error occured"; } if( !error.isEmpty() ) QMessageBox::critical( m_Parent, "Error saving...", error ); } } } } void QmitkDataManagerView::ReinitSelectedNodes( bool ) { - this->ReinitMultiWidgetEditor(); - std::vector selectedNodes = this->GetSelectedNodes(); + mitk::IRenderWindowPart* renderWindow = this->OpenRenderWindowPart(); - mitk::DataNode* node = 0; - for (std::vector::iterator it = selectedNodes.begin() - ; it != selectedNodes.end(); it++) + QList selectedNodes = this->GetCurrentSelection(); + + foreach(mitk::DataNode::Pointer node, selectedNodes) { - node = *it; mitk::BaseData::Pointer basedata = node->GetData(); if (basedata.IsNotNull()) { - mitk::RenderingManager::GetInstance()->InitializeViews( - basedata->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + renderWindow->GetRenderingManager()->InitializeViews( + basedata->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); + renderWindow->GetRenderingManager()->RequestUpdateAll(); } } } void QmitkDataManagerView::RemoveSelectedNodes( bool ) { QModelIndexList indexesOfSelectedRows = m_NodeTreeView->selectionModel()->selectedRows(); if(indexesOfSelectedRows.size() < 1) { return; } std::vector selectedNodes; mitk::DataNode* node = 0; QString question = tr("Do you really want to remove "); for (QModelIndexList::iterator it = indexesOfSelectedRows.begin() ; it != indexesOfSelectedRows.end(); it++) { node = m_NodeTreeModel->GetNode(*it); // if node is not defined or if the node contains geometry data do not remove it if ( node != 0 /*& strcmp(node->GetData()->GetNameOfClass(), "Geometry2DData") != 0*/ ) { selectedNodes.push_back(node); question.append(QString::fromStdString(node->GetName())); question.append(", "); } } // remove the last two characters = ", " question = question.remove(question.size()-2, 2); question.append(" from data storage?"); QMessageBox::StandardButton answerButton = QMessageBox::question( m_Parent , tr("DataManager") , question , QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if(answerButton == QMessageBox::Yes) { for (std::vector::iterator it = selectedNodes.begin() ; it != selectedNodes.end(); it++) { node = *it; this->GetDataStorage()->Remove(node); this->GlobalReinit(false); } } } void QmitkDataManagerView::MakeAllNodesInvisible( bool ) { - std::vector nodes = m_NodeTreeModel->GetNodeSet(); + QList nodes = m_NodeTreeModel->GetNodeSet(); - for (std::vector::iterator it = nodes.begin() - ; it != nodes.end(); it++) + foreach(mitk::DataNode::Pointer node, nodes) { - (*it)->SetVisibility(false); + node->SetVisibility(false); } //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkDataManagerView::ShowOnlySelectedNodes( bool ) { - std::vector selectedNodes = this->GetSelectedNodes(); - std::vector allNodes = m_NodeTreeModel->GetNodeSet(); - mitk::DataNode* node = 0; + QList selectedNodes = this->GetCurrentSelection(); + QList allNodes = m_NodeTreeModel->GetNodeSet(); - for (std::vector::iterator it = allNodes.begin() - ; it != allNodes.end(); it++) + foreach(mitk::DataNode::Pointer node, allNodes) { - node = *it; - if(std::find(selectedNodes.begin(), selectedNodes.end(), node) == selectedNodes.end()) - node->SetVisibility(false); - else - node->SetVisibility(true); + node->SetVisibility(selectedNodes.contains(node)); } //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkDataManagerView::ToggleVisibilityOfSelectedNodes( bool ) { - std::vector selectedNodes = this->GetSelectedNodes(); + QList selectedNodes = this->GetCurrentSelection(); bool isVisible = false; - mitk::DataNode* node = 0; - for (std::vector::iterator it = selectedNodes.begin() - ; it != selectedNodes.end(); it++) + foreach(mitk::DataNode::Pointer node, selectedNodes) { isVisible = false; - node = *it; node->GetBoolProperty("visible", isVisible); node->SetVisibility(!isVisible); } //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkDataManagerView::ShowInfoDialogForSelectedNodes( bool ) { - std::vector selectedNodes = this->GetSelectedNodes(); + QList selectedNodes = this->GetCurrentSelection(); QmitkInfoDialog _QmitkInfoDialog(selectedNodes, this->m_Parent); _QmitkInfoDialog.exec(); } void QmitkDataManagerView::Load( bool ) { QStringList fileNames = QFileDialog::getOpenFileNames(NULL, "Load data", "", mitk::CoreObjectFactory::GetInstance()->GetFileExtensions()); for ( QStringList::Iterator it = fileNames.begin(); it != fileNames.end(); ++it ) { FileOpen((*it).toAscii(), 0); } } void QmitkDataManagerView::FileOpen( const char * fileName, mitk::DataNode* parentNode ) { mitk::DataNodeFactory::Pointer factory = mitk::DataNodeFactory::New(); try { factory->SetFileName( fileName ); QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); factory->Update(); for ( unsigned int i = 0 ; i < factory->GetNumberOfOutputs( ); ++i ) { mitk::DataNode::Pointer node = factory->GetOutput( i ); if ( ( node.IsNotNull() ) && ( node->GetData() != NULL ) ) { this->GetDataStorage()->Add(node, parentNode); mitk::BaseData::Pointer basedata = node->GetData(); mitk::RenderingManager::GetInstance()->InitializeViews( basedata->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } } catch ( itk::ExceptionObject & ex ) { itkGenericOutputMacro( << "Exception during file open: " << ex ); } QApplication::restoreOverrideCursor(); } +QItemSelectionModel *QmitkDataManagerView::GetDataNodeSelectionModel() const +{ + return m_NodeTreeView->selectionModel(); +} + void QmitkDataManagerView::GlobalReinit( bool ) { - this->ReinitMultiWidgetEditor(); + mitk::IRenderWindowPart* renderWindow = this->OpenRenderWindowPart(); // get all nodes that have not set "includeInBoundingBox" to false mitk::NodePredicateNot::Pointer pred = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox" , mitk::BoolProperty::New(false))); mitk::DataStorage::SetOfObjects::ConstPointer rs = this->GetDataStorage()->GetSubset(pred); // calculate bounding geometry of these nodes mitk::TimeSlicedGeometry::Pointer bounds = this->GetDataStorage()->ComputeBoundingGeometry3D(rs, "visible"); // initialize the views to the bounding geometry - mitk::RenderingManager::GetInstance()->InitializeViews(bounds); -} - -std::vector QmitkDataManagerView::GetSelectedNodes() const -{ - QModelIndexList indexesOfSelectedRows = m_NodeTreeView->selectionModel()->selectedRows(); - std::vector selectedNodes; - - mitk::DataNode* node = 0; - for (QModelIndexList::iterator it = indexesOfSelectedRows.begin() - ; it != indexesOfSelectedRows.end(); it++) - { - node = 0; - node = m_NodeTreeModel->GetNode(*it); - // if node is not defined or if the node contains geometry data do not remove it - if ( node != 0 ) - selectedNodes.push_back(node); - } - - return selectedNodes; + renderWindow->GetRenderingManager()->InitializeViews(bounds); } -void QmitkDataManagerView::SelectionChanged( berry::IWorkbenchPart::Pointer part , berry::ISelection::ConstPointer selection ) +void QmitkDataManagerView::OnSelectionChanged( berry::IWorkbenchPart::Pointer part , const QList& selection ) { if(part.GetPointer() == this) return; - mitk::DataNodeSelection::ConstPointer _DataNodeSelection - = selection.Cast(); - if(_DataNodeSelection.IsNull()) - return; - - std::vector selectedNodes; - mitk::DataNodeObject* _DataNodeObject = 0; - mitk::DataNode* _DataNode = 0; QItemSelection newSelection; m_NodeTreeView->selectionModel()->reset(); - for(mitk::DataNodeSelection::iterator it = _DataNodeSelection->Begin(); - it != _DataNodeSelection->End(); ++it) + foreach(mitk::DataNode::Pointer node, selection) { - _DataNodeObject = dynamic_cast((*it).GetPointer()); - if(_DataNodeObject) - _DataNode = _DataNodeObject->GetDataNode(); - QModelIndex treeIndex = m_NodeTreeModel->GetIndex(_DataNode); + QModelIndex treeIndex = m_NodeTreeModel->GetIndex(node); if(treeIndex.isValid()) newSelection.select(treeIndex, treeIndex); } m_NodeTreeView->selectionModel()->select(newSelection, QItemSelectionModel::SelectCurrent); } void QmitkDataManagerView::OtsuFilter( bool ) { - std::vector selectedNodes = this->GetSelectedNodes(); + QList selectedNodes = this->GetCurrentSelection(); - mitk::DataNode* _DataNode = 0; mitk::Image::Pointer mitkImage = 0; - for (std::vector::iterator it = selectedNodes.begin() - ; it != selectedNodes.end(); it++) + foreach(mitk::DataNode::Pointer node, selectedNodes) { - _DataNode = *it; - mitkImage = dynamic_cast( _DataNode->GetData() ); + mitkImage = dynamic_cast( node->GetData() ); if(mitkImage.IsNull()) continue; try { // get selected mitk image const unsigned short dim = 3; typedef short InputPixelType; typedef unsigned char OutputPixelType; typedef itk::Image< InputPixelType, dim > InputImageType; typedef itk::Image< OutputPixelType, dim > OutputImageType; typedef itk::OtsuThresholdImageFilter< InputImageType, OutputImageType > FilterType; FilterType::Pointer filter = FilterType::New(); filter->SetOutsideValue( 1 ); filter->SetInsideValue( 0 ); InputImageType::Pointer itkImage; mitk::CastToItkImage(mitkImage, itkImage); filter->SetInput( itkImage ); filter->Update(); mitk::DataNode::Pointer resultNode = mitk::DataNode::New(); - std::string nameOfResultImage = _DataNode->GetName(); + std::string nameOfResultImage = node->GetName(); nameOfResultImage.append("Otsu"); resultNode->SetProperty("name", mitk::StringProperty::New(nameOfResultImage) ); resultNode->SetProperty("binary", mitk::BoolProperty::New(true) ); resultNode->SetData( mitk::ImportItkImage ( filter->GetOutput() ) ); - this->GetDataStorage()->Add(resultNode, _DataNode); + this->GetDataStorage()->Add(resultNode, node); } catch( std::exception& err ) { MITK_ERROR(this->GetClassName()) << err.what(); } } } void QmitkDataManagerView::NodeTreeViewRowsRemoved ( - const QModelIndex & parent, int start, int end ) + const QModelIndex & /*parent*/, int /*start*/, int /*end*/ ) { m_CurrentRowCount = m_NodeTreeModel->rowCount(); } void QmitkDataManagerView::NodeTreeViewRowsInserted( const QModelIndex & parent, int, int ) { m_NodeTreeView->setExpanded(parent, true); // a new row was inserted if( m_CurrentRowCount == 0 && m_NodeTreeModel->rowCount() == 1 ) { - this->ReinitMultiWidgetEditor(); + this->OpenRenderWindowPart(); m_CurrentRowCount = m_NodeTreeModel->rowCount(); /* std::vector nodes = m_NodeTreeModel->GetNodeSet(); if(nodes.size() == 1) { QModelIndex treeIndex = m_NodeTreeModel->GetIndex(nodes.front()); m_NodeTreeView->selectionModel()->setCurrentIndex( treeIndex, QItemSelectionModel::ClearAndSelect ); } */ } } void QmitkDataManagerView::NodeSelectionChanged( const QItemSelection & /*selected*/, const QItemSelection & /*deselected*/ ) { - std::vector nodes = m_NodeTreeModel->GetNodeSet(); - mitk::DataNode* node = 0; + QList nodes = m_NodeTreeModel->GetNodeSet(); - for (std::vector::iterator it = nodes.begin() - ; it != nodes.end(); it++) + foreach(mitk::DataNode::Pointer node, nodes) { - node = *it; - if ( node ) + if ( node.IsNotNull() ) node->SetBoolProperty("selected", false); } nodes.clear(); - nodes = this->GetSelectedNodes(); + nodes = this->GetCurrentSelection(); - for (std::vector::iterator it = nodes.begin() - ; it != nodes.end(); it++) + foreach(mitk::DataNode::Pointer node, nodes) { - node = *it; - if ( node ) + if ( node.IsNotNull() ) node->SetBoolProperty("selected", true); } //changing the selection does NOT require any rendering processes! //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } -void QmitkDataManagerView::ReinitMultiWidgetEditor() +mitk::IRenderWindowPart* QmitkDataManagerView::OpenRenderWindowPart() { - berry::IEditorPart::Pointer editor; - std::vector editors = - this->GetSite()->GetPage()->GetEditors(); - for (size_t i=0; i().IsNotNull() ) - { - editor = editors.at(i); - break; - } - } - - if ( editor.IsNull() ) - { - mitk::IDataStorageService::Pointer service = - berry::Platform::GetServiceRegistry().GetServiceById(mitk::IDataStorageService::ID); - - mitk::IDataStorageReference::Pointer DataStorageReference; - if (service.IsNotNull()) - { - DataStorageReference = service->GetDefaultDataStorage(); - } - mitk::DataStorageEditorInput::Pointer editorInput; - editorInput = new mitk::DataStorageEditorInput(DataStorageReference); - // open a new multi-widget editor, but do not give it the focus - berry::IEditorPart::Pointer editor = this->GetSite()->GetPage()->OpenEditor(editorInput, QmitkStdMultiWidgetEditor::EDITOR_ID, false); - } - else - this->GetSite()->GetPage()->OpenEditor(editor->GetEditorInput() - , QmitkStdMultiWidgetEditor::EDITOR_ID, true); + return this->GetRenderWindowPart(QmitkAbstractView::ACTIVATE | QmitkAbstractView::OPEN); } diff --git a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.h b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.h index 0d941cb85c..0e264906f9 100644 --- a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.h +++ b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.h @@ -1,272 +1,260 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef QMITKDATAMANAGERVIEW_H_ #define QMITKDATAMANAGERVIEW_H_ -// Own includes -#include -#include -#include -#include +// BlueBerry includes #include -#include /// Qmitk -#include -#include -#include +#include -#include -#include -#include +/// Qt +#include -#include #include // Forward declarations class QMenu; class QAction; class QComboBox; class QWidgetAction; class QSlider; class QModelIndex; class QTreeView; class QPushButton; class QToolBar; class QMenu; +class QmitkDnDFrameWidget; class QmitkDataStorageTreeModel; + /// /// \ingroup org_mitk_gui_qt_datamanager_internal /// /// \brief A View class that can show all data tree nodes of a certain DataStorage /// /// \TODO: complete PACS support, in save dialog show regular filename /// -class MITK_QT_DATAMANAGER QmitkDataManagerView : public berry::QtViewPart +class MITK_QT_DATAMANAGER QmitkDataManagerView : public QmitkAbstractView { Q_OBJECT public: static const std::string VIEW_ID; // = "org.mitk.extapp.defaultperspective" /// /// \brief Standard ctor. /// QmitkDataManagerView(); - QmitkDataManagerView(const QmitkDataManagerView& other); - /// /// \brief Standard dtor. /// virtual ~QmitkDataManagerView(); - /// - /// \brief Returns all selected nodes in a vector - /// - std::vector GetSelectedNodes() const; public slots: /// /// Invoked when the opacity slider changed /// void OpacityChanged(int value); /// /// Invoked when the opacity action changed /// In this function the the opacity slider is set to the selected nodes opacity value /// void OpacityActionChanged(); /// /// Invoked when the color button is pressed /// void ColorChanged(); /// /// Invoked when the color action changed /// void ColorActionChanged(); /// /// Invoked when the color button is pressed /// void TextureInterpolationChanged(); /// /// Invoked when the color action changed /// void TextureInterpolationToggled ( bool checked ); /// /// SurfaceRepresentationActionToggled /// void SurfaceRepresentationMenuAboutToShow (); ///public /// SurfaceRepresentationActionToggled /// void SurfaceRepresentationActionToggled ( bool checked ); /// /// \brief Shows a node context menu. /// void NodeTableViewContextMenuRequested( const QPoint & index ); /// /// \brief Invoked when an element should be saved. /// void SaveSelectedNodes( bool checked = false ); /// /// \brief Invoked when an element should be removed. /// void RemoveSelectedNodes( bool checked = false ); /// /// \brief Invoked when an element should be reinitiliased. /// void ReinitSelectedNodes( bool checked = false ); /// /// \brief Invoked when the visibility of the selected nodes should be toggled. /// void MakeAllNodesInvisible ( bool checked = false ); /// /// \brief Makes all selected nodes visible, all other nodes invisible. /// void ShowOnlySelectedNodes ( bool checked = false ); /// /// \brief Invoked when the visibility of the selected nodes should be toggled. /// void ToggleVisibilityOfSelectedNodes ( bool checked = false ); /// /// \brief Invoked when infos of the selected nodes should be shown in a dialog. /// void ShowInfoDialogForSelectedNodes ( bool checked = false ); /// /// \brief Shows a load dialog. /// void Load ( bool checked = false ); /// /// \brief Reinits everything. /// void GlobalReinit ( bool checked = false ); /// /// Invoked when the preferences were changed /// void OnPreferencesChanged(const berry::IBerryPreferences*); /// /// \brief will be toggled when a extension point context menu action is toggled /// this is a proxy method which will load the corresponding extension class /// and run IContextMenuAction /// void ContextMenuActionTriggered( bool ); /// - /// Invoked when the DataManager selection changed + /// Invoked when the MITK workbench selection changed /// - virtual void SelectionChanged(berry::IWorkbenchPart::Pointer part - , berry::ISelection::ConstPointer selection); + void OnSelectionChanged(berry::IWorkbenchPart::Pointer part, + const QList& selection); /// Invoked when the median action is invoked void OtsuFilter( bool checked = false ); /// When rows are inserted auto expand them void NodeTreeViewRowsInserted ( const QModelIndex & parent, int start, int end ); /// will setup m_CurrentRowCount void NodeTreeViewRowsRemoved ( const QModelIndex & parent, int start, int end ); /// Whenever the selection changes set the "selected" property respectively void NodeSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected ); protected: + /// /// \brief Create the view here. /// virtual void CreateQtPartControl(QWidget* parent); + void SetFocus(); - mitk::DataStorage::Pointer GetDataStorage() const; + /// /// \brief Shows a file open dialog. /// void FileOpen( const char * fileName, mitk::DataNode* parentNode ); + protected: + QWidget* m_Parent; QmitkDnDFrameWidget* m_DndFrameWidget; /// /// \brief A plain widget as the base pane. /// QmitkDataStorageTreeModel* m_NodeTreeModel; /// - /// \brief The BlueBerry selection provider - /// - QmitkDataNodeSelectionProvider::Pointer m_SelectionProvider; - /// /// Holds the preferences for the datamanager. /// berry::IBerryPreferences::Pointer m_DataManagerPreferencesNode; /// /// saves the configuration elements for the context menu actions from extension points /// std::map m_ConfElements; /// /// \brief The Table view to show the selected nodes. /// QTreeView* m_NodeTreeView; /// /// \brief The context menu that shows up when right clicking on a node. /// QMenu* m_NodeMenu; /// /// \brief flag indicating whether a surface created from a selected decimation is decimated with vtkQuadricDecimation or not /// bool m_SurfaceDecimation; ///# Actions for the Context Menu /// Global Reinit Action QAction* m_GlobalReinitAction; /// Save Action QAction* m_SaveAction; /// Remove Action QAction* m_RemoveAction; /// Reinit Action QAction* m_ReinitAction; /// A Slider widget to change the opacity of a node QSlider* m_OpacitySlider; /// Opacity action QWidgetAction* m_OpacityAction; /// button to change the color of a node QPushButton* m_ColorButton; /// Color action QWidgetAction* m_ColorAction; /// TextureInterpolation action QAction* m_TextureInterpolation; /// TextureInterpolation action QAction* m_SurfaceRepresentation; /// Show only selected nodes QAction* m_ShowOnlySelectedNodes; /// Toggles visibility of selected nodes QAction* m_ToggleSelectedVisibility; /// Shows infos for selected nodes QAction* m_ActionShowInfoDialog; /// Special filter action for images QAction* m_OtsuFilterAction; - /// A selection listener for datatreenode events - berry::ISelectionListener::Pointer m_SelectionListener; - /// berry::SelectionChangedAdapter must be a friend to call - friend struct berry::SelectionChangedAdapter; + /// saves the current amount of rows shown in the datamanager size_t m_CurrentRowCount; + private: + + QItemSelectionModel* GetDataNodeSelectionModel() const; + /// Reopen multi widget editor if it has been closed - void ReinitMultiWidgetEditor(); + mitk::IRenderWindowPart *OpenRenderWindowPart(); }; #endif /*QMITKDATAMANAGERVIEW_H_*/ diff --git a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkInfoDialog.cpp b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkInfoDialog.cpp index 0b1a7ce057..4d461f7eba 100644 --- a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkInfoDialog.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkInfoDialog.cpp @@ -1,128 +1,127 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkInfoDialog.h" #include "QmitkDataStorageComboBox.h" #include #include #include #include #include #include #include -QmitkInfoDialog::QmitkInfoDialog( std::vector _Nodes, QWidget * parent /*= 0*/, Qt::WindowFlags f /*= 0 */ ) +QmitkInfoDialog::QmitkInfoDialog( const QList &_Nodes, QWidget * parent /*= 0*/, Qt::WindowFlags f /*= 0 */ ) : QDialog(parent, f) { // DIM QGridLayout* parentLayout = new QGridLayout; QmitkDataStorageComboBox* _QmitkDataStorageComboBox = new QmitkDataStorageComboBox(this, true); m_KeyWord = new QLineEdit; m_KeyWord->installEventFilter(this); m_SearchButton = new QPushButton("Search (F3)", this); m_SearchButton->installEventFilter(this); m_TextBrowser = new QTextBrowser(this); QPushButton* _CancelButton = new QPushButton("Cancel", this); // SET this->setMinimumSize(512, 512); this->setLayout(parentLayout); this->setSizeGripEnabled(true); this->setModal(true); parentLayout->addWidget(_QmitkDataStorageComboBox, 0, 0, 1, 2); parentLayout->addWidget(m_KeyWord, 1, 0); parentLayout->addWidget(m_SearchButton, 1, 1); parentLayout->addWidget(m_TextBrowser, 2, 0, 1, 2); parentLayout->addWidget(_CancelButton, 3, 0, 1, 2); QObject::connect( _QmitkDataStorageComboBox, SIGNAL( OnSelectionChanged( const mitk::DataNode* ) ) , this, SLOT( OnSelectionChanged( const mitk::DataNode* ) ) ); - for (std::vector::iterator it = _Nodes.begin() - ; it != _Nodes.end(); it++) + foreach(mitk::DataNode::Pointer node, _Nodes) { - _QmitkDataStorageComboBox->AddNode(*it); + _QmitkDataStorageComboBox->AddNode(node); } QObject::connect( m_KeyWord, SIGNAL( textChanged ( const QString & ) ) , this, SLOT( KeyWordTextChanged(const QString &) ) ); QObject::connect( m_SearchButton, SIGNAL( clicked ( bool ) ) , this, SLOT( OnSearchButtonClicked( bool ) ) ); QObject::connect( _CancelButton, SIGNAL( clicked ( bool ) ) , this, SLOT( OnCancelButtonClicked( bool ) ) ); _CancelButton->setDefault(true); } void QmitkInfoDialog::OnSelectionChanged( const mitk::DataNode* node ) { std::ostringstream s; itk::Indent i(2); mitk::BaseData* _BaseData = node->GetData(); if(_BaseData) _BaseData->Print(s, i); m_TextBrowser->setPlainText(QString::fromStdString(s.str())); } void QmitkInfoDialog::OnSearchButtonClicked( bool /*checked*/ /*= false */ ) { QString keyWord = m_KeyWord->text(); QString text = m_TextBrowser->toPlainText(); if(keyWord.isEmpty() || text.isEmpty()) return; m_TextBrowser->find(keyWord); m_SearchButton->setText("Search Next(F3)"); } void QmitkInfoDialog::OnCancelButtonClicked( bool /*checked*/ /*= false */ ) { this->done(0); } bool QmitkInfoDialog::eventFilter( QObject *obj, QEvent *event ) { if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast(event); if(keyEvent->key() == Qt::Key_F3 || keyEvent->key() == Qt::Key_Return) { // trigger deletion of selected node(s) this->OnSearchButtonClicked(true); // return true: this means the delete key event is not send to the table return true; } } // standard event processing return QObject::eventFilter(obj, event); } void QmitkInfoDialog::KeyWordTextChanged(const QString & /*text*/) { QTextCursor textCursor = m_TextBrowser->textCursor(); textCursor.setPosition(0); m_TextBrowser->setTextCursor(textCursor); m_SearchButton->setText("Search (F3)"); } diff --git a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkInfoDialog.h b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkInfoDialog.h index bfdd1cbdb1..d8da23143d 100644 --- a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkInfoDialog.h +++ b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkInfoDialog.h @@ -1,56 +1,51 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef QMITKINFODIALOG_H_ #define QMITKINFODIALOG_H_ -#include +#include #include -//class QmitkDataStorageComboBox; -namespace mitk -{ - class DataNode; -} class QTextBrowser; class QLineEdit; /// /// A small class which "eats" all Del-Key-pressed events on the node table. /// When the Del Key is pressed selected nodes should be removed. /// class QmitkInfoDialog : public QDialog { Q_OBJECT public: - QmitkInfoDialog( std::vector _Nodes, QWidget * parent = 0, Qt::WindowFlags f = 0 ); + QmitkInfoDialog(const QList& _Nodes, QWidget * parent = 0, Qt::WindowFlags f = 0 ); public slots: void OnSelectionChanged(const mitk::DataNode*); void OnSearchButtonClicked ( bool checked = false ); void OnCancelButtonClicked ( bool checked = false ); void KeyWordTextChanged(const QString & text); protected: bool eventFilter(QObject *obj, QEvent *event); protected: QLineEdit* m_KeyWord; QPushButton* m_SearchButton; QTextBrowser* m_TextBrowser; }; -#endif // QMITKINFODIALOG_H_ \ No newline at end of file +#endif // QMITKINFODIALOG_H_ diff --git a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkPropertyListView.cpp b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkPropertyListView.cpp index ffe3bd4507..6b48081a14 100644 --- a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkPropertyListView.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkPropertyListView.cpp @@ -1,58 +1,59 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include #include #include #include #include "QmitkPropertyListView.h" #include #include #include #include const std::string QmitkPropertyListView::VIEW_ID = "org.mitk.views.propertylistview"; QmitkPropertyListView::QmitkPropertyListView() { } QmitkPropertyListView::~QmitkPropertyListView() { } void QmitkPropertyListView::CreateQtPartControl( QWidget* parent ) { m_NodePropertiesTableEditor = new QmitkPropertiesTableEditor; QVBoxLayout* layout = new QVBoxLayout; layout->addWidget(m_NodePropertiesTableEditor); parent->setLayout(layout); } -void QmitkPropertyListView::OnSelectionChanged( std::vector nodes ) +void QmitkPropertyListView::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*part*/, + const QList &nodes) { - if (nodes.empty() || (nodes.front() == NULL)) return; + if (nodes.empty() || (nodes.front().IsNull())) return; m_NodePropertiesTableEditor->SetPropertyList(nodes.front()->GetPropertyList()); } -bool QmitkPropertyListView::IsExclusiveFunctionality() const +void QmitkPropertyListView::SetFocus() { - return false; + m_NodePropertiesTableEditor->setFocus(); } diff --git a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkPropertyListView.h b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkPropertyListView.h index 4255f37021..c7a5c75a95 100644 --- a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkPropertyListView.h +++ b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/internal/QmitkPropertyListView.h @@ -1,77 +1,77 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef QmitkPropertyListView_h_ #define QmitkPropertyListView_h_ // Own includes -#include +#include + #include -#include #include class QmitkPropertiesTableEditor; /// /// A view to show /// -class MITK_QT_DATAMANAGER QmitkPropertyListView : public QmitkFunctionality +class QmitkPropertyListView : public QmitkAbstractView { Q_OBJECT public: berryObjectMacro(QmitkPropertyListView) /// /// The unique ID of this view /// static const std::string VIEW_ID; + /// /// \brief Standard ctor. /// QmitkPropertyListView(); /// /// \brief Standard dtor. /// virtual ~QmitkPropertyListView(); /// /// \brief Create the view here. /// void CreateQtPartControl(QWidget* parent); - /// - /// This is not a standalone functionality (can be easily used with other functionalities open) -> return false - /// - virtual bool IsExclusiveFunctionality() const; - /// /// Invoked when the DataManager selection changed /// - virtual void OnSelectionChanged(std::vector nodes); + virtual void OnSelectionChanged(berry::IWorkbenchPart::Pointer part, const QList& nodes); + +protected: + + void SetFocus(); private: /// /// \brief The properties table editor. /// QmitkPropertiesTableEditor* m_NodePropertiesTableEditor; friend struct berry::SelectionChangedAdapter; }; #endif /*QmitkPropertyListView_H_*/ diff --git a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/mitkIContextMenuAction.h b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/mitkIContextMenuAction.h index 5ed494012d..d0b7ae1b70 100644 --- a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/mitkIContextMenuAction.h +++ b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/mitkIContextMenuAction.h @@ -1,42 +1,41 @@ #ifndef mitkIContextMenuAction_H_ #define mitkIContextMenuAction_H_ #include #include #include #include #include "mitkDataStorage.h" class QmitkStdMultiWidget; namespace mitk { /** * A context menu action, which is linked to the context menu
* through an extension point. For an example check the
* plugin.xml and the connected classes of
* the the segmentation bundle and also the QmitkDataManagerView.cpp
* in this bundle. */ struct IContextMenuAction { berryInterfaceMacro(IContextMenuAction, mitk) /** * @brief Executes the action, that linked to the context menu entry. */ - virtual void Run( const std::vector& selectedNodes ) = 0; + virtual void Run( const QList& selectedNodes ) = 0; // Setters virtual void SetDataStorage(mitk::DataStorage* dataStorage) = 0; - virtual void SetStdMultiWidget(QmitkStdMultiWidget *stdMultiWidget) = 0; virtual void SetSmoothed(bool smoothed) = 0; virtual void SetDecimated(bool decimated) = 0; virtual void SetFunctionality(berry::QtViewPart* functionality) = 0; }; } Q_DECLARE_INTERFACE(mitk::IContextMenuAction, "org.mitk.datamanager.IContextMenuAction") #endif // mitkIContextMenuAction_H_ diff --git a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkAutocropAction.cpp b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkAutocropAction.cpp index 4728de952c..d6612e12f6 100644 --- a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkAutocropAction.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkAutocropAction.cpp @@ -1,146 +1,137 @@ #include "QmitkAutocropAction.h" #include "mitkAutoCropImageFilter.h" #include "mitkImageCast.h" #include "mitkRenderingManager.h" #include "mitkProgressBar.h" #include //needed for qApp #include QmitkAutocropAction::QmitkAutocropAction() { } QmitkAutocropAction::~QmitkAutocropAction() { } -void QmitkAutocropAction::Run( const std::vector& selectedNodes ) +void QmitkAutocropAction::Run( const QList &selectedNodes ) { - NodeList selection = selectedNodes; - - for ( NodeList::iterator iter = selection.begin(); iter != selection.end(); ++iter ) + foreach ( mitk::DataNode::Pointer node, selectedNodes ) { - mitk::DataNode* node = *iter; - if (node) { mitk::Image::Pointer image = dynamic_cast( node->GetData() ); if (image.IsNull()) return; mitk::ProgressBar::GetInstance()->AddStepsToDo(10); mitk::ProgressBar::GetInstance()->Progress(2); qApp->processEvents(); mitk::AutoCropImageFilter::Pointer cropFilter = mitk::AutoCropImageFilter::New(); cropFilter->SetInput( image ); cropFilter->SetBackgroundValue( 0 ); try { cropFilter->Update(); image = cropFilter->GetOutput(); if (image.IsNotNull()) { node->SetData( this->IncreaseCroppedImageSize(image) ); // bug fix 3145 // Reinit node mitk::RenderingManager::GetInstance()->InitializeViews( node->GetData()->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } catch(...) { MITK_ERROR << "Cropping image failed..."; } mitk::ProgressBar::GetInstance()->Progress(8); } else { MITK_INFO << " a NULL node selected"; } } } mitk::Image::Pointer QmitkAutocropAction::IncreaseCroppedImageSize( mitk::Image::Pointer image ) { typedef itk::Image< short, 3 > ImageType; typedef itk::Image< unsigned char, 3 > PADOutputImageType; ImageType::Pointer itkTransformImage = ImageType::New(); mitk::CastToItkImage( image, itkTransformImage ); typedef itk::ConstantPadImageFilter< ImageType, PADOutputImageType > PadFilterType; PadFilterType::Pointer padFilter = PadFilterType::New(); unsigned long upperPad[3]; unsigned long lowerPad[3]; int borderLiner = 3; mitk::Point3D mitkOriginPoint; double origin[3]; origin[0]=0; origin[1]=0; origin[2]=0; itkTransformImage->SetOrigin(origin); lowerPad[0]=borderLiner; lowerPad[1]=borderLiner; lowerPad[2]=borderLiner; upperPad[0]=borderLiner; upperPad[1]=borderLiner; upperPad[2]=borderLiner; padFilter->SetInput(itkTransformImage); padFilter->SetConstant(0); padFilter->SetPadUpperBound(upperPad); padFilter->SetPadLowerBound(lowerPad); padFilter->UpdateLargestPossibleRegion(); mitk::Image::Pointer paddedImage = mitk::Image::New(); paddedImage->InitializeByItk(padFilter->GetOutput()); mitk::CastToMitkImage(padFilter->GetOutput(), paddedImage); //calculate translation according to padding to get the new origin mitk::Point3D paddedOrigin = image->GetGeometry()->GetOrigin(); mitk::Vector3D spacing = image->GetGeometry()->GetSpacing(); paddedOrigin[0] -= (borderLiner)*spacing[0]; paddedOrigin[1] -= (borderLiner)*spacing[1]; paddedOrigin[2] -= (borderLiner)*spacing[2]; paddedImage->GetGeometry()->SetOrigin( paddedOrigin ); return paddedImage; } void QmitkAutocropAction::SetSmoothed(bool /*smoothed*/) { //not needed } -void QmitkAutocropAction::SetDecimated(bool decimated) -{ - //not needed -} - -void QmitkAutocropAction::SetDataStorage(mitk::DataStorage* dataStorage) +void QmitkAutocropAction::SetDecimated(bool /*decimated*/) { //not needed } -void QmitkAutocropAction::SetStdMultiWidget(QmitkStdMultiWidget *) +void QmitkAutocropAction::SetDataStorage(mitk::DataStorage* /*dataStorage*/) { //not needed } void QmitkAutocropAction::SetFunctionality(berry::QtViewPart */*functionality*/) { //not needed } diff --git a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkAutocropAction.h b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkAutocropAction.h index 6b2e088b4d..54e8556be9 100644 --- a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkAutocropAction.h +++ b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkAutocropAction.h @@ -1,42 +1,41 @@ #ifndef QMITK_AUTOCROPACTION_H #define QMITK_AUTOCROPACTION_H #include "mitkIContextMenuAction.h" #include "org_mitk_gui_qt_segmentation_Export.h" #include "vector" #include "mitkDataNode.h" #include "mitkImage.h" class QmitkStdMultiWidget; class MITK_QT_SEGMENTATION QmitkAutocropAction : public QObject, public mitk::IContextMenuAction { Q_OBJECT Q_INTERFACES(mitk::IContextMenuAction) public: QmitkAutocropAction(); virtual ~QmitkAutocropAction(); //interface methods - void Run( const std::vector& selectedNodes ); + void Run( const QList& selectedNodes ); void SetDataStorage(mitk::DataStorage* dataStorage); - void SetStdMultiWidget(QmitkStdMultiWidget *stdMultiWidget); void SetSmoothed(bool smoothed); void SetDecimated(bool decimated); void SetFunctionality(berry::QtViewPart* functionality); protected: mitk::Image::Pointer IncreaseCroppedImageSize( mitk::Image::Pointer image ); private: - typedef std::vector NodeList; + typedef QList NodeList; }; #endif // QMITK_AUTOCROPACTION_H diff --git a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkCreatePolygonModelAction.cpp b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkCreatePolygonModelAction.cpp index 9851a30d01..a467d1bd2f 100644 --- a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkCreatePolygonModelAction.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkCreatePolygonModelAction.cpp @@ -1,144 +1,151 @@ #include "QmitkCreatePolygonModelAction.h" // MITK #include #include #include #include #include +#include +#include + // Blueberry #include -#include +#include +#include using namespace berry; using namespace mitk; using namespace std; QmitkCreatePolygonModelAction::QmitkCreatePolygonModelAction() - : m_StdMultiWidget(0) { } QmitkCreatePolygonModelAction::~QmitkCreatePolygonModelAction() { } -void QmitkCreatePolygonModelAction::Run(const vector &selectedNodes) +void QmitkCreatePolygonModelAction::Run(const QList &selectedNodes) { DataNode::Pointer selectedNode = selectedNodes[0]; Image::Pointer image = dynamic_cast(selectedNode->GetData()); if (image.IsNull()) return; try { if (!m_IsSmoothed) { ShowSegmentationAsSurface::Pointer surfaceFilter = ShowSegmentationAsSurface::New(); itk::SimpleMemberCommand::Pointer successCommand = itk::SimpleMemberCommand::New(); successCommand->SetCallbackFunction(this, &QmitkCreatePolygonModelAction::OnSurfaceCalculationDone); surfaceFilter->AddObserver(ResultAvailable(), successCommand); itk::SimpleMemberCommand::Pointer errorCommand = itk::SimpleMemberCommand::New(); errorCommand->SetCallbackFunction(this, &QmitkCreatePolygonModelAction::OnSurfaceCalculationDone); surfaceFilter->AddObserver(ProcessingError(), errorCommand); surfaceFilter->SetDataStorage(*m_DataStorage); surfaceFilter->SetPointerParameter("Input", image); surfaceFilter->SetPointerParameter("Group node", selectedNode); surfaceFilter->SetParameter("Show result", true); surfaceFilter->SetParameter("Sync visibility", false); surfaceFilter->SetParameter("Smooth", false); surfaceFilter->SetParameter("Apply median", false); surfaceFilter->SetParameter("Median kernel size", 3u); surfaceFilter->SetParameter("Gaussian SD", 1.5f); surfaceFilter->SetParameter("Decimate mesh", m_IsDecimated); surfaceFilter->SetParameter("Decimation rate", 0.8f); StatusBar::GetInstance()->DisplayText("Surface creation started in background..."); surfaceFilter->StartAlgorithm(); } else { ShowSegmentationAsSmoothedSurface::Pointer surfaceFilter = ShowSegmentationAsSmoothedSurface::New(); itk::SimpleMemberCommand::Pointer successCommand = itk::SimpleMemberCommand::New(); successCommand->SetCallbackFunction(this, &QmitkCreatePolygonModelAction::OnSurfaceCalculationDone); surfaceFilter->AddObserver(mitk::ResultAvailable(), successCommand); itk::SimpleMemberCommand::Pointer errorCommand = itk::SimpleMemberCommand::New(); errorCommand->SetCallbackFunction(this, &QmitkCreatePolygonModelAction::OnSurfaceCalculationDone); surfaceFilter->AddObserver(mitk::ProcessingError(), errorCommand); surfaceFilter->SetDataStorage(*m_DataStorage); surfaceFilter->SetPointerParameter("Input", image); surfaceFilter->SetPointerParameter("Group node", selectedNode); - int timeNr = m_StdMultiWidget != 0 ? m_StdMultiWidget->GetTimeNavigationController()->GetTime()->GetPos() : 0; + berry::IWorkbenchPart::Pointer activePart = + berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetActivePage()->GetActivePart(); + mitk::IRenderWindowPart* renderPart = dynamic_cast(activePart.GetPointer()); + mitk::SliceNavigationController* timeNavController = 0; + if (renderPart != 0) + { + timeNavController = renderPart->GetRenderingManager()->GetTimeNavigationController(); + } + + int timeNr = timeNavController != 0 ? timeNavController->GetTime()->GetPos() : 0; surfaceFilter->SetParameter("TimeNr", timeNr); IPreferencesService::Pointer prefService = Platform::GetServiceRegistry().GetServiceById(IPreferencesService::ID); IPreferences::Pointer segPref = prefService->GetSystemPreferences()->Node("/org.mitk.views.segmentation"); bool smoothingHint = segPref->GetBool("smoothing hint", true); float smoothing = (float)segPref->GetDouble("smoothing value", 1.0); float decimation = (float)segPref->GetDouble("decimation rate", 0.5); float closing = (float)segPref->GetDouble("closing ratio", 0.0); if (smoothingHint) { smoothing = 0.0; Vector3D spacing = image->GetGeometry()->GetSpacing(); for (Vector3D::Iterator iter = spacing.Begin(); iter != spacing.End(); ++iter) smoothing = max(smoothing, *iter); } surfaceFilter->SetParameter("Smoothing", smoothing); surfaceFilter->SetParameter("Decimation", decimation); surfaceFilter->SetParameter("Closing", closing); ProgressBar::GetInstance()->AddStepsToDo(8); StatusBar::GetInstance()->DisplayText("Smoothed surface creation started in background..."); surfaceFilter->StartAlgorithm(); } } catch(...) { MITK_ERROR << "Surface creation failed!"; } } void QmitkCreatePolygonModelAction::OnSurfaceCalculationDone() { StatusBar::GetInstance()->Clear(); } void QmitkCreatePolygonModelAction::SetDataStorage(DataStorage *dataStorage) { m_DataStorage = dataStorage; } -void QmitkCreatePolygonModelAction::SetStdMultiWidget(QmitkStdMultiWidget *stdMultiWidget) -{ - m_StdMultiWidget = stdMultiWidget; -} - void QmitkCreatePolygonModelAction::SetSmoothed(bool smoothed) { m_IsSmoothed = smoothed; } void QmitkCreatePolygonModelAction::SetDecimated(bool decimated) { m_IsDecimated = decimated; } void QmitkCreatePolygonModelAction::SetFunctionality(QtViewPart *) { } diff --git a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkCreatePolygonModelAction.h b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkCreatePolygonModelAction.h index 379a59027e..cea5805fa9 100644 --- a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkCreatePolygonModelAction.h +++ b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkCreatePolygonModelAction.h @@ -1,44 +1,42 @@ #ifndef QMITKCREATEPOLYGONMODELACTION_H #define QMITKCREATEPOLYGONMODELACTION_H #include // Parent classes #include #include // Data members #include class QmitkStdMultiWidget; class MITK_QT_SEGMENTATION QmitkCreatePolygonModelAction : public QObject, public mitk::IContextMenuAction { Q_OBJECT Q_INTERFACES(mitk::IContextMenuAction) public: QmitkCreatePolygonModelAction(); ~QmitkCreatePolygonModelAction(); // IContextMenuAction - void Run(const std::vector &selectedNodes); + void Run(const QList &selectedNodes); void SetDataStorage(mitk::DataStorage *dataStorage); - void SetStdMultiWidget(QmitkStdMultiWidget *stdMultiWidget); void SetSmoothed(bool smoothed); void SetDecimated(bool decimated); void SetFunctionality(berry::QtViewPart *functionality); void OnSurfaceCalculationDone(); private: QmitkCreatePolygonModelAction(const QmitkCreatePolygonModelAction &); QmitkCreatePolygonModelAction & operator=(const QmitkCreatePolygonModelAction &); mitk::DataStorage::Pointer m_DataStorage; - QmitkStdMultiWidget *m_StdMultiWidget; bool m_IsSmoothed; bool m_IsDecimated; }; #endif diff --git a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkStatisticsAction.cpp b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkStatisticsAction.cpp index 7f806ac9d3..8ae4b2ceaf 100644 --- a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkStatisticsAction.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkStatisticsAction.cpp @@ -1,45 +1,40 @@ #include "QmitkStatisticsAction.h" QmitkStatisticsAction::QmitkStatisticsAction(): m_BlueBerryView(NULL) { } QmitkStatisticsAction::~QmitkStatisticsAction() { } -void QmitkStatisticsAction::Run(const std::vector& selectedNodes) +void QmitkStatisticsAction::Run(const QList& /*selectedNodes*/) { berry::IBundle::Pointer imageStatisticsBundle = berry::Platform::GetBundle("org.mitk.gui.qt.imagestatistics"); if (m_BlueBerryView && imageStatisticsBundle.IsNotNull()) { m_BlueBerryView->GetSite()->GetWorkbenchWindow()->GetActivePage()->ShowView("org.mitk.views.imagestatistics"); } } void QmitkStatisticsAction::SetFunctionality(berry::QtViewPart* functionality) { this->m_BlueBerryView = functionality; } void QmitkStatisticsAction::SetDataStorage(mitk::DataStorage* /*dataStorage*/) { //not needed } -void QmitkStatisticsAction::SetStdMultiWidget(QmitkStdMultiWidget *) -{ - // not needed -} - void QmitkStatisticsAction::SetSmoothed(bool /*smoothed*/) { //not needed } void QmitkStatisticsAction::SetDecimated(bool /*decimated*/) { //not needed } diff --git a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkStatisticsAction.h b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkStatisticsAction.h index 79e0a78bf6..21a181da3a 100644 --- a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkStatisticsAction.h +++ b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkStatisticsAction.h @@ -1,36 +1,35 @@ #ifndef QMITK_STATISTICSACTION_H #define QMITK_STATISTICSACTION_H #include #include "berryQtViewPart.h" #include "mitkIContextMenuAction.h" #include "org_mitk_gui_qt_segmentation_Export.h" class QmitkStdMultiWidget; class MITK_QT_SEGMENTATION QmitkStatisticsAction: public QObject, public mitk::IContextMenuAction { Q_OBJECT Q_INTERFACES(mitk::IContextMenuAction) public: QmitkStatisticsAction(); virtual ~QmitkStatisticsAction(); //interface methods - void Run( const std::vector& selectedNodes ); + void Run( const QList& selectedNodes ); void SetDataStorage(mitk::DataStorage* dataStorage); - void SetStdMultiWidget(QmitkStdMultiWidget *stdMultiWidget); void SetSmoothed(bool smoothed); void SetDecimated(bool decimated); void SetFunctionality(berry::QtViewPart* functionality); protected: //needs to be set over the IContextMenuAction (with this - QmitkDataManagerView - as parameter) berry::QtViewPart* m_BlueBerryView; }; #endif // QMITK_STATISTICSACTION_H diff --git a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkThresholdAction.cpp b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkThresholdAction.cpp index edf34fbf77..e48fdcad33 100644 --- a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkThresholdAction.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkThresholdAction.cpp @@ -1,103 +1,99 @@ #include "QmitkThresholdAction.h" // MITK #include #include #include // Qt #include #include using namespace berry; using namespace mitk; using namespace std; QmitkThresholdAction::QmitkThresholdAction() : m_ThresholdingDialog(NULL) { } QmitkThresholdAction::~QmitkThresholdAction() { } -void QmitkThresholdAction::Run(const vector &selectedNodes) +void QmitkThresholdAction::Run(const QList &selectedNodes) { m_ThresholdingToolManager = ToolManager::New(m_DataStorage); m_ThresholdingToolManager->RegisterClient(); m_ThresholdingToolManager->ActiveToolChanged += mitk::MessageDelegate(this, &QmitkThresholdAction::OnThresholdingToolManagerToolModified); m_ThresholdingDialog = new QDialog; connect(m_ThresholdingDialog, SIGNAL(finished(int)), this, SLOT(ThresholdingDone(int))); QVBoxLayout *layout = new QVBoxLayout; layout->setContentsMargins(0, 0, 0, 0); Tool *binaryThresholdTool = m_ThresholdingToolManager->GetToolById(m_ThresholdingToolManager->GetToolIdByToolType()); if (binaryThresholdTool != NULL) { QmitkToolGUI *gui = dynamic_cast(binaryThresholdTool->GetGUI("Qmitk", "GUI").GetPointer()); if (gui != NULL) { gui->SetTool(binaryThresholdTool); gui->setParent(m_ThresholdingDialog); layout->addWidget(gui); m_ThresholdingDialog->setLayout(layout); m_ThresholdingDialog->setFixedSize(300, 80); m_ThresholdingDialog->open(); } m_ThresholdingToolManager->SetReferenceData(selectedNodes[0]); m_ThresholdingToolManager->ActivateTool(m_ThresholdingToolManager->GetToolIdByToolType()); } } void QmitkThresholdAction::ThresholdingDone(int result) { if (result == QDialog::Rejected) m_ThresholdingToolManager->ActivateTool(-1); m_ThresholdingDialog->deleteLater(); m_ThresholdingDialog = NULL; m_ThresholdingToolManager->SetReferenceData(NULL); m_ThresholdingToolManager->SetWorkingData(NULL); RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkThresholdAction::OnThresholdingToolManagerToolModified() { if (m_ThresholdingToolManager.IsNotNull()) if (m_ThresholdingToolManager->GetActiveToolID() < 0) if (m_ThresholdingDialog != NULL) m_ThresholdingDialog->accept(); } void QmitkThresholdAction::SetDataStorage(DataStorage *dataStorage) { m_DataStorage = dataStorage; } -void QmitkThresholdAction::SetStdMultiWidget(QmitkStdMultiWidget *) -{ -} - void QmitkThresholdAction::SetSmoothed(bool) { } void QmitkThresholdAction::SetDecimated(bool) { } void QmitkThresholdAction::SetFunctionality(QtViewPart */*functionality*/) { } diff --git a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkThresholdAction.h b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkThresholdAction.h index 31c86be488..467469e44a 100644 --- a/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkThresholdAction.h +++ b/Modules/Bundles/org.mitk.gui.qt.segmentation/src/internal/QmitkThresholdAction.h @@ -1,48 +1,47 @@ #ifndef QMITKTHRESHOLDACTION_H #define QMITKTHRESHOLDACTION_H #include // Parent classes #include #include // Data members #include #include class QDialog; class QmitkStdMultiWidget; class MITK_QT_SEGMENTATION QmitkThresholdAction : public QObject, public mitk::IContextMenuAction { Q_OBJECT Q_INTERFACES(mitk::IContextMenuAction) public: QmitkThresholdAction(); ~QmitkThresholdAction(); // IContextMenuAction - void Run(const std::vector &selectedNodes); + void Run(const QList &selectedNodes); void SetDataStorage(mitk::DataStorage *dataStorage); - void SetStdMultiWidget(QmitkStdMultiWidget *stdMultiWidget); void SetSmoothed(bool smoothed); void SetDecimated(bool decimated); void SetFunctionality(berry::QtViewPart *functionality); void OnThresholdingToolManagerToolModified(); private slots: void ThresholdingDone(int); private: QmitkThresholdAction(const QmitkThresholdAction &); QmitkThresholdAction & operator=(const QmitkThresholdAction &); mitk::DataStorage::Pointer m_DataStorage; mitk::ToolManager::Pointer m_ThresholdingToolManager; QDialog *m_ThresholdingDialog; }; #endif