Commit 3812d3c0 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - property widget now more centralized in WPropertyWidget and now...

[CHANGE] - property widget now more centralized in WPropertyWidget and now also supporting WPropertyStruct.
parent cf674172
......@@ -375,7 +375,7 @@ public:
virtual bool setAsString( std::string value )
{
// this method splits the given string and simply forwards the call to the other properties
std::vector< std::string > propsAsString = string_utils::tokenize( value, "|" );
std::vector< std::string > propsAsString = string_utils::tokenize( value, "|", false );
if( size() != propsAsString.size() )
{
return false;
......@@ -388,6 +388,7 @@ public:
bool success = true;
for( std::vector< std::string >::const_iterator iter = propsAsString.begin(); iter != propsAsString.end(); ++iter )
{
success = success && l->get()[ curPropNb ]->setAsString( *iter );
curPropNb++;
}
......
......@@ -78,7 +78,8 @@ typedef enum
PV_TRIGGER, //!< for triggering an event
PV_MATRIX4X4, //!< for 4x4 matrices
PV_TRANSFERFUNCTION, //!< for transfer function textures
PV_STRUCT //!< for complex, structured properties (used by \ref WPropertyStruct)
PV_STRUCT, //!< for complex, structured properties (used by \ref WPropertyStruct)
PV_LIST //!< for a dynamic list of properties of the same type (see \ref WPropertyList)
}
PROPERTY_TYPE;
......
//---------------------------------------------------------------------------
//
// 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 <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "../WGuiConsts.h"
#include <core/common/WAssert.h>
#include "WPropertyStructWidget.h"
#include "WPropertyStructWidget.moc"
WPropertyStructWidget::WPropertyStructWidget( WPropertyGroupBase::SPtr property, QGridLayout* propertyGrid, QWidget* parent ):
WPropertyWidget( property, propertyGrid, parent ),
m_struct( property ),
m_layout( &m_parameterWidgets )
{
// although we could also work with other group types, we limit this widget to PV_STRUCT properties, because they have fixed size and cannot
// be modified somehow. If you remove this assert, ensure the widget is able to handle dynamic updates in the group!
WAssert( property->getType() == PV_STRUCT, "WPropertyStructWidget is only compatible with WPropertyStruct instances." );
// go through the widgets
WPropertyGroupBase::PropertySharedContainerType::ReadTicket r = property->getProperties();
for( WPropertyGroupBase::PropertyConstIterator iter = r->get().begin(); iter != r->get().end(); ++iter )
{
WAssert( ( *iter )->getType() != PV_GROUP, "WPropertyStructWidget does not support PV_GROUP properties in a struct." );
// create the widget. Leave the control layout NULL to only get the info widget and parameter widget without label
WPropertyWidget* w = WPropertyWidget::construct( *iter, NULL, this );
WAssert( w, "WPropertyStructWidget does not support other unsupported properties in a struct." );
// add the widgets
m_layout.addWidget( w );
// store the list of widgets to later forward the update calls
m_widgets.push_back( w );
}
// layout both against each other
m_layout.setMargin( WGLOBAL_MARGIN );
m_layout.setSpacing( WGLOBAL_SPACING );
m_parameterWidgets.setLayout( &m_layout );
// NOTE: an info layout is not needed. This is automatically done by the child widgets
}
WPropertyStructWidget::~WPropertyStructWidget()
{
// cleanup
}
void WPropertyStructWidget::update()
{
for( WidgetList::const_iterator iter = m_widgets.begin(); iter != m_widgets.end(); ++iter )
{
( *iter )->requestUpdate();
}
}
//---------------------------------------------------------------------------
//
// 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 <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WPROPERTYSTRUCTWIDGET_H
#define WPROPERTYSTRUCTWIDGET_H
#include <string>
#include <QtGui/QCheckBox>
#include <QtGui/QAction>
#include <QtGui/QHBoxLayout>
#include <core/common/WPropertyGroupBase.h>
#include "WPropertyWidget.h"
/**
* Implements a property widget for arbitrary WPropStruct. It only needs the WPropertyGroupBase interface, so can be used for other props
* providing this interface. But this widget assumes that the number of props inside the group is fixed.
*/
class WPropertyStructWidget: 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
*/
WPropertyStructWidget( WPropertyGroupBase::SPtr property, QGridLayout* propertyGrid, QWidget* parent = 0 );
/**
* Destructor.
*/
virtual ~WPropertyStructWidget();
protected:
/**
* Called whenever the widget should update.
*/
virtual void update();
/**
* The struct property
*/
WPropertyGroupBase::SPtr m_struct;
/**
* Layout used to position the label and the checkbox
*/
QHBoxLayout m_layout;
private:
/**
* List of widgets of thiss type
*/
typedef std::vector< WPropertyWidget* > WidgetList;
/**
* list of widgets maintained to forward update calls
*/
WidgetList m_widgets;
};
#endif // WPROPERTYSTRUCTWIDGET_H
......@@ -26,9 +26,25 @@
#include <QtGui/QApplication>
#include <core/common/WLogger.h>
#include "../events/WEventTypes.h"
#include "../events/WPropertyChangedEvent.h"
#include "WPropertyBoolWidget.h"
#include "WPropertyIntWidget.h"
#include "WPropertyStringWidget.h"
#include "WPropertyDoubleWidget.h"
#include "WPropertyColorWidget.h"
#include "WPropertyFilenameWidget.h"
#include "WPropertyTriggerWidget.h"
#include "WPropertySelectionWidget.h"
#include "WPropertyPositionWidget.h"
#include "WPropertyMatrix4X4Widget.h"
#include "WPropertyTransferFunctionWidget.h"
#include "WPropertyStructWidget.h"
#include "WQtPropertyGroupWidget.h"
#include "WPropertyWidget.h"
#include "WPropertyWidget.moc"
......@@ -73,7 +89,7 @@ WPropertyWidget::WPropertyWidget( boost::shared_ptr< WPropertyBase > property,
m_label.setHidden( m_property->isHidden() );
// setup the update callback
m_connection = m_property->getUpdateCondition()->subscribeSignal( boost::bind( &WPropertyWidget::propertyChangeNotifier, this ) );
m_connection = m_property->getUpdateCondition()->subscribeSignal( boost::bind( &WPropertyWidget::requestUpdate, this ) );
}
WPropertyWidget::~WPropertyWidget()
......@@ -82,7 +98,7 @@ WPropertyWidget::~WPropertyWidget()
m_connection.disconnect();
}
void WPropertyWidget::propertyChangeNotifier()
void WPropertyWidget::requestUpdate()
{
QCoreApplication::postEvent( this, new WPropertyChangedEvent() );
}
......@@ -136,3 +152,59 @@ void WPropertyWidget::invalidate( bool invalid )
}
}
QWidget* WPropertyWidget::getParameterWidgets()
{
return &m_parameterWidgets;
}
QWidget* WPropertyWidget::getInformationWidgets()
{
return &m_informationWidgets;
}
WPropertyWidget* WPropertyWidget::construct( WPropertyBase::SPtr property, QGridLayout* propertyGrid, QWidget* parent )
{
switch ( property->getType() )
{
case PV_BOOL:
return new WPropertyBoolWidget( property->toPropBool(), propertyGrid, parent );
break;
case PV_INT:
return new WPropertyIntWidget( property->toPropInt(), propertyGrid, parent );
break;
case PV_DOUBLE:
return new WPropertyDoubleWidget( property->toPropDouble(), propertyGrid, parent );
break;
case PV_STRING:
return new WPropertyStringWidget( property->toPropString(), propertyGrid, parent );
break;
case PV_PATH:
return new WPropertyFilenameWidget( property->toPropFilename(), propertyGrid, parent );
break;
case PV_SELECTION:
return new WPropertySelectionWidget( property->toPropSelection(), propertyGrid, parent );
break;
case PV_COLOR:
return new WPropertyColorWidget( property->toPropColor(), propertyGrid, parent );
break;
case PV_POSITION:
return new WPropertyPositionWidget( property->toPropPosition(), propertyGrid, parent );
break;
case PV_TRIGGER:
return new WPropertyTriggerWidget( property->toPropTrigger(), propertyGrid, parent );
break;
case PV_STRUCT:
return new WPropertyStructWidget( property->toPropGroupBase(), propertyGrid, parent );
break;
case PV_MATRIX4X4:
return new WPropertyMatrix4X4Widget( property->toPropMatrix4X4(), propertyGrid, parent );
break;
case PV_TRANSFERFUNCTION:
return new WPropertyTransferFunctionWidget( property->toPropTransferFunction(), propertyGrid, parent );
break;
default: // NOTE:: WPropGroup will be handled in WQtConrolPanel::buildPropWidget
WLogger::getLogger()->addLogMessage( "This property type is not yet supported.", "WPropertyWidget", LL_WARNING );
break;
}
return NULL;
}
......@@ -83,6 +83,36 @@ public:
*/
virtual std::string getTooltip() const;
/**
* Returns the parameter widget for this property.
*
* \return the widget
*/
QWidget* getParameterWidgets();
/**
* Returns the info widget for this property.
*
* \return the widget.
*/
QWidget* getInformationWidgets();
/**
* Constructs a proper widget for the specified property. If the widget type is not supported, NULL is returned.
*
* \param property the property to create the widget for
* \param propertyGrid grid to provide to he widget
* \param parent parent of the widget
*
* \return widget
*/
static WPropertyWidget* construct( WPropertyBase::SPtr property, QGridLayout* propertyGrid = NULL, QWidget* parent = NULL );
/**
* Request an update of the property widget. Can be called from any thread.
*/
virtual void requestUpdate();
protected:
/**
......@@ -125,11 +155,6 @@ protected:
*/
bool m_invalid;
/**
* Callback for WPropertyBase::getChangeCondition. It emits an event to ensure all updates are done in gui thread.
*/
virtual void propertyChangeNotifier();
/**
* Custom event dispatcher. Gets called by QT's Event system every time an event got sent to this widget. This event handler
* processes property change events.
......
......@@ -865,50 +865,13 @@ WQtPropertyGroupWidget* WQtControlPanel::buildPropWidget( WPropertyGroupBase::S
// iterate all properties.
for( WPropertyGroupBase::PropertyConstIterator iter = propAccess->get().begin(); iter != propAccess->get().end(); ++iter )
{
switch ( ( *iter )->getType() )
if( ( *iter )->getType() == PV_GROUP )
{
case PV_BOOL:
tab->addProp( ( *iter )->toPropBool() );
break;
case PV_INT:
tab->addProp( ( *iter )->toPropInt() );
break;
case PV_DOUBLE:
tab->addProp( ( *iter )->toPropDouble() );
break;
case PV_STRING:
tab->addProp( ( *iter )->toPropString() );
break;
case PV_PATH:
tab->addProp( ( *iter )->toPropFilename() );
break;
case PV_SELECTION:
tab->addProp( ( *iter )->toPropSelection() );
break;
case PV_COLOR:
tab->addProp( ( *iter )->toPropColor() );
break;
case PV_POSITION:
tab->addProp( ( *iter )->toPropPosition() );
break;
case PV_TRIGGER:
tab->addProp( ( *iter )->toPropTrigger() );
break;
case PV_GROUP:
tab->addGroup( buildPropWidget( ( *iter )->toPropGroupBase() ) );
break;
case PV_STRUCT:
tab->addGroup( buildPropWidget( ( *iter )->toPropGroupBase() ) );
break;
case PV_MATRIX4X4:
tab->addProp( ( *iter )->toPropMatrix4X4() );
break;
case PV_TRANSFERFUNCTION:
tab->addProp( ( *iter )->toPropTransferFunction() );
break;
default:
WLogger::getLogger()->addLogMessage( "This property type is not yet supported.", "ControlPanel", LL_WARNING );
break;
tab->addGroup( buildPropWidget( ( *iter )->toPropGroupBase() ) );
}
else
{
tab->addProp( *iter );
}
}
}
......
......@@ -97,81 +97,15 @@ bool WQtPropertyGroupWidget::event( QEvent* event )
return QWidget::event( event );
}
WPropertyBoolWidget* WQtPropertyGroupWidget::addProp( WPropBool property )
WPropertyWidget* WQtPropertyGroupWidget::addProp( WPropertyBase::SPtr property )
{
++m_numberOfWidgets;
return new WPropertyBoolWidget( property, m_controlLayout, this );
}
WPropertyIntWidget* WQtPropertyGroupWidget::addProp( WPropInt property )
{
++m_numberOfWidgets;
return new WPropertyIntWidget( property, m_controlLayout, this );
}
WPropertyDoubleWidget* WQtPropertyGroupWidget::addProp( WPropDouble property )
{
++m_numberOfWidgets;
return new WPropertyDoubleWidget( property, m_controlLayout, this );
}
WPropertyStringWidget* WQtPropertyGroupWidget::addProp( WPropString property )
{
++m_numberOfWidgets;
return new WPropertyStringWidget( property, m_controlLayout, this );
}
WPropertyColorWidget* WQtPropertyGroupWidget::addProp( WPropColor property )
{
++m_numberOfWidgets;
return new WPropertyColorWidget( property, m_controlLayout, this );
}
WPropertyFilenameWidget* WQtPropertyGroupWidget::addProp( WPropFilename property )
{
++m_numberOfWidgets;
return new WPropertyFilenameWidget( property, m_controlLayout, this );
}
WPropertyTriggerWidget* WQtPropertyGroupWidget::addProp( WPropTrigger property )
{
++m_numberOfWidgets;
return new WPropertyTriggerWidget( property, m_controlLayout, this );
}
WPropertyPositionWidget* WQtPropertyGroupWidget::addProp( WPropPosition property )
{
++m_numberOfWidgets;
return new WPropertyPositionWidget( property, m_controlLayout, this );
}
WPropertyMatrix4X4Widget* WQtPropertyGroupWidget::addProp( WPropMatrix4X4 property )
{
++m_numberOfWidgets;
return new WPropertyMatrix4X4Widget( property, m_controlLayout, this );
}
WPropertySelectionWidget* WQtPropertyGroupWidget::addProp( WPropSelection property )
{
++m_numberOfWidgets;
return new WPropertySelectionWidget( property, m_controlLayout, this );
}
WPropertyTransferFunctionWidget* WQtPropertyGroupWidget::addProp( WPropTransferFunction property )
{
++m_numberOfWidgets;
return new WPropertyTransferFunctionWidget( property, m_controlLayout, this );
// create a widget and increase counter if successful
WPropertyWidget* widget = WPropertyWidget::construct( property, m_controlLayout, this );
if( widget )
{
++m_numberOfWidgets;
}
return widget;
}
void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asScrollArea )
......
......@@ -30,6 +30,7 @@
#include <QtGui/QGridLayout>
#include <QtGui/QWidget>
#include "WPropertyBoolWidget.h"
#include "WPropertyIntWidget.h"
#include "WPropertyStringWidget.h"
......@@ -41,8 +42,11 @@
#include "WPropertyPositionWidget.h"
#include "WPropertyMatrix4X4Widget.h"
#include "WPropertyTransferFunctionWidget.h"
#include "WPropertyStructWidget.h"
#include "core/common/WPropertyVariable.h"
#include "core/common/WPropertyStruct.h"
#include "core/common/WPropertyGroupBase.h"
/**
* Container widget to contain a number of properties for the module context in the control panel.
......@@ -80,104 +84,13 @@ public:
QPushButton* addPushButton( QString label );
/**
* Adds a new bool property to the PropertyGroup.
*
* \param property the property to add.
*
* \return the widget that has been added.
*/
WPropertyBoolWidget* addProp( WPropBool property );
/**
* Adds a new int property to the PropertyGroup.
*
* \param property the property to add.
*
* \return the widget that has been added.
*/
WPropertyIntWidget* addProp( WPropInt property );
/**
* Adds a new double property to the PropertyGroup.
*
* \param property the property to add.
*
* \return the widget that has been added.
*/
WPropertyDoubleWidget* addProp( WPropDouble property );
/**
* Adds a new string property to the PropertyGroup.
*
* \param property the property to add.
*
* \return the widget that has been added.
*/
WPropertyStringWidget* addProp( WPropString property );
/**
* Adds a new path property to the PropertyGroup.
*
* \param property the property to add.
*
* \return the widget that has been added.
*/
WPropertyFilenameWidget* addProp( WPropFilename property );
/**
* Adds a new list property to the PropertyGroup.
* Adds a new property widget to the PropertyGroup. Returns NULL if property not supported.
*
* \param property the property to add.
*
* \return the widget that has been added.
*/
WPropertySelectionWidget* addProp( WPropSelection property );
/**
* Adds a new position property to the PropertyGroup.
*
* \param property the property to add.
*
* \return the widget that has been added.
*/
WPropertyPositionWidget* addProp( WPropPosition property );
/**
* Adds a new color property to the PropertyGroup.
*
* \param property the property to add.
*
* \return the widget that has been added.
*/
WPropertyColorWidget* addProp( WPropColor property );
/**
* Adds a new trigger property to the PropertyGroup.
*
* \param property the property to add.
*
* \return the widget that has been added.
*/
WPropertyTriggerWidget* addProp( WPropTrigger property );
/**
* Adds a new trigger property to the PropertyGroup.
*