Skip to content
Permalink
Browse files
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.
  • 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.
@@ -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 );
@@ -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 );
@@ -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()
@@ -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;
@@ -95,7 +95,7 @@ void QgsDoubleSpinBox::setClearValueMode(QgsDoubleSpinBox::ClearValueMode mode,
}
}

double QgsDoubleSpinBox::clearValue()
double QgsDoubleSpinBox::clearValue() const
{
if ( mClearValueMode == MinimumValue )
return minimum() ;
@@ -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 );
@@ -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 );
@@ -70,6 +70,7 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox

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

bool mShowClearButton;
ClearValueMode mClearValueMode;
@@ -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()
@@ -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;
@@ -95,7 +95,7 @@ void QgsSpinBox::setClearValueMode(QgsSpinBox::ClearValueMode mode, QString spec
}
}

int QgsSpinBox::clearValue()
int QgsSpinBox::clearValue() const
{
if ( mClearValueMode == MinimumValue )
return minimum() ;
@@ -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 );
@@ -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 );
@@ -70,6 +70,7 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox

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

bool mShowClearButton;
ClearValueMode mClearValueMode;
@@ -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();
@@ -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
@@ -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"
@@ -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& ) ) );
@@ -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() ) );
@@ -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() );

@@ -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() ) );
@@ -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& ) ) );
@@ -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& ) ) );
@@ -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() ) );
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>416</width>
<width>418</width>
<height>436</height>
</rect>
</property>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>

0 comments on commit 0fa40a6

Please sign in to comment.