Commit b6030a2f authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - properties can now be nested in groups

parent 36703156
......@@ -24,4 +24,4 @@
#include "WPreferences.h"
WProperties WPreferences::m_preferences;
WProperties WPreferences::m_preferences( "Preferences" );
......@@ -34,8 +34,7 @@
#include "WProperties.h"
WProperties::WProperties( std::string name, std::string description ):
m_name( name ),
m_description( description ),
WPropertyBase( name, description ),
m_propAccess( m_properties.getAccessObject() )
{
}
......@@ -44,14 +43,15 @@ WProperties::~WProperties()
{
}
std::string WProperties::getName() const
PROPERTY_TYPE WProperties::getType() const
{
return m_name;
return PV_GROUP;
}
std::string WProperties::getDescription() const
bool WProperties::setAsString( std::string /*value*/ )
{
return m_description;
// groups can't be set in any way. -> ignore it.
return true;
}
bool WProperties::propNamePredicate( boost::shared_ptr< WPropertyBase > prop1, boost::shared_ptr< WPropertyBase > prop2 ) const
......@@ -124,6 +124,14 @@ WProperties::PropertySharedContainerType::WSharedAccess WProperties::getAccessOb
return m_properties.getAccessObject();
}
WPropGroup WProperties::addPropertyGroup( std::string name, std::string description, bool hide )
{
WPropGroup p = WPropGroup( new WProperties( name, description ) );
p->setHidden( hide );
addProperty( p );
return p;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// convenience methods for
// template< typename T>
......
......@@ -36,16 +36,17 @@
#include "WSharedObject.h"
#include "WPropertyBase.h"
#include "WPropertyTypes.h"
#include "WPropertyVariable.h"
/**
* Class to manage properties of an object and to provide convenience methods for easy access and manipulation. It also allows
* thread safe iteration on its elements. The main purpose of this class is to group properties together and to allow searching properties by a
* given name. The name of each property in a group has to be unique and is constructed using the group names containing them: hello.you.property
* given name. The name of each property in a group has to be unique and is constructed using the group names containing them: hello/you/property
* is the property with the name "property" in the group "you" which against is in the group "hello".
* \note The root group of each module does not have a name.
*/
class WProperties
class WProperties: public WPropertyBase
{
public:
......@@ -84,27 +85,13 @@ public:
* \param name the name of the property group. The GUI is using this name for naming the tabs/group boxes
* \param description the description of the group.
*/
WProperties( std::string name = "", std::string description = "Root Group" );
WProperties( std::string name = "unnamed group", std::string description = "an unnamed group of properties" );
/**
* destructor
*/
virtual ~WProperties();
/**
* The name of this property group.
*
* \return the name
*/
std::string getName() const;
/**
* The description of this property group.
*
* \return the description.
*/
std::string getDescription() const;
/**
* Simply insert the specified property to the list.
*
......@@ -149,6 +136,15 @@ public:
// Convenience methods to create and add properties
///////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Create and add a new property group. Use these groups to structure your properties.
*
* \param name the name of the group.
* \param description the description of the group.
* \param hide true if group should be completely hidden.
*/
WPropGroup addPropertyGroup( std::string name, std::string description, bool hide = false );
/**
* Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
*
......@@ -217,6 +213,22 @@ public:
boost::shared_ptr< WCondition > condition,
WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
/**
* Gets the real type of this instance. In this case, PV_GROUP.
*
* \return the real type.
*/
virtual PROPERTY_TYPE getType() const;
/**
* This methods allows properties to be set by a string value. This method does nothing here, as groups can not be set in any kind.
*
* \param value the new value to set. IGNORED.
*
* \return always true
*/
virtual bool setAsString( std::string value );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Convenience methods to create and add properties
// NOTE: these methods use the type of the initial parameter to automatically use the proper type.
......@@ -775,16 +787,6 @@ public:
private:
/**
* The name of this properties group.
*/
std::string m_name;
/**
* The description of this property group.
*/
std::string m_description;
/**
* The set of proerties. This uses the operators ==,<,> WProperty to determine equalness.
*/
......
......@@ -30,6 +30,7 @@
#include "exceptions/WPropertyNameMalformed.h"
#include "WPropertyBase.h"
#include "WProperties.h"
#include "WPropertyVariable.h"
WPropertyBase::WPropertyBase( std::string name, std::string description ):
......@@ -120,3 +121,8 @@ WPropPosition WPropertyBase::toPropPosition()
return boost::shared_static_cast< WPVPosition >( shared_from_this() );
}
WPropGroup WPropertyBase::toPropGroup()
{
return boost::shared_static_cast< WPVGroup >( shared_from_this() );
}
......@@ -160,6 +160,13 @@ public:
*/
WPropPosition toPropPosition();
/**
* Helper converts this instance to its native type.
*
* \return the property as group
*/
WPropGroup toPropGroup();
/**
* Helper converts this instance to an arbitrary type.
*
......
......@@ -38,6 +38,7 @@
template < typename T >
class WPropertyVariable;
class WProperties;
////////////////////////////////////////////////////////////////////////////////////////////////////////
// NOTE: If you add new types here, please also add corresponding addProperty methods to WProperties
......@@ -53,6 +54,7 @@ class WPropertyVariable;
typedef enum
{
PV_UNKNOWN, // type not know
PV_GROUP, // the group property
PV_INT, // integer value
PV_DOUBLE, // floating point value
PV_BOOL, // boolean
......@@ -89,6 +91,11 @@ namespace WPVBaseTypes
* int32_t, double, bool, ... so we are able to change the type later on without modifications of thousands of modules.
*/
/**
* Group properties.
*/
typedef WProperties WPVGroup;
/**
* Int properties.
*/
......@@ -174,6 +181,11 @@ typedef boost::shared_ptr< WPVPosition > WPropPosition;
*/
typedef boost::shared_ptr< WPVColor > WPropColor;
/**
* Alias for the group properties.
*/
typedef boost::shared_ptr< WPVGroup > WPropGroup;
/**
* This namespace contains several helper classes which translate their template type to an enum.
*/
......
......@@ -24,6 +24,8 @@
#include <string>
#include <QtGui/QGroupBox>
#include "WQtDSBWidget.h"
WQtDSBWidget::WQtDSBWidget( std::string name, QWidget* parent )
......@@ -69,6 +71,19 @@ WPropertyFilenameWidget* WQtDSBWidget::addProp( WPropFilename property )
return new WPropertyFilenameWidget( property, &m_controlLayout, this );
}
void WQtDSBWidget::addGroup( WQtDSBWidget* widget )
{
// TODO(ebaum): extend it to collapse the group
QGroupBox* group = new QGroupBox( widget->getName() , this );
QGridLayout* grid = new QGridLayout();
grid->addWidget( widget, 0, 0 );
group->setLayout( grid );
// create a new group box
int row = m_controlLayout.rowCount();
m_controlLayout.addWidget( group, row, 0, 1, 2 );
}
void WQtDSBWidget::addSpacer()
{
m_pageLayout.addStretch();
......@@ -79,3 +94,9 @@ QString WQtDSBWidget::getName()
{
return m_name;
}
void WQtDSBWidget::setName( QString name )
{
m_name = name;
}
......@@ -137,6 +137,13 @@ public:
*/
WPropertyColorWidget* addProp( WPropColor property );
/**
* Adds an widget containing another property group to this widget. It encloses it with a GroupBox.
*
* \param widget the widget
*/
void addGroup( WQtDSBWidget* widget );
/**
* helper function to add a spacer at the end
*/
......@@ -147,6 +154,13 @@ public:
*/
QString getName();
/**
* Sets the name of this widget.
*
* \param name the name.
*/
void setName( QString name );
protected:
private:
......
......@@ -384,8 +384,7 @@ void WQtDatasetBrowser::selectRoiTreeItem()
buildPropTab( props );
}
void WQtDatasetBrowser::buildPropTab( boost::shared_ptr< WProperties > props )
WQtDSBWidget* WQtDatasetBrowser::buildPropWidget( boost::shared_ptr< WProperties > props )
{
WQtDSBWidget* tab = new WQtDSBWidget( "Settings" );
......@@ -394,6 +393,8 @@ void WQtDatasetBrowser::buildPropTab( boost::shared_ptr< WProperties > props )
WProperties::PropertyAccessType propAccess = props->getAccessObject();
propAccess->beginRead();
tab->setName( QString::fromStdString( props->getName() ) );
// iterate all properties. This Locks the properties set -> use endIteration to unlock
for ( WProperties::PropertyConstIterator iter = propAccess->get().begin(); iter != propAccess->get().end(); ++iter )
{
......@@ -427,6 +428,9 @@ void WQtDatasetBrowser::buildPropTab( boost::shared_ptr< WProperties > props )
WLogger::getLogger()->addLogMessage( "This property type \"PV_POSITION\" is not yet supported by the GUI.", "DatasetBrowser",
LL_WARNING );
break;
case PV_GROUP:
tab->addGroup( buildPropWidget( ( *iter )->toPropGroup() ) );
break;
default:
WLogger::getLogger()->addLogMessage( "This property type is not yet supported.", "DatasetBrowser", LL_WARNING );
break;
......@@ -435,7 +439,14 @@ void WQtDatasetBrowser::buildPropTab( boost::shared_ptr< WProperties > props )
}
propAccess->endRead();
}
tab->addSpacer();
return tab;
}
void WQtDatasetBrowser::buildPropTab( boost::shared_ptr< WProperties > props )
{
WQtDSBWidget* tab = buildPropWidget( props );
addTabWidgetContent( tab );
}
......@@ -498,7 +509,7 @@ void WQtDatasetBrowser::addTabWidgetContent( WQtDSBWidget* content )
sa->setWidget( content );
sa->setWidgetResizable( true );
m_tabWidget->addTab( sa, content->getName() );
m_tabWidget->addTab( sa, "Settings" );
}
void WQtDatasetBrowser::moveTreeItemDown()
......
......@@ -205,10 +205,16 @@ private slots:
/**
* function that builds the property tab
*
* \param props
* \param props the properties.
*/
void buildPropTab( boost::shared_ptr< WProperties > props );
/**
* Method builds a widgets containing all properties in props. It recursively calls itself to build group widgets for WPropGroup properties.
*
* \param props the properties.
*/
WQtDSBWidget* buildPropWidget( boost::shared_ptr< WProperties > props );
/**
* function gets called when a change to a tree item, eg. check box status, occurs
......
......@@ -64,7 +64,7 @@ WModule::WModule():
m_moduleState()
{
// initialize members
m_properties = boost::shared_ptr< WProperties >( new WProperties() );
m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "Module's properties" ) );
m_active = m_properties->addProperty( "active", "Determines whether the module should be activated.", true, true );
m_active->getCondition()->subscribeSignal( boost::bind( &WModule::activate, this ) );
......
......@@ -34,7 +34,7 @@ WRMBranch::WRMBranch( boost::shared_ptr< WROIManagerFibers > roiManager ) :
m_roiManager( roiManager )
{
setDirty();
m_properties = boost::shared_ptr< WProperties >( new WProperties() );
m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "This branch's properties" ) );
m_isNot = m_properties->addProperty( "NOT", "description", false, boost::bind( &WRMBranch::slotToggleNot, this ) );
m_bundleColor = m_properties->addProperty( "Bundle Color", "description", WColor( 1.0, 0.0, 0.0, 1.0 ),
boost::bind( &WRMBranch::slotChangeBundleColor, this ) );
......
......@@ -42,7 +42,7 @@ WRMROIRepresentation::WRMROIRepresentation( osg::ref_ptr< WROI > roi, boost::sha
{
roi->getSignalIsModified()->connect( boost::bind( &WRMROIRepresentation::setDirty, this ) );
setDirty();
m_properties = boost::shared_ptr< WProperties >( new WProperties() );
m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "This ROI's properties" ) );
m_isNot = m_properties->addProperty( "NOT", "description", false, boost::bind( &WRMROIRepresentation::slotToggleNot, this ) );
m_isActive = m_properties->addProperty( "active", "description", true, boost::bind( &WRMROIRepresentation::slotToggleNot, this ) );
m_isActive->setHidden( true );
......
......@@ -169,10 +169,25 @@ void WMTemplate::properties()
// These lines create some new properties and add them to the property list of this module. The specific type to create is determined by the
// initial value specified in the third argument. The first argument is the name of the property, which needs to be unique among all
// properties of this module. The second argument is a description. A nice feature is the possibility to specify an own condition, which gets
// fired when the property gets modified. This is especially useful to wake up the module's thread on property changes. So, the property
// m_anInteger will wake the module thread on changes. m_enableFeature and m_aColor should not wake up the module thread. They get read by
// the update callback of this modules OSG node, to update the color.
// properties of this group and must not contain any slashes (/). The second argument is a description. A nice feature is the possibility
// to specify an own condition, which gets fired when the property gets modified. This is especially useful to wake up the module's thread
// on property changes. So, the property m_anInteger will wake the module thread on changes. m_enableFeature and m_aColor should not wake up
// the module thread. They get read by the update callback of this modules OSG node, to update the color.
// Adding a lot of properties might confuse the user. Using WPropGroup, you have the possibility to group your properties together. A
// WPropGroup needs a name and can provide a description. As with properties, the name should not contain any "/" and must be unique.
m_group1 = m_properties->addPropertyGroup( "Group 1", "A nice group for grouping stuff." );
m_group1a = m_group1->addPropertyGroup( "Group 1a", "A group nested into \"Group 1\"." );
m_group2 = m_properties->addPropertyGroup( "Group 2", "Another nice group for grouping stuff." );
// To understand how the groups can be used, you should consider that m_properties itself is a WPropGroup! This means, you can use your newly
// created groups exactly in the same way as you would use m_properties.
m_group1Bool = m_group1->addProperty( "Funny stuff", "A grouped property", true );
// You even can add one property multiple times to different groups:
m_group2->addProperty( m_aColor );
m_group1a->addProperty( m_aDouble );
// How can the values of the properties be changed? You can take a look at moduleMain where this is shown. For short: m_anInteger->set( 2 )
// and m_anInteger->get().
......
......@@ -126,11 +126,31 @@ private:
*/
boost::shared_ptr< WCondition > m_propCondition;
/**
* To group properties, use WPropGroup.
*/
WPropGroup m_group1;
/**
* To group properties, use WPropGroup.
*/
WPropGroup m_group1a;
/**
* To group properties, use WPropGroup.
*/
WPropGroup m_group2;
/**
* En/Disables an feature.
*/
WPropBool m_enableFeature;
/**
* A nice feature trigger inside m_group1
*/
WPropBool m_group1Bool;
/**
* An integer value.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment