From deb927b082e5993d2938ba0770301eb63804b184 Mon Sep 17 00:00:00 2001 From: Sebastian Eichelbaum Date: Fri, 9 Apr 2010 19:50:02 +0200 Subject: [PATCH] [CHANGE] - basic structure for automatically updating properties --- .../datasetbrowser/WPropertyBoolWidget.cpp | 18 ++++-- .../qt4/datasetbrowser/WPropertyBoolWidget.h | 5 ++ .../datasetbrowser/WPropertyColorWidget.cpp | 8 ++- .../qt4/datasetbrowser/WPropertyColorWidget.h | 5 ++ .../datasetbrowser/WPropertyDoubleWidget.cpp | 21 ++++--- .../datasetbrowser/WPropertyDoubleWidget.h | 5 ++ .../WPropertyFilenameWidget.cpp | 7 ++- .../datasetbrowser/WPropertyFilenameWidget.h | 5 ++ .../qt4/datasetbrowser/WPropertyIntWidget.cpp | 24 +++++--- .../qt4/datasetbrowser/WPropertyIntWidget.h | 5 ++ .../datasetbrowser/WPropertyStringWidget.cpp | 8 ++- .../datasetbrowser/WPropertyStringWidget.h | 5 ++ src/gui/qt4/datasetbrowser/WPropertyWidget.h | 5 ++ src/gui/qt4/events/WEventTypes.h | 2 + src/gui/qt4/events/WPropertyChangedEvent.cpp | 39 +++++++++++++ src/gui/qt4/events/WPropertyChangedEvent.h | 55 +++++++++++++++++++ src/modules/template/WMTemplate.cpp | 1 + 17 files changed, 191 insertions(+), 27 deletions(-) create mode 100644 src/gui/qt4/events/WPropertyChangedEvent.cpp create mode 100644 src/gui/qt4/events/WPropertyChangedEvent.h diff --git a/src/gui/qt4/datasetbrowser/WPropertyBoolWidget.cpp b/src/gui/qt4/datasetbrowser/WPropertyBoolWidget.cpp index e38aa974d..fc6fd4b19 100644 --- a/src/gui/qt4/datasetbrowser/WPropertyBoolWidget.cpp +++ b/src/gui/qt4/datasetbrowser/WPropertyBoolWidget.cpp @@ -36,15 +36,14 @@ WPropertyBoolWidget::WPropertyBoolWidget( WPropBool property, QGridLayout* prope { // initialize members m_button.setCheckable( true ); - m_checkbox.setChecked( m_boolProperty->get() ); - m_button.setChecked( m_boolProperty->get() ); + update(); // layout both against each other - m_button.setVisible( asButton ); - m_checkbox.setVisible( !asButton ); - m_layout.addWidget( asButton ? static_cast< QWidget* >( &m_button ) : static_cast< QWidget* >( &m_checkbox ) ); + m_button.setVisible( m_asButton ); + m_checkbox.setVisible( !m_asButton ); + 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 ); } @@ -60,6 +59,13 @@ WPropertyBoolWidget::~WPropertyBoolWidget() // cleanup } +void WPropertyBoolWidget::update() +{ + // simply set the new state + m_checkbox.setChecked( m_boolProperty->get() ); + m_button.setChecked( m_boolProperty->get() ); +} + QPushButton* WPropertyBoolWidget::getButton() { return &m_button; diff --git a/src/gui/qt4/datasetbrowser/WPropertyBoolWidget.h b/src/gui/qt4/datasetbrowser/WPropertyBoolWidget.h index 389ed9810..170b9234e 100644 --- a/src/gui/qt4/datasetbrowser/WPropertyBoolWidget.h +++ b/src/gui/qt4/datasetbrowser/WPropertyBoolWidget.h @@ -66,6 +66,11 @@ public: protected: + /** + * Called whenever the widget should update. + */ + virtual void update(); + /** * The boolean property represented by this widget. */ diff --git a/src/gui/qt4/datasetbrowser/WPropertyColorWidget.cpp b/src/gui/qt4/datasetbrowser/WPropertyColorWidget.cpp index 5b26c625c..5f578880a 100644 --- a/src/gui/qt4/datasetbrowser/WPropertyColorWidget.cpp +++ b/src/gui/qt4/datasetbrowser/WPropertyColorWidget.cpp @@ -47,8 +47,7 @@ WPropertyColorWidget::WPropertyColorWidget( WPropColor property, QGridLayout* pr m_layout.addWidget( &m_button ); // 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( &m_button, SIGNAL( released() ), this, SLOT( buttonReleased() ) ); @@ -59,6 +58,11 @@ WPropertyColorWidget::~WPropertyColorWidget() // cleanup } +void WPropertyColorWidget::update() +{ + m_button.setPalette( QPalette( toQColor( m_colorProperty->get() ) ) ); +} + QColor WPropertyColorWidget::toQColor( WColor color ) { QColor tmp; diff --git a/src/gui/qt4/datasetbrowser/WPropertyColorWidget.h b/src/gui/qt4/datasetbrowser/WPropertyColorWidget.h index 36c53e321..5cb7833a0 100644 --- a/src/gui/qt4/datasetbrowser/WPropertyColorWidget.h +++ b/src/gui/qt4/datasetbrowser/WPropertyColorWidget.h @@ -56,6 +56,11 @@ public: protected: + /** + * Called whenever the widget should update. + */ + virtual void update(); + /** * The integer property represented by this widget. */ diff --git a/src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.cpp b/src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.cpp index dc82e4e0b..7ec6f6e49 100644 --- a/src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.cpp +++ b/src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.cpp @@ -44,6 +44,19 @@ WPropertyDoubleWidget::WPropertyDoubleWidget( WPropDouble property, QGridLayout* // layout both against each other 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 WPVDouble::PropertyConstraintMin minC = m_doubleProperty->getMin(); double min = 0.0; @@ -84,14 +97,6 @@ WPropertyDoubleWidget::WPropertyDoubleWidget( WPropDouble property, QGridLayout* // set the initial values m_spin.setValue( m_doubleProperty->get() ); 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() diff --git a/src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.h b/src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.h index d785ca238..c279ba08c 100644 --- a/src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.h +++ b/src/gui/qt4/datasetbrowser/WPropertyDoubleWidget.h @@ -56,6 +56,11 @@ public: protected: + /** + * Called whenever the widget should update. + */ + virtual void update(); + /** * The integer property represented by this widget. */ diff --git a/src/gui/qt4/datasetbrowser/WPropertyFilenameWidget.cpp b/src/gui/qt4/datasetbrowser/WPropertyFilenameWidget.cpp index aceb5a731..8ca9254cc 100644 --- a/src/gui/qt4/datasetbrowser/WPropertyFilenameWidget.cpp +++ b/src/gui/qt4/datasetbrowser/WPropertyFilenameWidget.cpp @@ -51,7 +51,7 @@ WPropertyFilenameWidget::WPropertyFilenameWidget( WPropFilename property, QGridL m_button.setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred ); // 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( &m_button, SIGNAL( released() ), this, SLOT( buttonReleased() ) ); @@ -62,6 +62,11 @@ WPropertyFilenameWidget::~WPropertyFilenameWidget() // cleanup } +void WPropertyFilenameWidget::update() +{ + m_button.setText( QString::fromStdString( m_fnProperty->get().file_string() ) ); +} + void WPropertyFilenameWidget::buttonReleased() { QString path; diff --git a/src/gui/qt4/datasetbrowser/WPropertyFilenameWidget.h b/src/gui/qt4/datasetbrowser/WPropertyFilenameWidget.h index 6c908ad39..b8ea4ec60 100644 --- a/src/gui/qt4/datasetbrowser/WPropertyFilenameWidget.h +++ b/src/gui/qt4/datasetbrowser/WPropertyFilenameWidget.h @@ -56,6 +56,11 @@ public: protected: + /** + * Called whenever the widget should update. + */ + virtual void update(); + /** * The filename property represented by this widget. */ diff --git a/src/gui/qt4/datasetbrowser/WPropertyIntWidget.cpp b/src/gui/qt4/datasetbrowser/WPropertyIntWidget.cpp index b0f05cb5b..7e63e56ca 100644 --- a/src/gui/qt4/datasetbrowser/WPropertyIntWidget.cpp +++ b/src/gui/qt4/datasetbrowser/WPropertyIntWidget.cpp @@ -50,6 +50,21 @@ WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* property m_layout.addWidget( &m_slider ); 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 WPVInt::PropertyConstraintMin minC = m_intProperty->getMin(); int min = 0; @@ -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_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 ) diff --git a/src/gui/qt4/datasetbrowser/WPropertyIntWidget.h b/src/gui/qt4/datasetbrowser/WPropertyIntWidget.h index 6f5b7dabb..f947dd2b4 100644 --- a/src/gui/qt4/datasetbrowser/WPropertyIntWidget.h +++ b/src/gui/qt4/datasetbrowser/WPropertyIntWidget.h @@ -57,6 +57,11 @@ public: protected: + /** + * Called whenever the widget should update. + */ + virtual void update(); + /** * The integer property represented by this widget. */ diff --git a/src/gui/qt4/datasetbrowser/WPropertyStringWidget.cpp b/src/gui/qt4/datasetbrowser/WPropertyStringWidget.cpp index d9e88389e..fbbae7df2 100644 --- a/src/gui/qt4/datasetbrowser/WPropertyStringWidget.cpp +++ b/src/gui/qt4/datasetbrowser/WPropertyStringWidget.cpp @@ -45,7 +45,7 @@ WPropertyStringWidget::WPropertyStringWidget( WPropString property, QGridLayout* m_layout.addWidget( &m_edit ); // 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( &m_edit, SIGNAL( returnPressed() ), this, SLOT( editChanged() ) ); @@ -57,6 +57,11 @@ WPropertyStringWidget::~WPropertyStringWidget() // cleanup } +void WPropertyStringWidget::update() +{ + m_edit.setText( QString( m_stringProperty->get().c_str() ) ); +} + void WPropertyStringWidget::editChanged() { std::string value = m_edit.text().toStdString(); @@ -71,3 +76,4 @@ void WPropertyStringWidget::textEdited( const QString& text ) invalidate( !m_stringProperty->accept( value ) ); } + diff --git a/src/gui/qt4/datasetbrowser/WPropertyStringWidget.h b/src/gui/qt4/datasetbrowser/WPropertyStringWidget.h index a0bd00579..a19d6cbb3 100644 --- a/src/gui/qt4/datasetbrowser/WPropertyStringWidget.h +++ b/src/gui/qt4/datasetbrowser/WPropertyStringWidget.h @@ -57,6 +57,11 @@ public: protected: + /** + * Called whenever the widget should update. + */ + virtual void update(); + /** * The integer property represented by this widget. */ diff --git a/src/gui/qt4/datasetbrowser/WPropertyWidget.h b/src/gui/qt4/datasetbrowser/WPropertyWidget.h index 5b18ca400..6b62b5a3b 100644 --- a/src/gui/qt4/datasetbrowser/WPropertyWidget.h +++ b/src/gui/qt4/datasetbrowser/WPropertyWidget.h @@ -82,6 +82,11 @@ public: protected: + /** + * Called whenever the widget should update itself. + */ + virtual void update() = 0; + /** * The property handled by the widget. */ diff --git a/src/gui/qt4/events/WEventTypes.h b/src/gui/qt4/events/WEventTypes.h index 98530161d..691edc2b1 100644 --- a/src/gui/qt4/events/WEventTypes.h +++ b/src/gui/qt4/events/WEventTypes.h @@ -48,6 +48,8 @@ // when a subject signals a newly registered data set #define WQT_UPDATE_TEXTURE_SORTER_EVENT QEvent::User + 5 +// when a property changes +#define WQT_PROPERTY_CHANGED_EVENT QEvent::User + 6 #endif // WEVENTTYPES_H diff --git a/src/gui/qt4/events/WPropertyChangedEvent.cpp b/src/gui/qt4/events/WPropertyChangedEvent.cpp new file mode 100644 index 000000000..8792745b6 --- /dev/null +++ b/src/gui/qt4/events/WPropertyChangedEvent.cpp @@ -0,0 +1,39 @@ +//--------------------------------------------------------------------------- +// +// 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 . +// +//--------------------------------------------------------------------------- + +#include "WEventTypes.h" + +#include "WPropertyChangedEvent.h" + +WPropertyChangedEvent::WPropertyChangedEvent() + : QEvent( static_cast< QEvent::Type >( WQT_PROPERTY_CHANGED_EVENT ) ) +{ + // initialize members +} + +WPropertyChangedEvent::~WPropertyChangedEvent() +{ + // cleanup +} + diff --git a/src/gui/qt4/events/WPropertyChangedEvent.h b/src/gui/qt4/events/WPropertyChangedEvent.h new file mode 100644 index 000000000..94deae6b7 --- /dev/null +++ b/src/gui/qt4/events/WPropertyChangedEvent.h @@ -0,0 +1,55 @@ +//--------------------------------------------------------------------------- +// +// 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 . +// +//--------------------------------------------------------------------------- + +#ifndef WPROPERTYCHANGEDEVENT_H +#define WPROPERTYCHANGEDEVENT_H + +#include + +#include + +/** + * 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 + diff --git a/src/modules/template/WMTemplate.cpp b/src/modules/template/WMTemplate.cpp index 4db79970d..404e25c3e 100644 --- a/src/modules/template/WMTemplate.cpp +++ b/src/modules/template/WMTemplate.cpp @@ -188,6 +188,7 @@ void WMTemplate::properties() // You even can add one property multiple times to different groups: m_group2->addProperty( m_aColor ); 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 ) // and m_anInteger->get(). -- GitLab