Commit 7fdd2e95 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[ADD] - added new properties to the GUI with new more generic widget classes

[CHANGE] - added new properties to navslices
parent e0358de4
...@@ -45,7 +45,7 @@ WProperties2::~WProperties2() ...@@ -45,7 +45,7 @@ WProperties2::~WProperties2()
void WProperties2::addProperty( boost::shared_ptr< WPropertyBase > prop ) void WProperties2::addProperty( boost::shared_ptr< WPropertyBase > prop )
{ {
boost::unique_lock< boost::shared_mutex > lock = boost::unique_lock< boost::shared_mutex >( m_updateLock ); boost::unique_lock< boost::shared_mutex > lock = boost::unique_lock< boost::shared_mutex >( m_updateLock );
m_properties.insert( prop ); m_properties.push_back( prop );
lock.unlock(); lock.unlock();
} }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include <set> #include <vector>
#include <boost/thread/thread.hpp> #include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
/** /**
* The iterator used to iterate over the property set * The iterator used to iterate over the property set
*/ */
typedef std::set< boost::shared_ptr< WPropertyBase > >::iterator PropertyIterator; typedef std::vector< boost::shared_ptr< WPropertyBase > >::const_iterator PropertyIterator;
/** /**
* standard constructor * standard constructor
...@@ -173,7 +173,7 @@ private: ...@@ -173,7 +173,7 @@ private:
/** /**
* The set of proerties. This uses the operators ==,<,> WProperty to determine equalnes. * The set of proerties. This uses the operators ==,<,> WProperty to determine equalnes.
*/ */
std::set< boost::shared_ptr< WPropertyBase > > m_properties; std::vector< boost::shared_ptr< WPropertyBase > > m_properties;
/** /**
* boost mutex object for thread safety of updating of properties * boost mutex object for thread safety of updating of properties
...@@ -189,21 +189,32 @@ private: ...@@ -189,21 +189,32 @@ private:
template< typename T> template< typename T>
boost::shared_ptr< WPropertyVariable< T > > WProperties2::addProperty( std::string name, std::string description, const T& initial ) boost::shared_ptr< WPropertyVariable< T > > WProperties2::addProperty( std::string name, std::string description, const T& initial )
{ {
return boost::shared_ptr< WPropertyVariable< T > >( new WPropertyVariable< T >( name, description, initial ) ); boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
new WPropertyVariable< T >( name, description, initial )
);
addProperty( p );
return p;
} }
template< typename T> template< typename T>
boost::shared_ptr< WPropertyVariable< T > > WProperties2::addProperty( std::string name, std::string description, const T& initial, boost::shared_ptr< WPropertyVariable< T > > WProperties2::addProperty( std::string name, std::string description, const T& initial,
boost::shared_ptr< WCondition > condition ) boost::shared_ptr< WCondition > condition )
{ {
return boost::shared_ptr< WPropertyVariable< T > >( new WPropertyVariable< T >( name, description, initial, condition ) ); boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
new WPropertyVariable< T >( name, description, initial, condition )
);
addProperty( p );
} }
template< typename T> template< typename T>
boost::shared_ptr< WPropertyVariable< T > > WProperties2::addProperty( std::string name, std::string description, const T& initial, boost::shared_ptr< WPropertyVariable< T > > WProperties2::addProperty( std::string name, std::string description, const T& initial,
WCondition::t_ConditionNotifierType notifier ) WCondition::t_ConditionNotifierType notifier )
{ {
return boost::shared_ptr< WPropertyVariable< T > >( new WPropertyVariable< T >( name, description, initial, notifier ) ); boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
new WPropertyVariable< T >( name, description, initial, notifier )
);
addProperty( p );
return p;
} }
template< typename T> template< typename T>
...@@ -211,8 +222,11 @@ boost::shared_ptr< WPropertyVariable< T > > WProperties2::addProperty( std::stri ...@@ -211,8 +222,11 @@ boost::shared_ptr< WPropertyVariable< T > > WProperties2::addProperty( std::stri
boost::shared_ptr< WCondition > condition, boost::shared_ptr< WCondition > condition,
WCondition::t_ConditionNotifierType notifier ) WCondition::t_ConditionNotifierType notifier )
{ {
return boost::shared_ptr< WPropertyVariable< T > >( new WPropertyVariable< T >( name, description, initial, condition, boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
notifier ) ); new WPropertyVariable< T >( name, description, initial, condition, notifier )
);
addProperty( p );
return p;
} }
#endif // WPROPERTIES2_H #endif // WPROPERTIES2_H
...@@ -24,7 +24,10 @@ ...@@ -24,7 +24,10 @@
#include <string> #include <string>
#include <boost/filesystem.hpp>
#include "WPropertyBase.h" #include "WPropertyBase.h"
#include "WPropertyVariable.h"
WPropertyBase::WPropertyBase( std::string name, std::string description ): WPropertyBase::WPropertyBase( std::string name, std::string description ):
m_name( name ), m_name( name ),
...@@ -54,6 +57,11 @@ PROPERTY_TYPE WPropertyBase::getType() const ...@@ -54,6 +57,11 @@ PROPERTY_TYPE WPropertyBase::getType() const
return m_type; return m_type;
} }
void WPropertyBase::updateType()
{
m_type = PV_UNKNOWN;
}
bool WPropertyBase::isHidden() const bool WPropertyBase::isHidden() const
{ {
return m_hidden; return m_hidden;
...@@ -64,3 +72,33 @@ void WPropertyBase::setHidden( bool hidden ) ...@@ -64,3 +72,33 @@ void WPropertyBase::setHidden( bool hidden )
m_hidden = hidden; m_hidden = hidden;
} }
WPropInt WPropertyBase::toPropInt()
{
return boost::shared_static_cast< WPropertyVariable< int32_t > >( shared_from_this() );
}
WPropDouble WPropertyBase::toPropDouble()
{
return boost::shared_static_cast< WPropertyVariable< double > >( shared_from_this() );
}
WPropBool WPropertyBase::toPropBool()
{
return boost::shared_static_cast< WPropertyVariable< bool > >( shared_from_this() );
}
WPropString WPropertyBase::toPropString()
{
return boost::shared_static_cast< WPropertyVariable< std::string > >( shared_from_this() );
}
WPropFilename WPropertyBase::toPropPath()
{
return boost::shared_static_cast< WPropertyVariable< boost::filesystem::path > >( shared_from_this() );
}
WPropList WPropertyBase::toPropList()
{
return boost::shared_static_cast< WPropertyVariable< std::list< std::string > > >( shared_from_this() );
}
...@@ -27,12 +27,15 @@ ...@@ -27,12 +27,15 @@
#include <string> #include <string>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include "WPropertyTypes.h" #include "WPropertyTypes.h"
/** /**
* Abstract base class for all properties. Simply provides name and type information. * Abstract base class for all properties. Simply provides name and type information.
*/ */
class WPropertyBase class WPropertyBase: public boost::enable_shared_from_this< WPropertyBase >
{ {
public: public:
...@@ -84,6 +87,52 @@ public: ...@@ -84,6 +87,52 @@ public:
*/ */
virtual PROPERTY_TYPE getType() const; virtual PROPERTY_TYPE getType() const;
/////////////////////////////////////////////////////////////////////////////////////////////
// Helpers for easy conversion to the possible types
/////////////////////////////////////////////////////////////////////////////////////////////
/**
* Helper converts this instance to its native type.
*
* \return the property as integer property
*/
WPropInt toPropInt();
/**
* Helper converts this instance to its native type.
*
* \return the property as double property
*/
WPropDouble toPropDouble();
/**
* Helper converts this instance to its native type.
*
* \return the property as bool property
*/
WPropBool toPropBool();
/**
* Helper converts this instance to its native type.
*
* \return the property as string property
*/
WPropString toPropString();
/**
* Helper converts this instance to its native type.
*
* \return the property as path property
*/
WPropFilename toPropPath();
/**
* Helper converts this instance to its native type.
*
* \return the property as list property
*/
WPropList toPropList();
protected: protected:
/** /**
...@@ -109,7 +158,7 @@ protected: ...@@ -109,7 +158,7 @@ protected:
/** /**
* Calculates the type of the property. This has to be done by the implementing class. * Calculates the type of the property. This has to be done by the implementing class.
*/ */
virtual void updateType() = 0; virtual void updateType();
private: private:
}; };
......
...@@ -32,21 +32,57 @@ ...@@ -32,21 +32,57 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
template < typename T >
class WPropertyVariable;
/** /**
* Enum of all possible types, that can be used with WProperty. * Enum of all possible types, that can be used with WProperty.
*/ */
typedef enum typedef enum
{ {
UNKNOWN, // type not know PV_UNKNOWN, // type not know
INT, // integer value PV_INT, // integer value
DOUBLE, // floating point value PV_DOUBLE, // floating point value
BOOL, // boolean PV_BOOL, // boolean
STRING, // a string PV_STRING, // a string
PATH, // a Boost Path object denoting a filename/path PV_PATH, // a Boost Path object denoting a filename/path
LIST // a list of strings PV_LIST // a list of strings
} }
PROPERTY_TYPE; PROPERTY_TYPE;
/**
* Some convenience type alias for a even more easy usage of WPropertyVariable
*/
/**
* Alias for int32_t property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< int32_t > > WPropInt;
/**
* Alias for int32_t property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< double > > WPropDouble;
/**
* Alias for bool property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< bool > > WPropBool;
/**
* Alias for string property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< std::string > > WPropString;
/**
* Alias for filename property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< boost::filesystem::path > > WPropFilename;
/**
* Alias for string list property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< std::list< std::string > > > WPropList;
/** /**
* This namespace contains several helper classes which translate their template type to an enum. * This namespace contains several helper classes which translate their template type to an enum.
*/ */
...@@ -66,7 +102,7 @@ namespace PROPERTY_TYPE_HELPER ...@@ -66,7 +102,7 @@ namespace PROPERTY_TYPE_HELPER
*/ */
PROPERTY_TYPE getType() PROPERTY_TYPE getType()
{ {
return UNKNOWN; return PV_UNKNOWN;
} }
}; };
...@@ -84,7 +120,7 @@ namespace PROPERTY_TYPE_HELPER ...@@ -84,7 +120,7 @@ namespace PROPERTY_TYPE_HELPER
*/ */
PROPERTY_TYPE getType() PROPERTY_TYPE getType()
{ {
return BOOL; return PV_BOOL;
} }
}; };
...@@ -102,7 +138,7 @@ namespace PROPERTY_TYPE_HELPER ...@@ -102,7 +138,7 @@ namespace PROPERTY_TYPE_HELPER
*/ */
PROPERTY_TYPE getType() PROPERTY_TYPE getType()
{ {
return INT; return PV_INT;
} }
}; };
...@@ -120,7 +156,7 @@ namespace PROPERTY_TYPE_HELPER ...@@ -120,7 +156,7 @@ namespace PROPERTY_TYPE_HELPER
*/ */
PROPERTY_TYPE getType() PROPERTY_TYPE getType()
{ {
return DOUBLE; return PV_DOUBLE;
} }
}; };
...@@ -138,7 +174,7 @@ namespace PROPERTY_TYPE_HELPER ...@@ -138,7 +174,7 @@ namespace PROPERTY_TYPE_HELPER
*/ */
PROPERTY_TYPE getType() PROPERTY_TYPE getType()
{ {
return STRING; return PV_STRING;
} }
}; };
...@@ -156,7 +192,7 @@ namespace PROPERTY_TYPE_HELPER ...@@ -156,7 +192,7 @@ namespace PROPERTY_TYPE_HELPER
*/ */
PROPERTY_TYPE getType() PROPERTY_TYPE getType()
{ {
return PATH; return PV_PATH;
} }
}; };
...@@ -174,10 +210,9 @@ namespace PROPERTY_TYPE_HELPER ...@@ -174,10 +210,9 @@ namespace PROPERTY_TYPE_HELPER
*/ */
PROPERTY_TYPE getType() PROPERTY_TYPE getType()
{ {
return LIST; return PV_LIST;
} }
}; };
} }
#endif // WPROPERTYTYPES_H #endif // WPROPERTYTYPES_H
...@@ -133,6 +133,7 @@ WPropertyVariable< T >::WPropertyVariable( std::string name, std::string descrip ...@@ -133,6 +133,7 @@ WPropertyVariable< T >::WPropertyVariable( std::string name, std::string descrip
WFlag< T >( new WCondition(), initial ), WFlag< T >( new WCondition(), initial ),
WPropertyBase( name, description ) WPropertyBase( name, description )
{ {
updateType();
} }
template < typename T > template < typename T >
...@@ -140,6 +141,7 @@ WPropertyVariable< T >::WPropertyVariable( std::string name, std::string descrip ...@@ -140,6 +141,7 @@ WPropertyVariable< T >::WPropertyVariable( std::string name, std::string descrip
WFlag< T >( condition, initial ), WFlag< T >( condition, initial ),
WPropertyBase( name, description ) WPropertyBase( name, description )
{ {
updateType();
} }
template < typename T > template < typename T >
...@@ -148,6 +150,8 @@ WPropertyVariable< T >::WPropertyVariable( std::string name, std::string descrip ...@@ -148,6 +150,8 @@ WPropertyVariable< T >::WPropertyVariable( std::string name, std::string descrip
WFlag< T >( new WCondition(), initial ), WFlag< T >( new WCondition(), initial ),
WPropertyBase( name, description ) WPropertyBase( name, description )
{ {
updateType();
// set custom notifier // set custom notifier
m_notifierConnection = WFlag< T >::getCondition()->subscribeSignal( notifier ); m_notifierConnection = WFlag< T >::getCondition()->subscribeSignal( notifier );
} }
...@@ -158,6 +162,7 @@ WPropertyVariable< T >::WPropertyVariable( std::string name, std::string descrip ...@@ -158,6 +162,7 @@ WPropertyVariable< T >::WPropertyVariable( std::string name, std::string descrip
WFlag< T >( condition, initial ), WFlag< T >( condition, initial ),
WPropertyBase( name, description ) WPropertyBase( name, description )
{ {
updateType();
// set custom notifier // set custom notifier
m_notifierConnection = WFlag< T >::getCondition()->subscribeSignal( notifier ); m_notifierConnection = WFlag< T >::getCondition()->subscribeSignal( notifier );
} }
...@@ -188,38 +193,5 @@ void WPropertyVariable< T >::updateType() ...@@ -188,38 +193,5 @@ void WPropertyVariable< T >::updateType()
m_type = tid.getType(); m_type = tid.getType();
} }
/**
* Some convenience type alias for a even more easy usage of WPropertyVariable
*/
/**
* Alias for int32_t property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< int32_t > > WPropInt;
/**
* Alias for int32_t property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< double > > WPropDouble;
/**
* Alias for bool property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< bool > > WPropBool;
/**
* Alias for string property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< std::string > > WPropString;
/**
* Alias for filename property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< boost::filesystem::path > > WPropFilename;
/**
* Alias for string list property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< std::list< std::string > > > WPropList;
#endif // WPROPERTYVARIABLE_H #endif // WPROPERTYVARIABLE_H
...@@ -15,7 +15,9 @@ SET(GUI_QT4_MOC_HDRS ...@@ -15,7 +15,9 @@ SET(GUI_QT4_MOC_HDRS
WQtNavGLWidget.h WQtNavGLWidget.h
WPropertyManager.h WPropertyManager.h
guiElements/WQtPushButton.h guiElements/WQtPushButton.h
datasetbrowser/WQtCheckBox.h datasetbrowser/WPropertyWidget.h
datasetbrowser/WPropertyBoolWidget.h
datasetbrowser/WPropertyIntWidget.h
datasetbrowser/WQtDatasetBrowser.h datasetbrowser/WQtDatasetBrowser.h
datasetbrowser/WQtDSBWidget.h datasetbrowser/WQtDSBWidget.h
datasetbrowser/WQtLineEdit.h datasetbrowser/WQtLineEdit.h
......
...@@ -22,27 +22,35 @@ ...@@ -22,27 +22,35 @@
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#include <string> #include "WPropertyBoolWidget.h"
#include "WQtCheckBox.h" #include "../../../common/WPropertyVariable.h"
WQtCheckBox::WQtCheckBox() WPropertyBoolWidget::WPropertyBoolWidget( WPropBool property, QGridLayout* propertyGrid, QWidget* parent ):
: QCheckBox() WPropertyWidget( property, propertyGrid, parent ),
m_boolProperty( property ),
m_checkbox( this ),
m_layout()
{ {
m_name = ""; // initialize members
connect( this, SIGNAL( toggled( bool ) ), this, SLOT( emitStateChanged() ) ); m_checkbox.setChecked( m_boolProperty->get() );
}
WQtCheckBox::~WQtCheckBox() // layout both against each other
{ m_layout.addWidget( &m_checkbox );
setLayout( &m_layout );
// connect the modification signal of m_checkbox with our callback
connect( &m_checkbox, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) );
} }
void WQtCheckBox::setName( QString name ) WPropertyBoolWidget::~WPropertyBoolWidget()
{ {
m_name = name; // cleanup
} }
void WQtCheckBox::emitStateChanged() void WPropertyBoolWidget::changed()
{ {
emit checkBoxStateChanged( m_name, this->isChecked() );