Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

Commit b4b4eb96 authored by Frédéric Larue's avatar Frédéric Larue
Browse files

ValueString()/SetValueString() functions added to UIParams, for the conversion...

ValueString()/SetValueString() functions added to UIParams, for the conversion to/parsing from character strings.
parent f9b11c73
......@@ -89,6 +89,9 @@ public:
inline bool IsEnabled () const { return m_Widget->isEnabled(); }
inline bool IsDisabled() const { return !m_Widget->isEnabled(); }
inline virtual QString ValueString() const = 0;
inline virtual bool SetValueString( const QString &valueString ) = 0;
signals:
void parameterUpdated( UIParam *p );
......
......@@ -27,6 +27,9 @@ public:
inline void ArrangeInLayout( QGridLayout *l, int line );
inline void ConnectModificationSignal();
inline virtual QString ValueString() const { return QString(); }
inline virtual bool SetValueString( const QString &valueString ) { return true; }
};
......
......@@ -30,6 +30,9 @@ public:
inline void ArrangeInLayout( QGridLayout *l, int line );
inline void ConnectModificationSignal();
inline virtual QString ValueString() const { return QString(); }
inline virtual bool SetValueString( const QString &valueString ) { return true; }
signals:
void animationStartRequired();
void animationPauseRequired();
......
......@@ -33,6 +33,9 @@ public:
inline void ConnectModificationSignal();
inline virtual QString ValueString() const;
inline virtual bool SetValueString( const QString &valueString );
signals:
void valueChanged( bool );
......@@ -58,6 +61,22 @@ inline void UIParamBoolean::ConnectModificationSignal()
QObject::connect( Widget(), SIGNAL(stateChanged(int)), this, SLOT(triggerParameterUpdate()) );
}
inline QString UIParamBoolean::ValueString() const
{
return Widget()->isChecked()? "true" : "false";
}
inline bool UIParamBoolean::SetValueString( const QString &valueString )
{
if( valueString == "true" )
Widget()->setChecked( true );
else if( valueString == "false" )
Widget()->setChecked( false );
else
return false;
return true;
}
......
......@@ -48,3 +48,23 @@ void UIParamBufferSize1D::onSizeChanged( int size )
emit valueChanged( (int) m_Pow2Value );
}
QString UIParamBufferSize1D::ValueString() const
{
return QString::number( Widget()->value() );
}
bool UIParamBufferSize1D::SetValueString( const QString &valueString )
{
bool ok;
int value = valueString.toInt( &ok );
if( !ok || (value & (value-1)) )
return false;
SetValue( value );
return true;
}
......@@ -37,6 +37,9 @@ public:
inline void ConnectModificationSignal();
virtual QString ValueString() const;
virtual bool SetValueString( const QString &valueString );
signals:
void valueChanged( int );
......
......@@ -83,3 +83,34 @@ void UIParamBufferSize2D::onSizeYChanged( int size )
emit valueChanged( QSize(m_Pow2ValueX,m_Pow2ValueY) );
}
QString UIParamBufferSize2D::ValueString() const
{
return QString::number( m_SpinSizeX->value() ) + " " + QString::number( m_SpinSizeY->value() );
}
bool UIParamBufferSize2D::SetValueString( const QString &valueString )
{
QStringList values = valueString.simplified().split( ' ' );
if( values.size() != 2 )
return false;
bool ok;
int valueX = values.front().toInt( &ok );
if( !ok || (valueX & (valueX-1)) )
return false;
int valueY = values.back().toInt( &ok );
if( !ok || (valueY & (valueY-1)) )
return false;
QSize s( valueX, valueY );
SetValue( s );
return true;
}
......@@ -40,6 +40,9 @@ public:
inline void ConnectModificationSignal();
virtual QString ValueString() const;
virtual bool SetValueString( const QString &valueString );
signals:
void valueChanged( const QSize& size );
......
......@@ -33,6 +33,9 @@ public:
inline ByteSizeInputWidget* Widget() { return (ByteSizeInputWidget*) m_Widget; }
inline void ConnectModificationSignal();
inline virtual QString ValueString() const;
inline virtual bool SetValueString( const QString &valueString );
};
......@@ -51,6 +54,22 @@ void UIParamByteSize::ConnectModificationSignal()
QObject::connect( Widget(), SIGNAL(byteSizeChanged(uint64_t)), this, SLOT(triggerParameterUpdate()) );
}
inline QString UIParamByteSize::ValueString() const
{
return QString::number( Value() );
}
inline bool UIParamByteSize::SetValueString( const QString &valueString )
{
bool ok;
uint64_t value = valueString.toULongLong( &ok );
if( ok )
SetValue( value );
return ok;
}
......
......@@ -96,3 +96,18 @@ void UIParamChildren::UpdateVisibility()
if( m_HiddenIfEmpty )
SetVisible( Count() != 0 );
}
QString UIParamChildren::ValueString() const
{
return Widget()->currentText();
}
bool UIParamChildren::SetValueString( const QString &valueString )
{
int i = Widget()->findText( valueString );
if( i >= 0 )
SetValue( valueString );
return i >= 0;
}
......@@ -42,6 +42,9 @@ public:
inline void ConnectModificationSignal();
virtual QString ValueString() const;
virtual bool SetValueString( const QString &valueString );
inline bool IsHiddenIfEmpty() const { return m_HiddenIfEmpty; }
inline void SetHiddenIfEmpty( bool hidden ) { m_HiddenIfEmpty = hidden; UpdateVisibility(); }
};
......
......@@ -97,3 +97,20 @@ void UIParamChoice::changeCurrentChoice( bool toggled )
emit valueChanged( foundData.value() );
}
}
QString UIParamChoice::ValueString() const
{
return Value();
}
bool UIParamChoice::SetValueString( const QString &valueString )
{
if( m_ButtonValueMapping.contains(valueString) )
{
SetValue( valueString );
return true;
}
return false;
}
......@@ -42,6 +42,9 @@ public:
void ArrangeInLayout( QGridLayout *l, int line );
inline void ConnectModificationSignal();
virtual QString ValueString() const;
virtual bool SetValueString( const QString &valueString );
signals:
void currentChoiceChanged();
void valueChanged( const QString& value );
......
......@@ -57,7 +57,6 @@ UIParamColorRGB::UIParamColorRGB( const QString& id,
}
void UIParamColorRGB::ColorChooserSelection()
{
// Present color chooser to the user
......@@ -97,4 +96,38 @@ void UIParamColorRGB::ColorChannelChanged()
m_colorChooser->setIcon(p);
emit valueChanged( currentColor );
}
\ No newline at end of file
}
QString UIParamColorRGB::ValueString() const
{
QString str;
QTextStream stream( &str );
stream << "#";
stream.setFieldWidth(2);
stream.setPadChar('0');
stream << QString::number( m_SpinChannels[0]->value(), 16 ).toUpper();
stream << QString::number( m_SpinChannels[1]->value(), 16 ).toUpper();
stream << QString::number( m_SpinChannels[2]->value(), 16 ).toUpper();
stream << "FF";
return str;
}
bool UIParamColorRGB::SetValueString( const QString &valueString )
{
QRegExp exp( "#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})[0-9a-fA-F]{2}" );
if( exp.indexIn( valueString ) < 0 )
return false;
int r = exp.cap(1).toInt( NULL, 16 );
int g = exp.cap(2).toInt( NULL, 16 );
int b = exp.cap(3).toInt( NULL, 16 );
SetValue( QColor(r,g,b) );
return true;
}
......@@ -38,6 +38,9 @@ public:
inline void ConnectModificationSignal();
virtual QString ValueString() const;
virtual bool SetValueString( const QString &valueString );
signals:
void valueChanged( const QColor& c );
......
......@@ -36,6 +36,9 @@ public:
inline void ConnectModificationSignal();
inline virtual QString ValueString() const;
inline virtual bool SetValueString( const QString &valueString );
signals:
void valueChanged( double value );
......@@ -68,6 +71,20 @@ inline void UIParamDouble::ConnectModificationSignal()
QObject::connect( Widget(), SIGNAL(valueChanged(double)), this, SLOT(triggerParameterUpdate()) );
}
inline QString UIParamDouble::ValueString() const
{
return QString::number( Value() );
}
inline bool UIParamDouble::SetValueString( const QString &valueString )
{
bool ok;
double value = valueString.toDouble( &ok );
if( ok )
SetValue( value );
return ok;
}
......
......@@ -35,6 +35,9 @@ public:
inline void ConnectModificationSignal();
inline virtual QString ValueString() const;
inline virtual bool SetValueString( const QString &valueString );
signals:
void valueChanged( float value );
......@@ -67,6 +70,20 @@ inline void UIParamFloat::ConnectModificationSignal()
QObject::connect( Widget(), SIGNAL(valueChanged(double)), this, SLOT(triggerParameterUpdate()) );
}
inline QString UIParamFloat::ValueString() const
{
return QString::number( Value() );
}
inline bool UIParamFloat::SetValueString( const QString &valueString )
{
bool ok;
float value = valueString.toFloat( &ok );
if( ok )
SetValue( value );
return ok;
}
......
......@@ -32,6 +32,9 @@ public:
inline void ArrangeInLayout( QGridLayout *l, int line );
inline void ConnectModificationSignal();
inline virtual QString ValueString() const { return QString(); }
inline virtual bool SetValueString( const QString &valueString ) { return true; }
};
......
......@@ -38,6 +38,9 @@ public:
inline void ArrangeInLayout( QGridLayout *l, int line );
inline void ConnectModificationSignal();
inline virtual QString ValueString() const;
inline virtual bool SetValueString( const QString &valueString );
};
......@@ -74,6 +77,71 @@ inline void UIParamGradient::ConnectModificationSignal()
QObject::connect( m_Widget, SIGNAL(gradientModified()), this, SLOT(triggerParameterUpdate()) );
}
inline QString UIParamGradient::ValueString() const
{
QString str;
QVector<float> values;
QVector<QColor> colors;
Widget()->getStops( values, colors );
for( int i=0; i<values.size(); ++i )
{
QTextStream stream( &str );
if( i != 0 )
stream << ", ";
stream << values[i] << ": ";
stream << "#";
stream.setFieldWidth(2);
stream.setPadChar('0');
stream << QString::number( colors[i].red() , 16 ).toUpper();
stream << QString::number( colors[i].green(), 16 ).toUpper();
stream << QString::number( colors[i].blue() , 16 ).toUpper();
stream << QString::number( colors[i].alpha(), 16 ).toUpper();
}
return str;
}
inline bool UIParamGradient::SetValueString( const QString &valueString )
{
QStringList stopStrings = valueString.split( ',' );
QList<float> values;
QList<QColor> colors;
QRegExp rgbaExp( "#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})" );
for( auto &stop : stopStrings )
{
QStringList valueAndColor = stop.remove( ' ' ).split( ':' );
if( valueAndColor.size() != 2 )
return false;
bool ok;
float value = valueAndColor.front().toFloat( &ok );
if( !ok )
return false;
if( rgbaExp.indexIn(valueAndColor.back()) < 0 )
return false;
int r = rgbaExp.cap(1).toInt( NULL, 16 );
int g = rgbaExp.cap(2).toInt( NULL, 16 );
int b = rgbaExp.cap(3).toInt( NULL, 16 );
int a = rgbaExp.cap(4).toInt( NULL, 16 );
values.push_back( value );
colors.push_back( QColor(r,g,b,a) );
}
Widget()->setStops( colors, values );
return true;
}
......
......@@ -36,6 +36,9 @@ public:
inline void ConnectModificationSignal();
inline virtual QString ValueString() const;
inline virtual bool SetValueString( const QString &valueString );
signals:
void valueChanged( int value );
......@@ -67,6 +70,20 @@ inline void UIParamInteger::ConnectModificationSignal()
QObject::connect( Widget(), SIGNAL(valueChanged(int)), this, SLOT(triggerParameterUpdate()) );
}
inline QString UIParamInteger::ValueString() const
{
return QString::number( Value() );
}
inline bool UIParamInteger::SetValueString( const QString &valueString )
{
bool ok;
int value = valueString.toInt( &ok );
if( ok )
SetValue( value );
return ok;
}
......
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