Skip to content

Commit 0fa40a6

Browse files
committedDec 4, 2014
Change some spin boxes in symbology to QgsDoubleSpinBox
Adds the handy 'clear' buttons to these spin boxes, such as offsets and rotation. Also standardises the display of some widgets in symbology.
1 parent 1a4b8bb commit 0fa40a6

21 files changed

+173
-93
lines changed
 

‎python/gui/editorwidgets/qgsdoublespinbox.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class QgsDoubleSpinBox : QDoubleSpinBox
3535
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );
3636

3737
//! returns the value used when clear() is called.
38-
double clearValue();
38+
double clearValue() const;
3939

4040
protected:
4141
virtual void resizeEvent( QResizeEvent* event );

‎python/gui/editorwidgets/qgsspinbox.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class QgsSpinBox : QSpinBox
3535
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );
3636

3737
//! returns the value used when clear() is called.
38-
int clearValue();
38+
int clearValue() const;
3939

4040
protected:
4141
virtual void resizeEvent( QResizeEvent* event );

‎src/gui/editorwidgets/qgsdoublespinbox.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ QgsDoubleSpinBox::QgsDoubleSpinBox( QWidget *parent )
4848
void QgsDoubleSpinBox::setShowClearButton( const bool showClearButton )
4949
{
5050
mShowClearButton = showClearButton;
51-
mClearButton->setVisible( mShowClearButton && isEnabled() && value() != minimum() );
51+
mClearButton->setVisible( shouldShowClearForValue( value() ) );
5252
}
5353

5454
void QgsDoubleSpinBox::changeEvent( QEvent *event )
5555
{
5656
QDoubleSpinBox::changeEvent( event );
57-
mClearButton->setVisible( mShowClearButton && isEnabled() && value() != minimum() );
57+
mClearButton->setVisible( shouldShowClearForValue( value() ) );
5858
}
5959

6060
void QgsDoubleSpinBox::changed( const double& value )
6161
{
62-
mClearButton->setVisible( mShowClearButton && isEnabled() && value != minimum() );
62+
mClearButton->setVisible( shouldShowClearForValue( value ) );
6363
}
6464

6565
void QgsDoubleSpinBox::clear()
@@ -81,7 +81,7 @@ void QgsDoubleSpinBox::setClearValue( double customValue , QString specialValueT
8181
}
8282
}
8383

84-
void QgsDoubleSpinBox::setClearValueMode(QgsDoubleSpinBox::ClearValueMode mode, QString clearValueText )
84+
void QgsDoubleSpinBox::setClearValueMode( QgsDoubleSpinBox::ClearValueMode mode, QString clearValueText )
8585
{
8686
mClearValueMode = mode;
8787
mCustomClearValue = 0;
@@ -95,7 +95,7 @@ void QgsDoubleSpinBox::setClearValueMode(QgsDoubleSpinBox::ClearValueMode mode,
9595
}
9696
}
9797

98-
double QgsDoubleSpinBox::clearValue()
98+
double QgsDoubleSpinBox::clearValue() const
9999
{
100100
if ( mClearValueMode == MinimumValue )
101101
return minimum() ;
@@ -110,6 +110,15 @@ int QgsDoubleSpinBox::frameWidth() const
110110
return style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
111111
}
112112

113+
bool QgsDoubleSpinBox::shouldShowClearForValue( const double value ) const
114+
{
115+
if ( !mShowClearButton || !isEnabled() )
116+
{
117+
return false;
118+
}
119+
return value != clearValue();
120+
}
121+
113122
void QgsDoubleSpinBox::resizeEvent( QResizeEvent * event )
114123
{
115124
QDoubleSpinBox::resizeEvent( event );

‎src/gui/editorwidgets/qgsdoublespinbox.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
5959
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );
6060

6161
//! returns the value used when clear() is called.
62-
double clearValue();
62+
double clearValue() const;
6363

6464
protected:
6565
virtual void resizeEvent( QResizeEvent* event );
@@ -70,6 +70,7 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
7070

7171
private:
7272
int frameWidth() const;
73+
bool shouldShowClearForValue( const double value ) const;
7374

7475
bool mShowClearButton;
7576
ClearValueMode mClearValueMode;

‎src/gui/editorwidgets/qgsspinbox.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ QgsSpinBox::QgsSpinBox( QWidget *parent )
4848
void QgsSpinBox::setShowClearButton( const bool showClearButton )
4949
{
5050
mShowClearButton = showClearButton;
51-
mClearButton->setVisible( mShowClearButton && isEnabled() && value() != minimum() );
51+
mClearButton->setVisible( shouldShowClearForValue( value() ) );
5252
}
5353

5454
void QgsSpinBox::changeEvent( QEvent *event )
5555
{
5656
QSpinBox::changeEvent( event );
57-
mClearButton->setVisible( mShowClearButton && isEnabled() && value() != minimum() );
57+
mClearButton->setVisible( shouldShowClearForValue( value() ) );
5858
}
5959

6060
void QgsSpinBox::changed( const int& value )
6161
{
62-
mClearButton->setVisible( mShowClearButton && isEnabled() && value != minimum() );
62+
mClearButton->setVisible( shouldShowClearForValue( value ) );
6363
}
6464

6565
void QgsSpinBox::clear()
@@ -81,7 +81,7 @@ void QgsSpinBox::setClearValue( int customValue, QString specialValueText )
8181
}
8282
}
8383

84-
void QgsSpinBox::setClearValueMode(QgsSpinBox::ClearValueMode mode, QString specialValueText )
84+
void QgsSpinBox::setClearValueMode( QgsSpinBox::ClearValueMode mode, QString specialValueText )
8585
{
8686
mClearValueMode = mode;
8787
mCustomClearValue = 0;
@@ -95,7 +95,7 @@ void QgsSpinBox::setClearValueMode(QgsSpinBox::ClearValueMode mode, QString spec
9595
}
9696
}
9797

98-
int QgsSpinBox::clearValue()
98+
int QgsSpinBox::clearValue() const
9999
{
100100
if ( mClearValueMode == MinimumValue )
101101
return minimum() ;
@@ -110,6 +110,15 @@ int QgsSpinBox::frameWidth() const
110110
return style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
111111
}
112112

113+
bool QgsSpinBox::shouldShowClearForValue( const int value ) const
114+
{
115+
if ( !mShowClearButton || !isEnabled() )
116+
{
117+
return false;
118+
}
119+
return value != clearValue();
120+
}
121+
113122
void QgsSpinBox::resizeEvent( QResizeEvent * event )
114123
{
115124
QSpinBox::resizeEvent( event );

‎src/gui/editorwidgets/qgsspinbox.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
5959
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );
6060

6161
//! returns the value used when clear() is called.
62-
int clearValue();
62+
int clearValue() const;
6363

6464
protected:
6565
virtual void resizeEvent( QResizeEvent* event );
@@ -70,6 +70,7 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
7070

7171
private:
7272
int frameWidth() const;
73+
bool shouldShowClearForValue( const int value ) const;
7374

7475
bool mShowClearButton;
7576
ClearValueMode mClearValueMode;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ QgsEllipseSymbolLayerV2Widget::QgsEllipseSymbolLayerV2Widget( const QgsVectorLay
3939
btnChangeColorBorder->setShowNoColor( true );
4040
btnChangeColorBorder->setNoColorString( tr( "Transparent border" ) );
4141

42+
spinOffsetX->setClearValue( 0.0 );
43+
spinOffsetY->setClearValue( 0.0 );
44+
mRotationSpinBox->setClearValue( 0.0 );
45+
4246
QStringList names;
4347
names << "circle" << "rectangle" << "cross" << "triangle";
4448
QSize iconSize = mShapeListWidget->iconSize();

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ QgsSimpleLineSymbolLayerV2Widget::QgsSimpleLineSymbolLayerV2Widget( const QgsVec
8383
btnChangeColor->setColorDialogTitle( tr( "Select line color" ) );
8484
btnChangeColor->setContext( "symbology" );
8585

86+
spinOffset->setClearValue( 0.0 );
87+
8688
if ( vl && vl->geometryType() != QGis::Polygon )
8789
{
8890
//draw inside polygon checkbox only makes sense for polygon layers
@@ -335,6 +337,9 @@ QgsSimpleMarkerSymbolLayerV2Widget::QgsSimpleMarkerSymbolLayerV2Widget( const Qg
335337
btnChangeColorBorder->setShowNoColor( true );
336338
btnChangeColorBorder->setNoColorString( tr( "Transparent border" ) );
337339

340+
spinOffsetX->setClearValue( 0.0 );
341+
spinOffsetY->setClearValue( 0.0 );
342+
338343
QSize size = lstNames->iconSize();
339344
QStringList names;
340345
names << "circle" << "rectangle" << "diamond" << "pentagon" << "cross" << "cross2" << "triangle"
@@ -605,6 +610,9 @@ QgsSimpleFillSymbolLayerV2Widget::QgsSimpleFillSymbolLayerV2Widget( const QgsVec
605610
btnChangeBorderColor->setShowNoColor( true );
606611
btnChangeBorderColor->setNoColorString( tr( "Transparent border" ) );
607612

613+
spinOffsetX->setClearValue( 0.0 );
614+
spinOffsetY->setClearValue( 0.0 );
615+
608616
connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
609617
connect( cboFillStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setBrushStyle() ) );
610618
connect( btnChangeBorderColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setBorderColor( const QColor& ) ) );
@@ -779,6 +787,9 @@ QgsGradientFillSymbolLayerV2Widget::QgsGradientFillSymbolLayerV2Widget( const Qg
779787
btnChangeColor2->setShowNoColor( true );
780788
btnChangeColor2->setNoColorString( tr( "Transparent" ) );
781789

790+
spinOffsetX->setClearValue( 0.0 );
791+
spinOffsetY->setClearValue( 0.0 );
792+
782793
connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
783794
connect( btnChangeColor2, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor2( const QColor& ) ) );
784795
connect( cboGradientColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
@@ -1162,6 +1173,9 @@ QgsShapeburstFillSymbolLayerV2Widget::QgsShapeburstFillSymbolLayerV2Widget( cons
11621173
btnChangeColor2->setShowNoColor( true );
11631174
btnChangeColor2->setNoColorString( tr( "Transparent" ) );
11641175

1176+
spinOffsetX->setClearValue( 0.0 );
1177+
spinOffsetY->setClearValue( 0.0 );
1178+
11651179
cboGradientColorRamp->setShowGradientOnly( true );
11661180
cboGradientColorRamp->populate( QgsStyleV2::defaultStyle() );
11671181

@@ -1448,6 +1462,8 @@ QgsMarkerLineSymbolLayerV2Widget::QgsMarkerLineSymbolLayerV2Widget( const QgsVec
14481462
mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
14491463
mOffsetAlongLineUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
14501464

1465+
spinOffset->setClearValue( 0.0 );
1466+
14511467
connect( spinInterval, SIGNAL( valueChanged( double ) ), this, SLOT( setInterval( double ) ) );
14521468
connect( mSpinOffsetAlongLine, SIGNAL( valueChanged( double ) ), this, SLOT( setOffsetAlongLine( double ) ) );
14531469
connect( chkRotateMarker, SIGNAL( clicked() ), this, SLOT( setRotate() ) );
@@ -1644,6 +1660,9 @@ QgsSvgMarkerSymbolLayerV2Widget::QgsSvgMarkerSymbolLayerV2Widget( const QgsVecto
16441660
mChangeBorderColorButton->setColorDialogTitle( tr( "Select border color" ) );
16451661
mChangeColorButton->setContext( "symbology" );
16461662

1663+
spinOffsetX->setClearValue( 0.0 );
1664+
spinOffsetY->setClearValue( 0.0 );
1665+
16471666
populateList();
16481667

16491668
connect( viewImages->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setName( const QModelIndex& ) ) );
@@ -2735,6 +2754,9 @@ QgsFontMarkerSymbolLayerV2Widget::QgsFontMarkerSymbolLayerV2Widget( const QgsVec
27352754
btnColor->setColorDialogTitle( tr( "Select symbol color" ) );
27362755
btnColor->setContext( "symbology" );
27372756

2757+
spinOffsetX->setClearValue( 0.0 );
2758+
spinOffsetY->setClearValue( 0.0 );
2759+
27382760
connect( cboFont, SIGNAL( currentFontChanged( const QFont & ) ), this, SLOT( setFontFamily( const QFont& ) ) );
27392761
connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize( double ) ) );
27402762
connect( btnColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
@@ -2925,6 +2947,9 @@ QgsRasterFillSymbolLayerWidget::QgsRasterFillSymbolLayerWidget( const QgsVectorL
29252947
mWidthUnitWidget->setUnits( QStringList() << tr( "Pixels" ) << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
29262948
mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
29272949

2950+
mSpinOffsetX->setClearValue( 0.0 );
2951+
mSpinOffsetY->setClearValue( 0.0 );
2952+
29282953
connect( cboCoordinateMode, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setCoordinateMode( int ) ) );
29292954
connect( mSpinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
29302955
connect( mSpinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );

‎src/ui/symbollayer/widget_ellipse.ui

Lines changed: 12 additions & 4 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>416</width>
9+
<width>418</width>
1010
<height>436</height>
1111
</rect>
1212
</property>
@@ -24,7 +24,10 @@
2424
</widget>
2525
</item>
2626
<item row="4" column="1">
27-
<widget class="QDoubleSpinBox" name="mRotationSpinBox">
27+
<widget class="QgsDoubleSpinBox" name="mRotationSpinBox">
28+
<property name="suffix">
29+
<string> °</string>
30+
</property>
2831
<property name="minimum">
2932
<double>-360.000000000000000</double>
3033
</property>
@@ -319,7 +322,7 @@
319322
<item row="6" column="1">
320323
<layout class="QHBoxLayout" name="horizontalLayout_5">
321324
<item>
322-
<widget class="QDoubleSpinBox" name="spinOffsetX">
325+
<widget class="QgsDoubleSpinBox" name="spinOffsetX">
323326
<property name="sizePolicy">
324327
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
325328
<horstretch>1</horstretch>
@@ -338,7 +341,7 @@
338341
</widget>
339342
</item>
340343
<item>
341-
<widget class="QDoubleSpinBox" name="spinOffsetY">
344+
<widget class="QgsDoubleSpinBox" name="spinOffsetY">
342345
<property name="sizePolicy">
343346
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
344347
<horstretch>1</horstretch>
@@ -430,6 +433,11 @@
430433
<extends>QToolButton</extends>
431434
<header>qgscolorbuttonv2.h</header>
432435
</customwidget>
436+
<customwidget>
437+
<class>QgsDoubleSpinBox</class>
438+
<extends>QDoubleSpinBox</extends>
439+
<header>qgsdoublespinbox.h</header>
440+
</customwidget>
433441
<customwidget>
434442
<class>QgsUnitSelectionWidget</class>
435443
<extends>QWidget</extends>

‎src/ui/symbollayer/widget_fontmarker.ui

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@
9696
</widget>
9797
</item>
9898
<item row="3" column="1">
99-
<widget class="QDoubleSpinBox" name="spinAngle">
99+
<widget class="QgsDoubleSpinBox" name="spinAngle">
100100
<property name="suffix">
101-
<string>°</string>
101+
<string> °</string>
102102
</property>
103103
<property name="decimals">
104-
<number>1</number>
104+
<number>2</number>
105105
</property>
106106
<property name="maximum">
107107
<double>360.000000000000000</double>
@@ -121,7 +121,7 @@
121121
<item row="4" column="1">
122122
<layout class="QHBoxLayout" name="horizontalLayout">
123123
<item>
124-
<widget class="QDoubleSpinBox" name="spinOffsetX">
124+
<widget class="QgsDoubleSpinBox" name="spinOffsetX">
125125
<property name="sizePolicy">
126126
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
127127
<horstretch>1</horstretch>
@@ -143,7 +143,7 @@
143143
</widget>
144144
</item>
145145
<item>
146-
<widget class="QDoubleSpinBox" name="spinOffsetY">
146+
<widget class="QgsDoubleSpinBox" name="spinOffsetY">
147147
<property name="sizePolicy">
148148
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
149149
<horstretch>1</horstretch>
@@ -242,6 +242,11 @@
242242
<extends>QToolButton</extends>
243243
<header>qgscolorbuttonv2.h</header>
244244
</customwidget>
245+
<customwidget>
246+
<class>QgsDoubleSpinBox</class>
247+
<extends>QDoubleSpinBox</extends>
248+
<header>qgsdoublespinbox.h</header>
249+
</customwidget>
245250
<customwidget>
246251
<class>QgsUnitSelectionWidget</class>
247252
<extends>QWidget</extends>

‎src/ui/symbollayer/widget_gradientfill.ui

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350
</widget>
351351
</item>
352352
<item row="7" column="1">
353-
<widget class="QDoubleSpinBox" name="mSpinAngle">
353+
<widget class="QgsDoubleSpinBox" name="mSpinAngle">
354354
<property name="suffix">
355355
<string> °</string>
356356
</property>
@@ -372,7 +372,7 @@
372372
<item row="8" column="1">
373373
<layout class="QHBoxLayout" name="horizontalLayout">
374374
<item>
375-
<widget class="QDoubleSpinBox" name="spinOffsetX">
375+
<widget class="QgsDoubleSpinBox" name="spinOffsetX">
376376
<property name="sizePolicy">
377377
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
378378
<horstretch>1</horstretch>
@@ -394,7 +394,7 @@
394394
</widget>
395395
</item>
396396
<item>
397-
<widget class="QDoubleSpinBox" name="spinOffsetY">
397+
<widget class="QgsDoubleSpinBox" name="spinOffsetY">
398398
<property name="sizePolicy">
399399
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
400400
<horstretch>1</horstretch>
@@ -465,6 +465,11 @@
465465
<extends>QComboBox</extends>
466466
<header>qgscolorrampcombobox.h</header>
467467
</customwidget>
468+
<customwidget>
469+
<class>QgsDoubleSpinBox</class>
470+
<extends>QDoubleSpinBox</extends>
471+
<header>qgsdoublespinbox.h</header>
472+
</customwidget>
468473
</customwidgets>
469474
<resources/>
470475
<connections>

0 commit comments

Comments
 (0)
Please sign in to comment.