Commit 114e16c3 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE #198] min max can only be changed in the property-given interval

parent 3dc6aafc
...@@ -25,62 +25,54 @@ ...@@ -25,62 +25,54 @@
#include <cmath> #include <cmath>
#include <limits> #include <limits>
#include <sstream> #include <sstream>
#include <iostream>
#include <string> #include <string>
#include <QtGui/QInputDialog> #include <QtGui/QInputDialog>
#include "../WGuiConsts.h" #include "../WGuiConsts.h"
#include "../WQt4Gui.h" #include "../WQt4Gui.h"
#include "../guiElements/WQtIntervalEdit.h"
#include "core/common/WLogger.h" #include "core/common/WLogger.h"
#include "core/common/WPropertyVariable.h" #include "core/common/WPropertyVariable.h"
#include "WPropertyDoubleWidget.h" #include "WPropertyDoubleWidget.h"
#include "WPropertyDoubleWidget.moc" #include "WPropertyDoubleWidget.moc"
const int WPropertyDoubleWidget::SliderResolution = 10000;
WPropertyDoubleWidget::WPropertyDoubleWidget( WPropDouble property, QGridLayout* propertyGrid, QWidget* parent ): WPropertyDoubleWidget::WPropertyDoubleWidget( WPropDouble property, QGridLayout* propertyGrid, QWidget* parent ):
WPropertyWidget( property, propertyGrid, parent ), WPropertyWidget( property, propertyGrid, parent ),
m_doubleProperty( property ), m_integralProperty( property ),
m_slider( Qt::Horizontal, &m_parameterWidgets ), m_slider( Qt::Horizontal, &m_parameterWidgets ),
m_edit( &m_parameterWidgets ), m_edit( &m_parameterWidgets ),
m_minButton( &m_parameterWidgets ), m_layout(),
m_maxButton( &m_parameterWidgets ), m_vLayout( &m_parameterWidgets ),
m_layout( &m_parameterWidgets ),
m_asText( &m_informationWidgets ), m_asText( &m_informationWidgets ),
m_infoLayout( &m_informationWidgets ) m_infoLayout( &m_informationWidgets ),
m_intervalEdit( &m_parameterWidgets )
{ {
// layout both against each other
if( WQt4Gui::getSettings().value( "qt4gui/sliderMinMaxEdit", false ).toBool() )
{
m_layout.addWidget( &m_minButton );
m_minButton.setToolTip( "Set minimum of slider.\n Be aware that strange values can cause errors." );
m_minButton.setMinimumWidth( 5 );
m_minButton.setMaximumWidth( 5 );
}
else
{
m_minButton.hide();
}
m_layout.addWidget( &m_slider ); m_layout.addWidget( &m_slider );
if( WQt4Gui::getSettings().value( "qt4gui/sliderMinMaxEdit", false ).toBool() )
{
m_layout.addWidget( &m_maxButton );
m_maxButton.setToolTip( "Set maximum of slider.\n Be aware that strange values can cause errors." );
m_maxButton.setMinimumWidth( 5 );
m_maxButton.setMaximumWidth( 5 );
}
else
{
m_maxButton.hide();
}
m_layout.addWidget( &m_edit ); m_layout.addWidget( &m_edit );
m_layout.setMargin( WGLOBAL_MARGIN ); m_layout.setMargin( WGLOBAL_MARGIN );
m_layout.setSpacing( WGLOBAL_SPACING ); m_layout.setSpacing( WGLOBAL_SPACING );
m_vLayout.setMargin( WGLOBAL_MARGIN );
m_vLayout.setSpacing( WGLOBAL_SPACING );
// add the m_layout to the vlayout
QWidget* layoutContainer = new QWidget();
layoutContainer->setLayout( &m_layout );
m_vLayout.addWidget( layoutContainer );
// configure the interval edit
m_vLayout.addWidget( &m_intervalEdit );
if( !WQt4Gui::getSettings().value( "qt4gui/sliderMinMaxEdit", false ).toBool() )
{
m_intervalEdit.hide();
}
m_parameterWidgets.setLayout( &m_layout ); m_parameterWidgets.setLayout( &m_vLayout );
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION ) // Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
m_infoLayout.addWidget( &m_asText ); m_infoLayout.addWidget( &m_asText );
...@@ -96,8 +88,8 @@ WPropertyDoubleWidget::WPropertyDoubleWidget( WPropDouble property, QGridLayout* ...@@ -96,8 +88,8 @@ WPropertyDoubleWidget::WPropertyDoubleWidget( WPropDouble property, QGridLayout*
connect( &m_slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderChanged( int ) ) ); connect( &m_slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderChanged( int ) ) );
connect( &m_edit, SIGNAL( editingFinished() ), this, SLOT( editChanged() ) ); connect( &m_edit, SIGNAL( editingFinished() ), this, SLOT( editChanged() ) );
connect( &m_edit, SIGNAL( textEdited( const QString& ) ), this, SLOT( textEdited( const QString& ) ) ); connect( &m_edit, SIGNAL( textEdited( const QString& ) ), this, SLOT( textEdited( const QString& ) ) );
connect( &m_maxButton, SIGNAL( pressed() ), this, SLOT( maxPressed() ) ); connect( &m_intervalEdit, SIGNAL( minimumChanged() ), this, SLOT( minMaxUpdated() ) );
connect( &m_minButton, SIGNAL( pressed() ), this, SLOT( minPressed() ) ); connect( &m_intervalEdit, SIGNAL( maximumChanged() ), this, SLOT( minMaxUpdated() ) );
} }
WPropertyDoubleWidget::~WPropertyDoubleWidget() WPropertyDoubleWidget::~WPropertyDoubleWidget()
...@@ -110,52 +102,60 @@ void WPropertyDoubleWidget::update() ...@@ -110,52 +102,60 @@ void WPropertyDoubleWidget::update()
// // calculate maximum size of the text widget. // // calculate maximum size of the text widget.
// // XXX: this is not the optimal way but works for now // // XXX: this is not the optimal way but works for now
// NO, it doesn't work on Mac OS X: You won't be able to any digits in it!, So I reset it to default which should work on other platforms too // NO, it doesn't work on Mac OS X: You won't be able to any digits in it!, So I reset it to default which should work on other platforms too
QString valStr = QString::number( m_doubleProperty->get() ); QString valStr = QString::number( m_integralProperty->get() );
m_edit.setText( valStr ); m_edit.setText( valStr );
// get the min constraint // get the min constraint
WPVDouble::PropertyConstraintMin minC = m_doubleProperty->getMin(); WPVDouble::PropertyConstraintMin minC = m_integralProperty->getMin();
WPVDouble::PropertyConstraintMax maxC = m_doubleProperty->getMax(); WPVDouble::PropertyConstraintMax maxC = m_integralProperty->getMax();
bool minMaxConstrained = minC && maxC; bool minMaxConstrained = minC && maxC;
if( minMaxConstrained ) if( minMaxConstrained )
{ {
// setup the slider // setup the slider
m_slider.setMinimum( 0 ); m_slider.setMinimum( 0 );
m_slider.setMaximum( 100 ); m_slider.setMaximum( SliderResolution );
m_min = minC->getMin();
m_max = maxC->getMax(); // update the interval edit too
m_intervalEdit.setAllowedMin( minC->getMin() );
m_intervalEdit.setAllowedMax( maxC->getMax() );
m_min = m_intervalEdit.getMin();
m_max = m_intervalEdit.getMax();
// updating the interval edit causes the proper values to be set in m_min and m_max
m_slider.setHidden( false ); m_slider.setHidden( false );
m_slider.setValue( toPercent( m_doubleProperty->get() ) ); m_intervalEdit.setHidden( false );
m_slider.setValue( toSliderValue( m_integralProperty->get() ) );
} }
else else
{ {
m_slider.setHidden( true ); m_slider.setHidden( true );
m_intervalEdit.setHidden( true );
} }
// do not forget to update the label // do not forget to update the label
m_asText.setText( valStr ); m_asText.setText( valStr );
} }
int WPropertyDoubleWidget::toPercent( double value ) int WPropertyDoubleWidget::toSliderValue( double value )
{ {
return 100.0 * ( ( value - m_min ) / ( m_max - m_min ) ); int perc = static_cast< double >( SliderResolution ) * ( ( value - m_min ) / ( m_max - m_min ) );
return std::min( std::max( perc, 0 ), SliderResolution );
} }
double WPropertyDoubleWidget::fromPercent( int perc ) double WPropertyDoubleWidget::fromSliderValue( int perc )
{ {
return ( static_cast< double >( perc ) / 100.0 ) * ( m_max - m_min ) + m_min; return ( static_cast< double >( perc ) / static_cast< double >( SliderResolution ) ) * ( m_max - m_min ) + m_min;
} }
void WPropertyDoubleWidget::sliderChanged( int value ) void WPropertyDoubleWidget::sliderChanged( int value )
{ {
if( !m_slider.isHidden() && toPercent( m_doubleProperty->get() ) != value ) if( !m_slider.isHidden() && toSliderValue( m_integralProperty->get() ) != value )
{ {
// set to the property // set to the property
invalidate( !m_doubleProperty->set( fromPercent( value ) ) ); // NOTE: set automatically checks the validity of the value invalidate( !m_integralProperty->set( fromSliderValue( value ) ) ); // NOTE: set automatically checks the validity of the value
// set the value in the line edit // set the value in the line edit
m_edit.setText( QString::number( m_doubleProperty->get() ) ); m_edit.setText( QString::number( m_integralProperty->get() ) );
} }
} }
...@@ -171,10 +171,10 @@ void WPropertyDoubleWidget::editChanged() ...@@ -171,10 +171,10 @@ void WPropertyDoubleWidget::editChanged()
return; return;
} }
// set to the property // set to the property
invalidate( !m_doubleProperty->set( value ) ); // NOTE: set automatically checks the validity of the value invalidate( !m_integralProperty->set( value ) ); // NOTE: set automatically checks the validity of the value
// update slider // update slider
m_slider.setValue( toPercent( value ) ); m_slider.setValue( toSliderValue( value ) );
} }
void WPropertyDoubleWidget::textEdited( const QString& text ) void WPropertyDoubleWidget::textEdited( const QString& text )
...@@ -190,41 +190,23 @@ void WPropertyDoubleWidget::textEdited( const QString& text ) ...@@ -190,41 +190,23 @@ void WPropertyDoubleWidget::textEdited( const QString& text )
} }
// simply check validity // simply check validity
invalidate( !m_doubleProperty->accept( value ) ); invalidate( !m_integralProperty->accept( value ) );
} }
void WPropertyDoubleWidget::minMaxUpdated()
void WPropertyDoubleWidget::maxPressed()
{ {
bool ok; m_min = m_intervalEdit.getMin();
double newMax = QInputDialog::getDouble( this, "Setting Maximum of Slider", m_max = m_intervalEdit.getMax();
"Maximum", m_max, m_min, std::numeric_limits< double >::max(), 18, &ok );
if( ok ) if( m_min > m_integralProperty->get() )
{ {
m_max = newMax; m_integralProperty->set( m_min );
if( m_doubleProperty->get() > newMax )
{
m_doubleProperty->set( newMax );
m_slider.setValue( toPercent( newMax ) );
}
m_doubleProperty->setMax( newMax );
} }
} if( m_max < m_integralProperty->get() )
void WPropertyDoubleWidget::minPressed()
{
bool ok;
double newMin = QInputDialog::getDouble( this, "Setting Minimum of Slider",
"Minimum", m_min, -std::numeric_limits< double >::max(), m_max, 18, &ok );
if( ok )
{ {
m_min = newMin; m_integralProperty->set( m_max );
if( m_doubleProperty->get() < newMin )
{
m_doubleProperty->set( newMin );
m_slider.setValue( toPercent( newMin ) );
}
m_doubleProperty->setMin( newMin );
} }
m_slider.setValue( toSliderValue( m_integralProperty->get() ) );
} }
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <QtGui/QHBoxLayout> #include <QtGui/QHBoxLayout>
#include <QtGui/QToolButton> #include <QtGui/QToolButton>
#include "../guiElements/WQtIntervalEdit.h"
#include "WPropertyWidget.h" #include "WPropertyWidget.h"
/** /**
...@@ -62,9 +63,9 @@ protected: ...@@ -62,9 +63,9 @@ protected:
virtual void update(); virtual void update();
/** /**
* The integer property represented by this widget. * The property represented by this widget.
*/ */
WPropDouble m_doubleProperty; WPropDouble m_integralProperty;
/** /**
* The slider allowing modification of the integer value * The slider allowing modification of the integer value
...@@ -77,37 +78,32 @@ protected: ...@@ -77,37 +78,32 @@ protected:
QLineEdit m_edit; QLineEdit m_edit;
/** /**
* The button bringing up the dialog for modifying min of the slider * Layout used to position the label and the checkbox
*/
QToolButton m_minButton;
/**
* The button bringing up the dialog for modifying max of the slider
*/ */
QToolButton m_maxButton; QHBoxLayout m_layout;
/** /**
* Layout used to position the label and the checkbox * Layout used to combine the property widgets with the WQtIntervalEdit.
*/ */
QHBoxLayout m_layout; QVBoxLayout m_vLayout;
/** /**
* Converts a given value to a percentage between m_min and m_max. * Converts a given value to a slider value between m_min and m_max.
* *
* \param value the value. * \param value the value.
* *
* \return the percentage. * \return the percentage.
*/ */
int toPercent( double value ); int toSliderValue( double value );
/** /**
* Converts the given percentage to the real double value using m_min and m_max. * Converts the given slider value to the real double value using m_min and m_max.
* *
* \param perc the percentage. * \param perc the percentage.
* *
* \return the real double value. * \return the real double value.
*/ */
double fromPercent( int perc ); double fromSliderValue( int perc );
/** /**
* The current minimum value. * The current minimum value.
...@@ -129,6 +125,16 @@ protected: ...@@ -129,6 +125,16 @@ protected:
*/ */
QHBoxLayout m_infoLayout; QHBoxLayout m_infoLayout;
/**
* The edit for the interval.
*/
WQtIntervalEdit< double, double > m_intervalEdit;
/**
* Resolution of the slider.
*/
const static int SliderResolution;
private: private:
public slots: public slots:
...@@ -152,14 +158,9 @@ public slots: ...@@ -152,14 +158,9 @@ public slots:
void textEdited( const QString& text ); void textEdited( const QString& text );
/** /**
* Called when the maxMin button is pressed to open maxMinDialog. * Called whenever the interval edit changes.
*/
void maxPressed();
/**
* Called when the maxMin button is pressed to open maxMinDialog.
*/ */
void minPressed(); void minMaxUpdated();
}; };
#endif // WPROPERTYDOUBLEWIDGET_H #endif // WPROPERTYDOUBLEWIDGET_H
......
...@@ -22,64 +22,57 @@ ...@@ -22,64 +22,57 @@
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#include <algorithm>
#include <cmath> #include <cmath>
#include <iostream>
#include <limits> #include <limits>
#include <sstream>
#include <iostream>
#include <string> #include <string>
#include <QtGui/QInputDialog> #include <QtGui/QInputDialog>
#include "../WGuiConsts.h" #include "../WGuiConsts.h"
#include "../WQt4Gui.h" #include "../WQt4Gui.h"
#include "../guiElements/WQtIntervalEdit.h"
#include "core/common/WLogger.h" #include "core/common/WLogger.h"
#include "core/common/WPropertyVariable.h" #include "core/common/WPropertyVariable.h"
#include "WPropertyIntWidget.h" #include "WPropertyIntWidget.h"
#include "WPropertyIntWidget.moc" #include "WPropertyIntWidget.moc"
const int WPropertyIntWidget::SliderResolution = 10000;
WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* propertyGrid, QWidget* parent ): WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* propertyGrid, QWidget* parent ):
WPropertyWidget( property, propertyGrid, parent ), WPropertyWidget( property, propertyGrid, parent ),
m_intProperty( property ), m_integralProperty( property ),
m_slider( Qt::Horizontal, &m_parameterWidgets ), m_slider( Qt::Horizontal, &m_parameterWidgets ),
m_edit( &m_parameterWidgets ), m_edit( &m_parameterWidgets ),
m_minButton( &m_parameterWidgets ), m_layout(),
m_maxButton( &m_parameterWidgets ), m_vLayout( &m_parameterWidgets ),
m_layout( &m_parameterWidgets ),
m_asText( &m_informationWidgets ), m_asText( &m_informationWidgets ),
m_infoLayout( &m_informationWidgets ) m_infoLayout( &m_informationWidgets ),
m_intervalEdit( &m_parameterWidgets )
{ {
// layout both against each other
if( WQt4Gui::getSettings().value( "qt4gui/sliderMinMaxEdit", false ).toBool() )
{
m_layout.addWidget( &m_minButton );
m_minButton.setToolTip( "Set minimum of slider.\n Be aware that strange values can cause errors." );
m_minButton.setMinimumWidth( 5 );
m_minButton.setMaximumWidth( 5 );
}
else
{
m_minButton.hide();
}
m_layout.addWidget( &m_slider ); m_layout.addWidget( &m_slider );
if( WQt4Gui::getSettings().value( "qt4gui/sliderMinMaxEdit", false ).toBool() )
{
m_layout.addWidget( &m_maxButton );
m_maxButton.setToolTip( "Set maximum of slider.\n Be aware that strange values can cause errors." );
m_maxButton.setMinimumWidth( 5 );
m_maxButton.setMaximumWidth( 5 );
}
else
{
m_maxButton.hide();
}
m_layout.addWidget( &m_edit ); m_layout.addWidget( &m_edit );
m_layout.setMargin( WGLOBAL_MARGIN ); m_layout.setMargin( WGLOBAL_MARGIN );
m_layout.setSpacing( WGLOBAL_SPACING ); m_layout.setSpacing( WGLOBAL_SPACING );
m_parameterWidgets.setLayout( &m_layout ); m_vLayout.setMargin( WGLOBAL_MARGIN );
m_vLayout.setSpacing( WGLOBAL_SPACING );
// add the m_layout to the vlayout
QWidget* layoutContainer = new QWidget();
layoutContainer->setLayout( &m_layout );
m_vLayout.addWidget( layoutContainer );
// configure the interval edit
m_vLayout.addWidget( &m_intervalEdit );
if( !WQt4Gui::getSettings().value( "qt4gui/sliderMinMaxEdit", false ).toBool() )
{
m_intervalEdit.hide();
}
m_parameterWidgets.setLayout( &m_vLayout );
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION ) // Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
m_infoLayout.addWidget( &m_asText ); m_infoLayout.addWidget( &m_asText );
...@@ -95,8 +88,8 @@ WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* property ...@@ -95,8 +88,8 @@ WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* property
connect( &m_slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderChanged( int ) ) ); connect( &m_slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderChanged( int ) ) );
connect( &m_edit, SIGNAL( editingFinished() ), this, SLOT( editChanged() ) ); connect( &m_edit, SIGNAL( editingFinished() ), this, SLOT( editChanged() ) );
connect( &m_edit, SIGNAL( textEdited( const QString& ) ), this, SLOT( textEdited( const QString& ) ) ); connect( &m_edit, SIGNAL( textEdited( const QString& ) ), this, SLOT( textEdited( const QString& ) ) );
connect( &m_maxButton, SIGNAL( pressed() ), this, SLOT( maxPressed() ) ); connect( &m_intervalEdit, SIGNAL( minimumChanged() ), this, SLOT( minMaxUpdated() ) );
connect( &m_minButton, SIGNAL( pressed() ), this, SLOT( minPressed() ) ); connect( &m_intervalEdit, SIGNAL( maximumChanged() ), this, SLOT( minMaxUpdated() ) );
} }
WPropertyIntWidget::~WPropertyIntWidget() WPropertyIntWidget::~WPropertyIntWidget()
...@@ -108,43 +101,61 @@ void WPropertyIntWidget::update() ...@@ -108,43 +101,61 @@ void WPropertyIntWidget::update()
{ {
// // calculate maximum size of the text widget. // // calculate maximum size of the text widget.
// // XXX: this is not the optimal way but works for now // // XXX: this is not the optimal way but works for now
// Same as in WPropertyDouble.cpp: This does not work as expected on Mac OS X => reset to default // NO, it doesn't work on Mac OS X: You won't be able to any digits in it!, So I reset it to default which should work on other platforms too
QString valStr = QString::number( m_integralProperty->get() );
// set the initial values
QString valStr = QString::number( m_intProperty->get() );
m_edit.setText( valStr ); m_edit.setText( valStr );
// get the min constraint // get the min constraint
WPVInt::PropertyConstraintMin minC = m_intProperty->getMin(); WPVInt::PropertyConstraintMin minC = m_integralProperty->getMin();
WPVInt::PropertyConstraintMax maxC = m_intProperty->getMax(); WPVInt::PropertyConstraintMax maxC = m_integralProperty->getMax();
bool minMaxConstrained = minC && maxC; bool minMaxConstrained = minC && maxC;
if( minMaxConstrained ) if( minMaxConstrained )
{ {
m_slider.setHidden( false ); // setup the slider
m_slider.setMinimum( minC->getMin() ); m_slider.setMinimum( 0 );
m_slider.setMaximum( maxC->getMax() ); m_slider.setMaximum( SliderResolution );
m_slider.setValue( m_intProperty->get() );
m_edit.setMaximumWidth( fontMetrics().width( QString::number( - ( maxC->getMax() - minC->getMin() ) ) ) + 5 ); // update the interval edit too
m_intervalEdit.setAllowedMin( minC->getMin() );
m_intervalEdit.setAllowedMax( maxC->getMax() );
m_min = m_intervalEdit.getMin();
m_max = m_intervalEdit.getMax();
// updating the interval edit causes the proper values to be set in m_min and m_max
m_slider.setHidden( false );
m_intervalEdit.setHidden( false );
m_slider.setValue( toSliderValue( m_integralProperty->get() ) );
} }
else else