diff --git a/Examples/Plugins/org.mitk.example.gui.customviewer/src/internal/CustomViewerWorkbenchWindowAdvisor.cpp b/Examples/Plugins/org.mitk.example.gui.customviewer/src/internal/CustomViewerWorkbenchWindowAdvisor.cpp index 702e98c500..297db86eea 100644 --- a/Examples/Plugins/org.mitk.example.gui.customviewer/src/internal/CustomViewerWorkbenchWindowAdvisor.cpp +++ b/Examples/Plugins/org.mitk.example.gui.customviewer/src/internal/CustomViewerWorkbenchWindowAdvisor.cpp @@ -1,166 +1,167 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "CustomViewerWorkbenchWindowAdvisor.h" #include "QtPerspectiveSwitcherTabBar.h" #include "org_mitk_example_gui_customviewer_Activator.h" #include #include #include #include #include #include -#include #include +#include #include #include CustomViewerWorkbenchWindowAdvisor::CustomViewerWorkbenchWindowAdvisor( berry::IWorkbenchWindowConfigurer::Pointer configurer) : berry::WorkbenchWindowAdvisor(configurer) { } CustomViewerWorkbenchWindowAdvisor::~CustomViewerWorkbenchWindowAdvisor() { } void CustomViewerWorkbenchWindowAdvisor::PostWindowCreate() { // for stylesheet customization // static_cast(this->GetWindowConfigurer()->GetWindow()->GetShell()->GetControl())->dumpObjectTree(); } // //! [CustomViewerWorkbenchWindowAdvisorPreWindowOpen] void CustomViewerWorkbenchWindowAdvisor::PreWindowOpen() { berry::IWorkbenchWindowConfigurer::Pointer configurer = this->GetWindowConfigurer(); configurer->SetTitle("Spartan Viewer"); configurer->SetShowMenuBar(false); configurer->SetShowToolBar(false); configurer->SetShowPerspectiveBar(false); configurer->SetShowStatusLine(false); } // //! [CustomViewerWorkbenchWindowAdvisorPreWindowOpen] // //! [WorkbenchWindowAdvisorCreateWindowContentsHead] void CustomViewerWorkbenchWindowAdvisor::CreateWindowContents(berry::Shell::Pointer shell) { // the all containing main window QMainWindow *mainWindow = static_cast(shell->GetControl()); // //! [WorkbenchWindowAdvisorCreateWindowContentsHead] mainWindow->setVisible(true); // the widgets QWidget *CentralWidget = new QWidget(mainWindow); CentralWidget->setObjectName("CentralWidget"); CentralWidget->setVisible(true); QtPerspectiveSwitcherTabBar *PerspectivesTabBar = new QtPerspectiveSwitcherTabBar(this->GetWindowConfigurer()->GetWindow()); PerspectivesTabBar->setObjectName("PerspectivesTabBar"); PerspectivesTabBar->addTab("Image Viewer"); PerspectivesTabBar->addTab("DICOM-Manager"); PerspectivesTabBar->setVisible(true); PerspectivesTabBar->setDrawBase(false); QPushButton *StyleUpdateButton = new QPushButton("Update Style", mainWindow); StyleUpdateButton->setMaximumWidth(100); StyleUpdateButton->setObjectName("StyleUpdateButton"); QObject::connect(StyleUpdateButton, SIGNAL(clicked()), this, SLOT(UpdateStyle())); QToolButton *OpenFileButton = new QToolButton(mainWindow); OpenFileButton->setMaximumWidth(100); OpenFileButton->setObjectName("FileOpenButton"); OpenFileButton->setText("Open File"); QObject::connect(OpenFileButton, SIGNAL(clicked()), this, SLOT(OpenFile())); QWidget *PageComposite = new QWidget(CentralWidget); PageComposite->setObjectName("PageComposite"); PageComposite->setVisible(true); // the layouts QVBoxLayout *CentralWidgetLayout = new QVBoxLayout(CentralWidget); CentralWidgetLayout->contentsMargins(); CentralWidgetLayout->setContentsMargins(9, 9, 9, 9); CentralWidgetLayout->setSpacing(0); CentralWidgetLayout->setObjectName("CentralWidgetLayout"); QHBoxLayout *PerspectivesLayer = new QHBoxLayout(mainWindow); PerspectivesLayer->setObjectName("PerspectivesLayer"); QHBoxLayout *PageCompositeLayout = new QHBoxLayout(PageComposite); PageCompositeLayout->setContentsMargins(0, 0, 0, 0); PageCompositeLayout->setSpacing(0); PageComposite->setLayout(PageCompositeLayout); // //! [WorkbenchWindowAdvisorCreateWindowContents] // all glued together mainWindow->setCentralWidget(CentralWidget); CentralWidgetLayout->addLayout(PerspectivesLayer); CentralWidgetLayout->addWidget(PageComposite); CentralWidget->setLayout(CentralWidgetLayout); PerspectivesLayer->addWidget(PerspectivesTabBar); PerspectivesLayer->addSpacing(300); PerspectivesLayer->addWidget(OpenFileButton); // for style customization convenience /*PerspectivesLayer->addSpacing(10); PerspectivesLayer->addWidget(StyleUpdateButton);*/ // for correct initial layout, see also bug#1654 CentralWidgetLayout->activate(); CentralWidgetLayout->update(); this->GetWindowConfigurer()->CreatePageComposite(PageComposite); // //! [WorkbenchWindowAdvisorCreateWindowContents] } // //! [WorkbenchWindowAdvisorUpdateStyle] void CustomViewerWorkbenchWindowAdvisor::UpdateStyle() { ctkPluginContext *pluginContext = org_mitk_example_gui_customviewer_Activator::GetPluginContext(); ctkServiceReference serviceReference = pluginContext->getServiceReference(); // granted by org.blueberry.ui.qt Q_ASSERT(serviceReference); berry::IQtStyleManager *styleManager = pluginContext->getService(serviceReference); Q_ASSERT(styleManager); styleManager->SetStyle("/home/me/customstyle.qss"); } // //! [WorkbenchWindowAdvisorUpdateStyle] // //! [WorkbenchWindowAdvisorOpenFile] + void CustomViewerWorkbenchWindowAdvisor::OpenFile() { - // Ask the user for a list of files to open - QStringList fileNames = QFileDialog::getOpenFileNames(nullptr, - "Open", - /*d->getLastFileOpenPath()*/ QString(), - mitk::CoreObjectFactory::GetInstance()->GetFileExtensions()); + QStringList fileNames = QFileDialog::getOpenFileNames( + nullptr, + QStringLiteral("Open"), + QString(), + QmitkIOUtil::GetFileOpenFilterString()); if (fileNames.empty()) return; mitk::WorkbenchUtil::LoadFiles(fileNames, this->GetWindowConfigurer()->GetWindow(), false); // //! [WorkbenchWindowAdvisorOpenFile] // //! [WorkbenchWindowAdvisorOpenFilePerspActive] berry::IWorkbenchWindow::Pointer window = this->GetWindowConfigurer()->GetWindow(); QString perspectiveId = "org.mitk.example.viewerperspective"; window->GetWorkbench()->ShowPerspective(perspectiveId, berry::IWorkbenchWindow::Pointer(window)); // //! [WorkbenchWindowAdvisorOpenFilePerspActive] } diff --git a/Plugins/org.mitk.gui.qt.datamanagerlight/CMakeLists.txt b/Plugins/org.mitk.gui.qt.datamanagerlight/CMakeLists.txt index 6b0ab31aa0..1d7f02526c 100644 --- a/Plugins/org.mitk.gui.qt.datamanagerlight/CMakeLists.txt +++ b/Plugins/org.mitk.gui.qt.datamanagerlight/CMakeLists.txt @@ -1,6 +1,7 @@ project(org_mitk_gui_qt_datamanagerlight) mitk_create_plugin( EXPORT_DIRECTIVE MITK_QT_DATAMANAGER EXPORTED_INCLUDE_SUFFIXES src + MODULE_DEPENDS MitkQtWidgets ) diff --git a/Plugins/org.mitk.gui.qt.datamanagerlight/src/internal/QmitkDataManagerLightView.cpp b/Plugins/org.mitk.gui.qt.datamanagerlight/src/internal/QmitkDataManagerLightView.cpp index 1154474c1d..50182c7332 100644 --- a/Plugins/org.mitk.gui.qt.datamanagerlight/src/internal/QmitkDataManagerLightView.cpp +++ b/Plugins/org.mitk.gui.qt.datamanagerlight/src/internal/QmitkDataManagerLightView.cpp @@ -1,258 +1,257 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkDataManagerLightView.h" #include "mitkNodePredicateDataType.h" #include #include #include #include #include #include #include #include -#include #include #include #include -#include +#include const std::string QmitkDataManagerLightView::VIEW_ID = "org.mitk.views.datamanagerlight"; struct QmitkDataManagerLightViewData { // static mitk::NodePredicateBase::Pointer m_Predicate; QIcon m_ItemIcon; // data QList m_DataNodes; int m_CurrentIndex; // widget QListWidget* m_ListWidget; QLabel* m_ImageInfoLabel; QPushButton* m_RemoveButton; }; QmitkDataManagerLightView::QmitkDataManagerLightView() : d( new QmitkDataManagerLightViewData ) { d->m_Predicate = mitk::NodePredicateDataType::New("Image"); d->m_ItemIcon = QIcon(":/org.mitk.gui.qt.datamanagerlight/Image_24.png"); d->m_CurrentIndex = -1; d->m_ListWidget = 0; d->m_ImageInfoLabel = 0; d->m_RemoveButton = 0; } QmitkDataManagerLightView::~QmitkDataManagerLightView() { delete d; } void QmitkDataManagerLightView::NodeAdded(const mitk::DataNode *node) { if( d->m_Predicate->CheckNode(node) ) { mitk::DataNode* nonConstNode = const_cast(node); d->m_DataNodes.append(nonConstNode); d->m_ListWidget->addItem( new QListWidgetItem( d->m_ItemIcon, QString::fromStdString( node->GetName() ) ) ); } } void QmitkDataManagerLightView::NodeRemoved(const mitk::DataNode *node) { this->RemoveNode( const_cast(node) ); } void QmitkDataManagerLightView::NodeChanged(const mitk::DataNode *node) { MITK_DEBUG << "NodeChanged"; if( d->m_DataNodes.contains(const_cast(node)) ) this->ToggleVisibility(); } void QmitkDataManagerLightView::RemoveNode(mitk::DataNode *node) { mitk::DataNode* nonConstNode = const_cast(node); int index = d->m_DataNodes.indexOf(nonConstNode); if( index >= 0 ) { MITK_DEBUG << "removing node at: " << index; QListWidgetItem* item = d->m_ListWidget->takeItem(index); delete item; d->m_DataNodes.removeAt(index); MITK_DEBUG << "item deleted"; } } void QmitkDataManagerLightView::CreateQtPartControl(QWidget* parent) { QPushButton* loadButton = new QPushButton(QIcon(":/org.mitk.gui.qt.datamanagerlight/Load_48.png"), "Load"); d->m_RemoveButton = new QPushButton(QIcon(":/org.mitk.gui.qt.datamanagerlight/Remove_48.png"), "Remove"); d->m_RemoveButton->setEnabled(false); d->m_ListWidget = new QListWidget; d->m_ImageInfoLabel = new QLabel; QGridLayout* layout = new QGridLayout; layout->addWidget( loadButton, 0,0 ); layout->addWidget( d->m_RemoveButton, 0,1 ); layout->addWidget( d->m_ImageInfoLabel, 1,0, 1, 2 ); layout->addWidget( d->m_ListWidget, 2,0,1,2 ); parent->setLayout(layout); connect(d->m_ListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(on_DataItemList_currentRowChanged(int)) ); connect(loadButton, SIGNAL(pressed()), this, SLOT(on_Load_pressed()) ); connect(d->m_RemoveButton, SIGNAL(pressed()), this, SLOT(on_Remove_pressed()) ); this->ListSelectionChanged(); } void QmitkDataManagerLightView::SetFocus() { d->m_ListWidget->setFocus(); } void QmitkDataManagerLightView::on_DataItemList_currentRowChanged(int currentRow) { MITK_DEBUG << "DataItemList currentRowChanged: " << currentRow; Q_UNUSED(currentRow) this->ListSelectionChanged(); } void QmitkDataManagerLightView::ListSelectionChanged() { d->m_CurrentIndex = d->m_ListWidget->currentRow(); MITK_DEBUG << "the currently selected index: " << d->m_CurrentIndex; QString newLabelText = "Current patient: "; if( d->m_CurrentIndex >= 0 ) { // TODO WHERE IS THE PATIENT NAME? std::string name = d->m_DataNodes.at(d->m_CurrentIndex)->GetName(); newLabelText.append( QString("%1" ).arg( QString::fromStdString(name) ) ); d->m_RemoveButton->setEnabled(true); } else { newLabelText.append("Unknown"); d->m_RemoveButton->setEnabled(false); } d->m_ImageInfoLabel->setText(newLabelText); this->ToggleVisibility(); } void QmitkDataManagerLightView::on_Load_pressed() { MITK_DEBUG << "on_Load_pressed"; - QStringList fileNames = QFileDialog::getOpenFileNames(nullptr, "Load data", "", mitk::CoreObjectFactory::GetInstance()->GetFileExtensions()); + QStringList fileNames = QFileDialog::getOpenFileNames(nullptr, "Load data", "", QmitkIOUtil::GetFileOpenFilterString()); for ( QStringList::Iterator it = fileNames.begin(); it != fileNames.end(); ++it ) { FileOpen((*it).toLatin1(), 0); } } void QmitkDataManagerLightView::FileOpen( const char * fileName, mitk::DataNode* /*parentNode*/ ) { try { QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); mitk::IOUtil::Load(fileName, *this->GetDataStorage()); mitk::RenderingManager::GetInstance()->InitializeViews(); } catch ( itk::ExceptionObject & ex ) { MITK_ERROR << "Exception during file open: " << ex; } QApplication::restoreOverrideCursor(); } void QmitkDataManagerLightView::on_Remove_pressed() { d->m_CurrentIndex = d->m_ListWidget->currentRow(); MITK_DEBUG << "the currently selected index: " << d->m_CurrentIndex; mitk::DataNode* node = d->m_DataNodes.at(d->m_CurrentIndex); QString question = tr("Do you really want to remove "); // TODO patient name? question.append( QString::fromStdString( node->GetName() ) ); question.append(" ?"); QMessageBox::StandardButton answerButton = QMessageBox::question( nullptr , tr("DataManagerLight") , question , QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if(answerButton == QMessageBox::Yes) { this->GetDataStorage()->Remove(node); this->GlobalReinit(); } } void QmitkDataManagerLightView::GlobalReinit() { mitk::IRenderWindowPart* renderWindow = this->GetRenderWindowPart(); // no render window available if (renderWindow == nullptr) return; // 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::TimeGeometry::Pointer bounds = this->GetDataStorage()->ComputeBoundingGeometry3D(rs, "visible"); // initialize the views to the bounding geometry renderWindow->GetRenderingManager()->InitializeViews(bounds); } void QmitkDataManagerLightView::ToggleVisibility() { bool changedAnything = false; bool isVisible = false; for(size_t i=0; im_DataNodes.size(); ++i) { isVisible = false; d->m_DataNodes.at(i)->GetVisibility(isVisible, 0 ); if( d->m_CurrentIndex == i && isVisible == false ) { d->m_DataNodes.at(i)->SetVisibility(true); changedAnything = true; } else if( d->m_CurrentIndex != i && isVisible == true ) { d->m_DataNodes.at(i)->SetVisibility(false); changedAnything = true; } } if( changedAnything ) mitk::RenderingManager::GetInstance()->RequestUpdateAll(); }