decimals moved from QskSpinBox to QskBoundedValueInput
This commit is contained in:
parent
089f0c3abe
commit
c5f8c549d3
@ -7,9 +7,18 @@
|
||||
#include "QskFunctions.h"
|
||||
|
||||
#include <qlocale.h>
|
||||
#include <cfloat>
|
||||
|
||||
class QskBoundedValueInput::PrivateData
|
||||
{
|
||||
public:
|
||||
qreal value = 0.0;
|
||||
int decimals = 2;
|
||||
};
|
||||
|
||||
QskBoundedValueInput::QskBoundedValueInput( QQuickItem* parent )
|
||||
: QskBoundedInput( parent )
|
||||
: Inherited( parent )
|
||||
, m_data( new PrivateData )
|
||||
{
|
||||
}
|
||||
|
||||
@ -17,9 +26,26 @@ QskBoundedValueInput::~QskBoundedValueInput()
|
||||
{
|
||||
}
|
||||
|
||||
void QskBoundedValueInput::setDecimals( int decimals )
|
||||
{
|
||||
decimals = qBound( 0, decimals, DBL_MAX_10_EXP + DBL_DIG );
|
||||
if ( decimals != m_data->decimals )
|
||||
{
|
||||
m_data->decimals = decimals;
|
||||
|
||||
update();
|
||||
resetImplicitSize();
|
||||
}
|
||||
}
|
||||
|
||||
int QskBoundedValueInput::decimals() const
|
||||
{
|
||||
return m_data->decimals;
|
||||
}
|
||||
|
||||
void QskBoundedValueInput::alignInput()
|
||||
{
|
||||
auto value = alignedValue( m_value );
|
||||
auto value = alignedValue( m_data->value );
|
||||
value = fixupValue( value );
|
||||
|
||||
setValueInternal( value );
|
||||
@ -38,7 +64,7 @@ void QskBoundedValueInput::setValueAsRatio( qreal ratio )
|
||||
|
||||
qreal QskBoundedValueInput::valueAsRatio() const
|
||||
{
|
||||
return valueAsRatio( m_value );
|
||||
return valueAsRatio( m_data->value );
|
||||
}
|
||||
|
||||
void QskBoundedValueInput::setValue( qreal value )
|
||||
@ -54,19 +80,19 @@ void QskBoundedValueInput::setValue( qreal value )
|
||||
|
||||
qreal QskBoundedValueInput::value() const
|
||||
{
|
||||
return m_value;
|
||||
return m_data->value;
|
||||
}
|
||||
|
||||
void QskBoundedValueInput::increment( qreal offset )
|
||||
{
|
||||
setValue( m_value + offset );
|
||||
setValue( m_data->value + offset );
|
||||
}
|
||||
|
||||
void QskBoundedValueInput::setValueInternal( qreal value )
|
||||
{
|
||||
if ( !qskFuzzyCompare( value, m_value ) )
|
||||
if ( !qskFuzzyCompare( value, m_data->value ) )
|
||||
{
|
||||
m_value = value;
|
||||
m_data->value = value;
|
||||
Q_EMIT valueChanged( value );
|
||||
|
||||
update();
|
||||
@ -74,13 +100,13 @@ void QskBoundedValueInput::setValueInternal( qreal value )
|
||||
}
|
||||
|
||||
QString QskBoundedValueInput::valueText() const
|
||||
{
|
||||
{
|
||||
return textFromValue( value() );
|
||||
}
|
||||
|
||||
|
||||
QString QskBoundedValueInput::textFromValue( qreal value ) const
|
||||
{
|
||||
return locale().toString( value );
|
||||
{
|
||||
return locale().toString( value, 'f', m_data->decimals );
|
||||
}
|
||||
|
||||
#include "moc_QskBoundedValueInput.cpp"
|
||||
|
@ -20,6 +20,9 @@ class QSK_EXPORT QskBoundedValueInput : public QskBoundedInput
|
||||
|
||||
Q_PROPERTY( QString valueText READ valueText NOTIFY valueChanged )
|
||||
|
||||
Q_PROPERTY( int decimals READ decimals
|
||||
WRITE setDecimals NOTIFY decimalsChanged )
|
||||
|
||||
using Inherited = QskBoundedInput;
|
||||
|
||||
public:
|
||||
@ -35,6 +38,9 @@ class QSK_EXPORT QskBoundedValueInput : public QskBoundedInput
|
||||
QString valueText() const;
|
||||
virtual QString textFromValue( qreal ) const;
|
||||
|
||||
void setDecimals( int );
|
||||
int decimals() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setValue( qreal );
|
||||
void setValueAsRatio( qreal );
|
||||
@ -42,6 +48,7 @@ class QSK_EXPORT QskBoundedValueInput : public QskBoundedInput
|
||||
|
||||
Q_SIGNALS:
|
||||
void valueChanged( qreal );
|
||||
void decimalsChanged( int );
|
||||
|
||||
protected:
|
||||
virtual qreal fixupValue( qreal ) const;
|
||||
@ -49,9 +56,9 @@ class QSK_EXPORT QskBoundedValueInput : public QskBoundedInput
|
||||
|
||||
private:
|
||||
void setValueInternal( qreal );
|
||||
void adjustValue();
|
||||
|
||||
qreal m_value = 0.0;
|
||||
class PrivateData;
|
||||
std::unique_ptr< PrivateData > m_data;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -9,8 +9,6 @@
|
||||
|
||||
#include <qbasictimer.h>
|
||||
|
||||
#include <cfloat>
|
||||
|
||||
QSK_SUBCONTROL( QskSpinBox, Panel )
|
||||
|
||||
QSK_SUBCONTROL( QskSpinBox, TextPanel )
|
||||
@ -109,8 +107,6 @@ class QskSpinBox::PrivateData
|
||||
this->repeatTimer.stop();
|
||||
}
|
||||
|
||||
int decimals = 2;
|
||||
|
||||
int autoRepeatDelay = 300;
|
||||
int autoRepeatInterval = 100;
|
||||
|
||||
@ -184,28 +180,6 @@ bool QskSpinBox::isWrapping() const
|
||||
return m_data->wrapping;
|
||||
}
|
||||
|
||||
void QskSpinBox::setDecimals( int decimals )
|
||||
{
|
||||
decimals = qBound( 0, decimals, DBL_MAX_10_EXP + DBL_DIG );
|
||||
if ( decimals != m_data->decimals )
|
||||
{
|
||||
m_data->decimals = decimals;
|
||||
|
||||
update();
|
||||
resetImplicitSize();
|
||||
}
|
||||
}
|
||||
|
||||
int QskSpinBox::decimals() const
|
||||
{
|
||||
return m_data->decimals;
|
||||
}
|
||||
|
||||
QString QskSpinBox::textFromValue( qreal value ) const
|
||||
{
|
||||
return locale().toString( value, 'f', m_data->decimals );
|
||||
}
|
||||
|
||||
void QskSpinBox::increment( qreal offset )
|
||||
{
|
||||
if ( m_data->wrapping )
|
||||
|
@ -19,9 +19,6 @@ class QSK_EXPORT QskSpinBox : public QskBoundedValueInput
|
||||
Q_PROPERTY( Decoration decoration READ decoration
|
||||
WRITE setDecoration RESET resetDecoration NOTIFY decorationChanged )
|
||||
|
||||
Q_PROPERTY( int decimals READ decimals
|
||||
WRITE setDecimals NOTIFY decimalsChanged )
|
||||
|
||||
public:
|
||||
QSK_SUBCONTROLS( Panel, TextPanel, Text,
|
||||
UpPanel, UpIndicator, DownPanel, DownIndicator )
|
||||
@ -51,18 +48,11 @@ class QSK_EXPORT QskSpinBox : public QskBoundedValueInput
|
||||
void setWrapping( bool );
|
||||
bool isWrapping() const;
|
||||
|
||||
void setDecimals( int );
|
||||
int decimals() const;
|
||||
|
||||
virtual QString textFromValue( qreal ) const override;
|
||||
|
||||
void increment( qreal ) override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void decorationChanged( Decoration );
|
||||
void wrappingChanged( bool );
|
||||
void decimalsChanged( int );
|
||||
void textChanged();
|
||||
|
||||
protected:
|
||||
void timerEvent( QTimerEvent* ) override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user