Commit deb927b0 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - basic structure for automatically updating properties

parent 8bef783e
...@@ -36,15 +36,14 @@ WPropertyBoolWidget::WPropertyBoolWidget( WPropBool property, QGridLayout* prope ...@@ -36,15 +36,14 @@ WPropertyBoolWidget::WPropertyBoolWidget( WPropBool property, QGridLayout* prope
{ {
// initialize members // initialize members
m_button.setCheckable( true ); m_button.setCheckable( true );
m_checkbox.setChecked( m_boolProperty->get() ); update();
m_button.setChecked( m_boolProperty->get() );
// layout both against each other // layout both against each other
m_button.setVisible( asButton ); m_button.setVisible( m_asButton );
m_checkbox.setVisible( !asButton ); m_checkbox.setVisible( !m_asButton );
m_layout.addWidget( asButton ? static_cast< QWidget* >( &m_button ) : static_cast< QWidget* >( &m_checkbox ) ); m_layout.addWidget( m_asButton ? static_cast< QWidget* >( &m_button ) : static_cast< QWidget* >( &m_checkbox ) );
if ( asButton ) if ( m_asButton )
{ {
m_layout.setContentsMargins( 1, 1, 1, 1 ); m_layout.setContentsMargins( 1, 1, 1, 1 );
} }
...@@ -60,6 +59,13 @@ WPropertyBoolWidget::~WPropertyBoolWidget() ...@@ -60,6 +59,13 @@ WPropertyBoolWidget::~WPropertyBoolWidget()
// cleanup // cleanup
} }
void WPropertyBoolWidget::update()
{
// simply set the new state
m_checkbox.setChecked( m_boolProperty->get() );
m_button.setChecked( m_boolProperty->get() );
}
QPushButton* WPropertyBoolWidget::getButton() QPushButton* WPropertyBoolWidget::getButton()
{ {
return &m_button; return &m_button;
......
...@@ -66,6 +66,11 @@ public: ...@@ -66,6 +66,11 @@ public:
protected: protected:
/**
* Called whenever the widget should update.
*/
virtual void update();
/** /**
* The boolean property represented by this widget. * The boolean property represented by this widget.
*/ */
......
...@@ -47,8 +47,7 @@ WPropertyColorWidget::WPropertyColorWidget( WPropColor property, QGridLayout* pr ...@@ -47,8 +47,7 @@ WPropertyColorWidget::WPropertyColorWidget( WPropColor property, QGridLayout* pr
m_layout.addWidget( &m_button ); m_layout.addWidget( &m_button );
// set the initial values // set the initial values
m_button.setPalette( QPalette( toQColor( m_colorProperty->get() ) ) ); update();
// connect the modification signal of the edit and slider with our callback // connect the modification signal of the edit and slider with our callback
connect( &m_button, SIGNAL( released() ), this, SLOT( buttonReleased() ) ); connect( &m_button, SIGNAL( released() ), this, SLOT( buttonReleased() ) );
...@@ -59,6 +58,11 @@ WPropertyColorWidget::~WPropertyColorWidget() ...@@ -59,6 +58,11 @@ WPropertyColorWidget::~WPropertyColorWidget()
// cleanup // cleanup
} }
void WPropertyColorWidget::update()
{
m_button.setPalette( QPalette( toQColor( m_colorProperty->get() ) ) );
}
QColor WPropertyColorWidget::toQColor( WColor color ) QColor WPropertyColorWidget::toQColor( WColor color )
{ {
QColor tmp; QColor tmp;
......
...@@ -56,6 +56,11 @@ public: ...@@ -56,6 +56,11 @@ public:
protected: protected:
/**
* Called whenever the widget should update.
*/
virtual void update();
/** /**
* The integer property represented by this widget. * The integer property represented by this widget.
*/ */
......
...@@ -44,6 +44,19 @@ WPropertyDoubleWidget::WPropertyDoubleWidget( WPropDouble property, QGridLayout* ...@@ -44,6 +44,19 @@ WPropertyDoubleWidget::WPropertyDoubleWidget( WPropDouble property, QGridLayout*
// layout both against each other // layout both against each other
m_layout.addWidget( &m_spin ); m_layout.addWidget( &m_spin );
update();
// connect the modification signal of the edit and slider with our callback
connect( &m_spin, SIGNAL( editingFinished() ), this, SLOT( spinChanged() ) );
}
WPropertyDoubleWidget::~WPropertyDoubleWidget()
{
// cleanup
}
void WPropertyDoubleWidget::update()
{
// get the min constraint // get the min constraint
WPVDouble::PropertyConstraintMin minC = m_doubleProperty->getMin(); WPVDouble::PropertyConstraintMin minC = m_doubleProperty->getMin();
double min = 0.0; double min = 0.0;
...@@ -84,14 +97,6 @@ WPropertyDoubleWidget::WPropertyDoubleWidget( WPropDouble property, QGridLayout* ...@@ -84,14 +97,6 @@ WPropertyDoubleWidget::WPropertyDoubleWidget( WPropDouble property, QGridLayout*
// set the initial values // set the initial values
m_spin.setValue( m_doubleProperty->get() ); m_spin.setValue( m_doubleProperty->get() );
m_spin.setSingleStep( ( max - min ) / 100.0 ); m_spin.setSingleStep( ( max - min ) / 100.0 );
// connect the modification signal of the edit and slider with our callback
connect( &m_spin, SIGNAL( editingFinished() ), this, SLOT( spinChanged() ) );
}
WPropertyDoubleWidget::~WPropertyDoubleWidget()
{
// cleanup
} }
void WPropertyDoubleWidget::spinChanged() void WPropertyDoubleWidget::spinChanged()
......
...@@ -56,6 +56,11 @@ public: ...@@ -56,6 +56,11 @@ public:
protected: protected:
/**
* Called whenever the widget should update.
*/
virtual void update();
/** /**
* The integer property represented by this widget. * The integer property represented by this widget.
*/ */
......
...@@ -51,7 +51,7 @@ WPropertyFilenameWidget::WPropertyFilenameWidget( WPropFilename property, QGridL ...@@ -51,7 +51,7 @@ WPropertyFilenameWidget::WPropertyFilenameWidget( WPropFilename property, QGridL
m_button.setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred ); m_button.setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred );
// set the initial values // set the initial values
m_button.setText( QString::fromStdString( m_fnProperty->get().file_string() ) ); update();
// connect the modification signal of the edit and slider with our callback // connect the modification signal of the edit and slider with our callback
connect( &m_button, SIGNAL( released() ), this, SLOT( buttonReleased() ) ); connect( &m_button, SIGNAL( released() ), this, SLOT( buttonReleased() ) );
...@@ -62,6 +62,11 @@ WPropertyFilenameWidget::~WPropertyFilenameWidget() ...@@ -62,6 +62,11 @@ WPropertyFilenameWidget::~WPropertyFilenameWidget()
// cleanup // cleanup
} }
void WPropertyFilenameWidget::update()
{
m_button.setText( QString::fromStdString( m_fnProperty->get().file_string() ) );
}
void WPropertyFilenameWidget::buttonReleased() void WPropertyFilenameWidget::buttonReleased()
{ {
QString path; QString path;
......
...@@ -56,6 +56,11 @@ public: ...@@ -56,6 +56,11 @@ public:
protected: protected:
/**
* Called whenever the widget should update.
*/
virtual void update();
/** /**
* The filename property represented by this widget. * The filename property represented by this widget.
*/ */
......
...@@ -50,6 +50,21 @@ WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* property ...@@ -50,6 +50,21 @@ WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* property
m_layout.addWidget( &m_slider ); m_layout.addWidget( &m_slider );
m_layout.addWidget( &m_edit ); m_layout.addWidget( &m_edit );
update();
// connect the modification signal of the edit and slider with our callback
connect( &m_slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderChanged( int ) ) );
connect( &m_edit, SIGNAL( returnPressed() ), this, SLOT( editChanged() ) );
connect( &m_edit, SIGNAL( textEdited( const QString& ) ), this, SLOT( textEdited( const QString& ) ) );
}
WPropertyIntWidget::~WPropertyIntWidget()
{
// cleanup
}
void WPropertyIntWidget::update()
{
// get the min constraint // get the min constraint
WPVInt::PropertyConstraintMin minC = m_intProperty->getMin(); WPVInt::PropertyConstraintMin minC = m_intProperty->getMin();
int min = 0; int min = 0;
...@@ -102,15 +117,6 @@ WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* property ...@@ -102,15 +117,6 @@ WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* property
m_edit.setText( QString( boost::lexical_cast< std::string >( m_intProperty->get() ).c_str() ) ); m_edit.setText( QString( boost::lexical_cast< std::string >( m_intProperty->get() ).c_str() ) );
m_slider.setValue( m_intProperty->get() ); m_slider.setValue( m_intProperty->get() );
// connect the modification signal of the edit and slider with our callback
connect( &m_slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderChanged( int ) ) );
connect( &m_edit, SIGNAL( returnPressed() ), this, SLOT( editChanged() ) );
connect( &m_edit, SIGNAL( textEdited( const QString& ) ), this, SLOT( textEdited( const QString& ) ) );
}
WPropertyIntWidget::~WPropertyIntWidget()
{
// cleanup
} }
void WPropertyIntWidget::sliderChanged( int value ) void WPropertyIntWidget::sliderChanged( int value )
......
...@@ -57,6 +57,11 @@ public: ...@@ -57,6 +57,11 @@ public:
protected: protected:
/**
* Called whenever the widget should update.
*/
virtual void update();
/** /**
* The integer property represented by this widget. * The integer property represented by this widget.
*/ */
......
...@@ -45,7 +45,7 @@ WPropertyStringWidget::WPropertyStringWidget( WPropString property, QGridLayout* ...@@ -45,7 +45,7 @@ WPropertyStringWidget::WPropertyStringWidget( WPropString property, QGridLayout*
m_layout.addWidget( &m_edit ); m_layout.addWidget( &m_edit );
// set the initial values // set the initial values
m_edit.setText( QString( m_stringProperty->get().c_str() ) ); update();
// connect the modification signal of the edit and slider with our callback // connect the modification signal of the edit and slider with our callback
connect( &m_edit, SIGNAL( returnPressed() ), this, SLOT( editChanged() ) ); connect( &m_edit, SIGNAL( returnPressed() ), this, SLOT( editChanged() ) );
...@@ -57,6 +57,11 @@ WPropertyStringWidget::~WPropertyStringWidget() ...@@ -57,6 +57,11 @@ WPropertyStringWidget::~WPropertyStringWidget()
// cleanup // cleanup
} }
void WPropertyStringWidget::update()
{
m_edit.setText( QString( m_stringProperty->get().c_str() ) );
}
void WPropertyStringWidget::editChanged() void WPropertyStringWidget::editChanged()
{ {
std::string value = m_edit.text().toStdString(); std::string value = m_edit.text().toStdString();
...@@ -71,3 +76,4 @@ void WPropertyStringWidget::textEdited( const QString& text ) ...@@ -71,3 +76,4 @@ void WPropertyStringWidget::textEdited( const QString& text )
invalidate( !m_stringProperty->accept( value ) ); invalidate( !m_stringProperty->accept( value ) );
} }
...@@ -57,6 +57,11 @@ public: ...@@ -57,6 +57,11 @@ public:
protected: protected:
/**
* Called whenever the widget should update.
*/
virtual void update();
/** /**
* The integer property represented by this widget. * The integer property represented by this widget.
*/ */
......
...@@ -82,6 +82,11 @@ public: ...@@ -82,6 +82,11 @@ public:
protected: protected:
/**
* Called whenever the widget should update itself.
*/
virtual void update() = 0;
/** /**
* The property handled by the widget. * The property handled by the widget.
*/ */
......
...@@ -48,6 +48,8 @@ ...@@ -48,6 +48,8 @@
// when a subject signals a newly registered data set // when a subject signals a newly registered data set
#define WQT_UPDATE_TEXTURE_SORTER_EVENT QEvent::User + 5 #define WQT_UPDATE_TEXTURE_SORTER_EVENT QEvent::User + 5
// when a property changes
#define WQT_PROPERTY_CHANGED_EVENT QEvent::User + 6
#endif // WEVENTTYPES_H #endif // WEVENTTYPES_H
//---------------------------------------------------------------------------
//
// 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 "WEventTypes.h"
#include "WPropertyChangedEvent.h"
WPropertyChangedEvent::WPropertyChangedEvent()
: QEvent( static_cast< QEvent::Type >( WQT_PROPERTY_CHANGED_EVENT ) )
{
// initialize members
}
WPropertyChangedEvent::~WPropertyChangedEvent()
{
// cleanup
}
//---------------------------------------------------------------------------
//
// 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 WPROPERTYCHANGEDEVENT_H
#define WPROPERTYCHANGEDEVENT_H
#include <boost/shared_ptr.hpp>
#include <QtCore/QEvent>
/**
* Event signalling a new module has been associated with the root container in the kernel. Please note that it is possible that
* the module is already marked as "ready" while processing this event due to the multithreading.
*/
class WPropertyChangedEvent: public QEvent
{
public:
/**
* Creates a new event instance denoting that a property has changed.
*/
WPropertyChangedEvent();
/**
* Destructor.
*/
virtual ~WPropertyChangedEvent();
protected:
private:
};
#endif // WPROPERTYCHANGEDEVENT_H
...@@ -188,6 +188,7 @@ void WMTemplate::properties() ...@@ -188,6 +188,7 @@ void WMTemplate::properties()
// You even can add one property multiple times to different groups: // You even can add one property multiple times to different groups:
m_group2->addProperty( m_aColor ); m_group2->addProperty( m_aColor );
m_group1a->addProperty( m_aDouble ); m_group1a->addProperty( m_aDouble );
m_group1a->addProperty( m_enableFeature );
// 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 ) // 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(). // and m_anInteger->get().
......
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