Commit afa68935 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[FIX #188] the property group widget now adds and removes properties on the...

[FIX #188] the property group widget now adds and removes properties on the fly if the get added/removed in the associated group. But there still is a problem with the QLayout which then somehow resizes itself. Which looks ugly.
parent 82609616
......@@ -931,41 +931,13 @@ void WQtControlPanel::setActiveModule( WModule::SPtr module, bool forceUpdate )
m_ignoreSelectionChange = false;
}
WQtPropertyGroupWidget* WQtControlPanel::buildPropWidget( WPropertyGroupBase::SPtr props )
{
WQtPropertyGroupWidget* tab = new WQtPropertyGroupWidget( props );
if( props.get() )
{
// read lock, gets unlocked upon destruction (out of scope)
WPropertyGroupBase::PropertySharedContainerType::ReadTicket propAccess = props->getProperties();
tab->setName( QString::fromStdString( props->getName() ) );
// iterate all properties.
for( WPropertyGroupBase::PropertyConstIterator iter = propAccess->get().begin(); iter != propAccess->get().end(); ++iter )
{
if( ( *iter )->getType() == PV_GROUP )
{
tab->addGroup( buildPropWidget( ( *iter )->toPropGroupBase() ) );
}
else
{
tab->addProp( *iter );
}
}
}
tab->addSpacer();
return tab;
}
void WQtControlPanel::buildPropTab( boost::shared_ptr< WProperties > props, boost::shared_ptr< WProperties > infoProps )
{
WQtPropertyGroupWidget* tab = NULL;
WQtPropertyGroupWidget* infoTab = NULL;
if( props )
{
tab = buildPropWidget( props );
tab = new WQtPropertyGroupWidget( props );
if( tab )
{
tab->setName( "Settings" );
......@@ -973,7 +945,7 @@ void WQtControlPanel::buildPropTab( boost::shared_ptr< WProperties > props, boos
}
if( infoProps )
{
infoTab = buildPropWidget( infoProps );
infoTab = new WQtPropertyGroupWidget( infoProps );
if( infoTab )
{
infoTab->setName( "Information" );
......
......@@ -426,16 +426,6 @@ private slots:
*/
void buildPropTab( boost::shared_ptr< WProperties > props, boost::shared_ptr< WProperties > infoProps );
/**
* Method builds a widgets containing all properties in props. It recursively calls itself to build group widgets for WPropertyGroupBase properties.
*
* \param props the properties.
*/
WQtPropertyGroupWidget* buildPropWidget( WPropertyGroupBase::SPtr props );
/**
* function gets called when a change to a tree item, eg. check box status, occurs
*/
/**
* Function gets change when a change to a tree item occurs.
*
......
......@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include <string>
#include <algorithm>
#include <QtGui/QApplication>
#include <QtGui/QGroupBox>
......@@ -33,6 +34,7 @@
#include "../events/WPropertyChangedEvent.h"
#include "core/common/WPropertyGroupBase.h"
#include "core/common/WLogger.h"
#include "../WGuiConsts.h"
......@@ -42,7 +44,6 @@
WQtPropertyGroupWidget::WQtPropertyGroupWidget( WPropertyGroupBase::SPtr group, QWidget* parent )
: QWidget( parent ),
m_name( group->getName().c_str() ),
m_numberOfWidgets( 0 ),
m_group( group )
{
// note: never do layouts as none pointers
......@@ -57,6 +58,18 @@ WQtPropertyGroupWidget::WQtPropertyGroupWidget( WPropertyGroupBase::SPtr group,
m_pageLayout->addLayout( m_controlLayout );
// add the groups children
// read lock, gets unlocked upon destruction (out of scope)
WPropertyGroupBase::PropertySharedContainerType::ReadTicket propAccess = group->getProperties();
setName( QString::fromStdString( group->getName() ) );
// iterate all properties.
for( WPropertyGroupBase::PropertyConstIterator iter = propAccess->get().begin(); iter != propAccess->get().end(); ++iter )
{
addProp( *iter );
}
addSpacer();
// empty groups are hidden too
// NOTE: the WPropertyGroupBase class fires the update condition if a prop gets added. So it automatically un-hides if a prop is added.
WPropertyGroupBase::PropertySharedContainerType::ReadTicket r = m_group->getReadTicket();
......@@ -89,29 +102,64 @@ bool WQtPropertyGroupWidget::event( QEvent* event )
if( event->type() == WQT_PROPERTY_CHANGED_EVENT )
{
WPropertyGroupBase::PropertySharedContainerType::ReadTicket r = m_group->getReadTicket();
// handle the case of a hidden property
setHidden( r->get().empty() | m_group->isHidden() );
emit hideSignal( m_group->isHidden() );
// Remove all items we have a widget for but which is not in the property group anymore
for( PropertyWidgets::iterator i = m_propWidgets.begin(); i != m_propWidgets.end(); ++i )
{
// element in the group?
WPropertyGroupBase::PropertyContainerType::const_iterator found = std::find( r->get().begin(), r->get().end(), i->first );
if( found == r->get().end() )
{
// NO! Remove the widget. But not yet.
delete( i->second );
i->second = NULL;
}
}
// Add all properties as widget of not yet there
for( WPropertyGroupBase::PropertyContainerType::const_iterator i = r->get().begin(); i != r->get().end(); ++i )
{
// is there a widget for this prop?
if( !m_propWidgets.count( *i ) )
{
// NO. Add it.
addProp( *i );
}
}
return true;
}
return QWidget::event( event );
}
WPropertyWidget* WQtPropertyGroupWidget::addProp( WPropertyBase::SPtr property )
void WQtPropertyGroupWidget::addProp( WPropertyBase::SPtr property )
{
if( property->getType() == PV_GROUP )
{
addGroup( property->toPropGroupBase() );
return;
}
// create a widget and increase counter if successful
WPropertyWidget* widget = WPropertyWidget::construct( property, m_controlLayout, this );
if( widget )
{
++m_numberOfWidgets;
m_propWidgets[ property ] = widget;
}
return widget;
}
void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asScrollArea )
void WQtPropertyGroupWidget::addGroup( WPropertyGroupBase::SPtr prop )
{
++m_numberOfWidgets;
addGroup( new WQtPropertyGroupWidget( prop ) );
}
void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asScrollArea )
{
// create a scrollbox and group box containing the widget
QWidget* group = new QWidget( this );
......@@ -174,6 +222,9 @@ void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asSc
// hide the box too if the property gets hidden
box->setHidden( widget->isHidden() );
connect( widget, SIGNAL( hideSignal( bool ) ), box, SLOT( setHidden( bool ) ) );
// also keep track of group widgets
m_propWidgets[ widget->getPropertyGroup() ] = box;
}
void WQtPropertyGroupWidget::addSpacer()
......@@ -194,5 +245,10 @@ void WQtPropertyGroupWidget::setName( QString name )
bool WQtPropertyGroupWidget::isEmpty() const
{
return !m_numberOfWidgets;
return m_propWidgets.empty();
}
WPropertyGroupBase::SPtr WQtPropertyGroupWidget::getPropertyGroup()
{
return m_group;
}
......@@ -26,11 +26,11 @@
#define WQTPROPERTYGROUPWIDGET_H
#include <string>
#include <map>
#include <QtGui/QGridLayout>
#include <QtGui/QWidget>
#include "WPropertyBoolWidget.h"
#include "WPropertyIntWidget.h"
#include "WPropertyStringWidget.h"
......@@ -84,13 +84,11 @@ public:
QPushButton* addPushButton( QString label );
/**
* Adds a new property widget to the PropertyGroup. Returns NULL if property not supported.
* Adds a new property widget to the PropertyGroup. Returns NULL if property not supported. This also supports groups.
*
* \param property the property to add.
*
* \return the widget that has been added.
*/
WPropertyWidget* addProp( WPropertyBase::SPtr property );
void addProp( WPropertyBase::SPtr property );
/**
* Adds an widget containing another property group to this widget. It encloses it with a GroupBox.
......@@ -100,6 +98,13 @@ public:
*/
void addGroup( WQtPropertyGroupWidget* widget, bool asScrollArea = false );
/**
* Add the given prop group to this widget.
*
* \param prop the property group
*/
void addGroup( WPropertyGroupBase::SPtr prop );
/**
* helper function to add a spacer at the end
*/
......@@ -119,6 +124,13 @@ public:
*/
void setName( QString name );
/**
* Get the managed group of this widget.
*
* \return the group
*/
WPropertyGroupBase::SPtr getPropertyGroup();
signals:
/**
......@@ -171,6 +183,16 @@ private:
*/
WPropertyGroupBase::SPtr m_group;
/**
* The map between a prop and the widget handling it.
*/
typedef std::map< WPropertyBase::SPtr, QWidget* > PropertyWidgets;
/**
* The map if property pointer to actual property widget.
*/
PropertyWidgets m_propWidgets;
/**
* The connection for propertyChangeNotifier().
*/
......
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