Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve data defined dialog, consider data defined color for single l…
…ine symbol layer
  • Loading branch information
mhugent committed Mar 27, 2013
1 parent 4281aeb commit f11eeeb
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
18 changes: 12 additions & 6 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -232,17 +232,17 @@ QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::create( const QgsStringMap& props

//data defined properties
if ( props.contains( "color_expression" ) )
l->setDataDefinedProperty( "color_expression", props["color_expression"] );
l->setDataDefinedProperty( "color", props["color_expression"] );
if ( props.contains( "width_expression" ) )
l->setDataDefinedProperty( "width_expression", props["width_expression"] );
l->setDataDefinedProperty( "width", props["width_expression"] );
if ( props.contains( "offset_expression" ) )
l->setDataDefinedProperty( "offset_expression", props["offset_expression"] );
l->setDataDefinedProperty( "offset", props["offset_expression"] );
if ( props.contains( "customdash_expression" ) )
l->setDataDefinedProperty( "customdash_expression", props["customdash_expression"] );
l->setDataDefinedProperty( "customdash", props["customdash_expression"] );
if ( props.contains( "joinstyle_expression" ) )
l->setDataDefinedProperty( "joinstyle_expression", props["joinstyle_expression"] );
l->setDataDefinedProperty( "joinstyle", props["joinstyle_expression"] );
if ( props.contains( "capstyle_expression" ) )
l->setDataDefinedProperty( "capstyle_expression", props["capstyle_expression"] );
l->setDataDefinedProperty( "capstyle", props["capstyle_expression"] );

return l;
}
Expand Down Expand Up @@ -336,6 +336,12 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
mSelPen.setWidthF( scaledWidth );
}

//color
if ( mStrokeColorExpression )
{
mPen.setColor( QColor( mStrokeColorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
}

p->setPen( context.selected() ? mSelPen : mPen );
if ( mOffset == 0 )
{
Expand Down
40 changes: 32 additions & 8 deletions src/gui/symbology-ng/qgsdatadefinedsymboldialog.cpp
Expand Up @@ -22,19 +22,34 @@ QgsDataDefinedSymbolDialog::QgsDataDefinedSymbolDialog( const QMap< QString, QPa
for ( ; it != properties.constEnd(); ++it )
{
//check box
mTableWidget->setCellWidget( i, 0, new QCheckBox( this ) );
QCheckBox* cb = new QCheckBox( this );
cb->setChecked( !it.value().second.isEmpty() );
mTableWidget->setCellWidget( i, 0, cb );

//property name
QTableWidgetItem* propertyItem = new QTableWidgetItem( it.value().first );
propertyItem->setData( Qt::UserRole, it.key() );
mTableWidget->setItem( i, 1, propertyItem );

//attribute list
QString expressionString = it.value().second;
QComboBox* attributeComboBox = new QComboBox( this );
attributeComboBox->addItem( it.value().second );
attributeComboBox->addItem( QString() );
for ( int j = 0; j < attributeFields.count(); ++j )
{
attributeComboBox->addItem( attributeFields.at( j ).name() );
}

int attrComboIndex = comboIndexForExpressionString( expressionString, attributeComboBox );
if ( attrComboIndex >= 0 )
{
attributeComboBox->setCurrentIndex( attrComboIndex );
}
else
{
attributeComboBox->setItemText( 0, expressionString );
}

mTableWidget->setCellWidget( i, 2, attributeComboBox );

//expression button
Expand All @@ -43,8 +58,6 @@ QgsDataDefinedSymbolDialog::QgsDataDefinedSymbolDialog( const QMap< QString, QPa
mTableWidget->setCellWidget( i, 3, expressionButton );
++i;
}

//connect( this, SIGNAL( cellClicked( int, int ) ), this, SLOT( handleCellClick(int,int) ) );
}

QgsDataDefinedSymbolDialog::~QgsDataDefinedSymbolDialog()
Expand Down Expand Up @@ -113,10 +126,9 @@ void QgsDataDefinedSymbolDialog::expressionButtonClicked()
if ( d.exec() == QDialog::Accepted )
{
QString expressionString = d.expressionText();
QString attributeString = expressionString.trimmed();
attributeString.remove( 0, 1 ).chop( 1 );
int comboIndex = attributeCombo->findText( attributeString );
if ( attributeString.size() < 1 || comboIndex == -1 )
int comboIndex = comboIndexForExpressionString( d.expressionText(), attributeCombo );

if ( comboIndex == -1 )
{
attributeCombo->setItemText( 0, d.expressionText() );
attributeCombo->setCurrentIndex( 0 );
Expand All @@ -128,3 +140,15 @@ void QgsDataDefinedSymbolDialog::expressionButtonClicked()
}
}
}

int QgsDataDefinedSymbolDialog::comboIndexForExpressionString( const QString& expr, const QComboBox* cb )
{
QString attributeString = expr.trimmed();
int comboIndex = cb->findText( attributeString );
if ( comboIndex == -1 )
{
attributeString.remove( 0, 1 ).chop( 1 );
comboIndex = cb->findText( attributeString );
}
return comboIndex;
}
5 changes: 5 additions & 0 deletions src/gui/symbology-ng/qgsdatadefinedsymboldialog.h
Expand Up @@ -5,6 +5,7 @@
#include <QDialog>

class QgsVectorLayer;
class QComboBox;

class QgsDataDefinedSymbolDialog: public QDialog, private Ui::QgsDataDefinedSymbolDialog
{
Expand All @@ -19,6 +20,10 @@ class QgsDataDefinedSymbolDialog: public QDialog, private Ui::QgsDataDefinedSymb

private:
const QgsVectorLayer* mVectorLayer;

/**Tries to fiend a combo box field for an expression string (considering whitespaces, brackets around attribute names)
@return index or -1 in case not found*/
int comboIndexForExpressionString( const QString& expr, const QComboBox* cb );
};

#endif // QGSDATADEFINEDSYMBOLLAYERDIALOG_H
1 change: 1 addition & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Expand Up @@ -229,6 +229,7 @@ void QgsSimpleLineSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked()
mLayer->setDataDefinedProperty( it.key(), it.value() );
}
}
emit changed();
}
}

Expand Down

0 comments on commit f11eeeb

Please sign in to comment.