Commit ab8b9cad authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - constraints now used for int properties in GUI

parent d726b84a
......@@ -25,6 +25,8 @@
#ifndef WPROPERTYCONSTRAINTMAX_H
#define WPROPERTYCONSTRAINTMAX_H
#include <iostream>
#include "WPropertyTypes.h"
#include "WPropertyConstraintTypes.h"
......@@ -96,7 +98,7 @@ WPropertyConstraintMax< T >::~WPropertyConstraintMax()
template < typename T >
bool WPropertyConstraintMax< T >::accept( boost::shared_ptr< WPropertyVariable< T > > /* property */, T value )
{
return value >= m_max;
return value <= m_max;
}
template < typename T >
......
......@@ -27,6 +27,7 @@
#include <stdint.h>
#include <iostream>
#include <string>
#include <list>
#include <vector>
......@@ -154,6 +155,16 @@ public:
virtual PROPERTYCONSTRAINT_TYPE getType();
};
/**
* Alias for min constraints. It is an alias for convenience.
*/
typedef boost::shared_ptr< WPropertyConstraintMin< T > > PropertyConstraintMin;
/**
* Alias for max constraints. It is an alias for convenience.
*/
typedef boost::shared_ptr< WPropertyConstraintMax< T > > PropertyConstraintMax;
/**
* Add a new constraint. This is useful to disallow several (custom) values for this property.
*
......@@ -169,7 +180,7 @@ public:
*
* \return the new constraint.
*/
static boost::shared_ptr< WPropertyConstraintMin< T > > minConstraint( T min );
static PropertyConstraintMin minConstraint( T min );
/**
* Creates a new WPropertyConstraintMax for this WPropertyVariable.
......@@ -178,7 +189,7 @@ public:
*
* \return the new constraint.
*/
static boost::shared_ptr< WPropertyConstraintMax< T > > maxConstraint( T max );
static PropertyConstraintMax maxConstraint( T max );
/**
* Set a minimum constraint.
......@@ -187,7 +198,7 @@ public:
*
* \return the newly created constraint.
*/
boost::shared_ptr< WPropertyConstraintMin< T > > setMin( T min );
PropertyConstraintMin setMin( T min );
/**
* Set a maximum constraint.
......@@ -196,21 +207,21 @@ public:
*
* \return the newly created constraint.
*/
boost::shared_ptr< WPropertyConstraintMax< T > > setMax( T max );
PropertyConstraintMax setMax( T max );
/**
* Gets the current minimum constraint value.
*
* \return the minimum constraint, or NULL if none.
*/
boost::shared_ptr< WPropertyConstraintMin< T > > getMin();
PropertyConstraintMin getMin();
/**
* Gets the current maximum constraint value.
*
* \return the maximum constraint, or NULL if none.
*/
boost::shared_ptr< WPropertyConstraintMax< T > > getMax();
PropertyConstraintMax getMax();
protected:
......
......@@ -25,6 +25,8 @@
#ifndef WPROPERTYBOOLWIDGET_H
#define WPROPERTYBOOLWIDGET_H
#include <string>
#include <QtGui/QCheckBox>
#include <QtGui/QHBoxLayout>
......
......@@ -24,11 +24,13 @@
#include <iostream>
#include <sstream>
#include <cmath>
#include "WPropertyIntWidget.h"
#include "../../../common/WLogger.h"
#include "../../../common/WPropertyVariable.h"
#include "WPropertyIntWidget.h"
WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* propertyGrid, QWidget* parent ):
WPropertyWidget( property, propertyGrid, parent ),
m_intProperty( property ),
......@@ -45,6 +47,56 @@ WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* property
m_layout.addWidget( &m_slider );
m_layout.addWidget( &m_edit );
// get the min constraint
WPVInt::PropertyConstraintMin minC = m_intProperty->getMin();
int min = 0;
if ( minC.get() )
{
min = minC->getMin();
}
else
{
WLogger::getLogger()->addLogMessage( "The property has no minimum constraint. You should define it to avoid unexpected behaviour.",
"PropertyWidget( " + m_intProperty->getName() + " )", LL_WARNING );
}
// get the max constraint
WPVInt::PropertyConstraintMax maxC = m_intProperty->getMax();
int max = 100;
if ( maxC.get() )
{
max = maxC->getMax();
}
else
{
WLogger::getLogger()->addLogMessage( "The property has no maximum constraint. You should define it to avoid unexpected behaviour.",
"PropertyWidget( " + m_intProperty->getName() + " )", LL_WARNING );
}
// setup the slider
m_slider.setMinimum( min );
m_slider.setMaximum( max );
// calculate maximum size of the text widget.
// XXX: this is not the optimal way but works for now
int length = min < 0 ? 2 : 1; // reserve some extra space for the "-" in negative numbers
float fmax = static_cast<float>( std::max( std::abs( min ), std::abs( max ) ) ); // use the number with the most numbers
while ( ( fmax / 10 ) >= 1.0 )
{
++length;
fmax /= 10.0;
}
// resize the text widget
m_edit.setMaxLength( length );
m_edit.setMaximumWidth( m_edit.minimumSizeHint().width() * length / 2 );
m_edit.resize( m_edit.minimumSizeHint().width() * length / 2, m_edit.size().height() );
// set the initial values
std::ostringstream s;
s << m_intProperty->get();
m_edit.setText( QString( s.str().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() ) );
......
......@@ -25,6 +25,8 @@
#ifndef WPROPERTYINTWIDGET_H
#define WPROPERTYINTWIDGET_H
#include <string>
#include <QtGui/QLineEdit>
#include <QtGui/QSlider>
#include <QtGui/QHBoxLayout>
......
......@@ -28,10 +28,14 @@ WPropertyWidget::WPropertyWidget( boost::shared_ptr< WPropertyBase > property,
QWidget( parent ),
m_property( property ),
m_propertyGrid( propertyGrid ),
m_label( this )
m_label( this ),
m_invalid( true )
{
// initialize members
m_label.setText( property->getName().c_str() );
// set tooltips
m_label.setToolTip( getTooltip().c_str() );
setToolTip( m_label.toolTip() );
// setup grid layout
int row = m_propertyGrid->rowCount();
......@@ -44,6 +48,15 @@ WPropertyWidget::~WPropertyWidget()
// cleanup
}
std::string WPropertyWidget::getTooltip() const
{
std::string tip = "<b>Property: </b>" + m_property->getName() + "<br/>";
tip += "<b>Status: </b>";
tip += m_invalid ? "<font color=#FF0000><b>invalid</b></font>" : "valid";
tip += "<br/><br/>";
return tip + m_property->getDescription();
}
boost::shared_ptr< WPropertyBase > WPropertyWidget::getProperty()
{
return m_property;
......@@ -51,9 +64,15 @@ boost::shared_ptr< WPropertyBase > WPropertyWidget::getProperty()
void WPropertyWidget::invalidate( bool invalid )
{
m_invalid = invalid;
// update tooltip
m_label.setToolTip( getTooltip().c_str() );
setToolTip( m_label.toolTip() );
if ( invalid )
{
m_label.setText( ( m_property->getName() + "!" ).c_str() );
m_label.setText( ( "<font color=#FF0000><b>" + m_property->getName() + "</b></font>" ).c_str() );
}
else
{
......
......@@ -25,6 +25,8 @@
#ifndef WPROPERTYWIDGET_H
#define WPROPERTYWIDGET_H
#include <string>
#include <boost/shared_ptr.hpp>
#include <QtGui/QWidget>
......@@ -71,6 +73,13 @@ public:
*/
virtual void invalidate( bool invalid = true );
/**
* Gets the tooltip that should be used for this widget.
*
* \return the tooltip.
*/
virtual std::string getTooltip() const;
protected:
/**
......@@ -88,6 +97,11 @@ protected:
*/
QLabel m_label;
/**
* Flag denoting whether the widget is set to an invalid value.
*/
bool m_invalid;
private:
};
......
......@@ -124,10 +124,13 @@ void WMNavSlices::properties()
m_axialPos = m_properties2->addProperty( "axialPos", "Position of axial slice.", 80 );
m_axialPos->setMin( 0 );
m_axialPos->setMin( 10 );
m_axialPos->setMax( 160 );
m_coronalPos = m_properties2->addProperty( "coronalPos", "Position of coronal slice.", 100 );
m_coronalPos->setMin( 0 );
m_coronalPos->setMax( 160 );
m_sagittalPos = m_properties2->addProperty( "sagittalPos", "Position of sagittal slice.", 80 );
m_sagittalPos->setMin( 0 );
m_sagittalPos->setMax( 160 );
m_maxAxial = m_properties2->addProperty( "maxAxial", "Max position of axial slice.", 160, true );
m_maxCoronal = m_properties2->addProperty( "maxCoronal", "Max position of coronal slice.", 200, true );
......
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