356 changes: 272 additions & 84 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* *
***************************************************************************/
#include "qgsellipsesymbollayerv2.h"
#include "qgsexpression.h"
#include "qgsfeature.h"
#include "qgsrendercontext.h"
#include "qgsvectorlayer.h"
Expand All @@ -24,7 +25,9 @@
#include <QDomElement>

QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2(): mSymbolName( "circle" ), mSymbolWidth( 4 ), mSymbolWidthUnit( QgsSymbolV2::MM ), mSymbolHeight( 3 ),
mSymbolHeightUnit( QgsSymbolV2::MM ), mFillColor( Qt::black ), mOutlineColor( Qt::white ), mOutlineWidth( 0 ), mOutlineWidthUnit( QgsSymbolV2::MM )
mSymbolHeightUnit( QgsSymbolV2::MM ), mFillColor( Qt::white ), mOutlineColor( Qt::black ), mOutlineWidth( 0 ), mOutlineWidthUnit( QgsSymbolV2::MM ),
mWidthExpression( 0 ), mHeightExpression( 0 ), mRotationExpression( 0 ), mOutlineWidthExpression( 0 ), mFillColorExpression( 0 ),
mOutlineColorExpression( 0 ), mSymbolNameExpression( 0 )
{
mPen.setColor( mOutlineColor );
mPen.setWidth( 1.0 );
Expand Down Expand Up @@ -91,63 +94,95 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
}

//data defined properties
if ( properties.contains( "height_field" ) )
if ( properties.contains( "width_expression" ) )
{
layer->setHeightField( properties["height_field"] );
layer->setDataDefinedProperty( "width", properties["width_expression"] );
}
if ( properties.contains( "width_field" ) )
if ( properties.contains( "height_expression" ) )
{
layer->setWidthField( properties["width_field"] );
layer->setDataDefinedProperty( "height", properties["height_expression"] );
}
if ( properties.contains( "rotation_field" ) )
if ( properties.contains( "rotation_expression" ) )
{
layer->setRotationField( properties["rotation_field"] );
layer->setDataDefinedProperty( "rotation", properties["rotation_expression"] );
}
if ( properties.contains( "outline_width_field" ) )
if ( properties.contains( "outline_width_expression" ) )
{
layer->setOutlineWidthField( properties["outline_width_field"] );
layer->setDataDefinedProperty( "outline_width", properties[ "outline_width_expression" ] );
}
if ( properties.contains( "fill_color_field" ) )
if ( properties.contains( "fill_color_expression" ) )
{
layer->setFillColorField( properties["fill_color_field"] );
layer->setDataDefinedProperty( "fill_color", properties["fill_color_expression"] );
}
if ( properties.contains( "outline_color_field" ) )
if ( properties.contains( "outline_color_expression" ) )
{
layer->setOutlineColorField( properties["outline_color_field"] );
layer->setDataDefinedProperty( "outline_color", properties["outline_color_expression"] );
}
if ( properties.contains( "symbol_name_field" ) )
if ( properties.contains( "symbol_name_expression" ) )
{
layer->setSymbolNameField( properties["symbol_name_field"] );
layer->setDataDefinedProperty( "symbol_name", properties["symbol_name_expression"] );
}

//compatibility with old project file format
if ( !properties["width_field"].isEmpty() )
{
layer->setDataDefinedProperty( "width", properties["width_field"] );
}
if ( !properties["height_field"].isEmpty() )
{
layer->setDataDefinedProperty( "height", properties["height_field"] );
}
if ( !properties["rotation_field"].isEmpty() )
{
layer->setDataDefinedProperty( "rotation", properties["rotation_field"] );
}
if ( !properties["outline_width_field"].isEmpty() )
{
layer->setDataDefinedProperty( "outline_width", properties[ "outline_width_field" ] );
}
if ( !properties["fill_color_field"].isEmpty() )
{
layer->setDataDefinedProperty( "fill_color", properties["fill_color_field"] );
}
if ( !properties["outline_color_field"].isEmpty() )
{
layer->setDataDefinedProperty( "outline_color", properties["outline_color_field"] );
}
if ( !properties["symbol_name_field"].isEmpty() )
{
layer->setDataDefinedProperty( "symbol_name", properties["symbol_name_field"] );
}

return layer;
}

void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
{
const QgsFeature* f = context.feature();

if ( f )
if ( mOutlineWidthExpression )
{
if ( mOutlineWidthIndex != -1 )
{
double width = f->attribute( mOutlineWidthIndex ).toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit );
mPen.setWidthF( width );
}
if ( mFillColorIndex != -1 )
{
mBrush.setColor( QColor( f->attribute( mFillColorIndex ).toString() ) );
}
if ( mOutlineColorIndex != -1 )
{
mPen.setColor( QColor( f->attribute( mOutlineColorIndex ).toString() ) );
}

if ( mWidthIndex != -1 || mHeightIndex != -1 || mSymbolNameIndex != -1 )
double width = mOutlineWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
width *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit );
mPen.setWidthF( width );
}
if ( mFillColorExpression )
{
QString colorString = mFillColorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
mBrush.setColor( QColor( colorString ) );
}
if ( mOutlineColorExpression )
{
QString colorString = mOutlineColorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
mPen.setColor( QColor( colorString ) );
}
if ( mWidthExpression || mHeightExpression || mSymbolNameExpression )
{
QString symbolName = mSymbolName;
if ( mSymbolNameExpression )
{
QString symbolName = ( mSymbolNameIndex == -1 ) ? mSymbolName : f->attribute( mSymbolNameIndex ).toString();
preparePath( symbolName, context, f );
symbolName = mSymbolNameExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
}
preparePath( symbolName, context, context.feature() );
}

QPainter* p = context.renderContext().painter();
Expand All @@ -158,9 +193,9 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend

//priority for rotation: 1. data defined symbol level, 2. symbol layer rotation (mAngle)
double rotation = 0.0;
if ( f && mRotationIndex != -1 )
if ( mRotationExpression )
{
rotation = f->attribute( mRotationIndex ).toDouble();
rotation = mRotationExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
}
else if ( !doubleNear( mAngle, 0.0 ) )
{
Expand Down Expand Up @@ -193,19 +228,7 @@ void QgsEllipseSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
mPen.setColor( mOutlineColor );
mPen.setWidthF( mOutlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) );
mBrush.setColor( mFillColor );

//resolve data defined attribute indices
const QgsVectorLayer* vlayer = context.layer();
if ( vlayer )
{
mWidthIndex = vlayer->fieldNameIndex( mWidthField );
mHeightIndex = vlayer->fieldNameIndex( mHeightField );
mRotationIndex = vlayer->fieldNameIndex( mRotationField );
mOutlineWidthIndex = vlayer->fieldNameIndex( mOutlineWidthField );
mFillColorIndex = vlayer->fieldNameIndex( mFillColorField );
mOutlineColorIndex = vlayer->fieldNameIndex( mOutlineColorField );
mSymbolNameIndex = vlayer->fieldNameIndex( mSymbolNameField );
}
prepareExpressions( context.layer() );
}

void QgsEllipseSymbolLayerV2::stopRender( QgsSymbolV2RenderContext & )
Expand Down Expand Up @@ -346,13 +369,67 @@ QgsStringMap QgsEllipseSymbolLayerV2::properties() const
map["outline_color"] = QgsSymbolLayerV2Utils::encodeColor( mOutlineColor );
map["outline_color_field"] = mOutlineColorField;
map["symbol_name_field"] = mSymbolNameField;

//data defined properties
if ( mWidthExpression )
{
map["width_expression"] = mWidthExpression->dump();
}
if ( mHeightExpression )
{
map["height_expression"] = mHeightExpression->dump();
}
if ( mRotationExpression )
{
map["rotation_expression"] = mRotationExpression->dump();
}
if ( mOutlineWidthExpression )
{
map["outline_width_expression"] = mOutlineWidthExpression->dump();
}
if ( mFillColorExpression )
{
map["fill_color_expression"] = mFillColorExpression->dump();
}
if ( mOutlineColorExpression )
{
map["outline_color_expression"] = mOutlineColorExpression->dump();
}
if ( mSymbolNameExpression )
{
map["symbol_name_expression"] = mSymbolNameExpression->dump();
}
return map;
}

bool QgsEllipseSymbolLayerV2::hasDataDefinedProperty() const
{
return ( mWidthIndex != -1 || mHeightIndex != -1 || mOutlineWidthIndex != -1
|| mFillColorIndex != -1 || mOutlineColorIndex != -1 );
return ( mWidthExpression || mHeightExpression || mRotationExpression || mOutlineWidthExpression ||
mFillColorExpression || mOutlineColorExpression || mSymbolNameExpression );
}

void QgsEllipseSymbolLayerV2::prepareExpressions( const QgsVectorLayer* vl )
{
if ( !vl )
{
return;
}

const QgsFields& fields = vl->pendingFields();
if ( mWidthExpression )
mWidthExpression->prepare( fields );
if ( mHeightExpression )
mHeightExpression->prepare( fields );
if ( mRotationExpression )
mRotationExpression->prepare( fields );
if ( mOutlineWidthExpression )
mOutlineWidthExpression->prepare( fields );
if ( mFillColorExpression )
mFillColorExpression->prepare( fields );
if ( mOutlineColorExpression )
mOutlineColorExpression->prepare( fields );
if ( mSymbolNameExpression )
mSymbolNameExpression->prepare( fields );
}

void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV2RenderContext& context, const QgsFeature* f )
Expand All @@ -362,32 +439,34 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV

double width = 0;

if ( f && mWidthIndex != -1 ) //1. priority: data defined setting on symbol layer level
if ( mWidthExpression ) //1. priority: data defined setting on symbol layer level
{
width = f->attribute( mWidthIndex ).toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolWidthUnit );
width = mWidthExpression->evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
}
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
{
width = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolWidthUnit );
width = mSize;
}
else //3. priority: global width setting
{
width = mSymbolWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolWidthUnit );
width = mSymbolWidth;
}
width *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolWidthUnit );

double height = 0;
if ( f && mHeightIndex != -1 ) //1. priority: data defined setting on symbol layer level
if ( mHeightExpression ) //1. priority: data defined setting on symbol layer level
{
height = f->attribute( mHeightIndex ).toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolHeightUnit );
height = mHeightExpression->evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
}
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
{
height = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolHeightUnit );
height = mSize;
}
else //3. priority: global height setting
{
height = mSymbolHeight * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolHeightUnit );
height = mSymbolHeight;
}
height *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolHeightUnit );

if ( symbolName == "circle" )
{
Expand Down Expand Up @@ -415,51 +494,160 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV

QSet<QString> QgsEllipseSymbolLayerV2::usedAttributes() const
{
QSet<QString> dataDefinedAttributes;
if ( !mWidthField.isEmpty() )
QSet<QString> attributes;

//add data defined attributes
QStringList columns;
if ( mWidthExpression )
columns.append( mWidthExpression->referencedColumns() );
if ( mHeightExpression )
columns.append( mHeightExpression->referencedColumns() );
if ( mRotationExpression )
columns.append( mRotationExpression->referencedColumns() );
if ( mOutlineWidthExpression )
columns.append( mOutlineWidthExpression->referencedColumns() );
if ( mFillColorExpression )
columns.append( mFillColorExpression->referencedColumns() );
if ( mOutlineColorExpression )
columns.append( mOutlineColorExpression->referencedColumns() );
if ( mSymbolNameExpression )
columns.append( mSymbolNameExpression->referencedColumns() );

QStringList::const_iterator it = columns.constBegin();
for ( ; it != columns.constEnd(); ++it )
{
attributes.insert( *it );
}
return attributes;
}

void QgsEllipseSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit )
{
mSymbolWidthUnit = unit;
mSymbolHeightUnit = unit;
mOutlineWidthUnit = unit;
}

QgsSymbolV2::OutputUnit QgsEllipseSymbolLayerV2::outputUnit() const
{
QgsSymbolV2::OutputUnit unit = mSymbolWidthUnit;
if ( mSymbolHeightUnit != unit || mOutlineWidthUnit != unit )
{
dataDefinedAttributes.insert( mWidthField );
return QgsSymbolV2::Mixed;
}
if ( !mHeightField.isEmpty() )
return unit;
}

const QgsExpression* QgsEllipseSymbolLayerV2::dataDefinedProperty( const QString& property ) const
{
if ( property == "width" )
{
dataDefinedAttributes.insert( mHeightField );
return mWidthExpression;
}
if ( !mRotationField.isEmpty() )
else if ( property == "height" )
{
dataDefinedAttributes.insert( mRotationField );
return mHeightExpression;
}
if ( !mOutlineWidthField.isEmpty() )
else if ( property == "rotation" )
{
dataDefinedAttributes.insert( mOutlineWidthField );
return mRotationExpression;
}
if ( !mFillColorField.isEmpty() )
else if ( property == "outline_width" )
{
dataDefinedAttributes.insert( mFillColorField );
return mOutlineWidthExpression;
}
if ( !mOutlineColorField.isEmpty() )
else if ( property == "fill_color" )
{
dataDefinedAttributes.insert( mOutlineColorField );
return mFillColorExpression;
}
if ( !mSymbolNameField.isEmpty() )
else if ( property == "outline_color" )
{
dataDefinedAttributes.insert( mSymbolNameField );
return mOutlineColorExpression;
}
return dataDefinedAttributes;
else if ( property == "symbol_name" )
{
return mSymbolNameExpression;
}
return 0;
}

void QgsEllipseSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit )
QString QgsEllipseSymbolLayerV2::dataDefinedPropertyString( const QString& property ) const
{
mSymbolWidthUnit = unit;
mSymbolHeightUnit = unit;
mOutlineWidthUnit = unit;
const QgsExpression* ex = dataDefinedProperty( property );
return ( ex ? ex->dump() : QString() );
}

QgsSymbolV2::OutputUnit QgsEllipseSymbolLayerV2::outputUnit() const
void QgsEllipseSymbolLayerV2::setDataDefinedProperty( const QString& property, const QString& expressionString )
{
QgsSymbolV2::OutputUnit unit = mSymbolWidthUnit;
if ( mSymbolHeightUnit != unit || mOutlineWidthUnit != unit )
if ( property == "width" )
{
return QgsSymbolV2::Mixed;
delete mWidthExpression; mWidthExpression = new QgsExpression( expressionString );
}
return unit;
else if ( property == "height" )
{
delete mHeightExpression; mHeightExpression = new QgsExpression( expressionString );
}
else if ( property == "rotation" )
{
delete mRotationExpression; mRotationExpression = new QgsExpression( expressionString );
}
else if ( property == "outline_width" )
{
delete mOutlineWidthExpression; mOutlineWidthExpression = new QgsExpression( expressionString );
}
else if ( property == "fill_color" )
{
delete mFillColorExpression; mFillColorExpression = new QgsExpression( expressionString );
}
else if ( property == "outline_color" )
{
delete mOutlineColorExpression; mOutlineColorExpression = new QgsExpression( expressionString );
}
else if ( property == "symbol_name" )
{
delete mSymbolNameExpression; mSymbolNameExpression = new QgsExpression( expressionString );
}
}

void QgsEllipseSymbolLayerV2::removeDataDefinedProperty( const QString& property )
{
if ( property == "width" )
{
delete mWidthExpression; mWidthExpression = 0;
}
else if ( property == "height" )
{
delete mHeightExpression; mHeightExpression = 0;
}
else if ( property == "rotation" )
{
delete mRotationExpression; mRotationExpression = 0;
}
else if ( property == "outline_width" )
{
delete mOutlineWidthExpression; mOutlineWidthExpression = 0;
}
else if ( property == "fill_color" )
{
delete mFillColorExpression; mFillColorExpression = 0;
}
else if ( property == "outline_color" )
{
delete mOutlineColorExpression; mOutlineColorExpression = 0;
}
else if ( property == "symbol_name" )
{
delete mSymbolNameExpression; mSymbolNameExpression = 0;
}
}

void QgsEllipseSymbolLayerV2::removeDataDefinedProperties()
{
delete mWidthExpression; mWidthExpression = 0;
delete mHeightExpression; mHeightExpression = 0;
delete mRotationExpression; mRotationExpression = 0;
delete mOutlineWidthExpression; mOutlineWidthExpression = 0;
delete mFillColorExpression; mFillColorExpression = 0;
delete mOutlineColorExpression; mOutlineColorExpression = 0;
delete mSymbolNameExpression; mSymbolNameExpression = 0;
}
35 changes: 18 additions & 17 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "qgsmarkersymbollayerv2.h"
#include <QPainterPath>

class QgsExpression;

/**A symbol layer for rendering objects with major and minor axis (e.g. ellipse, rectangle )*/
class CORE_EXPORT QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
{
Expand Down Expand Up @@ -91,6 +93,12 @@ class CORE_EXPORT QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;

const QgsExpression* dataDefinedProperty( const QString& property ) const;
QString dataDefinedPropertyString( const QString& property ) const;
void setDataDefinedProperty( const QString& property, const QString& expressionString );
void removeDataDefinedProperty( const QString& property );
void removeDataDefinedProperties();

private:
QString mSymbolName;
double mSymbolWidth;
Expand All @@ -102,23 +110,6 @@ class CORE_EXPORT QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
double mOutlineWidth;
QgsSymbolV2::OutputUnit mOutlineWidthUnit;

#if 0
/**Take width from attribute (-1 if fixed width)*/
QPair<int, QString> mWidthField;
/**Take height from attribute (-1 if fixed height)*/
QPair<int, QString> mHeightField;
/**Take symbol rotation from attribute (-1 if fixed rotation)*/
QPair<int, QString> mRotationField;
/**Take outline width from attribute (-1 if fixed outline width)*/
QPair<int, QString> mOutlineWidthField;
/**Take fill color from attribute (-1 if fixed fill color)*/
QPair<int, QString> mFillColorField;
/**Take outline color from attribute (-1 if fixed outline color)*/
QPair<int, QString> mOutlineColorField;
/**Take shape name from attribute (-1 if fixed shape type)*/
QPair<int, QString> mSymbolNameField;
#endif //0

//data defined property fields
QString mWidthField;
QString mHeightField;
Expand All @@ -128,6 +119,14 @@ class CORE_EXPORT QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
QString mOutlineColorField;
QString mSymbolNameField;

QgsExpression* mWidthExpression;
QgsExpression* mHeightExpression;
QgsExpression* mRotationExpression;
QgsExpression* mOutlineWidthExpression;
QgsExpression* mFillColorExpression;
QgsExpression* mOutlineColorExpression;
QgsExpression* mSymbolNameExpression;

//field indices for data defined properties
//resolved in startRender method
int mWidthIndex;
Expand All @@ -151,6 +150,8 @@ class CORE_EXPORT QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2

/**True if this symbol layer uses a data defined property*/
bool hasDataDefinedProperty() const;

void prepareExpressions( const QgsVectorLayer* vl );
};

#endif // QGSELLIPSESYMBOLLAYERV2_H
198 changes: 36 additions & 162 deletions src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* *
***************************************************************************/
#include "qgsellipsesymbollayerv2widget.h"
#include "qgsdatadefinedsymboldialog.h"
#include "qgsellipsesymbollayerv2.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"
Expand Down Expand Up @@ -42,7 +43,6 @@ QgsEllipseSymbolLayerV2Widget::QgsEllipseSymbolLayerV2Widget( const QgsVectorLay
}

blockComboSignals( true );
fillDataDefinedComboBoxes();
blockComboSignals( false );
}

Expand Down Expand Up @@ -75,63 +75,6 @@ void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
mSymbolWidthUnitComboBox->setCurrentIndex( mLayer->symbolWidthUnit() );
mOutlineWidthUnitComboBox->setCurrentIndex( mLayer->outlineWidthUnit() );
mSymbolHeightUnitComboBox->setCurrentIndex( mLayer->symbolHeightUnit() );

if ( mLayer->widthField().isEmpty() )
{
mDDSymbolWidthComboBox->setCurrentIndex( 0 );
}
else
{
mDDSymbolWidthComboBox->setCurrentIndex( mDDSymbolWidthComboBox->findText( mLayer->widthField() ) );
}
if ( mLayer->heightField().isEmpty() )
{
mDDSymbolHeightComboBox->setCurrentIndex( 0 );
}
else
{
mDDSymbolHeightComboBox->setCurrentIndex( mDDSymbolHeightComboBox->findText( mLayer->heightField() ) );
}
if ( mLayer->rotationField().isEmpty() )
{
mDDRotationComboBox->setCurrentIndex( 0 );
}
else
{
mDDRotationComboBox->setCurrentIndex( mDDRotationComboBox->findText( mLayer->rotationField() ) );
}
if ( mLayer->outlineWidthField().isEmpty() )
{
mDDOutlineWidthComboBox->setCurrentIndex( 0 );
}
else
{
mDDOutlineWidthComboBox->setCurrentIndex( mDDOutlineWidthComboBox->findText( mLayer->outlineWidthField() ) );
}
if ( mLayer->fillColorField().isEmpty() )
{
mDDFillColorComboBox->setCurrentIndex( 0 );
}
else
{
mDDFillColorComboBox->setCurrentIndex( mDDFillColorComboBox->findText( mLayer->fillColorField() ) );
}
if ( mLayer->outlineColorField().isEmpty() )
{
mDDOutlineColorComboBox->setCurrentIndex( 0 );
}
else
{
mDDOutlineColorComboBox->setCurrentIndex( mDDOutlineColorComboBox->findText( mLayer->outlineColorField() ) );
}
if ( mLayer->symbolNameField().isEmpty() )
{
mDDShapeComboBox->setCurrentIndex( 0 );
}
else
{
mDDShapeComboBox->setCurrentIndex( mDDShapeComboBox->findText( mLayer->symbolNameField() ) );
}
}
blockComboSignals( false );
}
Expand Down Expand Up @@ -218,103 +161,6 @@ void QgsEllipseSymbolLayerV2Widget::on_btnChangeColorFill_clicked()
}
}

void QgsEllipseSymbolLayerV2Widget::fillDataDefinedComboBoxes()
{
mDDSymbolWidthComboBox->clear();
mDDSymbolWidthComboBox->addItem( "", -1 );
mDDSymbolHeightComboBox->clear();
mDDSymbolHeightComboBox->addItem( "", -1 );
mDDRotationComboBox->clear();
mDDRotationComboBox->addItem( "", -1 );
mDDOutlineWidthComboBox->clear();
mDDOutlineWidthComboBox->addItem( "", -1 );
mDDFillColorComboBox->clear();
mDDFillColorComboBox->addItem( "", -1 );
mDDOutlineColorComboBox->clear();
mDDOutlineColorComboBox->addItem( "", -1 );
mDDShapeComboBox->clear();
mDDShapeComboBox->addItem( "", -1 );

if ( mVectorLayer )
{
const QgsFields& fm = mVectorLayer->pendingFields();
for ( int index = 0; index < fm.count(); ++index )
{
QString fieldName = fm[index].name();

mDDSymbolWidthComboBox->addItem( fieldName, index );
mDDSymbolHeightComboBox->addItem( fieldName, index );
mDDRotationComboBox->addItem( fieldName, index );
mDDOutlineWidthComboBox->addItem( fieldName, index );
mDDFillColorComboBox->addItem( fieldName, index );
mDDOutlineColorComboBox->addItem( fieldName, index );
mDDShapeComboBox->addItem( fieldName, index );
}
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDDSymbolWidthComboBox_currentIndexChanged( int idx )
{
if ( mLayer )
{
mLayer->setWidthField( mDDSymbolWidthComboBox->itemText( idx ) );
emit changed();
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDDSymbolHeightComboBox_currentIndexChanged( int idx )
{
if ( mLayer )
{
mLayer->setHeightField( mDDSymbolHeightComboBox->itemText( idx ) );
emit changed();
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDDRotationComboBox_currentIndexChanged( int idx )
{
if ( mLayer )
{
mLayer->setRotationField( mDDRotationComboBox->itemText( idx ) );
emit changed();
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDDOutlineWidthComboBox_currentIndexChanged( int idx )
{
if ( mLayer )
{
mLayer->setOutlineWidthField( mDDOutlineWidthComboBox->itemText( idx ) );
emit changed();
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDDFillColorComboBox_currentIndexChanged( int idx )
{
if ( mLayer )
{
mLayer->setFillColorField( mDDFillColorComboBox->itemText( idx ) );
emit changed();
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDDOutlineColorComboBox_currentIndexChanged( int idx )
{
if ( mLayer )
{
mLayer->setOutlineColorField( mDDOutlineColorComboBox->itemText( idx ) );
emit changed();
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDDShapeComboBox_currentIndexChanged( int idx )
{
if ( mLayer )
{
mLayer->setSymbolNameField( mDDShapeComboBox->itemText( idx ) );
}
}

void QgsEllipseSymbolLayerV2Widget::on_mSymbolWidthUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
Expand All @@ -341,14 +187,42 @@ void QgsEllipseSymbolLayerV2Widget::on_mSymbolHeightUnitComboBox_currentIndexCha

void QgsEllipseSymbolLayerV2Widget::blockComboSignals( bool block )
{
mDDSymbolWidthComboBox->blockSignals( block );
mDDSymbolHeightComboBox->blockSignals( block );
mDDRotationComboBox->blockSignals( block );
mDDOutlineWidthComboBox->blockSignals( block );
mDDFillColorComboBox->blockSignals( block );
mDDOutlineColorComboBox->blockSignals( block );
mDDShapeComboBox->blockSignals( block );
mSymbolWidthUnitComboBox->blockSignals( block );
mOutlineWidthUnitComboBox->blockSignals( block );
mSymbolHeightUnitComboBox->blockSignals( block );
}

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

QMap<QString, QPair< QString, QString> > dataDefinedProperties;
dataDefinedProperties.insert( "width", qMakePair( tr( "Symbol width" ), mLayer->dataDefinedPropertyString( "width" ) ) );
dataDefinedProperties.insert( "height", qMakePair( tr( "Symbol height" ), mLayer->dataDefinedPropertyString( "height" ) ) );
dataDefinedProperties.insert( "rotation", qMakePair( tr( "Rotation" ), mLayer->dataDefinedPropertyString( "rotation" ) ) );
dataDefinedProperties.insert( "outline_width", qMakePair( tr( "Outline width" ), mLayer->dataDefinedPropertyString( "outline_width" ) ) );
dataDefinedProperties.insert( "fill_color", qMakePair( tr( "Fill color" ), mLayer->dataDefinedPropertyString( "fill_color" ) ) );
dataDefinedProperties.insert( "outline_color", qMakePair( tr( "Border color" ), mLayer->dataDefinedPropertyString( "outline_color" ) ) );
dataDefinedProperties.insert( "symbol_name", qMakePair( tr( "Symbol name" ), mLayer->dataDefinedPropertyString( "symbol_name" ) ) );

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();
}
}
12 changes: 2 additions & 10 deletions src/gui/symbology-ng/qgsellipsesymbollayerv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class GUI_EXPORT QgsEllipseSymbolLayerV2Widget: public QgsSymbolLayerV2Widget, p

private:
void blockComboSignals( bool block );
//insert available attributes for data defined symbolisation
void fillDataDefinedComboBoxes();

private slots:
void on_mShapeListWidget_itemSelectionChanged();
Expand All @@ -50,17 +48,11 @@ class GUI_EXPORT QgsEllipseSymbolLayerV2Widget: public QgsSymbolLayerV2Widget, p
void on_btnChangeColorBorder_clicked();
void on_btnChangeColorFill_clicked();

void on_mDDSymbolWidthComboBox_currentIndexChanged( int idx );
void on_mDDSymbolHeightComboBox_currentIndexChanged( int idx );
void on_mDDRotationComboBox_currentIndexChanged( int idx );
void on_mDDOutlineWidthComboBox_currentIndexChanged( int idx );
void on_mDDFillColorComboBox_currentIndexChanged( int idx );
void on_mDDOutlineColorComboBox_currentIndexChanged( int idx );
void on_mDDShapeComboBox_currentIndexChanged( int idx );

void on_mSymbolWidthUnitComboBox_currentIndexChanged( int index );
void on_mOutlineWidthUnitComboBox_currentIndexChanged( int index );
void on_mSymbolHeightUnitComboBox_currentIndexChanged( int index );

void on_mDataDefinedPropertiesButton_clicked();
};

#endif // QGSELLIPSESYMBOLLAYERV2WIDGET_H
509 changes: 215 additions & 294 deletions src/ui/symbollayer/widget_ellipse.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,311 +7,232 @@
<x>0</x>
<y>0</y>
<width>336</width>
<height>357</height>
<height>466</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="margin">
<number>1</number>
</property>
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Settings</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Border color</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButtonV2" name="btnChangeColorFill">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="btnChangeColorBorder">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mSymbolWidthUnitLabel">
<property name="text">
<string>Symbol width unit</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="mOutlineWidthUnitComboBox">
<item>
<property name="text">
<string>Millimeter</string>
</property>
</item>
<item>
<property name="text">
<string>Map unit</string>
</property>
</item>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mOutlineWidthLabel">
<property name="text">
<string>Outline width</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="mOutlineWidthSpinBox">
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QDoubleSpinBox" name="mRotationSpinBox"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="mRotationLabel">
<property name="text">
<string>Rotation</string>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="mWidthSpinBox">
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="mSymbolWidthUnitComboBox">
<item>
<property name="text">
<string>Millimeter</string>
</property>
</item>
<item>
<property name="text">
<string>Map unit</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Fill color</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Border color</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="mOutlineWidthSpinBox">
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="btnChangeColorBorder">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mSymbolWidthUnitLabel">
<property name="text">
<string>Symbol width unit</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mOutlineWidthLabel">
<property name="text">
<string>Outline width</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButtonV2" name="btnChangeColorFill">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QComboBox" name="mSymbolHeightUnitComboBox">
<item>
<property name="text">
<string>Millimeter</string>
</property>
</item>
<item>
<property name="text">
<string>Map unit</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mSymbolWidthLabel">
<property name="text">
<string>Symbol width</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="mRotationLabel">
<property name="text">
<string>Rotation</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<widget class="QListWidget" name="mShapeListWidget">
<property name="dragDropMode">
<enum>QAbstractItemView::NoDragDrop</enum>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="flow">
<enum>QListView::LeftToRight</enum>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="spacing">
<number>4</number>
</property>
<property name="gridSize">
<size>
<width>30</width>
<height>24</height>
</size>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="selectionRectVisible">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="mOutlineWidthUnitLabel">
<property name="text">
<string>Outline width unit</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="mOutlineWidthUnitComboBox">
<item>
<property name="text">
<string>Millimeter</string>
</property>
</item>
<item>
<property name="text">
<string>Map unit</string>
</property>
</item>
</widget>
</item>
<item row="6" column="1">
<widget class="QDoubleSpinBox" name="mRotationSpinBox"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="mSymbolHeightLabel">
<property name="text">
<string>Symbol height</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QDoubleSpinBox" name="mHeightSpinBox">
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="mSymbolHeightUnitLabel">
<property name="text">
<string>Symbol height unit</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="mDataDefinedPropertiesLabel">
<property name="text">
<string>Data defined properties</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mDataDefinedPropertiesButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="mSymbolWidthUnitComboBox">
<item>
<property name="text">
<string>Millimeter</string>
</property>
</item>
<item>
<property name="text">
<string>Map unit</string>
</property>
</item>
</widget>
</item>
<item row="7" column="1">
<widget class="QDoubleSpinBox" name="mHeightSpinBox">
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="mOutlineWidthUnitLabel">
<property name="text">
<string>Outline width unit</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<widget class="QListWidget" name="mShapeListWidget">
<property name="dragDropMode">
<enum>QAbstractItemView::NoDragDrop</enum>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="flow">
<enum>QListView::LeftToRight</enum>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="spacing">
<number>4</number>
</property>
<property name="gridSize">
<size>
<width>30</width>
<height>24</height>
</size>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="selectionRectVisible">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Fill color</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mSymbolWidthLabel">
<property name="text">
<string>Symbol width</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="mSymbolHeightLabel">
<property name="text">
<string>Symbol height</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="mWidthSpinBox">
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QComboBox" name="mSymbolHeightUnitComboBox">
<item>
<property name="text">
<string>Millimeter</string>
</property>
</item>
<item>
<property name="text">
<string>Map unit</string>
</property>
</item>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="mSymbolHeightUnitLabel">
<property name="text">
<string>Symbol height unit</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Data defined settings</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="mDdSymbolWidthLabel">
<property name="text">
<string>Symbol width</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="mDDSymbolWidthComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mDdSymbolHeightLabel">
<property name="text">
<string>Symbol height</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mDDSymbolHeightComboBox"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mDDOutlineWidthLabel">
<property name="text">
<string>Outline width</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="mDDOutlineWidthComboBox"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mDDFillColorLabel">
<property name="text">
<string>Fill color</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="mDDFillColorComboBox"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="mDDOutlineLabel">
<property name="text">
<string>Outline color</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="mDDOutlineColorComboBox"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="mDDShapeLabel">
<property name="text">
<string>Shape</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="mDDRotationComboBox"/>
</item>
<item row="6" column="1">
<widget class="QComboBox" name="mDDShapeComboBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mDDRotationLabel">
<property name="text">
<string>Rotation</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down