diff --git a/Modules/QtWidgets/src/QmitkAutomatedLayoutWidget.cpp b/Modules/QtWidgets/src/QmitkAutomatedLayoutWidget.cpp index f0897a3d6b..5404d060f1 100644 --- a/Modules/QtWidgets/src/QmitkAutomatedLayoutWidget.cpp +++ b/Modules/QtWidgets/src/QmitkAutomatedLayoutWidget.cpp @@ -1,62 +1,62 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include <QmitkAutomatedLayoutWidget.h> #include <mitkNodePredicateDataType.h> #include <mitkNodePredicateAnd.h> #include <mitkNodePredicateNot.h> #include <mitkNodePredicateProperty.h> #include <mitkImage.h> #include <ui_QmitkAutomatedLayoutWidget.h> QmitkAutomatedLayoutWidget::QmitkAutomatedLayoutWidget(QWidget* parent) : QWidget(parent) - , m_Controls(nullptr) + , m_Controls(new Ui::QmitkAutomatedLayoutWidget) { m_Controls->setupUi(this); auto isImage = mitk::TNodePredicateDataType<mitk::Image>::New(); auto isNotHelper = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("helper object")); auto isNotHidden = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("hidden object")); auto isValidImage = mitk::NodePredicateAnd::New(isImage, isNotHelper, isNotHidden); m_Controls->dataSelector->SetNodePredicate(isValidImage); m_Controls->dataSelector->SetInvalidInfo(QStringLiteral("Please select images for the layout")); m_Controls->dataSelector->SetPopUpTitel(QStringLiteral("Select input images")); m_Controls->dataSelector->SetPopUpHint(QStringLiteral("Select as many images as you want to compare")); m_Controls->setLayoutButton->setEnabled(false); connect(m_Controls->dataSelector, &QmitkMultiNodeSelectionWidget::DialogClosed, this, &QmitkAutomatedLayoutWidget::OnSelectionDialogClosed); connect(m_Controls->setLayoutButton, &QPushButton::clicked, this, &QmitkAutomatedLayoutWidget::OnSetLayoutClicked); } void QmitkAutomatedLayoutWidget::SetDataStorage(mitk::DataStorage::Pointer dataStorage) { // smart pointer to data storage needs to be saved here because dataSelector makes it a regular pointer m_DataStorage = dataStorage; m_Controls->dataSelector->SetDataStorage(m_DataStorage); } void QmitkAutomatedLayoutWidget::OnSetLayoutClicked() { auto selectedNodes = m_Controls->dataSelector->GetSelectedNodes(); emit SetDataBasedLayout(selectedNodes); this->hide(); } void QmitkAutomatedLayoutWidget::OnSelectionDialogClosed() { bool setLayoutEnabled = m_Controls->dataSelector->GetSelectedNodes().size() > 0; m_Controls->setLayoutButton->setEnabled(setLayoutEnabled); this->show(); } diff --git a/Modules/QtWidgets/src/QmitkMultiWidgetLayoutSelectionWidget.cpp b/Modules/QtWidgets/src/QmitkMultiWidgetLayoutSelectionWidget.cpp index 7c76184229..da35c00133 100644 --- a/Modules/QtWidgets/src/QmitkMultiWidgetLayoutSelectionWidget.cpp +++ b/Modules/QtWidgets/src/QmitkMultiWidgetLayoutSelectionWidget.cpp @@ -1,160 +1,160 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include <QmitkMultiWidgetLayoutSelectionWidget.h> #include <ui_QmitkMultiWidgetLayoutSelectionWidget.h> #include <QFileDialog> #include <usGetModuleContext.h> #include <usModuleContext.h> #include <usModuleResource.h> #include <usModuleResourceStream.h> QmitkMultiWidgetLayoutSelectionWidget::QmitkMultiWidgetLayoutSelectionWidget(QWidget* parent/* = 0*/) : QWidget(parent) - , ui(nullptr) + , ui(new Ui::QmitkMultiWidgetLayoutSelectionWidget) { Init(); } void QmitkMultiWidgetLayoutSelectionWidget::Init() { ui->setupUi(this); auto stylesheet = "QTableWidget::item{background-color: white;}\nQTableWidget::item:selected{background-color: #1C97EA;}"; ui->tableWidget->setStyleSheet(stylesheet); m_AutomatedDataLayoutWidget = new QmitkAutomatedLayoutWidget(this); connect(m_AutomatedDataLayoutWidget, &QmitkAutomatedLayoutWidget::SetDataBasedLayout, this, &QmitkMultiWidgetLayoutSelectionWidget::SetDataBasedLayout); m_AutomatedDataLayoutWidget->hide(); connect(ui->tableWidget, &QTableWidget::itemSelectionChanged, this, &QmitkMultiWidgetLayoutSelectionWidget::OnTableItemSelectionChanged); connect(ui->setLayoutPushButton, &QPushButton::clicked, this, &QmitkMultiWidgetLayoutSelectionWidget::OnSetLayoutButtonClicked); connect(ui->dataBasedLayoutButton, &QPushButton::clicked, this, &QmitkMultiWidgetLayoutSelectionWidget::OnDataBasedLayoutButtonClicked); connect(ui->loadLayoutPushButton, &QPushButton::clicked, this, &QmitkMultiWidgetLayoutSelectionWidget::OnLoadLayoutButtonClicked); connect(ui->saveLayoutPushButton, &QPushButton::clicked, this, &QmitkMultiWidgetLayoutSelectionWidget::OnSaveLayoutButtonClicked); connect(ui->selectDefaultLayoutComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QmitkMultiWidgetLayoutSelectionWidget::OnLayoutPresetSelected); ui->selectDefaultLayoutComboBox->addItem("Select a layout preset"); auto presetResources = us::GetModuleContext()->GetModule()->FindResources("/", "mxnLayout_*.json", false); for (const auto& resource : presetResources) { us::ModuleResourceStream jsonStream(resource); auto data = nlohmann::json::parse(jsonStream); auto resourceName = data["name"].get<std::string>(); ui->selectDefaultLayoutComboBox->addItem(QString::fromStdString(resourceName)); m_PresetMap[ui->selectDefaultLayoutComboBox->count() - 1] = data; } } void QmitkMultiWidgetLayoutSelectionWidget::SetDataStorage(mitk::DataStorage::Pointer dataStorage) { if (m_AutomatedDataLayoutWidget == nullptr) return; m_AutomatedDataLayoutWidget->SetDataStorage(dataStorage); } void QmitkMultiWidgetLayoutSelectionWidget::OnTableItemSelectionChanged() { QItemSelectionModel* selectionModel = ui->tableWidget->selectionModel(); int row = 0; int column = 0; QModelIndexList indices = selectionModel->selectedIndexes(); if (indices.size() > 0) { row = indices[0].row(); column = indices[0].column(); QModelIndex topLeft = ui->tableWidget->model()->index(0, 0, QModelIndex()); QModelIndex bottomRight = ui->tableWidget->model()->index(row, column, QModelIndex()); QItemSelection cellSelection; cellSelection.select(topLeft, bottomRight); selectionModel->select(cellSelection, QItemSelectionModel::Select); } } void QmitkMultiWidgetLayoutSelectionWidget::OnSetLayoutButtonClicked() { int row = 0; int column = 0; QModelIndexList indices = ui->tableWidget->selectionModel()->selectedIndexes(); if (indices.size() > 0) { // find largest row and column for (const auto& modelIndex : std::as_const(indices)) { if (modelIndex.row() > row) { row = modelIndex.row(); } if (modelIndex.column() > column) { column = modelIndex.column(); } } close(); emit LayoutSet(row+1, column+1); } ui->selectDefaultLayoutComboBox->setCurrentIndex(0); } void QmitkMultiWidgetLayoutSelectionWidget::OnDataBasedLayoutButtonClicked() { this->hide(); m_AutomatedDataLayoutWidget->setWindowFlags(Qt::Popup); m_AutomatedDataLayoutWidget->move(this->pos().x() - m_AutomatedDataLayoutWidget->width() + this->width(), this->pos().y()); m_AutomatedDataLayoutWidget->show(); } void QmitkMultiWidgetLayoutSelectionWidget::OnSaveLayoutButtonClicked() { QString filename = QFileDialog::getSaveFileName(nullptr, "Select where to save the current layout", "", "MITK Window Layout (*.json)"); if (filename.isEmpty()) return; QString fileExt(".json"); if (!filename.endsWith(fileExt)) filename += fileExt; auto outStream = std::ofstream(filename.toStdString()); emit SaveLayout(&outStream); } void QmitkMultiWidgetLayoutSelectionWidget::OnLoadLayoutButtonClicked() { QString filename = QFileDialog::getOpenFileName(nullptr, "Load a layout file", "", "MITK Window Layouts (*.json)"); if (filename.isEmpty()) return; ui->selectDefaultLayoutComboBox->setCurrentIndex(0); std::ifstream f(filename.toStdString()); auto jsonData = nlohmann::json::parse(f); emit LoadLayout(&jsonData); } void QmitkMultiWidgetLayoutSelectionWidget::OnLayoutPresetSelected(int index) { if (index == 0) { // First entry is only for description return; } auto jsonData = m_PresetMap[index]; close(); emit LoadLayout(&jsonData); }