Commit 67ebf72e authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[FIX] - group widgets now get hidden properly.

parent 321e7faf
......@@ -804,8 +804,7 @@ void WQtControlPanel::selectDataModule( boost::shared_ptr< WDataSet > dataSet )
WQtPropertyGroupWidget* WQtControlPanel::buildPropWidget( boost::shared_ptr< WProperties > props )
{
WQtPropertyGroupWidget* tab = new WQtPropertyGroupWidget( props->getName() );
WQtPropertyGroupWidget* tab = new WQtPropertyGroupWidget( props );
if ( props.get() )
{
// read lock, gets unlocked upon destruction (out of scope)
......
......@@ -24,18 +24,45 @@
#include <string>
#include <QtGui/QApplication>
#include <QtGui/QGroupBox>
#include <QtGui/QPushButton>
#include <QtGui/QScrollArea>
#include "../events/WEventTypes.h"
#include "../events/WPropertyChangedEvent.h"
#include "../../../common/WProperties.h"
#include "WQtPropertyGroupWidget.h"
WQtPropertyGroupWidget::WQtPropertyGroupWidget( WPropGroup group, QWidget* parent )
: QWidget( parent ),
m_name( group->getName().c_str() ),
m_numberOfWidgets( 0 ),
m_group( group )
{
// note: never do layouts as none pointers
// on destruction of a widget it will try to delete them which will cause crashes
m_pageLayout = new QVBoxLayout();
m_controlLayout = new QGridLayout();
m_pageLayout->addLayout( m_controlLayout );
// NOTE: a simple setHidden( group->isHidden() ) causes the QWidgets to popup if hidden is false. This is why we set hidden only if it really
// is needed
if ( group->isHidden() )
{
setHidden( true );
}
// setup the update callback
m_connection = m_group->getUpdateCondition()->subscribeSignal( boost::bind( &WQtPropertyGroupWidget::propertyChangeNotifier, this ) );
}
WQtPropertyGroupWidget::WQtPropertyGroupWidget( std::string name, QWidget* parent )
: QWidget( parent ),
m_name( name.c_str() ),
// m_controlLayout(),
// m_pageLayout(),
m_numberOfWidgets( 0 )
m_numberOfWidgets( 0 ),
m_group()
{
// note: never do layouts as none pointers
// on destruction of a widget it will try to delete them which will cause crashes
......@@ -46,6 +73,26 @@ WQtPropertyGroupWidget::WQtPropertyGroupWidget( std::string name, QWidget* paren
WQtPropertyGroupWidget::~WQtPropertyGroupWidget()
{
// cleanup
m_connection.disconnect();
}
void WQtPropertyGroupWidget::propertyChangeNotifier()
{
QCoreApplication::postEvent( this, new WPropertyChangedEvent() );
}
bool WQtPropertyGroupWidget::event( QEvent* event )
{
// a property changed
if ( event->type() == WQT_PROPERTY_CHANGED_EVENT )
{
setHidden( m_group->isHidden() );
emit hideSignal( m_group->isHidden() );
return true;
}
return QWidget::event( event );
}
WPropertyBoolWidget* WQtPropertyGroupWidget::addProp( WPropBool property )
......@@ -177,6 +224,10 @@ void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asSc
// insert into layout
int row = m_controlLayout->rowCount();
m_controlLayout->addWidget( box, row, 0, 1, 2 );
// hide the box too if the property gets hidden
box->setHidden( widget->isHidden() );
connect( widget, SIGNAL( hideSignal( bool ) ), box, SLOT( setHidden( bool ) ) );
}
void WQtPropertyGroupWidget::addSpacer()
......
......@@ -51,12 +51,19 @@ class WQtPropertyGroupWidget : public QWidget
Q_OBJECT
public:
/**
* Creates new widget for a property group. Use this constructor to provide automatic hidden-flag management.
* \param group The group
* \param parent The widget managing this widget
*/
WQtPropertyGroupWidget( WPropGroup group, QWidget* parent = 0 );
/**
* Creates new widget for a property group
* \param name Name of the widget
* \param parent The widget managing this widget
*/
explicit WQtPropertyGroupWidget( std::string name, QWidget* parent = 0 );
WQtPropertyGroupWidget( std::string name, QWidget* parent = 0 );
/**
* destructor
......@@ -191,7 +198,33 @@ public:
*/
void setName( QString name );
signals:
/**
* A Signal which gets emitted whenever the widget should be hidden. This is a useful signal for containers which embed this group.
*
* \param hide if true, the widget should be hidden.
*/
void hideSignal( bool hide );
protected:
/**
* 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.
*
* \note QT Doc says: use event() for custom events.
* \param event the event that got transmitted.
*
* \return true if the event got handled properly.
*/
virtual bool event( QEvent* event );
private:
/**
......@@ -213,6 +246,16 @@ private:
* The number of widgets inside this one.
*/
unsigned int m_numberOfWidgets;
/**
* The property group handled here.
*/
WPropGroup m_group;
/**
* The connection for propertyChangeNotifier().
*/
boost::signals2::connection m_connection;
};
#endif // WQTPROPERTYGROUPWIDGET_H
......@@ -266,6 +266,7 @@ void WMTemplate::properties()
// Properties can be hidden on the fly. The GUI updates automatically. This is a very useful feature. You can create properties which depend
// on a current selection and blend them in our out accordingly.
m_aHiddenInt = m_group2->addProperty( "Hide me please", "A property used to demonstrate the hidden feature.", 1, true );
m_aHiddenGroup = m_group2->addPropertyGroup( "Hide me please too", "A property used to demonstrate the hidden feature.", true );
// Add another button to group2. But this time, we do not want to wake up the main thread. We handle this directly. Fortunately,
// WPropertyVariable offers you the possibility to specify your own change callback. This callback is used for hiding the m_aColor property
......@@ -754,10 +755,10 @@ void WMTemplate::hideButtonPressed()
// switch the hide flag of the color prop.
m_aColor->setHidden( !m_aColor->isHidden() );
m_aHiddenInt->setHidden( !m_aHiddenInt->isHidden() );
m_aHiddenGroup->setHidden( !m_aHiddenGroup->isHidden() );
// never forget to reset a trigger. If not done, the trigger is disabled in the GUI and can't be used again.
m_hideButton->set( WPVBaseTypes::PV_TRIGGER_READY );
// NOTE: this again triggers an update, which is why we need to check the state of the trigger in this if-clause.
}
}
......@@ -197,6 +197,11 @@ private:
*/
WPropInt m_aHiddenInt;
/**
* A group used to show that even hiding whole groups is possible.
*/
WPropGroup m_aHiddenGroup;
/**
* A trigger which can be used to trigger some kind of operation.
*/
......
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