From fcfafa0a51a3d4daa8aa7a6abc655e0defcd618b Mon Sep 17 00:00:00 2001 From: Nathan Woodrow Date: Sun, 28 Sep 2014 17:24:10 +1000 Subject: [PATCH] Use a single format string using Qt format for renderer label --- .../qgsgraduatedsymbolrendererv2.sip | 12 +--- .../qgsgraduatedsymbolrendererv2.cpp | 24 ++----- .../qgsgraduatedsymbolrendererv2.h | 16 ++--- .../qgsgraduatedsymbolrendererv2widget.cpp | 16 ++--- src/ui/qgsgraduatedsymbolrendererv2widget.ui | 66 +++++-------------- 5 files changed, 36 insertions(+), 98 deletions(-) diff --git a/python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip b/python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip index e6a9be69469..25133ec69b5 100644 --- a/python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip +++ b/python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip @@ -46,19 +46,13 @@ class QgsRendererRangeV2LabelFormat %End public: QgsRendererRangeV2LabelFormat(); - QgsRendererRangeV2LabelFormat( QString prefix, QString separator, QString suffix, int decimalPlaces=4, bool trimTrailingZeroes=false ); + QgsRendererRangeV2LabelFormat( QString format, int decimalPlaces=4, bool trimTrailingZeroes=false ); bool operator==( const QgsRendererRangeV2LabelFormat & other ) const; bool operator!=( const QgsRendererRangeV2LabelFormat & other ) const; - QString prefix() const; - void setPrefix( QString prefix ); - - QString separator() const; - void setSeparator( QString separator ); - - QString suffix() const; - void setSuffix( QString suffix ); + QString format() const; + void setFormat( QString format ); int decimalPlaces() const; void setDecimalPlaces( int decimalPlaces ); diff --git a/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp b/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp index bf692fe565e..30a401e6259 100644 --- a/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp +++ b/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp @@ -167,21 +167,17 @@ void QgsRendererRangeV2::toSld( QDomDocument &doc, QDomElement &element, QgsStri /////////// QgsRendererRangeV2LabelFormat::QgsRendererRangeV2LabelFormat(): - mPrefix( "" ), - mSeparator( " - " ), - mSuffix( "" ), + mFormat( " %1 - %2 " ), mDecimalPlaces( 4 ), mTrimTrailingZeroes( false ), mReTrailingZeroes( "\\.?0*$" ) { } -QgsRendererRangeV2LabelFormat::QgsRendererRangeV2LabelFormat( QString prefix, QString separator, QString suffix, int decimalPlaces, bool trimTrailingZeroes ): +QgsRendererRangeV2LabelFormat::QgsRendererRangeV2LabelFormat( QString format, int decimalPlaces, bool trimTrailingZeroes ): mReTrailingZeroes( "\\.?0*$" ) { - setPrefix( prefix ); - setSeparator( separator ); - setSuffix( suffix ); + setFormat( format ); setDecimalPlaces( decimalPlaces ); setTrimTrailingZeroes( trimTrailingZeroes ); } @@ -190,9 +186,7 @@ QgsRendererRangeV2LabelFormat::QgsRendererRangeV2LabelFormat( QString prefix, QS bool QgsRendererRangeV2LabelFormat::operator==( const QgsRendererRangeV2LabelFormat &other ) const { return - prefix() == other.prefix() && - separator() == other.separator() && - suffix() == other.suffix() && + format() == other.format() && decimalPlaces() == other.decimalPlaces() && trimTrailingZeroes() == other.trimTrailingZeroes(); } @@ -226,23 +220,19 @@ QString QgsRendererRangeV2LabelFormat::labelForRange( double lower, double upper if ( upperStr.contains( '.' ) ) upperStr = upperStr.replace( mReTrailingZeroes, "" ); } - return mPrefix + lowerStr + mSeparator + upperStr + mSuffix; + return mFormat.arg(lowerStr, upperStr); } void QgsRendererRangeV2LabelFormat::setFromDomElement( QDomElement &element ) { - mPrefix = element.attribute( "prefix", "" ); - mSeparator = element.attribute( "separator", " - " ); - mSuffix = element.attribute( "suffix", "" ); + mFormat = element.attribute( "format", " %1 - %2" ); mDecimalPlaces = element.attribute( "decimalplaces", "4" ).toInt(); mTrimTrailingZeroes = element.attribute( "trimtrailingzeroes", "false" ) == "true"; } void QgsRendererRangeV2LabelFormat::saveToDomElement( QDomElement &element ) { - element.setAttribute( "prefix", mPrefix ); - element.setAttribute( "separator", mSeparator ); - element.setAttribute( "suffix", mSuffix ); + element.setAttribute( "format", mFormat ); element.setAttribute( "decimalplaces", mDecimalPlaces ); element.setAttribute( "trimtrailingzeroes", mTrimTrailingZeroes ? "true" : "false" ); } diff --git a/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h b/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h index ca751a85203..f80f94e13e4 100644 --- a/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h +++ b/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h @@ -71,19 +71,13 @@ class CORE_EXPORT QgsRendererRangeV2LabelFormat { public: QgsRendererRangeV2LabelFormat(); - QgsRendererRangeV2LabelFormat( QString prefix, QString separator, QString suffix, int decimalPlaces = 4, bool trimTrailingZeroes = false ); + QgsRendererRangeV2LabelFormat( QString format, int decimalPlaces = 4, bool trimTrailingZeroes = false ); bool operator==( const QgsRendererRangeV2LabelFormat & other ) const; bool operator!=( const QgsRendererRangeV2LabelFormat & other ) const; - QString prefix() const { return mPrefix; } - void setPrefix( QString prefix ) { mPrefix = prefix; } - - QString separator() const { return mSeparator; } - void setSeparator( QString separator ) { mSeparator = separator; } - - QString suffix() const { return mSuffix; } - void setSuffix( QString suffix ) { mSuffix = suffix; } + QString format() const { return mFormat; } + void setFormat( QString format ) { mFormat = format; } int decimalPlaces() const { return mDecimalPlaces; } void setDecimalPlaces( int decimalPlaces ); @@ -99,9 +93,7 @@ class CORE_EXPORT QgsRendererRangeV2LabelFormat void saveToDomElement( QDomElement &element ); protected: - QString mPrefix; - QString mSeparator; - QString mSuffix; + QString mFormat; int mDecimalPlaces; bool mTrimTrailingZeroes; QRegExp mReTrailingZeroes; diff --git a/src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp b/src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp index e9606074ce2..2168a91de3a 100644 --- a/src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp +++ b/src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp @@ -457,9 +457,7 @@ void QgsGraduatedSymbolRendererV2Widget::connectUpdateHandlers() connect( cbxInvertedColorRamp, SIGNAL( toggled( bool ) ) , this, SLOT( reapplyColorRamp() ) ); connect( spinDecimalPlaces, SIGNAL( valueChanged( int ) ), this, SLOT( labelFormatChanged() ) ); connect( cbxTrimTrailingZeroes, SIGNAL( toggled( bool ) ), this, SLOT( labelFormatChanged() ) ); - connect( txtPrefix, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) ); - connect( txtSeparator, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) ); - connect( txtSuffix, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) ); + connect( txtFormat, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) ); connect( mModel, SIGNAL( rowsMoved() ), this, SLOT( rowsMoved() ) ); connect( mModel, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), this, SLOT( modelDataChanged( ) ) ); @@ -475,9 +473,7 @@ void QgsGraduatedSymbolRendererV2Widget::disconnectUpdateHandlers() disconnect( cbxInvertedColorRamp, SIGNAL( toggled( bool ) ) , this, SLOT( reapplyColorRamp() ) ); disconnect( spinDecimalPlaces, SIGNAL( valueChanged( int ) ), this, SLOT( labelFormatChanged() ) ); disconnect( cbxTrimTrailingZeroes, SIGNAL( toggled( bool ) ), this, SLOT( labelFormatChanged() ) ); - disconnect( txtPrefix, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) ); - disconnect( txtSeparator, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) ); - disconnect( txtSuffix, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) ); + disconnect( txtFormat, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) ); disconnect( mModel, SIGNAL( rowsMoved() ), this, SLOT( rowsMoved() ) ); disconnect( mModel, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), this, SLOT( modelDataChanged( ) ) ); @@ -518,9 +514,7 @@ void QgsGraduatedSymbolRendererV2Widget::updateUiFromRenderer( bool updateCount } QgsRendererRangeV2LabelFormat labelFormat = mRenderer->labelFormat(); - txtPrefix->setText( labelFormat.prefix() ); - txtSeparator->setText( labelFormat.separator() ); - txtSuffix->setText( labelFormat.suffix() ); + txtFormat->setText( labelFormat.format() ); spinDecimalPlaces->setValue( labelFormat.decimalPlaces() ); cbxTrimTrailingZeroes->setChecked( labelFormat.trimTrailingZeroes() ); @@ -859,9 +853,7 @@ void QgsGraduatedSymbolRendererV2Widget::scaleMethodChanged( QgsSymbolV2::ScaleM void QgsGraduatedSymbolRendererV2Widget::labelFormatChanged() { QgsRendererRangeV2LabelFormat labelFormat = QgsRendererRangeV2LabelFormat( - txtPrefix->text(), - txtSeparator->text(), - txtSuffix->text(), + txtFormat->text(), spinDecimalPlaces->value(), cbxTrimTrailingZeroes->isChecked() ); mRenderer->setLabelFormat( labelFormat, true ); diff --git a/src/ui/qgsgraduatedsymbolrendererv2widget.ui b/src/ui/qgsgraduatedsymbolrendererv2widget.ui index 9075bdd472d..7f66b97bdc2 100644 --- a/src/ui/qgsgraduatedsymbolrendererv2widget.ui +++ b/src/ui/qgsgraduatedsymbolrendererv2widget.ui @@ -6,7 +6,7 @@ 0 0 - 637 + 647 339 @@ -186,13 +186,13 @@ - Label + Label Format Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - txtPrefix + txtFormat @@ -202,35 +202,7 @@ 0 - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - #.## - - - - - - - Qt::AlignCenter - - - - - - - #.## - - - - - + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter @@ -238,19 +210,6 @@ - - - - Decimal places - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - spinDecimalPlaces - - - @@ -281,6 +240,19 @@ + + + + Decimal places + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + spinDecimalPlaces + + + @@ -386,9 +358,7 @@ - txtPrefix - txtSeparator - txtSuffix + txtFormat spinDecimalPlaces cbxTrimTrailingZeroes btnChangeGraduatedSymbol