From 8102fd2ba0b9522353116151d8213c67e5aa5d3c Mon Sep 17 00:00:00 2001 From: Sebastian Eichelbaum Date: Mon, 8 Feb 2010 10:36:00 +0100 Subject: [PATCH] [ADD] - added string and double property widgets --- src/gui/qt4/CMakeLists.txt | 2 + .../datasetbrowser/WPropertyDoubleWidget.cpp | 107 ++++++++++++++++++ .../datasetbrowser/WPropertyDoubleWidget.h | 87 ++++++++++++++ .../qt4/datasetbrowser/WPropertyIntWidget.cpp | 5 +- .../datasetbrowser/WPropertyStringWidget.cpp | 73 ++++++++++++ .../datasetbrowser/WPropertyStringWidget.h | 86 ++++++++++++++ src/gui/qt4/datasetbrowser/WQtDSBWidget.cpp | 8 +- src/gui/qt4/datasetbrowser/WQtDSBWidget.h | 6 +- .../connectomeView/WMConnectomeView.cpp | 4 +- src/modules/connectomeView/WMConnectomeView.h | 4 +- src/modules/navSlices/WMNavSlices.cpp | 6 + 11 files changed, 374 insertions(+), 14 deletions(-) create mode 100644 src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.cpp create mode 100644 src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.h create mode 100644 src/gui/qt4/datasetbrowser/WPropertyStringWidget.cpp create mode 100644 src/gui/qt4/datasetbrowser/WPropertyStringWidget.h diff --git a/src/gui/qt4/CMakeLists.txt b/src/gui/qt4/CMakeLists.txt index 9e5b96ffe..ff55395e8 100644 --- a/src/gui/qt4/CMakeLists.txt +++ b/src/gui/qt4/CMakeLists.txt @@ -18,6 +18,8 @@ SET(GUI_QT4_MOC_HDRS datasetbrowser/WPropertyWidget.h datasetbrowser/WPropertyBoolWidget.h datasetbrowser/WPropertyIntWidget.h + datasetbrowser/WPropertyDoubleWidget.h + datasetbrowser/WPropertyStringWidget.h datasetbrowser/WQtDatasetBrowser.h datasetbrowser/WQtDSBWidget.h datasetbrowser/WQtLineEdit.h diff --git a/src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.cpp b/src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.cpp new file mode 100644 index 000000000..3298b953d --- /dev/null +++ b/src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.cpp @@ -0,0 +1,107 @@ +//--------------------------------------------------------------------------- +// +// Project: OpenWalnut ( http://www.openwalnut.org ) +// +// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS +// For more information see http://www.openwalnut.org/copying +// +// This file is part of OpenWalnut. +// +// OpenWalnut is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// OpenWalnut is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with OpenWalnut. If not, see . +// +//--------------------------------------------------------------------------- + +#include + +#include + +#include "../../../common/WLogger.h" +#include "../../../common/WPropertyVariable.h" + +#include "WPropertyDoubleWidget.h" + +WPropertyDoubleWidget::WPropertyDoubleWidget( WPropDouble property, QGridLayout* propertyGrid, QWidget* parent ): + WPropertyWidget( property, propertyGrid, parent ), + m_doubleProperty( property ), + m_spin( this ), + m_layout() +{ + // initialize members + setLayout( &m_layout ); + + // layout both against each other + m_layout.addWidget( &m_spin ); + + // get the min constraint + WPVDouble::PropertyConstraintMin minC = m_doubleProperty->getMin(); + double min = 0.0; + if ( minC.get() ) + { + min = minC->getMin(); + } + else + { + WLogger::getLogger()->addLogMessage( + std::string( "The property has no minimum constraint. You should define it to avoid unexpected behaviour. ") + + std::string( "Using default (" + boost::lexical_cast< std::string >( min ) + ")." ), + "PropertyWidget( " + m_doubleProperty->getName() + " )", LL_WARNING ); + } + + // get the max constraint + WPVDouble::PropertyConstraintMax maxC = m_doubleProperty->getMax(); + double max = 100.0; + if ( maxC.get() ) + { + max = maxC->getMax(); + } + else + { + WLogger::getLogger()->addLogMessage( + std::string( "The property has no maximum constraint. You should define it to avoid unexpected behaviour. ") + + std::string( "Using default (" + boost::lexical_cast< std::string >( max ) + ")." ), + "PropertyWidget( " + m_doubleProperty->getName() + " )", LL_WARNING ); + } + + // setup the slider + m_spin.setMinimum( min ); + m_spin.setMaximum( max ); + + // set the initial values + m_spin.setValue( m_doubleProperty->get() ); + m_spin.setSingleStep( ( max - min ) / 100.0 ); + + // connect the modification signal of the edit and slider with our callback + connect( &m_spin, SIGNAL( valueChanged( double ) ), this, SLOT( spinChanged( double ) ) ); +} + +WPropertyDoubleWidget::~WPropertyDoubleWidget() +{ + // cleanup +} + +void WPropertyDoubleWidget::spinChanged( double value ) +{ + // set to the property + if ( !m_doubleProperty->accept( value ) ) + { + // this is not a valid value! + invalidate(); + } + else + { + invalidate( false ); + m_doubleProperty->set( value ); + } +} + diff --git a/src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.h b/src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.h new file mode 100644 index 000000000..bf55d8ab4 --- /dev/null +++ b/src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.h @@ -0,0 +1,87 @@ +//--------------------------------------------------------------------------- +// +// Project: OpenWalnut ( http://www.openwalnut.org ) +// +// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS +// For more information see http://www.openwalnut.org/copying +// +// This file is part of OpenWalnut. +// +// OpenWalnut is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// OpenWalnut is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with OpenWalnut. If not, see . +// +//--------------------------------------------------------------------------- + +#ifndef WPROPERTYDOUBLEWIDGET_H +#define WPROPERTYDOUBLEWIDGET_H + +#include + +#include +#include + +#include "WPropertyWidget.h" + +/** + * Implements a property widget for WPropDouble. + */ +class WPropertyDoubleWidget: public WPropertyWidget +{ + Q_OBJECT +public: + + /** + * Constructor. Creates a new widget appropriate for the specified property. + * + * \param property the property to handle + * \param parent the parent widget. + * \param propertyGrid the grid used to layout the labels and property widgets + */ + WPropertyDoubleWidget( WPropDouble property, QGridLayout* propertyGrid, QWidget* parent = 0 ); + + /** + * Destructor. + */ + virtual ~WPropertyDoubleWidget(); + +protected: + + /** + * The integer property represented by this widget. + */ + WPropDouble m_doubleProperty; + + /** + * Spin box for doubles + */ + QDoubleSpinBox m_spin; + + /** + * Layout used to position the label and the checkbox + */ + QHBoxLayout m_layout; + +private: + +public slots: + + /** + * Called whenever the spin box changes + * + * \param value the new value + */ + void spinChanged( double value ); +}; + +#endif // WPROPERTYDOUBLEWIDGET_H + diff --git a/src/gui/qt4/datasetbrowser/WPropertyIntWidget.cpp b/src/gui/qt4/datasetbrowser/WPropertyIntWidget.cpp index 3bc3afd24..e9530d32d 100644 --- a/src/gui/qt4/datasetbrowser/WPropertyIntWidget.cpp +++ b/src/gui/qt4/datasetbrowser/WPropertyIntWidget.cpp @@ -23,7 +23,6 @@ //--------------------------------------------------------------------------- #include -#include #include #include @@ -98,9 +97,7 @@ WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* property m_edit.resize( m_edit.minimumSizeHint().width() * length / 2, m_edit.size().height() ); // set the initial values - std::ostringstream s; - s << m_intProperty->get(); - m_edit.setText( QString( s.str().c_str() ) ); + m_edit.setText( QString( boost::lexical_cast< std::string >( m_intProperty->get() ).c_str() ) ); m_slider.setValue( m_intProperty->get() ); // connect the modification signal of the edit and slider with our callback diff --git a/src/gui/qt4/datasetbrowser/WPropertyStringWidget.cpp b/src/gui/qt4/datasetbrowser/WPropertyStringWidget.cpp new file mode 100644 index 000000000..805f75c1d --- /dev/null +++ b/src/gui/qt4/datasetbrowser/WPropertyStringWidget.cpp @@ -0,0 +1,73 @@ +//--------------------------------------------------------------------------- +// +// Project: OpenWalnut ( http://www.openwalnut.org ) +// +// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS +// For more information see http://www.openwalnut.org/copying +// +// This file is part of OpenWalnut. +// +// OpenWalnut is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// OpenWalnut is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with OpenWalnut. If not, see . +// +//--------------------------------------------------------------------------- + +#include +#include + +#include + +#include "../../../common/WLogger.h" +#include "../../../common/WPropertyVariable.h" + +#include "WPropertyStringWidget.h" + +WPropertyStringWidget::WPropertyStringWidget( WPropString property, QGridLayout* propertyGrid, QWidget* parent ): + WPropertyWidget( property, propertyGrid, parent ), + m_stringProperty( property ), + m_edit( this ), + m_layout() +{ + // initialize members + setLayout( &m_layout ); + + // layout both against each other + m_layout.addWidget( &m_edit ); + + // set the initial values + m_edit.setText( QString( m_stringProperty->get().c_str() ) ); + + // connect the modification signal of the edit and slider with our callback + connect( &m_edit, SIGNAL( returnPressed() ), this, SLOT( editChanged() ) ); +} + +WPropertyStringWidget::~WPropertyStringWidget() +{ + // cleanup +} + +void WPropertyStringWidget::editChanged() +{ + std::string value = m_edit.text().toStdString(); + // now: is the value acceptable by the property? + if ( !m_stringProperty->accept( value ) ) + { + invalidate(); + } + else + { + invalidate( false ); + m_stringProperty->set( value ); + } +} + diff --git a/src/gui/qt4/datasetbrowser/WPropertyStringWidget.h b/src/gui/qt4/datasetbrowser/WPropertyStringWidget.h new file mode 100644 index 000000000..baa25183a --- /dev/null +++ b/src/gui/qt4/datasetbrowser/WPropertyStringWidget.h @@ -0,0 +1,86 @@ +//--------------------------------------------------------------------------- +// +// Project: OpenWalnut ( http://www.openwalnut.org ) +// +// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS +// For more information see http://www.openwalnut.org/copying +// +// This file is part of OpenWalnut. +// +// OpenWalnut is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// OpenWalnut is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with OpenWalnut. If not, see . +// +//--------------------------------------------------------------------------- + +#ifndef WPROPERTYSTRINGWIDGET_H +#define WPROPERTYSTRINGWIDGET_H + +#include + +#include +#include +#include + +#include "WPropertyWidget.h" + +/** + * Implements a property widget for WPropString. + */ +class WPropertyStringWidget: public WPropertyWidget +{ + Q_OBJECT +public: + + /** + * Constructor. Creates a new widget appropriate for the specified property. + * + * \param property the property to handle + * \param parent the parent widget. + * \param propertyGrid the grid used to layout the labels and property widgets + */ + WPropertyStringWidget( WPropString property, QGridLayout* propertyGrid, QWidget* parent = 0 ); + + /** + * Destructor. + */ + virtual ~WPropertyStringWidget(); + +protected: + + /** + * The integer property represented by this widget. + */ + WPropString m_stringProperty; + + /** + * The edit field showing the value + */ + QLineEdit m_edit; + + /** + * Layout used to position the label and the checkbox + */ + QHBoxLayout m_layout; + +private: + +public slots: + + /** + * Called whenever the edit field changes + */ + void editChanged(); +}; + +#endif // WPROPERTYSTRINGWIDGET_H + diff --git a/src/gui/qt4/datasetbrowser/WQtDSBWidget.cpp b/src/gui/qt4/datasetbrowser/WQtDSBWidget.cpp index 095f05578..3d266f1a9 100644 --- a/src/gui/qt4/datasetbrowser/WQtDSBWidget.cpp +++ b/src/gui/qt4/datasetbrowser/WQtDSBWidget.cpp @@ -49,14 +49,14 @@ WPropertyIntWidget* WQtDSBWidget::addPropInt( WPropInt property ) return new WPropertyIntWidget( property, &m_controlLayout, this ); } -WPropertyIntWidget* WQtDSBWidget::addPropDouble( WPropDouble property ) +WPropertyDoubleWidget* WQtDSBWidget::addPropDouble( WPropDouble property ) { - return NULL; + return new WPropertyDoubleWidget( property, &m_controlLayout, this ); } -WPropertyIntWidget* WQtDSBWidget::addPropString( WPropString property ) +WPropertyStringWidget* WQtDSBWidget::addPropString( WPropString property ) { - return NULL; + return new WPropertyStringWidget( property, &m_controlLayout, this ); } void WQtDSBWidget::addSpacer() diff --git a/src/gui/qt4/datasetbrowser/WQtDSBWidget.h b/src/gui/qt4/datasetbrowser/WQtDSBWidget.h index 303e4b0ef..ca395d6b4 100644 --- a/src/gui/qt4/datasetbrowser/WQtDSBWidget.h +++ b/src/gui/qt4/datasetbrowser/WQtDSBWidget.h @@ -36,6 +36,8 @@ #include "WPropertyBoolWidget.h" #include "WPropertyIntWidget.h" +#include "WPropertyStringWidget.h" +#include "WPropertyDoubleWidget.h" #include "../../../common/WPropertyVariable.h" @@ -90,7 +92,7 @@ public: * * \return the widget that has been added. */ - WPropertyIntWidget* addPropDouble( WPropDouble property ); + WPropertyDoubleWidget* addPropDouble( WPropDouble property ); /** * Adds a new int property to the DSB. @@ -99,7 +101,7 @@ public: * * \return the widget that has been added. */ - WPropertyIntWidget* addPropString( WPropString property ); + WPropertyStringWidget* addPropString( WPropString property ); /** * helper function to add a spacer at the end diff --git a/src/modules/connectomeView/WMConnectomeView.cpp b/src/modules/connectomeView/WMConnectomeView.cpp index a10922c10..be3aa3cb4 100644 --- a/src/modules/connectomeView/WMConnectomeView.cpp +++ b/src/modules/connectomeView/WMConnectomeView.cpp @@ -102,8 +102,8 @@ void WMConnectomeView::connectors() addConnector( m_mrtInput ); // this is the scalar field input - m_fiberInput = boost::shared_ptr< WModuleInputForwardData< WDataSetFibers2 > >( - new WModuleInputForwardData< WDataSetFibers2 >( shared_from_this(), + m_fiberInput = boost::shared_ptr< WModuleInputForwardData< WDataSetFibers > >( + new WModuleInputForwardData< WDataSetFibers >( shared_from_this(), "fibers", "The fiber dataset used to find connection path." ) ); diff --git a/src/modules/connectomeView/WMConnectomeView.h b/src/modules/connectomeView/WMConnectomeView.h index 574377d68..855916515 100644 --- a/src/modules/connectomeView/WMConnectomeView.h +++ b/src/modules/connectomeView/WMConnectomeView.h @@ -33,7 +33,7 @@ #include #include -#include "../../dataHandler/WDataSetFibers2.h" +#include "../../dataHandler/WDataSetFibers.h" #include "../../kernel/WModule.h" #include "../../kernel/WModuleContainer.h" @@ -116,7 +116,7 @@ private: /** * The fiber dataset used. */ - boost::shared_ptr< WModuleInputForwardData< WDataSetFibers2 > > m_fiberInput; + boost::shared_ptr< WModuleInputForwardData< WDataSetFibers > > m_fiberInput; /** * the current dataset diff --git a/src/modules/navSlices/WMNavSlices.cpp b/src/modules/navSlices/WMNavSlices.cpp index e859daebb..9302a130e 100644 --- a/src/modules/navSlices/WMNavSlices.cpp +++ b/src/modules/navSlices/WMNavSlices.cpp @@ -141,6 +141,12 @@ void WMNavSlices::properties() m_maxAxial = m_properties2->addProperty( "maxAxial", "Max position of axial slice.", 160, true ); m_maxCoronal = m_properties2->addProperty( "maxCoronal", "Max position of coronal slice.", 200, true ); m_maxSagittal = m_properties2->addProperty( "maxSagittal", "Max position of sagittal slice.", 160, true ); + + WPropDouble d = m_properties2->addProperty( "hallo", "Position of axial slice.", 5.0 ); + d->setMin( 0.5 ); + d->setMax( 10.2 ); + + WPropString s = m_properties2->addProperty( "hallo2", "Position of axial slice.", std::string( "hallo du" ) ); } void WMNavSlices::notifyDataChange( boost::shared_ptr input, -- GitLab