Skip to content

Commit

Permalink
Change some spin boxes in symbology to QgsDoubleSpinBox
Browse files Browse the repository at this point in the history
Adds the handy 'clear' buttons to these spin boxes, such as
offsets and rotation.
Also standardises the display of some widgets in symbology.
  • Loading branch information
nyalldawson committed Dec 4, 2014
1 parent 1a4b8bb commit 0fa40a6
Show file tree
Hide file tree
Showing 21 changed files with 173 additions and 93 deletions.
2 changes: 1 addition & 1 deletion python/gui/editorwidgets/qgsdoublespinbox.sip
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class QgsDoubleSpinBox : QDoubleSpinBox
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );

//! returns the value used when clear() is called.
double clearValue();
double clearValue() const;

protected:
virtual void resizeEvent( QResizeEvent* event );
Expand Down
2 changes: 1 addition & 1 deletion python/gui/editorwidgets/qgsspinbox.sip
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class QgsSpinBox : QSpinBox
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );

//! returns the value used when clear() is called.
int clearValue();
int clearValue() const;

protected:
virtual void resizeEvent( QResizeEvent* event );
Expand Down
19 changes: 14 additions & 5 deletions src/gui/editorwidgets/qgsdoublespinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ QgsDoubleSpinBox::QgsDoubleSpinBox( QWidget *parent )
void QgsDoubleSpinBox::setShowClearButton( const bool showClearButton )
{
mShowClearButton = showClearButton;
mClearButton->setVisible( mShowClearButton && isEnabled() && value() != minimum() );
mClearButton->setVisible( shouldShowClearForValue( value() ) );
}

void QgsDoubleSpinBox::changeEvent( QEvent *event )
{
QDoubleSpinBox::changeEvent( event );
mClearButton->setVisible( mShowClearButton && isEnabled() && value() != minimum() );
mClearButton->setVisible( shouldShowClearForValue( value() ) );
}

void QgsDoubleSpinBox::changed( const double& value )
{
mClearButton->setVisible( mShowClearButton && isEnabled() && value != minimum() );
mClearButton->setVisible( shouldShowClearForValue( value ) );
}

void QgsDoubleSpinBox::clear()
Expand All @@ -81,7 +81,7 @@ void QgsDoubleSpinBox::setClearValue( double customValue , QString specialValueT
}
}

void QgsDoubleSpinBox::setClearValueMode(QgsDoubleSpinBox::ClearValueMode mode, QString clearValueText )
void QgsDoubleSpinBox::setClearValueMode( QgsDoubleSpinBox::ClearValueMode mode, QString clearValueText )
{
mClearValueMode = mode;
mCustomClearValue = 0;
Expand All @@ -95,7 +95,7 @@ void QgsDoubleSpinBox::setClearValueMode(QgsDoubleSpinBox::ClearValueMode mode,
}
}

double QgsDoubleSpinBox::clearValue()
double QgsDoubleSpinBox::clearValue() const
{
if ( mClearValueMode == MinimumValue )
return minimum() ;
Expand All @@ -110,6 +110,15 @@ int QgsDoubleSpinBox::frameWidth() const
return style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
}

bool QgsDoubleSpinBox::shouldShowClearForValue( const double value ) const
{
if ( !mShowClearButton || !isEnabled() )
{
return false;
}
return value != clearValue();
}

void QgsDoubleSpinBox::resizeEvent( QResizeEvent * event )
{
QDoubleSpinBox::resizeEvent( event );
Expand Down
3 changes: 2 additions & 1 deletion src/gui/editorwidgets/qgsdoublespinbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );

//! returns the value used when clear() is called.
double clearValue();
double clearValue() const;

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

private:
int frameWidth() const;
bool shouldShowClearForValue( const double value ) const;

bool mShowClearButton;
ClearValueMode mClearValueMode;
Expand Down
19 changes: 14 additions & 5 deletions src/gui/editorwidgets/qgsspinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ QgsSpinBox::QgsSpinBox( QWidget *parent )
void QgsSpinBox::setShowClearButton( const bool showClearButton )
{
mShowClearButton = showClearButton;
mClearButton->setVisible( mShowClearButton && isEnabled() && value() != minimum() );
mClearButton->setVisible( shouldShowClearForValue( value() ) );
}

void QgsSpinBox::changeEvent( QEvent *event )
{
QSpinBox::changeEvent( event );
mClearButton->setVisible( mShowClearButton && isEnabled() && value() != minimum() );
mClearButton->setVisible( shouldShowClearForValue( value() ) );
}

void QgsSpinBox::changed( const int& value )
{
mClearButton->setVisible( mShowClearButton && isEnabled() && value != minimum() );
mClearButton->setVisible( shouldShowClearForValue( value ) );
}

void QgsSpinBox::clear()
Expand All @@ -81,7 +81,7 @@ void QgsSpinBox::setClearValue( int customValue, QString specialValueText )
}
}

void QgsSpinBox::setClearValueMode(QgsSpinBox::ClearValueMode mode, QString specialValueText )
void QgsSpinBox::setClearValueMode( QgsSpinBox::ClearValueMode mode, QString specialValueText )
{
mClearValueMode = mode;
mCustomClearValue = 0;
Expand All @@ -95,7 +95,7 @@ void QgsSpinBox::setClearValueMode(QgsSpinBox::ClearValueMode mode, QString spec
}
}

int QgsSpinBox::clearValue()
int QgsSpinBox::clearValue() const
{
if ( mClearValueMode == MinimumValue )
return minimum() ;
Expand All @@ -110,6 +110,15 @@ int QgsSpinBox::frameWidth() const
return style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
}

bool QgsSpinBox::shouldShowClearForValue( const int value ) const
{
if ( !mShowClearButton || !isEnabled() )
{
return false;
}
return value != clearValue();
}

void QgsSpinBox::resizeEvent( QResizeEvent * event )
{
QSpinBox::resizeEvent( event );
Expand Down
3 changes: 2 additions & 1 deletion src/gui/editorwidgets/qgsspinbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );

//! returns the value used when clear() is called.
int clearValue();
int clearValue() const;

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

private:
int frameWidth() const;
bool shouldShowClearForValue( const int value ) const;

bool mShowClearButton;
ClearValueMode mClearValueMode;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ QgsEllipseSymbolLayerV2Widget::QgsEllipseSymbolLayerV2Widget( const QgsVectorLay
btnChangeColorBorder->setShowNoColor( true );
btnChangeColorBorder->setNoColorString( tr( "Transparent border" ) );

spinOffsetX->setClearValue( 0.0 );
spinOffsetY->setClearValue( 0.0 );
mRotationSpinBox->setClearValue( 0.0 );

QStringList names;
names << "circle" << "rectangle" << "cross" << "triangle";
QSize iconSize = mShapeListWidget->iconSize();
Expand Down
25 changes: 25 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ QgsSimpleLineSymbolLayerV2Widget::QgsSimpleLineSymbolLayerV2Widget( const QgsVec
btnChangeColor->setColorDialogTitle( tr( "Select line color" ) );
btnChangeColor->setContext( "symbology" );

spinOffset->setClearValue( 0.0 );

if ( vl && vl->geometryType() != QGis::Polygon )
{
//draw inside polygon checkbox only makes sense for polygon layers
Expand Down Expand Up @@ -335,6 +337,9 @@ QgsSimpleMarkerSymbolLayerV2Widget::QgsSimpleMarkerSymbolLayerV2Widget( const Qg
btnChangeColorBorder->setShowNoColor( true );
btnChangeColorBorder->setNoColorString( tr( "Transparent border" ) );

spinOffsetX->setClearValue( 0.0 );
spinOffsetY->setClearValue( 0.0 );

QSize size = lstNames->iconSize();
QStringList names;
names << "circle" << "rectangle" << "diamond" << "pentagon" << "cross" << "cross2" << "triangle"
Expand Down Expand Up @@ -605,6 +610,9 @@ QgsSimpleFillSymbolLayerV2Widget::QgsSimpleFillSymbolLayerV2Widget( const QgsVec
btnChangeBorderColor->setShowNoColor( true );
btnChangeBorderColor->setNoColorString( tr( "Transparent border" ) );

spinOffsetX->setClearValue( 0.0 );
spinOffsetY->setClearValue( 0.0 );

connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
connect( cboFillStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setBrushStyle() ) );
connect( btnChangeBorderColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setBorderColor( const QColor& ) ) );
Expand Down Expand Up @@ -779,6 +787,9 @@ QgsGradientFillSymbolLayerV2Widget::QgsGradientFillSymbolLayerV2Widget( const Qg
btnChangeColor2->setShowNoColor( true );
btnChangeColor2->setNoColorString( tr( "Transparent" ) );

spinOffsetX->setClearValue( 0.0 );
spinOffsetY->setClearValue( 0.0 );

connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
connect( btnChangeColor2, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor2( const QColor& ) ) );
connect( cboGradientColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
Expand Down Expand Up @@ -1162,6 +1173,9 @@ QgsShapeburstFillSymbolLayerV2Widget::QgsShapeburstFillSymbolLayerV2Widget( cons
btnChangeColor2->setShowNoColor( true );
btnChangeColor2->setNoColorString( tr( "Transparent" ) );

spinOffsetX->setClearValue( 0.0 );
spinOffsetY->setClearValue( 0.0 );

cboGradientColorRamp->setShowGradientOnly( true );
cboGradientColorRamp->populate( QgsStyleV2::defaultStyle() );

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

spinOffset->setClearValue( 0.0 );

connect( spinInterval, SIGNAL( valueChanged( double ) ), this, SLOT( setInterval( double ) ) );
connect( mSpinOffsetAlongLine, SIGNAL( valueChanged( double ) ), this, SLOT( setOffsetAlongLine( double ) ) );
connect( chkRotateMarker, SIGNAL( clicked() ), this, SLOT( setRotate() ) );
Expand Down Expand Up @@ -1644,6 +1660,9 @@ QgsSvgMarkerSymbolLayerV2Widget::QgsSvgMarkerSymbolLayerV2Widget( const QgsVecto
mChangeBorderColorButton->setColorDialogTitle( tr( "Select border color" ) );
mChangeColorButton->setContext( "symbology" );

spinOffsetX->setClearValue( 0.0 );
spinOffsetY->setClearValue( 0.0 );

populateList();

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

spinOffsetX->setClearValue( 0.0 );
spinOffsetY->setClearValue( 0.0 );

connect( cboFont, SIGNAL( currentFontChanged( const QFont & ) ), this, SLOT( setFontFamily( const QFont& ) ) );
connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize( double ) ) );
connect( btnColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
Expand Down Expand Up @@ -2925,6 +2947,9 @@ QgsRasterFillSymbolLayerWidget::QgsRasterFillSymbolLayerWidget( const QgsVectorL
mWidthUnitWidget->setUnits( QStringList() << tr( "Pixels" ) << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );

mSpinOffsetX->setClearValue( 0.0 );
mSpinOffsetY->setClearValue( 0.0 );

connect( cboCoordinateMode, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setCoordinateMode( int ) ) );
connect( mSpinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
connect( mSpinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
Expand Down
16 changes: 12 additions & 4 deletions src/ui/symbollayer/widget_ellipse.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>416</width>
<width>418</width>
<height>436</height>
</rect>
</property>
Expand All @@ -24,7 +24,10 @@
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="mRotationSpinBox">
<widget class="QgsDoubleSpinBox" name="mRotationSpinBox">
<property name="suffix">
<string> °</string>
</property>
<property name="minimum">
<double>-360.000000000000000</double>
</property>
Expand Down Expand Up @@ -319,7 +322,7 @@
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QDoubleSpinBox" name="spinOffsetX">
<widget class="QgsDoubleSpinBox" name="spinOffsetX">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
Expand All @@ -338,7 +341,7 @@
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="spinOffsetY">
<widget class="QgsDoubleSpinBox" name="spinOffsetY">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
Expand Down Expand Up @@ -430,6 +433,11 @@
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
</customwidget>
<customwidget>
<class>QgsDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>qgsdoublespinbox.h</header>
</customwidget>
<customwidget>
<class>QgsUnitSelectionWidget</class>
<extends>QWidget</extends>
Expand Down
15 changes: 10 additions & 5 deletions src/ui/symbollayer/widget_fontmarker.ui
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="spinAngle">
<widget class="QgsDoubleSpinBox" name="spinAngle">
<property name="suffix">
<string>°</string>
<string> °</string>
</property>
<property name="decimals">
<number>1</number>
<number>2</number>
</property>
<property name="maximum">
<double>360.000000000000000</double>
Expand All @@ -121,7 +121,7 @@
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QDoubleSpinBox" name="spinOffsetX">
<widget class="QgsDoubleSpinBox" name="spinOffsetX">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
Expand All @@ -143,7 +143,7 @@
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="spinOffsetY">
<widget class="QgsDoubleSpinBox" name="spinOffsetY">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
Expand Down Expand Up @@ -242,6 +242,11 @@
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
</customwidget>
<customwidget>
<class>QgsDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>qgsdoublespinbox.h</header>
</customwidget>
<customwidget>
<class>QgsUnitSelectionWidget</class>
<extends>QWidget</extends>
Expand Down
11 changes: 8 additions & 3 deletions src/ui/symbollayer/widget_gradientfill.ui
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
</widget>
</item>
<item row="7" column="1">
<widget class="QDoubleSpinBox" name="mSpinAngle">
<widget class="QgsDoubleSpinBox" name="mSpinAngle">
<property name="suffix">
<string> °</string>
</property>
Expand All @@ -372,7 +372,7 @@
<item row="8" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QDoubleSpinBox" name="spinOffsetX">
<widget class="QgsDoubleSpinBox" name="spinOffsetX">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
Expand All @@ -394,7 +394,7 @@
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="spinOffsetY">
<widget class="QgsDoubleSpinBox" name="spinOffsetY">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
Expand Down Expand Up @@ -465,6 +465,11 @@
<extends>QComboBox</extends>
<header>qgscolorrampcombobox.h</header>
</customwidget>
<customwidget>
<class>QgsDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>qgsdoublespinbox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
Expand Down
Loading

0 comments on commit 0fa40a6

Please sign in to comment.