diff --git a/Modules/QmitkExt/QmitkLineEdit.cpp b/Modules/QmitkExt/QmitkLineEdit.cpp deleted file mode 100644 index c3a667d038..0000000000 --- a/Modules/QmitkExt/QmitkLineEdit.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/*=================================================================== - -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 "QmitkLineEdit.h" -#include - -QmitkLineEdit::QmitkLineEdit(QWidget* parent) - : QLineEdit(parent) -{ - this->Initialize(); -} - -QmitkLineEdit::QmitkLineEdit(const QString& defaultText, QWidget* parent) - : QLineEdit(parent), - m_DefaultText(defaultText) -{ - this->Initialize(); -} - -QmitkLineEdit::~QmitkLineEdit() -{ -} - -void QmitkLineEdit::focusInEvent(QFocusEvent* event) -{ - QLineEdit::focusInEvent(event); - emit this->FocusChanged(true); -} - -void QmitkLineEdit::focusOutEvent(QFocusEvent* event) -{ - QLineEdit::focusOutEvent(event); - emit this->FocusChanged(false); -} - -QString QmitkLineEdit::GetDefaultText() const -{ - return m_DefaultText; -} - -void QmitkLineEdit::Initialize() -{ - m_DefaultPalette.setColor(QPalette::Text, QApplication::palette().color(QPalette::Disabled, QPalette::Text)); - - this->ShowDefaultText(true); - - connect(this, SIGNAL(FocusChanged(bool)), this, SLOT(OnFocusChanged(bool))); - connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(OnTextChanged(const QString&))); -} - -void QmitkLineEdit::OnFocusChanged(bool hasFocus) -{ - if (hasFocus) - { - if (this->text() == m_DefaultText && this->palette() == m_DefaultPalette) - this->ShowDefaultText(false); - } - else - { - if (this->text().isEmpty()) - this->ShowDefaultText(true); - } -} - -void QmitkLineEdit::OnTextChanged(const QString& text) -{ - if (this->palette() == m_DefaultPalette) - this->setPalette(QPalette()); -} - -void QmitkLineEdit::SetDefaultText(const QString& defaultText) -{ - m_DefaultText = defaultText; -} - -void QmitkLineEdit::ShowDefaultText(bool show) -{ - this->blockSignals(true); - - if (show) - { - this->setPalette(m_DefaultPalette); - this->setText(m_DefaultText); - } - else - { - this->setPalette(QPalette()); - this->clear(); - } - - this->blockSignals(false); -} diff --git a/Modules/QmitkExt/QmitkLineEdit.h b/Modules/QmitkExt/QmitkLineEdit.h deleted file mode 100644 index b0e1f3756a..0000000000 --- a/Modules/QmitkExt/QmitkLineEdit.h +++ /dev/null @@ -1,56 +0,0 @@ -/*=================================================================== - -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. - -===================================================================*/ - -#ifndef QmitkLineEdit_h -#define QmitkLineEdit_h - -#include -#include - -class QmitkExt_EXPORT QmitkLineEdit : public QLineEdit -{ - Q_OBJECT - Q_PROPERTY(QString DefaultText READ GetDefaultText WRITE SetDefaultText FINAL) - -public: - explicit QmitkLineEdit(QWidget* parent = NULL); - explicit QmitkLineEdit(const QString& defaultText, QWidget* parent = NULL); - ~QmitkLineEdit(); - - QString GetDefaultText() const; - void SetDefaultText(const QString& defaultText); - -protected: - void focusInEvent(QFocusEvent* event); - void focusOutEvent(QFocusEvent* event); - -private: - void Initialize(); - void ShowDefaultText(bool show); - -signals: - void FocusChanged(bool hasFocus); - -private slots: - void OnFocusChanged(bool hasFocus); - void OnTextChanged(const QString& text); - -private: - QString m_DefaultText; - QPalette m_DefaultPalette; -}; - -#endif diff --git a/Modules/QmitkExt/files.cmake b/Modules/QmitkExt/files.cmake index 4d39ec9497..dd754e7401 100644 --- a/Modules/QmitkExt/files.cmake +++ b/Modules/QmitkExt/files.cmake @@ -1,222 +1,218 @@ set(CPP_FILES QmitkApplicationBase/QmitkIOUtil.cpp #QmitkModels/QmitkDataStorageListModel.cpp #QmitkModels/QmitkPropertiesTableModel.cpp #QmitkModels/QmitkDataStorageTreeModel.cpp #QmitkModels/QmitkDataStorageTableModel.cpp #QmitkModels/QmitkPropertyDelegate.cpp #QmitkModels/QmitkPointListModel.cpp #QmitkAlgorithmFunctionalityComponent.cpp #QmitkBaseAlgorithmComponent.cpp QmitkAboutDialog/QmitkAboutDialog.cpp #QmitkFunctionalityComponents/QmitkSurfaceCreatorComponent.cpp #QmitkFunctionalityComponents/QmitkPixelGreyValueManipulatorComponent.cpp #QmitkFunctionalityComponents/QmitkConnectivityFilterComponent.cpp #QmitkFunctionalityComponents/QmitkImageCropperComponent.cpp #QmitkFunctionalityComponents/QmitkSeedPointSetComponent.cpp #QmitkFunctionalityComponents/QmitkSurfaceTransformerComponent.cpp QmitkPropertyObservers/QmitkBasePropertyView.cpp QmitkPropertyObservers/QmitkBoolPropertyWidget.cpp QmitkPropertyObservers/QmitkColorPropertyEditor.cpp QmitkPropertyObservers/QmitkColorPropertyView.cpp QmitkPropertyObservers/QmitkEnumerationPropertyWidget.cpp QmitkPropertyObservers/QmitkNumberPropertyEditor.cpp QmitkPropertyObservers/QmitkNumberPropertyView.cpp QmitkPropertyObservers/QmitkPropertyViewFactory.cpp QmitkPropertyObservers/QmitkStringPropertyEditor.cpp QmitkPropertyObservers/QmitkStringPropertyOnDemandEdit.cpp QmitkPropertyObservers/QmitkStringPropertyView.cpp QmitkPropertyObservers/QmitkNumberPropertySlider.cpp QmitkPropertyObservers/QmitkUGCombinedRepresentationPropertyWidget.cpp qclickablelabel.cpp #QmitkAbortEventFilter.cpp # QmitkApplicationCursor.cpp QmitkCallbackFromGUIThread.cpp QmitkEditPointDialog.cpp QmitkExtRegisterClasses.cpp QmitkFileChooser.cpp # QmitkRenderingManager.cpp # QmitkRenderingManagerFactory.cpp # QmitkRenderWindow.cpp # QmitkEventAdapter.cpp QmitkFloatingPointSpanSlider.cpp QmitkColorTransferFunctionCanvas.cpp QmitkStandardViews.cpp QmitkStepperAdapter.cpp # QmitkLineEditLevelWindowWidget.cpp # mitkSliderLevelWindowWidget.cpp # QmitkLevelWindowWidget.cpp # QmitkPointListWidget.cpp # QmitkPointListView.cpp QmitkPiecewiseFunctionCanvas.cpp QmitkSliderNavigatorWidget.cpp QmitkTransferFunctionCanvas.cpp QmitkCrossWidget.cpp #QmitkLevelWindowRangeChangeDialog.cpp #QmitkLevelWindowPresetDefinitionDialog.cpp # QmitkLevelWindowWidgetContextMenu.cpp QmitkSliceWidget.cpp # QmitkStdMultiWidget.cpp QmitkTransferFunctionWidget.cpp QmitkTransferFunctionGeneratorWidget.cpp QmitkSelectableGLWidget.cpp # QmitkPropertyListPopup.cpp # QmitkMaterialEditor.cpp # QmitkMaterialShowcase.cpp # QmitkPropertiesTableEditor.cpp QmitkPrimitiveMovieNavigatorWidget.cpp # QmitkDataStorageComboBox.cpp QmitkHistogram.cpp QmitkHistogramWidget.cpp QmitkPlotWidget.cpp QmitkPlotDialog.cpp QmitkPointListModel.cpp QmitkPointListView.cpp QmitkPointListWidget.cpp QmitkPointListViewWidget.cpp QmitkCorrespondingPointSetsView.cpp QmitkCorrespondingPointSetsModel.cpp QmitkCorrespondingPointSetsWidget.cpp QmitkVideoBackground.cpp QmitkHotkeyLineEdit.cpp QmitkBoundingObjectWidget.cpp QmitkModuleTableModel.cpp QmitkModulesDialog.cpp QmitkHistogramJSWidget.cpp - - QmitkLineEdit.cpp ) if( NOT ${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}.${VTK_BUILD_VERSION} VERSION_LESS 5.4.0 ) set(CPP_FILES ${CPP_FILES} QmitkVtkHistogramWidget.cpp QmitkVtkLineProfileWidget.cpp ) endif() if(NOT APPLE) set(CPP_FILES ${CPP_FILES} QmitkBaseComponent.cpp QmitkBaseFunctionalityComponent.cpp QmitkFunctionalityComponentContainer.cpp QmitkFunctionalityComponents/QmitkThresholdComponent.cpp ) endif() QT4_ADD_RESOURCES(CPP_FILES resources/QmitkResources.qrc) set(MOC_H_FILES QmitkPropertyObservers/QmitkBasePropertyView.h QmitkPropertyObservers/QmitkBoolPropertyWidget.h QmitkPropertyObservers/QmitkColorPropertyEditor.h QmitkPropertyObservers/QmitkColorPropertyView.h QmitkPropertyObservers/QmitkEnumerationPropertyWidget.h QmitkPropertyObservers/QmitkNumberPropertyEditor.h QmitkPropertyObservers/QmitkNumberPropertyView.h QmitkPropertyObservers/QmitkStringPropertyEditor.h QmitkPropertyObservers/QmitkStringPropertyOnDemandEdit.h QmitkPropertyObservers/QmitkStringPropertyView.h QmitkPropertyObservers/QmitkNumberPropertySlider.h QmitkPropertyObservers/QmitkUGCombinedRepresentationPropertyWidget.h # QmitkFunctionalityComponents/QmitkSurfaceCreatorComponent.h #QmitkFunctionalityComponents/QmitkPixelGreyValueManipulatorComponent.h # QmitkFunctionalityComponents/QmitkConnectivityFilterComponent.h # QmitkFunctionalityComponents/QmitkImageCropperComponent.h # QmitkFunctionalityComponents/QmitkSeedPointSetComponent.h # QmitkFunctionalityComponents/QmitkSurfaceTransformerComponent.h qclickablelabel.h QmitkCallbackFromGUIThread.h QmitkEditPointDialog.h #QmitkAlgorithmFunctionalityComponent.h #QmitkBaseAlgorithmComponent.h QmitkStandardViews.h QmitkStepperAdapter.h QmitkSliderNavigatorWidget.h QmitkSliceWidget.h QmitkColorTransferFunctionCanvas.h QmitkPiecewiseFunctionCanvas.h QmitkTransferFunctionCanvas.h QmitkFloatingPointSpanSlider.h QmitkCrossWidget.h QmitkTransferFunctionWidget.h QmitkTransferFunctionGeneratorWidget.h # QmitkPropertyListPopup.h #QmitkSelectableGLWidget.h QmitkPrimitiveMovieNavigatorWidget.h QmitkPlotWidget.h QmitkPointListModel.h QmitkPointListView.h QmitkPointListWidget.h QmitkPointListViewWidget.h QmitkCorrespondingPointSetsView.h QmitkCorrespondingPointSetsModel.h QmitkCorrespondingPointSetsWidget.h QmitkHistogramWidget.h QmitkVideoBackground.h QmitkFileChooser.h QmitkHotkeyLineEdit.h QmitkAboutDialog/QmitkAboutDialog.h QmitkBoundingObjectWidget.h QmitkPlotWidget.h QmitkHistogramJSWidget.h - - QmitkLineEdit.h ) if( NOT ${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}.${VTK_BUILD_VERSION} VERSION_LESS 5.4.0 ) set(MOC_H_FILES ${MOC_H_FILES} QmitkVtkHistogramWidget.h QmitkVtkLineProfileWidget.h ) endif() if(NOT APPLE) set(MOC_H_FILES ${MOC_H_FILES} QmitkBaseComponent.h QmitkBaseFunctionalityComponent.h QmitkFunctionalityComponentContainer.h QmitkFunctionalityComponents/QmitkThresholdComponent.h ) endif() set(UI_FILES QmitkSliderNavigator.ui # QmitkLevelWindowRangeChange.ui # QmitkLevelWindowPresetDefinition.ui # QmitkLevelWindowWidget.ui QmitkSliceWidget.ui QmitkTransferFunctionWidget.ui QmitkTransferFunctionGeneratorWidget.ui QmitkSelectableGLWidget.ui QmitkPrimitiveMovieNavigatorWidget.ui QmitkFunctionalityComponentContainerControls.ui QmitkFunctionalityComponents/QmitkThresholdComponentControls.ui QmitkAboutDialog/QmitkAboutDialogGUI.ui ) set(QRC_FILES QmitkExt.qrc ) diff --git a/Plugins/org.mitk.gui.qt.properties/files.cmake b/Plugins/org.mitk.gui.qt.properties/files.cmake index 6a61ba0288..91f67d3f75 100644 --- a/Plugins/org.mitk.gui.qt.properties/files.cmake +++ b/Plugins/org.mitk.gui.qt.properties/files.cmake @@ -1,45 +1,49 @@ set(SRC_CPP_FILES ) set(INTERNAL_CPP_FILES org_mitk_gui_qt_properties_Activator.cpp QmitkPropertiesPreferencePage.cpp QmitkPropertyItemDelegate.cpp QmitkPropertyItem.cpp QmitkPropertyItemModel.cpp QmitkPropertyItemSortFilterProxyModel.cpp QmitkPropertyTreeView.cpp + QmitkAddNewPropertyDialog.cpp ) set(UI_FILES src/internal/QmitkPropertiesPreferencePage.ui src/internal/QmitkPropertyTreeView.ui + src/internal/QmitkAddNewPropertyDialog.ui ) set(MOC_H_FILES src/internal/QmitkPropertiesPreferencePage.h src/internal/org_mitk_gui_qt_properties_Activator.h src/internal/QmitkPropertyItemDelegate.h src/internal/QmitkPropertyItemModel.h src/internal/QmitkPropertyItemSortFilterProxyModel.h src/internal/QmitkPropertyTreeView.h + src/internal/QmitkAddNewPropertyDialog.h ) set(CACHED_RESOURCE_FILES resources/icon.png plugin.xml ) set(QRC_FILES + resources/Properties.qrc ) set(CPP_FILES ) foreach(file ${SRC_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/${file}) endforeach() foreach(file ${INTERNAL_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/internal/${file}) endforeach() diff --git a/Plugins/org.mitk.gui.qt.properties/resources/Properties.qrc b/Plugins/org.mitk.gui.qt.properties/resources/Properties.qrc new file mode 100644 index 0000000000..2c45d2a2e6 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.properties/resources/Properties.qrc @@ -0,0 +1,5 @@ + + + new.png + + diff --git a/Plugins/org.mitk.gui.qt.properties/resources/new.png b/Plugins/org.mitk.gui.qt.properties/resources/new.png new file mode 100644 index 0000000000..4c3efdd6fa Binary files /dev/null and b/Plugins/org.mitk.gui.qt.properties/resources/new.png differ diff --git a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkAddNewPropertyDialog.cpp b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkAddNewPropertyDialog.cpp new file mode 100644 index 0000000000..55e6f2c830 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkAddNewPropertyDialog.cpp @@ -0,0 +1,172 @@ +/*=================================================================== + +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 "QmitkAddNewPropertyDialog.h" +#include +#include +#include + +QmitkAddNewPropertyDialog::QmitkAddNewPropertyDialog(mitk::DataNode::Pointer dataNode, mitk::BaseRenderer::Pointer renderer, QWidget* parent) + : QDialog(parent), + m_DataNode(dataNode), + m_Renderer(renderer) +{ + m_Controls.setupUi(this); + + QStringList types; + types << "bool" << "double" << "float" << "int" << "string"; + + m_Controls.typeComboBox->addItems(types); + + connect(m_Controls.typeComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(ShowAdequateValueWidget(const QString&))); + connect(m_Controls.addButton, SIGNAL(clicked()), this, SLOT(AddNewProperty())); + connect(m_Controls.cancelButton, SIGNAL(clicked()), this, SLOT(reject())); + + this->ShowAdequateValueWidget(types[0]); +} + +QmitkAddNewPropertyDialog::~QmitkAddNewPropertyDialog() +{ +} + +void QmitkAddNewPropertyDialog::AddNewProperty() +{ + if (m_Controls.nameLineEdit->text().isEmpty()) + { + QMessageBox::critical(this, "No name specified", "Enter a property name."); + return; + } + + if (!this->ValidateValue()) + { + QMessageBox::critical(this, "Invalid value", "Enter a valid " + m_Controls.typeComboBox->currentText() + " value."); + return; + } + + m_DataNode->SetProperty(m_Controls.nameLineEdit->text().toAscii(), this->CreateProperty(), m_Renderer); + + this->accept(); +} + +mitk::BaseProperty::Pointer QmitkAddNewPropertyDialog::CreateProperty() const +{ + QString type = m_Controls.typeComboBox->currentText(); + + if (type == "bool") + { + return mitk::BoolProperty::New(m_Controls.valueCheckBox->isChecked()).GetPointer(); + } + else if (type == "double") + { + return mitk::DoubleProperty::New(m_Controls.valueLineEdit->text().toDouble()).GetPointer(); + } + else if (type == "float") + { + return mitk::FloatProperty::New(m_Controls.valueLineEdit->text().toFloat()).GetPointer(); + } + else if (type == "int") + { + return mitk::IntProperty::New(m_Controls.valueLineEdit->text().toInt()).GetPointer(); + } + else if (type == "string") + { + return mitk::StringProperty::New(m_Controls.valueLineEdit->text().toStdString()).GetPointer(); + } + else + { + assert(false && "Property creation for selected type not implemented!"); + } + + return NULL; +} + +bool QmitkAddNewPropertyDialog::ValidateValue() +{ + QString type = m_Controls.typeComboBox->currentText(); + + if (type == "bool") + { + return true; + } + else if (type == "double") + { + bool ok = false; + m_Controls.valueLineEdit->text().toDouble(&ok); + + return ok; + } + else if (type == "float") + { + bool ok = false; + m_Controls.valueLineEdit->text().toFloat(&ok); + + return ok; + } + else if (type == "int") + { + bool ok = false; + m_Controls.valueLineEdit->text().toInt(&ok); + + return ok; + } + else if (type == "string") + { + return true; + } + else + { + assert(false && "Value validation for selected type not implemented!"); + } + + return false; +} + +void QmitkAddNewPropertyDialog::ShowAdequateValueWidget(const QString& type) +{ + m_Controls.valueLineEdit->clear(); + m_Controls.valueLineEdit->hide(); + + m_Controls.valueCheckBox->setChecked(false); + m_Controls.valueCheckBox->hide(); + + if (type == "bool") + { + m_Controls.valueCheckBox->show(); + } + else if (type == "double") + { + m_Controls.valueLineEdit->setText("0"); + m_Controls.valueLineEdit->show(); + } + else if (type == "float") + { + m_Controls.valueLineEdit->setText("0"); + m_Controls.valueLineEdit->show(); + } + else if (type == "int") + { + m_Controls.valueLineEdit->setText("0"); + m_Controls.valueLineEdit->show(); + } + else if (type == "string") + { + m_Controls.valueLineEdit->show(); + } + else + { + assert(false && "No adequate value widget specified for selected type!"); + } +} \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkAddNewPropertyDialog.h b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkAddNewPropertyDialog.h new file mode 100644 index 0000000000..67a6a42e70 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkAddNewPropertyDialog.h @@ -0,0 +1,47 @@ +/*=================================================================== + +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. + +===================================================================*/ + +#ifndef QmitkAddNewPropertyDialog_h +#define QmitkAddNewPropertyDialog_h + +#include +#include +#include +#include +#include + +class QmitkAddNewPropertyDialog : public QDialog +{ + Q_OBJECT + +public: + explicit QmitkAddNewPropertyDialog(mitk::DataNode::Pointer dataNode, mitk::BaseRenderer::Pointer renderer = NULL, QWidget* parent = NULL); + ~QmitkAddNewPropertyDialog(); + +private slots: + void AddNewProperty(); + void ShowAdequateValueWidget(const QString& type); + bool ValidateValue(); + +private: + mitk::BaseProperty::Pointer CreateProperty() const; + + Ui::QmitkAddNewPropertyDialog m_Controls; + mitk::DataNode::Pointer m_DataNode; + mitk::BaseRenderer::Pointer m_Renderer; +}; + +#endif diff --git a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkAddNewPropertyDialog.ui b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkAddNewPropertyDialog.ui new file mode 100644 index 0000000000..cdc9275679 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkAddNewPropertyDialog.ui @@ -0,0 +1,127 @@ + + + QmitkAddNewPropertyDialog + + + + 0 + 0 + 253 + 150 + + + + Add new property + + + + + + + + Name + + + + + + + + + + Type + + + + + + + + + + Value + + + + + + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 2 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + &Add + + + false + + + true + + + + + + + &Cancel + + + false + + + + + + + + + nameLineEdit + typeComboBox + valueLineEdit + valueCheckBox + addButton + cancelButton + + + + diff --git a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertiesPreferencePage.cpp b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertiesPreferencePage.cpp index c68d346a73..67a6181d93 100644 --- a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertiesPreferencePage.cpp +++ b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertiesPreferencePage.cpp @@ -1,79 +1,82 @@ /*=================================================================== 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 "QmitkPropertiesPreferencePage.h" #include const std::string QmitkPropertiesPreferencePage::FILTER_PROPERTIES = "filter properties"; const std::string QmitkPropertiesPreferencePage::SHOW_ALIASES = "show aliases"; const std::string QmitkPropertiesPreferencePage::SHOW_DESCRIPTIONS = "show descriptions"; const std::string QmitkPropertiesPreferencePage::SHOW_ALIASES_IN_DESCRIPTION = "show aliases in description"; +const std::string QmitkPropertiesPreferencePage::DEVELOPER_MODE = "enable developer mode"; QmitkPropertiesPreferencePage::QmitkPropertiesPreferencePage() : m_Control(NULL), m_Preferences(berry::Platform::GetServiceRegistry().GetServiceById(berry::IPreferencesService::ID)->GetSystemPreferences()->Node("/org.mitk.views.properties")) { } QmitkPropertiesPreferencePage::~QmitkPropertiesPreferencePage() { } void QmitkPropertiesPreferencePage::CreateQtControl(QWidget* parent) { m_Control = new QWidget(parent); m_Controls.setupUi(m_Control); connect(m_Controls.showDescriptionsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(OnShowDescriptionsStateChanged(int))); this->Update(); } QWidget* QmitkPropertiesPreferencePage::GetQtControl() const { return m_Control; } void QmitkPropertiesPreferencePage::Init(berry::IWorkbench::Pointer) { } void QmitkPropertiesPreferencePage::OnShowDescriptionsStateChanged(int state) { m_Controls.showAliasesInDescriptionCheckBox->setEnabled(state != Qt::Unchecked); } bool QmitkPropertiesPreferencePage::PerformOk() { m_Preferences->PutBool(FILTER_PROPERTIES, m_Controls.filterPropertiesCheckBox->isChecked()); m_Preferences->PutBool(SHOW_ALIASES, m_Controls.showAliasesCheckBox->isChecked()); m_Preferences->PutBool(SHOW_DESCRIPTIONS, m_Controls.showDescriptionsCheckBox->isChecked()); m_Preferences->PutBool(SHOW_ALIASES_IN_DESCRIPTION, m_Controls.showAliasesInDescriptionCheckBox->isChecked()); + m_Preferences->PutBool(DEVELOPER_MODE, m_Controls.enableDeveloperModeCheckBox->isChecked()); return true; } void QmitkPropertiesPreferencePage::PerformCancel() { } void QmitkPropertiesPreferencePage::Update() { m_Controls.filterPropertiesCheckBox->setChecked(m_Preferences->GetBool(FILTER_PROPERTIES, true)); m_Controls.showAliasesCheckBox->setChecked(m_Preferences->GetBool(SHOW_ALIASES, true)); m_Controls.showDescriptionsCheckBox->setChecked(m_Preferences->GetBool(SHOW_DESCRIPTIONS, true)); m_Controls.showAliasesInDescriptionCheckBox->setChecked(m_Preferences->GetBool(SHOW_ALIASES_IN_DESCRIPTION, true)); + m_Controls.enableDeveloperModeCheckBox->setChecked(m_Preferences->GetBool(DEVELOPER_MODE, false)); } diff --git a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertiesPreferencePage.h b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertiesPreferencePage.h index c8aa2ac2b7..ac9e77823e 100644 --- a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertiesPreferencePage.h +++ b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertiesPreferencePage.h @@ -1,53 +1,54 @@ /*=================================================================== 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. ===================================================================*/ #ifndef QmitkPropertiesPreferencePage_h #define QmitkPropertiesPreferencePage_h #include #include class QmitkPropertiesPreferencePage : public QObject, public berry::IQtPreferencePage { Q_OBJECT Q_INTERFACES(berry::IPreferencePage) public: static const std::string FILTER_PROPERTIES; static const std::string SHOW_ALIASES; static const std::string SHOW_DESCRIPTIONS; static const std::string SHOW_ALIASES_IN_DESCRIPTION; + static const std::string DEVELOPER_MODE; QmitkPropertiesPreferencePage(); ~QmitkPropertiesPreferencePage(); void CreateQtControl(QWidget* parent); QWidget* GetQtControl() const; void Init(berry::IWorkbench::Pointer workbench); bool PerformOk(); void PerformCancel(); void Update(); private slots: void OnShowDescriptionsStateChanged(int state); private: QWidget* m_Control; Ui::QmitkPropertiesPreferencePage m_Controls; berry::IPreferences::Pointer m_Preferences; }; #endif diff --git a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertiesPreferencePage.ui b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertiesPreferencePage.ui index 98ad654dc8..318d3156ff 100644 --- a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertiesPreferencePage.ui +++ b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertiesPreferencePage.ui @@ -1,108 +1,130 @@ QmitkPropertiesPreferencePage 0 0 400 - 300 + 577 - + Aliases Replace genuine property names by aliases true Descriptions Show descriptions true margin-left: 18px; Show aliases of genuine property names true Filters Only show filtered properties true + + + + Developer Mode + + + + + + true + + + Enabled + + + false + + + + + + Qt::Vertical 20 204 showAliasesCheckBox showDescriptionsCheckBox diff --git a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyItemModel.cpp b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyItemModel.cpp index ec5b066bda..f57e188d6a 100644 --- a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyItemModel.cpp +++ b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyItemModel.cpp @@ -1,515 +1,520 @@ /*=================================================================== 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 "mitkGetPropertyService.h" #include "QmitkPropertiesPreferencePage.h" #include "QmitkPropertyItem.h" #include "QmitkPropertyItemModel.h" #include #include #include #include #include #include #include #include static QColor MitkToQt(const mitk::Color &color) { return QColor(color.GetRed() * 255, color.GetGreen() * 255, color.GetBlue() * 255); } static mitk::BaseProperty* GetBaseProperty(const QVariant& data) { return data.isValid() ? reinterpret_cast(data.value()) : NULL; } static mitk::Color QtToMitk(const QColor &color) { mitk::Color mitkColor; mitkColor.SetRed(color.red() / 255.0f); mitkColor.SetGreen(color.green() / 255.0f); mitkColor.SetBlue(color.blue() / 255.0f); return mitkColor; } class PropertyEqualTo { public: PropertyEqualTo(const mitk::BaseProperty* property) : m_Property(property) { } bool operator()(const mitk::PropertyList::PropertyMapElementType& pair) const { return pair.second.GetPointer() == m_Property; } private: const mitk::BaseProperty* m_Property; }; QmitkPropertyItemModel::QmitkPropertyItemModel(QObject* parent) : QAbstractItemModel(parent), m_PropertyAliases(NULL), m_PropertyFilters(NULL) { this->CreateRootItem(); } QmitkPropertyItemModel::~QmitkPropertyItemModel() { this->SetNewPropertyList(NULL); } int QmitkPropertyItemModel::columnCount(const QModelIndex& parent) const { if (parent.isValid()) return static_cast(parent.internalPointer())->GetColumnCount(); else return m_RootItem->GetColumnCount(); } void QmitkPropertyItemModel::CreateRootItem() { QList rootData; rootData << "Property" << "Value"; m_RootItem.reset(new QmitkPropertyItem(rootData)); this->reset(); } QVariant QmitkPropertyItemModel::data(const QModelIndex& index, int role) const { if(!index.isValid()) return QVariant(); mitk::BaseProperty* property = index.column() == 1 ? GetBaseProperty(static_cast(index.internalPointer())->GetData(1)) : NULL; if (role == Qt::DisplayRole) { if (index.column() == 0) { return static_cast(index.internalPointer())->GetData(0); } else if (index.column() == 1 && property != NULL) { if (mitk::ColorProperty* colorProperty = dynamic_cast(property)) return MitkToQt(colorProperty->GetValue()); else if (dynamic_cast(property) == NULL) return QString::fromStdString(property->GetValueAsString()); } } else if (index.column() == 1 && property != NULL) { if (role == Qt::CheckStateRole) { if (mitk::BoolProperty* boolProperty = dynamic_cast(property)) return boolProperty->GetValue() ? Qt::Checked : Qt::Unchecked; } else if (role == Qt::EditRole) { if (dynamic_cast(property) != NULL) { return QString::fromStdString(property->GetValueAsString()); } else if (mitk::IntProperty* intProperty = dynamic_cast(property)) { return intProperty->GetValue(); } else if (mitk::FloatProperty* floatProperty = dynamic_cast(property)) { return floatProperty->GetValue(); } else if (mitk::DoubleProperty* doubleProperty = dynamic_cast(property)) { return doubleProperty->GetValue(); } else if (mitk::EnumerationProperty* enumProperty = dynamic_cast(property)) { QStringList values; for (mitk::EnumerationProperty::EnumConstIterator it = enumProperty->Begin(); it != enumProperty->End(); it++) values << QString::fromStdString(it->second); return values; } else if (mitk::ColorProperty* colorProperty = dynamic_cast(property)) { return MitkToQt(colorProperty->GetValue()); } } else if (role == mitk::PropertyRole) { return QVariant::fromValue(property); } } return QVariant(); } QModelIndex QmitkPropertyItemModel::FindProperty(const mitk::BaseProperty* property) { if (property == NULL) return QModelIndex(); typedef mitk::PropertyList::PropertyMap PropertyMap; const PropertyMap* propertyMap = m_PropertyList->GetMap(); PropertyMap::const_iterator it = std::find_if(propertyMap->begin(), propertyMap->end(), PropertyEqualTo(property)); if (it == propertyMap->end()) return QModelIndex(); QString name = QString::fromStdString(it->first); if (!name.contains('.')) { QModelIndexList item = this->match(index(0, 0), Qt::DisplayRole, name, 1, Qt::MatchExactly); if (!item.empty()) return item[0]; } else { QStringList names = name.split('.'); QModelIndexList items = this->match(index(0, 0), Qt::DisplayRole, names.last(), -1, Qt::MatchRecursive | Qt::MatchExactly); foreach(QModelIndex item, items) { QModelIndex candidate = item; for (int i = names.length() - 1; i != 0; --i) { QModelIndex parent = item.parent(); if (parent.parent() == QModelIndex()) { if (parent.data() != names.first()) break; return candidate; } if (parent.data() != names[i - 1]) break; item = parent; } } } return QModelIndex(); } Qt::ItemFlags QmitkPropertyItemModel::flags(const QModelIndex& index) const { Qt::ItemFlags flags = QAbstractItemModel::flags(index); if (index.column() == 1) { if (index.data(Qt::EditRole).isValid()) flags |= Qt::ItemIsEditable; if (index.data(Qt::CheckStateRole).isValid()) flags |= Qt::ItemIsUserCheckable; } return flags; } mitk::PropertyList* QmitkPropertyItemModel::GetPropertyList() const { return m_PropertyList.GetPointer(); } QVariant QmitkPropertyItemModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) return m_RootItem->GetData(section); return QVariant(); } QModelIndex QmitkPropertyItemModel::index(int row, int column, const QModelIndex& parent) const { if (!this->hasIndex(row, column, parent)) return QModelIndex(); QmitkPropertyItem* parentItem = parent.isValid() ? static_cast(parent.internalPointer()) : m_RootItem.get(); QmitkPropertyItem* childItem = parentItem->GetChild(row); return childItem != NULL ? this->createIndex(row, column, childItem) : QModelIndex(); } void QmitkPropertyItemModel::OnPreferencesChanged(const berry::IBerryPreferences* preferences) { bool showAliases = preferences->GetBool(QmitkPropertiesPreferencePage::SHOW_ALIASES, true); bool filterProperties = preferences->GetBool(QmitkPropertiesPreferencePage::FILTER_PROPERTIES, true); bool updateAliases = showAliases != (m_PropertyAliases != NULL); bool updateFilters = filterProperties != (m_PropertyFilters != NULL); bool resetPropertyList = false; if (updateAliases) { m_PropertyAliases = showAliases ? mitk::GetPropertyService() : NULL; resetPropertyList = m_PropertyList.IsNotNull(); } if (updateFilters) { m_PropertyFilters = filterProperties ? mitk::GetPropertyService() : NULL; if (!resetPropertyList) resetPropertyList = m_PropertyList.IsNotNull(); } if (resetPropertyList) this->SetNewPropertyList(m_PropertyList.GetPointer()); } void QmitkPropertyItemModel::OnPropertyDeleted(const itk::Object* property, const itk::EventObject&) { /*QModelIndex index = this->FindProperty(static_cast(property)); if (index != QModelIndex()) this->reset();*/ } void QmitkPropertyItemModel::OnPropertyListDeleted(const itk::Object*) { this->CreateRootItem(); } void QmitkPropertyItemModel::OnPropertyModified(const itk::Object* property, const itk::EventObject&) { QModelIndex index = this->FindProperty(static_cast(property)); if (index != QModelIndex()) emit dataChanged(index, index); } QModelIndex QmitkPropertyItemModel::parent(const QModelIndex& child) const { if (!child.isValid()) return QModelIndex(); QmitkPropertyItem* parentItem = static_cast(child.internalPointer())->GetParent(); if (parentItem == m_RootItem.get()) return QModelIndex(); return this->createIndex(parentItem->GetRow(), 0, parentItem); } int QmitkPropertyItemModel::rowCount(const QModelIndex& parent) const { if (parent.column() > 0) return 0; QmitkPropertyItem *parentItem = parent.isValid() ? static_cast(parent.internalPointer()) : m_RootItem.get(); return parentItem->GetChildCount(); } bool QmitkPropertyItemModel::setData(const QModelIndex& index, const QVariant& value, int role) { if (!index.isValid() || index.column() != 1 || (role != Qt::EditRole && role != Qt::CheckStateRole)) return false; mitk::BaseProperty* property = GetBaseProperty(static_cast(index.internalPointer())->GetData(1)); if (property == NULL) return false; if (mitk::BoolProperty* boolProperty = dynamic_cast(property)) { boolProperty->SetValue(value.toInt() == Qt::Checked ? true : false); } else if (mitk::StringProperty* stringProperty = dynamic_cast(property)) { stringProperty->SetValue(value.toString().toStdString()); } else if (mitk::IntProperty* intProperty = dynamic_cast(property)) { intProperty->SetValue(value.toInt()); } else if (mitk::FloatProperty* floatProperty = dynamic_cast(property)) { floatProperty->SetValue(value.toFloat()); } else if (mitk::DoubleProperty* doubleProperty = dynamic_cast(property)) { doubleProperty->SetValue(value.toDouble()); } else if (mitk::EnumerationProperty* enumProperty = dynamic_cast(property)) { std::string selection = value.toString().toStdString(); if (selection != enumProperty->GetValueAsString() && enumProperty->IsValidEnumerationValue(selection)) enumProperty->SetValue(selection); } else if (mitk::ColorProperty* colorProperty = dynamic_cast(property)) { colorProperty->SetValue(QtToMitk(value.value())); } m_PropertyList->InvokeEvent(itk::ModifiedEvent()); m_PropertyList->Modified(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); return true; } void QmitkPropertyItemModel::SetNewPropertyList(mitk::PropertyList* propertyList) { typedef mitk::PropertyList::PropertyMap PropertyMap; this->beginResetModel(); if (m_PropertyList.IsNotNull()) { mitk::MessageDelegate1 delegate(this, &QmitkPropertyItemModel::OnPropertyListDeleted); m_PropertyList.ObjectDelete.RemoveListener(delegate); const PropertyMap* propertyMap = m_PropertyList->GetMap(); for (PropertyMap::const_iterator propertyIt = propertyMap->begin(); propertyIt != propertyMap->end(); ++propertyIt) { std::map::const_iterator tagIt = m_PropertyModifiedTags.find(propertyIt->first); if (tagIt != m_PropertyModifiedTags.end()) propertyIt->second->RemoveObserver(tagIt->second); tagIt = m_PropertyDeletedTags.find(propertyIt->first); if (tagIt != m_PropertyDeletedTags.end()) propertyIt->second->RemoveObserver(tagIt->second); } m_PropertyModifiedTags.clear(); } m_PropertyList = propertyList; if (m_PropertyList.IsNotNull()) { mitk::MessageDelegate1 delegate(this, &QmitkPropertyItemModel::OnPropertyListDeleted); m_PropertyList.ObjectDelete.AddListener(delegate); mitk::MessageDelegate2 propertyDelegate(this, &QmitkPropertyItemModel::OnPropertyModified); itk::MemberCommand::Pointer modifiedCommand = itk::MemberCommand::New(); modifiedCommand->SetCallbackFunction(this, &QmitkPropertyItemModel::OnPropertyModified); const PropertyMap* propertyMap = m_PropertyList->GetMap(); for (PropertyMap::const_iterator it = propertyMap->begin(); it != propertyMap->end(); ++it) m_PropertyModifiedTags.insert(std::make_pair(it->first, it->second->AddObserver(itk::ModifiedEvent(), modifiedCommand))); itk::MemberCommand::Pointer deletedCommand = itk::MemberCommand::New(); deletedCommand->SetCallbackFunction(this, &QmitkPropertyItemModel::OnPropertyDeleted); for (PropertyMap::const_iterator it = propertyMap->begin(); it != propertyMap->end(); ++it) m_PropertyDeletedTags.insert(std::make_pair(it->first, it->second->AddObserver(itk::DeleteEvent(), deletedCommand))); } this->CreateRootItem(); if (m_PropertyList != NULL && !m_PropertyList->IsEmpty()) { mitk::PropertyList::PropertyMap filteredProperties; bool filterProperties = false; if (m_PropertyFilters != NULL && (m_PropertyFilters->HasFilter() || m_PropertyFilters->HasFilter(m_ClassName.toStdString()))) { filteredProperties = m_PropertyFilters->ApplyFilter(*m_PropertyList->GetMap(), m_ClassName.toStdString()); filterProperties = true; } const mitk::PropertyList::PropertyMap* propertyMap = !filterProperties ? m_PropertyList->GetMap() : &filteredProperties; mitk::PropertyList::PropertyMap::const_iterator end = propertyMap->end(); for (mitk::PropertyList::PropertyMap::const_iterator iter = propertyMap->begin(); iter != end; ++iter) { std::vector aliases; if (m_PropertyAliases != NULL) { aliases = m_PropertyAliases->GetAliases(iter->first, m_ClassName.toStdString()); if (aliases.empty() && !m_ClassName.isEmpty()) aliases = m_PropertyAliases->GetAliases(iter->first); } if (aliases.empty()) { QList data; data << QString::fromStdString(iter->first) << QVariant::fromValue((reinterpret_cast(iter->second.GetPointer()))); m_RootItem->AppendChild(new QmitkPropertyItem(data)); } else { std::vector::const_iterator end = aliases.end(); for (std::vector::const_iterator aliasIter = aliases.begin(); aliasIter != end; ++aliasIter) { QList data; data << QString::fromStdString(*aliasIter) << QVariant::fromValue((reinterpret_cast(iter->second.GetPointer()))); m_RootItem->AppendChild(new QmitkPropertyItem(data)); } } } } this->endResetModel(); } void QmitkPropertyItemModel::SetPropertyList(mitk::PropertyList* propertyList, const QString& className) { if (m_PropertyList.GetPointer() != propertyList) { m_ClassName = className; this->SetNewPropertyList(propertyList); } } + +void QmitkPropertyItemModel::Update() +{ + this->SetNewPropertyList(m_PropertyList); +} diff --git a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyItemModel.h b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyItemModel.h index 4bd0601b89..d744598fef 100644 --- a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyItemModel.h +++ b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyItemModel.h @@ -1,79 +1,80 @@ /*=================================================================== 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. ===================================================================*/ #ifndef QmitkPropertyItemModel_h #define QmitkPropertyItemModel_h #include #include #include class QmitkPropertyItem; namespace berry { struct IBerryPreferences; } namespace mitk { class IPropertyAliases; class IPropertyFilters; enum { PropertyRole = Qt::UserRole + 1 }; } class QmitkPropertyItemModel : public QAbstractItemModel { Q_OBJECT public: explicit QmitkPropertyItemModel(QObject* parent = NULL); ~QmitkPropertyItemModel(); int columnCount(const QModelIndex& parent = QModelIndex()) const; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; Qt::ItemFlags flags(const QModelIndex& index) const; mitk::PropertyList* GetPropertyList() const; QVariant headerData(int section, Qt::Orientation orientation, int role) const; QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const; void OnPreferencesChanged(const berry::IBerryPreferences* preferences); QModelIndex parent(const QModelIndex& child) const; int rowCount(const QModelIndex& parent = QModelIndex()) const; bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); void SetPropertyList(mitk::PropertyList* propertyList, const QString& className = ""); + void Update(); private: void CreateRootItem(); QModelIndex FindProperty(const mitk::BaseProperty* property); void OnPropertyDeleted(const itk::Object* property, const itk::EventObject& event); void OnPropertyListDeleted(const itk::Object* propertyList); void OnPropertyModified(const itk::Object* property, const itk::EventObject& event); void SetNewPropertyList(mitk::PropertyList* propertyList); mitk::IPropertyAliases* m_PropertyAliases; mitk::IPropertyFilters* m_PropertyFilters; mitk::WeakPointer m_PropertyList; QString m_ClassName; std::auto_ptr m_RootItem; std::map m_PropertyDeletedTags; std::map m_PropertyModifiedTags; }; #endif diff --git a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyTreeView.cpp b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyTreeView.cpp index 13f9810a7e..26ef08b667 100644 --- a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyTreeView.cpp +++ b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyTreeView.cpp @@ -1,289 +1,370 @@ /*=================================================================== 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 "mitkGetPropertyService.h" +#include "QmitkAddNewPropertyDialog.h" #include "QmitkPropertiesPreferencePage.h" #include "QmitkPropertyItemDelegate.h" #include "QmitkPropertyItemModel.h" #include "QmitkPropertyItemSortFilterProxyModel.h" #include "QmitkPropertyTreeView.h" #include #include #include +#include #include const std::string QmitkPropertyTreeView::VIEW_ID = "org.mitk.views.properties"; QmitkPropertyTreeView::QmitkPropertyTreeView() - : m_PropertyNameChangedTag(0), + : m_Parent(NULL), + m_PropertyNameChangedTag(0), m_PropertyAliases(NULL), m_PropertyDescriptions(NULL), m_ShowAliasesInDescription(true), + m_DeveloperMode(false), m_ProxyModel(NULL), m_Model(NULL), - m_Delegate(NULL) + m_Delegate(NULL), + m_Renderer(NULL) { } QmitkPropertyTreeView::~QmitkPropertyTreeView() { } void QmitkPropertyTreeView::CreateQtPartControl(QWidget* parent) { + m_Parent = parent; + m_Controls.setupUi(parent); - m_Controls.filter->SetDefaultText("Filter"); + m_Controls.propertyListComboBox->addItem("global"); + + m_Controls.newButton->setEnabled(false); m_Controls.description->hide(); + m_Controls.propertyListLabel->hide(); + m_Controls.propertyListComboBox->hide(); + m_Controls.newButton->hide(); m_ProxyModel = new QmitkPropertyItemSortFilterProxyModel(m_Controls.treeView); m_Model = new QmitkPropertyItemModel(m_ProxyModel); m_ProxyModel->setSourceModel(m_Model); m_ProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); m_ProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); m_ProxyModel->setDynamicSortFilter(true); m_Delegate = new QmitkPropertyItemDelegate(m_Controls.treeView); m_Controls.treeView->setItemDelegateForColumn(1, m_Delegate); m_Controls.treeView->setModel(m_ProxyModel); m_Controls.treeView->setColumnWidth(0, 180); m_Controls.treeView->sortByColumn(0, Qt::AscendingOrder); m_Controls.treeView->setSelectionBehavior(QAbstractItemView::SelectRows); m_Controls.treeView->setSelectionMode(QAbstractItemView::SingleSelection); m_Controls.treeView->setEditTriggers(QAbstractItemView::SelectedClicked | QAbstractItemView::DoubleClicked); - connect(m_Controls.filter, SIGNAL(textChanged(const QString&)), this, SLOT(OnFilterTextChanged(const QString&))); + connect(m_Controls.filterLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(OnFilterTextChanged(const QString&))); + connect(m_Controls.propertyListComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(OnPropertyListChanged(int))); + connect(m_Controls.newButton, SIGNAL(clicked()), this, SLOT(OnAddNewProperty())); connect(m_Controls.treeView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(OnCurrentRowChanged(const QModelIndex&, const QModelIndex&))); connect(m_Model, SIGNAL(modelReset()), this, SLOT(OnModelReset())); } QString QmitkPropertyTreeView::GetPropertyNameOrAlias(const QModelIndex& index) { QString propertyName; if (index.isValid()) { QModelIndex current = index; while (current.isValid()) { QString name = m_ProxyModel->data(m_ProxyModel->index(current.row(), 0, current.parent())).toString(); propertyName.prepend(propertyName.isEmpty() ? name : name.append('.')); current = current.parent(); } } return propertyName; } void QmitkPropertyTreeView::OnCurrentRowChanged(const QModelIndex& current, const QModelIndex&) { if (m_PropertyDescriptions != NULL && current.isValid()) { QString name = this->GetPropertyNameOrAlias(current); if (!name.isEmpty()) { QString alias; bool isTrueName = true; if (m_PropertyAliases != NULL) { std::string trueName = m_PropertyAliases->GetPropertyName(name.toStdString()); if (trueName.empty() && !m_SelectionClassName.empty()) trueName = m_PropertyAliases->GetPropertyName(name.toStdString(), m_SelectionClassName); if (!trueName.empty()) { alias = name; name = QString::fromStdString(trueName); isTrueName = false; } } QString description = QString::fromStdString(m_PropertyDescriptions->GetDescription(name.toStdString())); std::vector aliases; if (!isTrueName && m_PropertyAliases != NULL) { aliases = m_PropertyAliases->GetAliases(name.toStdString(), m_SelectionClassName); if (aliases.empty() && !m_SelectionClassName.empty()) aliases = m_PropertyAliases->GetAliases(name.toStdString()); } if (!description.isEmpty() || !aliases.empty()) { QString customizedDescription; if (m_ShowAliasesInDescription && !aliases.empty()) { customizedDescription = "

" + name + "

"; std::size_t numAliases = aliases.size(); std::size_t lastAlias = numAliases - 1; for (std::size_t i = 0; i < numAliases; ++i) { customizedDescription += i != lastAlias ? "
" : "
"; customizedDescription += QString::fromStdString(aliases[i]) + "
"; } } else { customizedDescription = "

" + name + "

"; } if (!description.isEmpty()) customizedDescription += description; m_Controls.description->setText(customizedDescription); m_Controls.description->show(); return; } } } m_Controls.description->hide(); } void QmitkPropertyTreeView::OnFilterTextChanged(const QString& filter) { m_ProxyModel->setFilterWildcard(filter); if (filter.isEmpty()) m_Controls.treeView->collapseAll(); else m_Controls.treeView->expandAll(); } void QmitkPropertyTreeView::OnModelReset() { m_Controls.description->hide(); } void QmitkPropertyTreeView::OnPreferencesChanged(const berry::IBerryPreferences* preferences) { bool showAliases = preferences->GetBool(QmitkPropertiesPreferencePage::SHOW_ALIASES, true); bool showDescriptions = preferences->GetBool(QmitkPropertiesPreferencePage::SHOW_DESCRIPTIONS, true); bool showAliasesInDescription = preferences->GetBool(QmitkPropertiesPreferencePage::SHOW_ALIASES_IN_DESCRIPTION, true); + bool developerMode = preferences->GetBool(QmitkPropertiesPreferencePage::DEVELOPER_MODE, true); bool updateAliases = showAliases != (m_PropertyAliases != NULL); bool updateDescriptions = showDescriptions != (m_PropertyDescriptions != NULL); bool updateAliasesInDescription = showAliasesInDescription != m_ShowAliasesInDescription; + bool updateDeveloperMode = developerMode != m_DeveloperMode; if (updateAliases) m_PropertyAliases = showAliases ? mitk::GetPropertyService() : NULL; if (updateDescriptions) m_PropertyDescriptions = showDescriptions ? mitk::GetPropertyService() : NULL; if (updateAliasesInDescription) m_ShowAliasesInDescription = showAliasesInDescription; if (updateDescriptions || updateAliasesInDescription) { QModelIndexList selection = m_Controls.treeView->selectionModel()->selectedRows(); if (!selection.isEmpty()) this->OnCurrentRowChanged(selection[0], selection[0]); } + if (updateDeveloperMode) + { + m_DeveloperMode = developerMode; + + if (!developerMode) + m_Controls.propertyListComboBox->setCurrentIndex(0); + + m_Controls.propertyListLabel->setVisible(developerMode); + m_Controls.propertyListComboBox->setVisible(developerMode); + m_Controls.newButton->setVisible(developerMode); + } + m_Model->OnPreferencesChanged(preferences); } void QmitkPropertyTreeView::OnPropertyNameChanged(const itk::EventObject&) { mitk::PropertyList* propertyList = m_Model->GetPropertyList(); if (propertyList != NULL) { mitk::BaseProperty* nameProperty = propertyList->GetProperty("name"); if (nameProperty != NULL) { std::ostringstream partName; partName << "Properties (" << nameProperty->GetValueAsString() << ')'; this->SetPartName(partName.str()); } } } void QmitkPropertyTreeView::OnSelectionChanged(berry::IWorkbenchPart::Pointer, const QList& nodes) { mitk::PropertyList* propertyList = m_Model->GetPropertyList(); if (propertyList != NULL) { mitk::BaseProperty* nameProperty = propertyList->GetProperty("name"); if (nameProperty != NULL) nameProperty->RemoveObserver(m_PropertyNameChangedTag); m_PropertyNameChangedTag = 0; } if (nodes.empty() || nodes.front().IsNull()) { + m_SelectedNode = NULL; + this->SetPartName("Properties"); m_Model->SetPropertyList(NULL); m_Delegate->SetPropertyList(NULL); + + m_Controls.newButton->setEnabled(false); } else { - QString selectionClassName = nodes.front()->GetData() != NULL - ? nodes.front()->GetData()->GetNameOfClass() + m_SelectedNode = nodes.front(); + + QString selectionClassName = m_SelectedNode->GetData() != NULL + ? m_SelectedNode->GetData()->GetNameOfClass() : ""; m_SelectionClassName = selectionClassName.toStdString(); - m_Model->SetPropertyList(nodes.front()->GetPropertyList(), selectionClassName); - m_Delegate->SetPropertyList(nodes.front()->GetPropertyList()); + m_Model->SetPropertyList(m_SelectedNode->GetPropertyList(m_Renderer), selectionClassName); + m_Delegate->SetPropertyList(m_SelectedNode->GetPropertyList(m_Renderer)); OnPropertyNameChanged(itk::ModifiedEvent()); - mitk::BaseProperty* nameProperty = nodes.front()->GetProperty("name"); + mitk::BaseProperty* nameProperty = m_SelectedNode->GetProperty("name"); if (nameProperty != NULL) { itk::ReceptorMemberCommand::Pointer command = itk::ReceptorMemberCommand::New(); command->SetCallbackFunction(this, &QmitkPropertyTreeView::OnPropertyNameChanged); m_PropertyNameChangedTag = nameProperty->AddObserver(itk::ModifiedEvent(), command); } + + m_Controls.newButton->setEnabled(true); } if (!m_ProxyModel->filterRegExp().isEmpty()) m_Controls.treeView->expandAll(); } void QmitkPropertyTreeView::SetFocus() { - m_Controls.filter->setFocus(); + m_Controls.filterLineEdit->setFocus(); +} + +void QmitkPropertyTreeView::RenderWindowPartActivated(mitk::IRenderWindowPart* renderWindowPart) +{ + QHash renderWindows = this->GetRenderWindowPart()->GetQmitkRenderWindows(); + + Q_FOREACH(QString renderWindow, renderWindows.keys()) + { + m_Controls.propertyListComboBox->addItem(renderWindow); + } +} + +void QmitkPropertyTreeView::RenderWindowPartDeactivated(mitk::IRenderWindowPart*) +{ + m_Controls.propertyListComboBox->clear(); + m_Controls.propertyListComboBox->addItem("global"); +} + +void QmitkPropertyTreeView::OnPropertyListChanged(int index) +{ + if (index == -1) + return; + + QString renderWindow = m_Controls.propertyListComboBox->itemText(index); + + m_Renderer = renderWindow != "global" + ? this->GetRenderWindowPart()->GetQmitkRenderWindow(renderWindow)->GetRenderer() + : NULL; + + QList nodes; + + if (m_SelectedNode.IsNotNull()) + nodes << m_SelectedNode; + + berry::IWorkbenchPart::Pointer workbenchPart; + + this->OnSelectionChanged(workbenchPart, nodes); +} + +void QmitkPropertyTreeView::OnAddNewProperty() +{ + QmitkAddNewPropertyDialog dialog(m_SelectedNode, m_Renderer, m_Parent); + + if (dialog.exec() == QDialog::Accepted) + this->m_Model->Update(); } diff --git a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyTreeView.h b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyTreeView.h index f5daca356d..bd2362423e 100644 --- a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyTreeView.h +++ b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyTreeView.h @@ -1,73 +1,84 @@ /*=================================================================== 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. ===================================================================*/ #ifndef QmitkPropertyTreeView_h #define QmitkPropertyTreeView_h +#include +#include #include #include class QmitkPropertyItemDelegate; class QmitkPropertyItemModel; class QmitkPropertyItemSortFilterProxyModel; namespace mitk { class IPropertyAliases; class IPropertyDescriptions; } -class QmitkPropertyTreeView : public QmitkAbstractView +class QmitkPropertyTreeView : public QmitkAbstractView, public mitk::IRenderWindowPartListener { Q_OBJECT public: static const std::string VIEW_ID; berryObjectMacro(QmitkPropertyTreeView); QmitkPropertyTreeView(); ~QmitkPropertyTreeView(); void SetFocus(); + void RenderWindowPartActivated(mitk::IRenderWindowPart* renderWindowPart); + void RenderWindowPartDeactivated(mitk::IRenderWindowPart*); + protected: void CreateQtPartControl(QWidget* parent); private: QString GetPropertyNameOrAlias(const QModelIndex& index); void OnPreferencesChanged(const berry::IBerryPreferences* preferences); void OnPropertyNameChanged(const itk::EventObject& event); void OnSelectionChanged(berry::IWorkbenchPart::Pointer part, const QList& nodes); private slots: void OnCurrentRowChanged(const QModelIndex& current, const QModelIndex& previous); + void OnPropertyListChanged(int index); + void OnAddNewProperty(); void OnFilterTextChanged(const QString& filter); void OnModelReset(); private: + QWidget* m_Parent; unsigned long m_PropertyNameChangedTag; std::string m_SelectionClassName; mitk::IPropertyAliases* m_PropertyAliases; mitk::IPropertyDescriptions* m_PropertyDescriptions; bool m_ShowAliasesInDescription; + bool m_DeveloperMode; Ui::QmitkPropertyTreeView m_Controls; QmitkPropertyItemSortFilterProxyModel* m_ProxyModel; QmitkPropertyItemModel* m_Model; QmitkPropertyItemDelegate* m_Delegate; + mitk::DataNode::Pointer m_SelectedNode; + mitk::BaseRenderer* m_Renderer; }; #endif diff --git a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyTreeView.ui b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyTreeView.ui index 87333b23d5..d19de2b57a 100644 --- a/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyTreeView.ui +++ b/Plugins/org.mitk.gui.qt.properties/src/internal/QmitkPropertyTreeView.ui @@ -1,85 +1,134 @@ QmitkPropertyTreeView 0 0 300 600 - + - + - + + + + + + 0 + 0 + + + + Property List + + + + + + + + 0 + 0 + + + + + + + + Add new property + + + + + + + :/Properties/new.png:/Properties/new.png + + + + 16 + 16 + + + + false + + + + + + + + + Filter + + Qt::NoFocus ::item { border-right: 1px solid palette(midlight); padding-bottom: 1px; padding-top: 1px; } ::item:last { border-right: 0; } ::item:selected { background: palette(highlight); color: palette(highlighted-text); } Qt::ScrollBarAsNeeded true true 54 0 0 Qt::RichText true - - - QmitkLineEdit - QLineEdit -
QmitkLineEdit.h
-
-
- + + +