Commit 6606694a authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - properties now (hopefully) update in the GUI if the module updates the property

parent d0a08508
......@@ -412,6 +412,9 @@ template < typename T >
WPropertyVariable< T >::~WPropertyVariable()
{
// clean up
m_updateCondition->remove( m_constraintsChanged );
m_updateCondition->remove( WFlag< T >::getValueChangeCondition() );
m_notifierConnection.disconnect();
m_constraints.clear();
}
......
......@@ -24,6 +24,11 @@
#include <string>
#include <QtGui/QApplication>
#include "../events/WEventTypes.h"
#include "../events/WPropertyChangedEvent.h"
#include "WPropertyWidget.h"
WPropertyWidget::WPropertyWidget( boost::shared_ptr< WPropertyBase > property, QGridLayout* propertyGrid, QWidget* parent ):
......@@ -47,11 +52,32 @@ WPropertyWidget::WPropertyWidget( boost::shared_ptr< WPropertyBase > property,
m_propertyGrid->addWidget( &m_label, row, 0 );
m_propertyGrid->addWidget( this, row, 1 );
}
// setup the update callback
m_connection = m_property->getUpdateCondition()->subscribeSignal( boost::bind( &WPropertyWidget::propertyChangeNotifier, this ) );
}
WPropertyWidget::~WPropertyWidget()
{
// cleanup
m_connection.disconnect();
}
void WPropertyWidget::propertyChangeNotifier()
{
QCoreApplication::postEvent( this, new WPropertyChangedEvent() );
}
bool WPropertyWidget::event( QEvent* event )
{
// a property changed
if ( event->type() == WQT_PROPERTY_CHANGED_EVENT )
{
update();
return true;
}
return QWidget::event( event );
}
std::string WPropertyWidget::getTooltip() const
......
......@@ -112,6 +112,27 @@ 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.
*
* \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 );
/**
* The connection for propertyChangeNotifier().
*/
boost::signals2::connection m_connection;
private:
};
......
......@@ -162,6 +162,8 @@ void WMTemplate::properties()
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
m_enableFeature = m_properties->addProperty( "Enable Feature", "Description.", true );
m_anInteger = m_properties->addProperty( "Number of Shape Rows", "Number of shape rows.", 10, m_propCondition );
m_anIntegerClone = m_properties->addProperty( "CLONE!Number of Shape Rows",
"A property which gets modified if \"Number of shape rows\" gets modified.", 10 );
m_aDouble = m_properties->addProperty( "Shape Radii", "Shape radii.", 20.0, m_propCondition );
m_aString = m_properties->addProperty( "A String", "Something.", std::string( "hello" ), m_propCondition );
m_aFile = m_properties->addProperty( "A Filenname", "Description.", WKernel::getAppPathObject(), m_propCondition );
......@@ -173,6 +175,10 @@ void WMTemplate::properties()
// 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.
//
// m_anIntegerClone has a special purpose in this example. It shows that you can simply update properties from within your module whilst the
// GUI updates itself. You can, for example, set constraints or simply modify values depending on input data, most probably useful to set
// nice default values or min/max constraints.
// 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.
......@@ -346,6 +352,12 @@ void WMTemplate::moduleMain()
int rows = m_anInteger->get( true );
double radii = m_aDouble->get( true );
// You can set other properties here. This example simply sets the value of m_anIntegerClone. The set command allows an additional
// parameter. If it is true, the specified property condition does not fire if it is set. This is useful if your module main loop
// waits for the condition of the property you want to set. Setting the property without suppressing the notification would cause
// another loop in your module.
m_anIntegerClone->set( m_anInteger->get(), true );
debugLog() << "Number of Rows: " << rows;
debugLog() << "Radii: " << radii;
debugLog() << "Current dataset: " << m_dataSet->getFileName() << " with name: " << m_dataSet->getName();
......
......@@ -156,6 +156,11 @@ private:
*/
WPropInt m_anInteger;
/**
* An integer value. It is synchronized with m_anInteger.
*/
WPropInt m_anIntegerClone;
/**
* A double 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