From b37adad53644d53c95bdb92c3963dc4d73134c51 Mon Sep 17 00:00:00 2001 From: apl Date: Fri, 30 Aug 2013 13:00:08 +0000 Subject: [PATCH] add extension point for formatting --- src/QDS/QDS_Datum.cxx | 45 ++++++++++++++++++++++++++++++++++------ src/QDS/QDS_Datum.h | 4 ++++ src/QDS/QDS_LineEdit.cxx | 35 +++---------------------------- src/QDS/QDS_LineEdit.h | 27 ++++++++++++++++++++++-- 4 files changed, 71 insertions(+), 40 deletions(-) diff --git a/src/QDS/QDS_Datum.cxx b/src/QDS/QDS_Datum.cxx index 12f90b3c1..1ac00eaf5 100644 --- a/src/QDS/QDS_Datum.cxx +++ b/src/QDS/QDS_Datum.cxx @@ -431,7 +431,7 @@ QString QDS_Datum::minimumValue() const QString min; if ( !myDicItem.IsNull() && myDicItem->HasData( DDS_DicItem::MinValue ) ) - min = format( format(), type(), myDicItem->GetMinValue() ); + min = formatValue( (double)myDicItem->GetMinValue() ); return min; } @@ -445,7 +445,7 @@ QString QDS_Datum::maximumValue() const QString max; if ( !myDicItem.IsNull() && myDicItem->HasData( DDS_DicItem::MaxValue ) ) - max = format( format(), type(), myDicItem->GetMaxValue() ); + max = formatValue( myDicItem->GetMaxValue() ); return max; } @@ -684,7 +684,7 @@ void QDS_Datum::reset() initDatum(); mySourceValue = defaultValue(); - setString( format( ( myFlags & NotFormat ) ? (QString) "" : format(), type(), mySourceValue ) ); + setString( formatValue( mySourceValue ) ); invalidateCache(); onParamChanged(); @@ -767,7 +767,7 @@ void QDS_Datum::setStringValue( const QString& txt ) initDatum(); mySourceValue = txt; - QString aStr = format( ( flags() & NotFormat ) ? (QString) "" : format(), type(), txt ); + QString aStr = formatValue( txt ); setString( aStr ); myTargetValue = aStr; @@ -795,7 +795,7 @@ void QDS_Datum::setDoubleValue( const double num ) if ( !myDicItem.IsNull() && !( flags() & NotConvert ) ) val = myDicItem->FromSI( val ); - QString aStr = format( ( flags() & NotFormat ) ? (QString) "" : format(), type(), val ); + QString aStr = formatValue( val ); setString( aStr ); myTargetValue = aStr; @@ -823,7 +823,7 @@ void QDS_Datum::setIntegerValue( const int num ) if ( !myDicItem.IsNull() && !( flags() & NotConvert ) ) val = myDicItem->FromSI( val ); - QString aStr = format( ( flags() & NotFormat ) ? (QString) "" : format(), type(), val ); + QString aStr = formatValue( val ); setString( aStr ); myTargetValue = aStr; @@ -1937,6 +1937,39 @@ void QDS_Datum::initDatum() const parent()->removeEventFilter( (QObject*)this ); } +/*! + \brief Format integer value according to datum formatting and type. + \internal + \param theValue the value being formatted. + \return formatted string value. +*/ +QString QDS_Datum::formatValue( const int theValue ) const +{ + return format( flags() & NotFormat ? "" : format(), type(), theValue ); +} + +/*! + \brief Format double value according to datum formatting and type. + \internal + \param theValue the value being formatted. + \return formatted string value. +*/ +QString QDS_Datum::formatValue( const double theValue ) const +{ + return format( flags() & NotFormat ? "" : format(), type(), theValue ); +} + +/*! + \brief Format string value according to datum formatting and type. + \internal + \param theValue the value being formatted. + \return formatted string value. +*/ +QString QDS_Datum::formatValue( const QString& theValue ) const +{ + return format( flags() & NotFormat ? "" : format(), type(), theValue ); +} + /*! \brief Get wrapper for specified subwidget. \internal diff --git a/src/QDS/QDS_Datum.h b/src/QDS/QDS_Datum.h index 286407bf6..6319ac077 100644 --- a/src/QDS/QDS_Datum.h +++ b/src/QDS/QDS_Datum.h @@ -174,6 +174,10 @@ protected: void initDatum() const; + virtual QString formatValue( const int ) const; + virtual QString formatValue( const double ) const; + virtual QString formatValue( const QString& ) const; + private: void initialize(); diff --git a/src/QDS/QDS_LineEdit.cxx b/src/QDS/QDS_LineEdit.cxx index f1dcc2c79..dd4202a66 100644 --- a/src/QDS/QDS_LineEdit.cxx +++ b/src/QDS/QDS_LineEdit.cxx @@ -25,35 +25,6 @@ #include #include -/*! - \class QDS_LineEdit::Editor - \internal - \brief Improved version of QLineEdit. -*/ - -class QDS_LineEdit::Editor : public QLineEdit -{ -public: - Editor( QWidget* parent = 0 ) : QLineEdit( parent ), myNumber( 2 ) {}; - virtual ~Editor() {}; - - void setNumber( const int num ) { myNumber = num; }; - - virtual QSize minimumSizeHint() const - { - return QLineEdit::minimumSizeHint(). - expandedTo( QSize( fontMetrics().width( "0" ) * myNumber, 0 ) ); - } - - virtual QSize sizeHint() const - { - return minimumSizeHint(); - } - -private: - int myNumber; -}; - /* \class QDS_LineEdit @@ -130,9 +101,9 @@ void QDS_LineEdit::unitSystemChanged( const QString& system ) num += aLen.toInt(); } - int zeroLen = format( format(), type(), 0 ).length(); - int minLen = format( format(), type(), minValue() ).length(); - int maxLen = format( format(), type(), maxValue() ).length(); + int zeroLen = formatValue( 0 ).length(); + int minLen = formatValue( minValue() ).length(); + int maxLen = formatValue( maxValue() ).length(); num = qMax( qMax( num, zeroLen ), qMax( minLen, maxLen ) ); ((Editor*)le)->setNumber( num ); diff --git a/src/QDS/QDS_LineEdit.h b/src/QDS/QDS_LineEdit.h index 01e2a19a9..f10cd95de 100644 --- a/src/QDS/QDS_LineEdit.h +++ b/src/QDS/QDS_LineEdit.h @@ -25,7 +25,7 @@ #include "QDS_Datum.h" -class QLineEdit; +#include class QDS_EXPORT QDS_LineEdit : public QDS_Datum { @@ -33,7 +33,7 @@ class QDS_EXPORT QDS_LineEdit : public QDS_Datum Q_PROPERTY( bool Selection READ hasSelection WRITE setSelection ) -protected: +public: class Editor; public: @@ -67,4 +67,27 @@ protected: virtual void unitSystemChanged( const QString& ); }; +class QDS_LineEdit::Editor : public QLineEdit +{ +public: + Editor( QWidget* parent = 0 ) : QLineEdit( parent ), myNumber( 2 ) {}; + virtual ~Editor() {}; + + void setNumber( const int num ) { myNumber = num; }; + + virtual QSize minimumSizeHint() const + { + return QLineEdit::minimumSizeHint(). + expandedTo( QSize( fontMetrics().width( "0" ) * myNumber, 0 ) ); + } + + virtual QSize sizeHint() const + { + return minimumSizeHint(); + } + +private: + int myNumber; +}; + #endif -- 2.39.2