Commit 7fdd2e95 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - added new properties to the GUI with new more generic widget classes

[CHANGE] - added new properties to navslices
parent e0358de4
......@@ -45,7 +45,7 @@ WProperties2::~WProperties2()
void WProperties2::addProperty( boost::shared_ptr< WPropertyBase > prop )
{
boost::unique_lock< boost::shared_mutex > lock = boost::unique_lock< boost::shared_mutex >( m_updateLock );
m_properties.insert( prop );
m_properties.push_back( prop );
lock.unlock();
}
......
......@@ -27,7 +27,7 @@
#include <map>
#include <string>
#include <set>
#include <vector>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
......@@ -48,7 +48,7 @@ public:
/**
* The iterator used to iterate over the property set
*/
typedef std::set< boost::shared_ptr< WPropertyBase > >::iterator PropertyIterator;
typedef std::vector< boost::shared_ptr< WPropertyBase > >::const_iterator PropertyIterator;
/**
* standard constructor
......@@ -173,7 +173,7 @@ private:
/**
* The set of proerties. This uses the operators ==,<,> WProperty to determine equalnes.
*/
std::set< boost::shared_ptr< WPropertyBase > > m_properties;
std::vector< boost::shared_ptr< WPropertyBase > > m_properties;
/**
* boost mutex object for thread safety of updating of properties
......@@ -189,21 +189,32 @@ private:
template< typename T>
boost::shared_ptr< WPropertyVariable< T > > WProperties2::addProperty( std::string name, std::string description, const T& initial )
{
return boost::shared_ptr< WPropertyVariable< T > >( new WPropertyVariable< T >( name, description, initial ) );
boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
new WPropertyVariable< T >( name, description, initial )
);
addProperty( p );
return p;
}
template< typename T>
boost::shared_ptr< WPropertyVariable< T > > WProperties2::addProperty( std::string name, std::string description, const T& initial,
boost::shared_ptr< WCondition > condition )
{
return boost::shared_ptr< WPropertyVariable< T > >( new WPropertyVariable< T >( name, description, initial, condition ) );
boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
new WPropertyVariable< T >( name, description, initial, condition )
);
addProperty( p );
}
template< typename T>
boost::shared_ptr< WPropertyVariable< T > > WProperties2::addProperty( std::string name, std::string description, const T& initial,
WCondition::t_ConditionNotifierType notifier )
{
return boost::shared_ptr< WPropertyVariable< T > >( new WPropertyVariable< T >( name, description, initial, notifier ) );
boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
new WPropertyVariable< T >( name, description, initial, notifier )
);
addProperty( p );
return p;
}
template< typename T>
......@@ -211,8 +222,11 @@ boost::shared_ptr< WPropertyVariable< T > > WProperties2::addProperty( std::stri
boost::shared_ptr< WCondition > condition,
WCondition::t_ConditionNotifierType notifier )
{
return boost::shared_ptr< WPropertyVariable< T > >( new WPropertyVariable< T >( name, description, initial, condition,
notifier ) );
boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
new WPropertyVariable< T >( name, description, initial, condition, notifier )
);
addProperty( p );
return p;
}
#endif // WPROPERTIES2_H
......@@ -24,7 +24,10 @@
#include <string>
#include <boost/filesystem.hpp>
#include "WPropertyBase.h"
#include "WPropertyVariable.h"
WPropertyBase::WPropertyBase( std::string name, std::string description ):
m_name( name ),
......@@ -54,6 +57,11 @@ PROPERTY_TYPE WPropertyBase::getType() const
return m_type;
}
void WPropertyBase::updateType()
{
m_type = PV_UNKNOWN;
}
bool WPropertyBase::isHidden() const
{
return m_hidden;
......@@ -64,3 +72,33 @@ void WPropertyBase::setHidden( bool hidden )
m_hidden = hidden;
}
WPropInt WPropertyBase::toPropInt()
{
return boost::shared_static_cast< WPropertyVariable< int32_t > >( shared_from_this() );
}
WPropDouble WPropertyBase::toPropDouble()
{
return boost::shared_static_cast< WPropertyVariable< double > >( shared_from_this() );
}
WPropBool WPropertyBase::toPropBool()
{
return boost::shared_static_cast< WPropertyVariable< bool > >( shared_from_this() );
}
WPropString WPropertyBase::toPropString()
{
return boost::shared_static_cast< WPropertyVariable< std::string > >( shared_from_this() );
}
WPropFilename WPropertyBase::toPropPath()
{
return boost::shared_static_cast< WPropertyVariable< boost::filesystem::path > >( shared_from_this() );
}
WPropList WPropertyBase::toPropList()
{
return boost::shared_static_cast< WPropertyVariable< std::list< std::string > > >( shared_from_this() );
}
......@@ -27,12 +27,15 @@
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include "WPropertyTypes.h"
/**
* Abstract base class for all properties. Simply provides name and type information.
*/
class WPropertyBase
class WPropertyBase: public boost::enable_shared_from_this< WPropertyBase >
{
public:
......@@ -84,6 +87,52 @@ public:
*/
virtual PROPERTY_TYPE getType() const;
/////////////////////////////////////////////////////////////////////////////////////////////
// Helpers for easy conversion to the possible types
/////////////////////////////////////////////////////////////////////////////////////////////
/**
* Helper converts this instance to its native type.
*
* \return the property as integer property
*/
WPropInt toPropInt();
/**
* Helper converts this instance to its native type.
*
* \return the property as double property
*/
WPropDouble toPropDouble();
/**
* Helper converts this instance to its native type.
*
* \return the property as bool property
*/
WPropBool toPropBool();
/**
* Helper converts this instance to its native type.
*
* \return the property as string property
*/
WPropString toPropString();
/**
* Helper converts this instance to its native type.
*
* \return the property as path property
*/
WPropFilename toPropPath();
/**
* Helper converts this instance to its native type.
*
* \return the property as list property
*/
WPropList toPropList();
protected:
/**
......@@ -109,7 +158,7 @@ protected:
/**
* Calculates the type of the property. This has to be done by the implementing class.
*/
virtual void updateType() = 0;
virtual void updateType();
private:
};
......
......@@ -32,21 +32,57 @@
#include <boost/filesystem.hpp>
template < typename T >
class WPropertyVariable;
/**
* Enum of all possible types, that can be used with WProperty.
*/
typedef enum
{
UNKNOWN, // type not know
INT, // integer value
DOUBLE, // floating point value
BOOL, // boolean
STRING, // a string
PATH, // a Boost Path object denoting a filename/path
LIST // a list of strings
PV_UNKNOWN, // type not know
PV_INT, // integer value
PV_DOUBLE, // floating point value
PV_BOOL, // boolean
PV_STRING, // a string
PV_PATH, // a Boost Path object denoting a filename/path
PV_LIST // a list of strings
}
PROPERTY_TYPE;
/**
* Some convenience type alias for a even more easy usage of WPropertyVariable
*/
/**
* Alias for int32_t property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< int32_t > > WPropInt;
/**
* Alias for int32_t property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< double > > WPropDouble;
/**
* Alias for bool property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< bool > > WPropBool;
/**
* Alias for string property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< std::string > > WPropString;
/**
* Alias for filename property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< boost::filesystem::path > > WPropFilename;
/**
* Alias for string list property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< std::list< std::string > > > WPropList;
/**
* This namespace contains several helper classes which translate their template type to an enum.
*/
......@@ -66,7 +102,7 @@ namespace PROPERTY_TYPE_HELPER
*/
PROPERTY_TYPE getType()
{
return UNKNOWN;
return PV_UNKNOWN;
}
};
......@@ -84,7 +120,7 @@ namespace PROPERTY_TYPE_HELPER
*/
PROPERTY_TYPE getType()
{
return BOOL;
return PV_BOOL;
}
};
......@@ -102,7 +138,7 @@ namespace PROPERTY_TYPE_HELPER
*/
PROPERTY_TYPE getType()
{
return INT;
return PV_INT;
}
};
......@@ -120,7 +156,7 @@ namespace PROPERTY_TYPE_HELPER
*/
PROPERTY_TYPE getType()
{
return DOUBLE;
return PV_DOUBLE;
}
};
......@@ -138,7 +174,7 @@ namespace PROPERTY_TYPE_HELPER
*/
PROPERTY_TYPE getType()
{
return STRING;
return PV_STRING;
}
};
......@@ -156,7 +192,7 @@ namespace PROPERTY_TYPE_HELPER
*/
PROPERTY_TYPE getType()
{
return PATH;
return PV_PATH;
}
};
......@@ -174,10 +210,9 @@ namespace PROPERTY_TYPE_HELPER
*/
PROPERTY_TYPE getType()
{
return LIST;
return PV_LIST;
}
};
}
#endif // WPROPERTYTYPES_H
......@@ -133,6 +133,7 @@ WPropertyVariable< T >::WPropertyVariable( std::string name, std::string descrip
WFlag< T >( new WCondition(), initial ),
WPropertyBase( name, description )
{
updateType();
}
template < typename T >
......@@ -140,6 +141,7 @@ WPropertyVariable< T >::WPropertyVariable( std::string name, std::string descrip
WFlag< T >( condition, initial ),
WPropertyBase( name, description )
{
updateType();
}
template < typename T >
......@@ -148,6 +150,8 @@ WPropertyVariable< T >::WPropertyVariable( std::string name, std::string descrip
WFlag< T >( new WCondition(), initial ),
WPropertyBase( name, description )
{
updateType();
// set custom notifier
m_notifierConnection = WFlag< T >::getCondition()->subscribeSignal( notifier );
}
......@@ -158,6 +162,7 @@ WPropertyVariable< T >::WPropertyVariable( std::string name, std::string descrip
WFlag< T >( condition, initial ),
WPropertyBase( name, description )
{
updateType();
// set custom notifier
m_notifierConnection = WFlag< T >::getCondition()->subscribeSignal( notifier );
}
......@@ -188,38 +193,5 @@ void WPropertyVariable< T >::updateType()
m_type = tid.getType();
}
/**
* Some convenience type alias for a even more easy usage of WPropertyVariable
*/
/**
* Alias for int32_t property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< int32_t > > WPropInt;
/**
* Alias for int32_t property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< double > > WPropDouble;
/**
* Alias for bool property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< bool > > WPropBool;
/**
* Alias for string property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< std::string > > WPropString;
/**
* Alias for filename property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< boost::filesystem::path > > WPropFilename;
/**
* Alias for string list property variables.
*/
typedef boost::shared_ptr< WPropertyVariable< std::list< std::string > > > WPropList;
#endif // WPROPERTYVARIABLE_H
......@@ -15,7 +15,9 @@ SET(GUI_QT4_MOC_HDRS
WQtNavGLWidget.h
WPropertyManager.h
guiElements/WQtPushButton.h
datasetbrowser/WQtCheckBox.h
datasetbrowser/WPropertyWidget.h
datasetbrowser/WPropertyBoolWidget.h
datasetbrowser/WPropertyIntWidget.h
datasetbrowser/WQtDatasetBrowser.h
datasetbrowser/WQtDSBWidget.h
datasetbrowser/WQtLineEdit.h
......
......@@ -22,27 +22,35 @@
//
//---------------------------------------------------------------------------
#include <string>
#include "WPropertyBoolWidget.h"
#include "WQtCheckBox.h"
#include "../../../common/WPropertyVariable.h"
WQtCheckBox::WQtCheckBox()
: QCheckBox()
WPropertyBoolWidget::WPropertyBoolWidget( WPropBool property, QGridLayout* propertyGrid, QWidget* parent ):
WPropertyWidget( property, propertyGrid, parent ),
m_boolProperty( property ),
m_checkbox( this ),
m_layout()
{
m_name = "";
connect( this, SIGNAL( toggled( bool ) ), this, SLOT( emitStateChanged() ) );
}
// initialize members
m_checkbox.setChecked( m_boolProperty->get() );
WQtCheckBox::~WQtCheckBox()
{
// layout both against each other
m_layout.addWidget( &m_checkbox );
setLayout( &m_layout );
// connect the modification signal of m_checkbox with our callback
connect( &m_checkbox, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) );
}
void WQtCheckBox::setName( QString name )
WPropertyBoolWidget::~WPropertyBoolWidget()
{
m_name = name;
// cleanup
}
void WQtCheckBox::emitStateChanged()
void WPropertyBoolWidget::changed()
{
emit checkBoxStateChanged( m_name, this->isChecked() );
// set the value
m_boolProperty->set( m_checkbox.isChecked() );
}
......@@ -22,53 +22,62 @@
//
//---------------------------------------------------------------------------
#ifndef WQTCHECKBOX_H
#define WQTCHECKBOX_H
#include <string>
#ifndef WPROPERTYBOOLWIDGET_H
#define WPROPERTYBOOLWIDGET_H
#include <QtGui/QCheckBox>
#include <QtGui/QHBoxLayout>
#include "WPropertyWidget.h"
/**
* implements a QCheckBox with a boost signal
* Implements a property widget for WPropBool.
*/
class WQtCheckBox : public QCheckBox
class WPropertyBoolWidget: public WPropertyWidget
{
Q_OBJECT
public:
/**
* standard constructor
/**
* Constructor. Creates a new widget appropriate for the specified property.
*
* \param property the property to handle
* \param parent the parent widget.
* \param propertyGrid the grid used to layout the labels and property widgets
*/
explicit WQtCheckBox();
WPropertyBoolWidget( WPropBool property, QGridLayout* propertyGrid, QWidget* parent = 0 );
/**
* destructor
* Destructor.
*/
virtual ~WQtCheckBox();
virtual ~WPropertyBoolWidget();
protected:
/**
* setter for name
* \param name The new name of the check box
* The boolean property represented by this widget.
*/
void setName( QString name );
WPropBool m_boolProperty;
private:
QString m_name; //!< Name of the check box.
/**
* The checkbox - represents the boolean value.
*/
QCheckBox m_checkbox;
public slots:
/**
* This function emits checkBoxStateChanged signal.
* Layout used to position the label and the checkbox
*/
void emitStateChanged();
QHBoxLayout m_layout;
private:
public slots:
signals:
/**
* Signal indicating that the state of the check box has changed.
* \param name name of the check box
* \param value Indicated whether the box is checked or not.
* called whenever the user modifies the widget
*/
void checkBoxStateChanged( QString name, bool value );
void changed();
};
#endif // WQTCHECKBOX_H
#endif // WPROPERTYBOOLWIDGET_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 <iostream>
#include <sstream>
#include "WPropertyIntWidget.h"
#include "../../../common/WPropertyVariable.h"
WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* propertyGrid, QWidget* parent ):
WPropertyWidget( property, propertyGrid, parent ),
m_intProperty( property ),
m_slider( Qt::Horizontal, this ),
m_edit( this ),
m_layout()
{
// initialize members
m_edit.resize( m_edit.minimumSizeHint().width() , m_edit.size().height() );
m_edit.setMaximumWidth( m_edit.minimumSizeHint().width() );
setLayout( &m_layout );
// layout both against each other
m_layout.addWidget( &m_slider );
m_layout.addWidget( &m_edit );
// 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() ) );
}