Skip to content

Commit

Permalink
improve GUI consistency & UX for data-defined style
Browse files Browse the repository at this point in the history
data defined buttons added to the gui
fixes #9881
  • Loading branch information
vmora authored and nyalldawson committed Jan 21, 2015
1 parent ecb93b1 commit 6fb347d
Show file tree
Hide file tree
Showing 22 changed files with 2,268 additions and 1,863 deletions.
8 changes: 8 additions & 0 deletions python/core/qgsdatadefined.sip
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class QgsDataDefined
const QString& expr = QString(),
const QString& field = QString() );

/**
* Construct a new data defined object, analyse the expression to determine
* if it's a simple field
*
* @param expression can be null
*/
QgsDataDefined( const QgsExpression * expression );

~QgsDataDefined();

/**Returns whether the data defined container is set to all the default
Expand Down
9 changes: 0 additions & 9 deletions python/gui/symbology-ng/qgssymbollayerv2widget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class QgsSimpleLineSymbolLayerV2Widget : QgsSymbolLayerV2Widget
void on_mPenWidthUnitWidget_changed();
void on_mOffsetUnitWidget_changed();
void on_mDashPatternUnitWidget_changed();
void on_mDataDefinedPropertiesButton_clicked();
void on_mDrawInsideCheckBox_stateChanged( int state );

protected:
Expand Down Expand Up @@ -77,7 +76,6 @@ class QgsSimpleMarkerSymbolLayerV2Widget : QgsSymbolLayerV2Widget
void on_mSizeUnitWidget_changed();
void on_mOffsetUnitWidget_changed();
void on_mOutlineWidthUnitWidget_changed();
void on_mDataDefinedPropertiesButton_clicked();
void on_mOutlineStyleComboBox_currentIndexChanged( int index );
void on_mOutlineWidthSpinBox_valueChanged( double d );
void on_mHorizontalAnchorComboBox_currentIndexChanged( int index );
Expand Down Expand Up @@ -110,7 +108,6 @@ class QgsSimpleFillSymbolLayerV2Widget : QgsSymbolLayerV2Widget
void offsetChanged();
void on_mBorderWidthUnitWidget_changed();
void on_mOffsetUnitWidget_changed();
void on_mDataDefinedPropertiesButton_clicked();
};


Expand Down Expand Up @@ -141,7 +138,6 @@ class QgsGradientFillSymbolLayerV2Widget : QgsSymbolLayerV2Widget
void offsetChanged();
void referencePointChanged();
void on_mOffsetUnitWidget_changed();
void on_mDataDefinedPropertiesButton_clicked();
void colorModeChanged();
void on_mSpinAngle_valueChanged( double value );
};
Expand Down Expand Up @@ -174,7 +170,6 @@ class QgsShapeburstFillSymbolLayerV2Widget : QgsSymbolLayerV2Widget
void on_mButtonEditRamp_clicked();
void offsetChanged();
void on_mOffsetUnitWidget_changed();
void on_mDataDefinedPropertiesButton_clicked();
void on_mIgnoreRingsCheckBox_stateChanged( int state );
};

Expand Down Expand Up @@ -204,8 +199,6 @@ class QgsMarkerLineSymbolLayerV2Widget : QgsSymbolLayerV2Widget
void on_mIntervalUnitWidget_changed();
void on_mOffsetUnitWidget_changed();
void on_mOffsetAlongLineUnitWidget_changed();
void on_mDataDefinedPropertiesButton_clicked();

};


Expand Down Expand Up @@ -241,11 +234,9 @@ class QgsSvgMarkerSymbolLayerV2Widget : QgsSymbolLayerV2Widget
void on_mSizeUnitWidget_changed();
void on_mBorderWidthUnitWidget_changed();
void on_mOffsetUnitWidget_changed();
void on_mDataDefinedPropertiesButton_clicked();
void on_mHorizontalAnchorComboBox_currentIndexChanged( int index );
void on_mVerticalAnchorComboBox_currentIndexChanged( int index );


protected:

void populateList();
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsdatadefined.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ QgsDataDefined::QgsDataDefined( bool active,
mExpressionPrepared = false;
}

QgsDataDefined::QgsDataDefined( const QgsExpression * expression )
: mActive( bool( expression ) )
, mUseExpression( expression && expression->rootNode() && !dynamic_cast<const QgsExpression::NodeColumnRef*>( expression->rootNode() ) )
, mExpressionString( mUseExpression ? expression->dump() : "" )
, mField( !mUseExpression ? ( expression ? expression->dump() : "" ) : "" )
{
mExpression = 0;
mExpressionPrepared = false;
}

QgsDataDefined::~QgsDataDefined()
{
mExpressionParams.clear();
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsdatadefined.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ class CORE_EXPORT QgsDataDefined
const QString& expr = QString(),
const QString& field = QString() );

/**
* Construct a new data defined object, analyse the expression to determine
* if it's a simple field
*
* @param expression can be null
*/
explicit QgsDataDefined( const QgsExpression * expression );

~QgsDataDefined();

/**Returns whether the data defined container is set to all the default
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsdatadefinedbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl,
fieldType = tr( "string" );
break;
case QVariant::Int:
fieldMatch = mDataTypes.testFlag( Int );
fieldMatch = mDataTypes.testFlag( Int ) || mDataTypes.testFlag( Double );
fieldType = tr( "integer" );
break;
case QVariant::Double:
Expand Down
60 changes: 13 additions & 47 deletions src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
blockComboSignals( false );

registerDataDefinedButton( mSymbolWidthDDBtn, "width", QgsDataDefinedButton::Double, "" );
registerDataDefinedButton( mSymbolHeightDDBtn, "height", QgsDataDefinedButton::Double, "" );
registerDataDefinedButton( mRotationDDBtn, "rotation", QgsDataDefinedButton::Double, "" );
registerDataDefinedButton( mOutlineWidthDDBtn, "outline_width", QgsDataDefinedButton::Double, "" );
registerDataDefinedButton( mFillColorDDBtn, "fill_color", QgsDataDefinedButton::String, "'red,green,blue,alpha' e.g. '255,0,0,255'" );
registerDataDefinedButton( mBorderColorDDBtn, "outline_color", QgsDataDefinedButton::String, "'red,green,blue,alpha' e.g. '255,0,0,255'" );
registerDataDefinedButton( mOutlineStyleDDBtn, "outline_style", QgsDataDefinedButton::String, "'no'|'solid'|'dash'|'dot'|'dash dot'|'dash dot dot'" );
registerDataDefinedButton( mShapeDDBtn, "symbol_name", QgsDataDefinedButton::String, "'circle', 'rectangle', 'cross', 'triangle'" );
registerDataDefinedButton( mOffsetDDBtn, "offset", QgsDataDefinedButton::String, "'x,y' e.g. '2,3.5'" );
registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, "'left', 'center' or 'right'" );
registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, "'top', 'center' or 'bottom'" );

}

QgsSymbolLayerV2* QgsEllipseSymbolLayerV2Widget::symbolLayer()
Expand Down Expand Up @@ -273,53 +286,6 @@ void QgsEllipseSymbolLayerV2Widget::on_mVerticalAnchorComboBox_currentIndexChang
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked()
{
if ( !mLayer )
{
return;
}

QList< QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry > dataDefinedProperties;
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "width", tr( "Symbol width" ), mLayer->dataDefinedPropertyString( "width" ),
QgsDataDefinedSymbolDialog::doubleHelpText() );
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "height", tr( "Symbol height" ), mLayer->dataDefinedPropertyString( "height" ),
QgsDataDefinedSymbolDialog::doubleHelpText() );
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "rotation", tr( "Rotation" ), mLayer->dataDefinedPropertyString( "rotation" ),
QgsDataDefinedSymbolDialog::doubleHelpText() );
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "outline_width", tr( "Outline width" ), mLayer->dataDefinedPropertyString( "outline_width" ),
QgsDataDefinedSymbolDialog::doubleHelpText() );
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "fill_color", tr( "Fill color" ), mLayer->dataDefinedPropertyString( "fill_color" ),
QgsDataDefinedSymbolDialog::colorHelpText() );
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "outline_color", tr( "Border color" ), mLayer->dataDefinedPropertyString( "outline_color" ),
QgsDataDefinedSymbolDialog::colorHelpText() );
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "symbol_name", tr( "Symbol name" ), mLayer->dataDefinedPropertyString( "symbol_name" ),
"'circle'|'rectangle'|'cross'|'triangle'" );
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "offset", tr( "Offset" ), mLayer->dataDefinedPropertyString( "offset" ),
QgsDataDefinedSymbolDialog::offsetHelpText() );
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "horizontal_anchor_point", tr( "Horizontal anchor point" ), mLayer->dataDefinedPropertyString( "horizontal_anchor_point" ),
QgsDataDefinedSymbolDialog::horizontalAnchorHelpText() );
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "vertical_anchor_point", tr( "Vertical anchor point" ), mLayer->dataDefinedPropertyString( "vertical_anchor_point" ),
QgsDataDefinedSymbolDialog::verticalAnchorHelpText() );
QgsDataDefinedSymbolDialog d( dataDefinedProperties, mVectorLayer );
if ( d.exec() == QDialog::Accepted )
{
//empty all existing properties first
mLayer->removeDataDefinedProperties();

QMap<QString, QString> properties = d.dataDefinedProperties();
QMap<QString, QString>::const_iterator it = properties.constBegin();
for ( ; it != properties.constEnd(); ++it )
{
if ( !it.value().isEmpty() )
{
mLayer->setDataDefinedProperty( it.key(), it.value() );
}
}
emit changed();
}
}

void QgsEllipseSymbolLayerV2Widget::setOffset()
{
mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
Expand Down
1 change: 0 additions & 1 deletion src/gui/symbology-ng/qgsellipsesymbollayerv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class GUI_EXPORT QgsEllipseSymbolLayerV2Widget: public QgsSymbolLayerV2Widget, p
void on_mOffsetUnitWidget_changed();
void on_mHorizontalAnchorComboBox_currentIndexChanged( int index );
void on_mVerticalAnchorComboBox_currentIndexChanged( int index );
void on_mDataDefinedPropertiesButton_clicked();

void setOffset();
};
Expand Down
Loading

2 comments on commit 6fb347d

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 6fb347d Jan 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vmora , @nyalldawson , wouhou, glad this made it in time for 2.8.

There's something wrong with the symbology panel interface now, it's requiring way too much horizontal spacing, for no apparent reason. The result is that by default part of the symbology interface is chopped away and the user has to use the horizontal scroll bar, which is irritating.

For e.g., the simple line symbology panel:
problem_symbology_scroll

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 6fb347d Jan 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the image above, the size of the third window is roughly that of the default window size; imagine the user being hit by that upon his/her first visit of symbology settings. Ouch.

Please sign in to comment.