Skip to content

Commit fcfafa0

Browse files
committedSep 28, 2014
Use a single format string using Qt format for renderer label
1 parent 428375e commit fcfafa0

File tree

5 files changed

+36
-98
lines changed

5 files changed

+36
-98
lines changed
 

‎python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,13 @@ class QgsRendererRangeV2LabelFormat
4646
%End
4747
public:
4848
QgsRendererRangeV2LabelFormat();
49-
QgsRendererRangeV2LabelFormat( QString prefix, QString separator, QString suffix, int decimalPlaces=4, bool trimTrailingZeroes=false );
49+
QgsRendererRangeV2LabelFormat( QString format, int decimalPlaces=4, bool trimTrailingZeroes=false );
5050

5151
bool operator==( const QgsRendererRangeV2LabelFormat & other ) const;
5252
bool operator!=( const QgsRendererRangeV2LabelFormat & other ) const;
5353

54-
QString prefix() const;
55-
void setPrefix( QString prefix );
56-
57-
QString separator() const;
58-
void setSeparator( QString separator );
59-
60-
QString suffix() const;
61-
void setSuffix( QString suffix );
54+
QString format() const;
55+
void setFormat( QString format );
6256

6357
int decimalPlaces() const;
6458
void setDecimalPlaces( int decimalPlaces );

‎src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,17 @@ void QgsRendererRangeV2::toSld( QDomDocument &doc, QDomElement &element, QgsStri
167167
///////////
168168

169169
QgsRendererRangeV2LabelFormat::QgsRendererRangeV2LabelFormat():
170-
mPrefix( "" ),
171-
mSeparator( " - " ),
172-
mSuffix( "" ),
170+
mFormat( " %1 - %2 " ),
173171
mDecimalPlaces( 4 ),
174172
mTrimTrailingZeroes( false ),
175173
mReTrailingZeroes( "\\.?0*$" )
176174
{
177175
}
178176

179-
QgsRendererRangeV2LabelFormat::QgsRendererRangeV2LabelFormat( QString prefix, QString separator, QString suffix, int decimalPlaces, bool trimTrailingZeroes ):
177+
QgsRendererRangeV2LabelFormat::QgsRendererRangeV2LabelFormat( QString format, int decimalPlaces, bool trimTrailingZeroes ):
180178
mReTrailingZeroes( "\\.?0*$" )
181179
{
182-
setPrefix( prefix );
183-
setSeparator( separator );
184-
setSuffix( suffix );
180+
setFormat( format );
185181
setDecimalPlaces( decimalPlaces );
186182
setTrimTrailingZeroes( trimTrailingZeroes );
187183
}
@@ -190,9 +186,7 @@ QgsRendererRangeV2LabelFormat::QgsRendererRangeV2LabelFormat( QString prefix, QS
190186
bool QgsRendererRangeV2LabelFormat::operator==( const QgsRendererRangeV2LabelFormat &other ) const
191187
{
192188
return
193-
prefix() == other.prefix() &&
194-
separator() == other.separator() &&
195-
suffix() == other.suffix() &&
189+
format() == other.format() &&
196190
decimalPlaces() == other.decimalPlaces() &&
197191
trimTrailingZeroes() == other.trimTrailingZeroes();
198192
}
@@ -226,23 +220,19 @@ QString QgsRendererRangeV2LabelFormat::labelForRange( double lower, double upper
226220
if ( upperStr.contains( '.' ) ) upperStr = upperStr.replace( mReTrailingZeroes, "" );
227221
}
228222

229-
return mPrefix + lowerStr + mSeparator + upperStr + mSuffix;
223+
return mFormat.arg(lowerStr, upperStr);
230224
}
231225

232226
void QgsRendererRangeV2LabelFormat::setFromDomElement( QDomElement &element )
233227
{
234-
mPrefix = element.attribute( "prefix", "" );
235-
mSeparator = element.attribute( "separator", " - " );
236-
mSuffix = element.attribute( "suffix", "" );
228+
mFormat = element.attribute( "format", " %1 - %2" );
237229
mDecimalPlaces = element.attribute( "decimalplaces", "4" ).toInt();
238230
mTrimTrailingZeroes = element.attribute( "trimtrailingzeroes", "false" ) == "true";
239231
}
240232

241233
void QgsRendererRangeV2LabelFormat::saveToDomElement( QDomElement &element )
242234
{
243-
element.setAttribute( "prefix", mPrefix );
244-
element.setAttribute( "separator", mSeparator );
245-
element.setAttribute( "suffix", mSuffix );
235+
element.setAttribute( "format", mFormat );
246236
element.setAttribute( "decimalplaces", mDecimalPlaces );
247237
element.setAttribute( "trimtrailingzeroes", mTrimTrailingZeroes ? "true" : "false" );
248238
}

‎src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,13 @@ class CORE_EXPORT QgsRendererRangeV2LabelFormat
7171
{
7272
public:
7373
QgsRendererRangeV2LabelFormat();
74-
QgsRendererRangeV2LabelFormat( QString prefix, QString separator, QString suffix, int decimalPlaces = 4, bool trimTrailingZeroes = false );
74+
QgsRendererRangeV2LabelFormat( QString format, int decimalPlaces = 4, bool trimTrailingZeroes = false );
7575

7676
bool operator==( const QgsRendererRangeV2LabelFormat & other ) const;
7777
bool operator!=( const QgsRendererRangeV2LabelFormat & other ) const;
7878

79-
QString prefix() const { return mPrefix; }
80-
void setPrefix( QString prefix ) { mPrefix = prefix; }
81-
82-
QString separator() const { return mSeparator; }
83-
void setSeparator( QString separator ) { mSeparator = separator; }
84-
85-
QString suffix() const { return mSuffix; }
86-
void setSuffix( QString suffix ) { mSuffix = suffix; }
79+
QString format() const { return mFormat; }
80+
void setFormat( QString format ) { mFormat = format; }
8781

8882
int decimalPlaces() const { return mDecimalPlaces; }
8983
void setDecimalPlaces( int decimalPlaces );
@@ -99,9 +93,7 @@ class CORE_EXPORT QgsRendererRangeV2LabelFormat
9993
void saveToDomElement( QDomElement &element );
10094

10195
protected:
102-
QString mPrefix;
103-
QString mSeparator;
104-
QString mSuffix;
96+
QString mFormat;
10597
int mDecimalPlaces;
10698
bool mTrimTrailingZeroes;
10799
QRegExp mReTrailingZeroes;

‎src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,7 @@ void QgsGraduatedSymbolRendererV2Widget::connectUpdateHandlers()
457457
connect( cbxInvertedColorRamp, SIGNAL( toggled( bool ) ) , this, SLOT( reapplyColorRamp() ) );
458458
connect( spinDecimalPlaces, SIGNAL( valueChanged( int ) ), this, SLOT( labelFormatChanged() ) );
459459
connect( cbxTrimTrailingZeroes, SIGNAL( toggled( bool ) ), this, SLOT( labelFormatChanged() ) );
460-
connect( txtPrefix, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) );
461-
connect( txtSeparator, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) );
462-
connect( txtSuffix, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) );
460+
connect( txtFormat, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) );
463461

464462
connect( mModel, SIGNAL( rowsMoved() ), this, SLOT( rowsMoved() ) );
465463
connect( mModel, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), this, SLOT( modelDataChanged( ) ) );
@@ -475,9 +473,7 @@ void QgsGraduatedSymbolRendererV2Widget::disconnectUpdateHandlers()
475473
disconnect( cbxInvertedColorRamp, SIGNAL( toggled( bool ) ) , this, SLOT( reapplyColorRamp() ) );
476474
disconnect( spinDecimalPlaces, SIGNAL( valueChanged( int ) ), this, SLOT( labelFormatChanged() ) );
477475
disconnect( cbxTrimTrailingZeroes, SIGNAL( toggled( bool ) ), this, SLOT( labelFormatChanged() ) );
478-
disconnect( txtPrefix, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) );
479-
disconnect( txtSeparator, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) );
480-
disconnect( txtSuffix, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) );
476+
disconnect( txtFormat, SIGNAL( textChanged( QString ) ), this, SLOT( labelFormatChanged() ) );
481477

482478
disconnect( mModel, SIGNAL( rowsMoved() ), this, SLOT( rowsMoved() ) );
483479
disconnect( mModel, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), this, SLOT( modelDataChanged( ) ) );
@@ -518,9 +514,7 @@ void QgsGraduatedSymbolRendererV2Widget::updateUiFromRenderer( bool updateCount
518514
}
519515

520516
QgsRendererRangeV2LabelFormat labelFormat = mRenderer->labelFormat();
521-
txtPrefix->setText( labelFormat.prefix() );
522-
txtSeparator->setText( labelFormat.separator() );
523-
txtSuffix->setText( labelFormat.suffix() );
517+
txtFormat->setText( labelFormat.format() );
524518
spinDecimalPlaces->setValue( labelFormat.decimalPlaces() );
525519
cbxTrimTrailingZeroes->setChecked( labelFormat.trimTrailingZeroes() );
526520

@@ -859,9 +853,7 @@ void QgsGraduatedSymbolRendererV2Widget::scaleMethodChanged( QgsSymbolV2::ScaleM
859853
void QgsGraduatedSymbolRendererV2Widget::labelFormatChanged()
860854
{
861855
QgsRendererRangeV2LabelFormat labelFormat = QgsRendererRangeV2LabelFormat(
862-
txtPrefix->text(),
863-
txtSeparator->text(),
864-
txtSuffix->text(),
856+
txtFormat->text(),
865857
spinDecimalPlaces->value(),
866858
cbxTrimTrailingZeroes->isChecked() );
867859
mRenderer->setLabelFormat( labelFormat, true );

‎src/ui/qgsgraduatedsymbolrendererv2widget.ui

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>637</width>
9+
<width>647</width>
1010
<height>339</height>
1111
</rect>
1212
</property>
@@ -186,13 +186,13 @@
186186
<item row="3" column="0">
187187
<widget class="QLabel" name="label">
188188
<property name="text">
189-
<string>Label </string>
189+
<string>Label Format</string>
190190
</property>
191191
<property name="alignment">
192192
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
193193
</property>
194194
<property name="buddy">
195-
<cstring>txtPrefix</cstring>
195+
<cstring>txtFormat</cstring>
196196
</property>
197197
</widget>
198198
</item>
@@ -202,55 +202,14 @@
202202
<number>0</number>
203203
</property>
204204
<item>
205-
<widget class="QLineEdit" name="txtPrefix">
206-
<property name="alignment">
207-
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
208-
</property>
209-
</widget>
210-
</item>
211-
<item>
212-
<widget class="QLabel" name="label_3">
213-
<property name="text">
214-
<string>#.##</string>
215-
</property>
216-
</widget>
217-
</item>
218-
<item>
219-
<widget class="QLineEdit" name="txtSeparator">
220-
<property name="alignment">
221-
<set>Qt::AlignCenter</set>
222-
</property>
223-
</widget>
224-
</item>
225-
<item>
226-
<widget class="QLabel" name="label_17">
227-
<property name="text">
228-
<string>#.##</string>
229-
</property>
230-
</widget>
231-
</item>
232-
<item>
233-
<widget class="QLineEdit" name="txtSuffix">
205+
<widget class="QLineEdit" name="txtFormat">
234206
<property name="alignment">
235207
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
236208
</property>
237209
</widget>
238210
</item>
239211
</layout>
240212
</item>
241-
<item row="3" column="2">
242-
<widget class="QLabel" name="label_16">
243-
<property name="text">
244-
<string>Decimal places</string>
245-
</property>
246-
<property name="alignment">
247-
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
248-
</property>
249-
<property name="buddy">
250-
<cstring>spinDecimalPlaces</cstring>
251-
</property>
252-
</widget>
253-
</item>
254213
<item row="3" column="3">
255214
<layout class="QHBoxLayout" name="horizontalLayout_7">
256215
<item>
@@ -281,6 +240,19 @@
281240
</item>
282241
</layout>
283242
</item>
243+
<item row="3" column="2">
244+
<widget class="QLabel" name="label_16">
245+
<property name="text">
246+
<string>Decimal places</string>
247+
</property>
248+
<property name="alignment">
249+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
250+
</property>
251+
<property name="buddy">
252+
<cstring>spinDecimalPlaces</cstring>
253+
</property>
254+
</widget>
255+
</item>
284256
</layout>
285257
</item>
286258
<item>
@@ -386,9 +358,7 @@
386358
</customwidget>
387359
</customwidgets>
388360
<tabstops>
389-
<tabstop>txtPrefix</tabstop>
390-
<tabstop>txtSeparator</tabstop>
391-
<tabstop>txtSuffix</tabstop>
361+
<tabstop>txtFormat</tabstop>
392362
<tabstop>spinDecimalPlaces</tabstop>
393363
<tabstop>cbxTrimTrailingZeroes</tabstop>
394364
<tabstop>btnChangeGraduatedSymbol</tabstop>

0 commit comments

Comments
 (0)
Please sign in to comment.