Skip to content
Permalink
Browse files
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 f11eeebe9b9b758eedbbac9bbd3c4e095f61abb6
@@ -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;
}
@@ -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 )
{
@@ -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
@@ -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()
@@ -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 );
@@ -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,6 +5,7 @@
#include <QDialog>

class QgsVectorLayer;
class QComboBox;

class QgsDataDefinedSymbolDialog: public QDialog, private Ui::QgsDataDefinedSymbolDialog
{
@@ -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
@@ -229,6 +229,7 @@ void QgsSimpleLineSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked()
mLayer->setDataDefinedProperty( it.key(), it.value() );
}
}
emit changed();
}
}

0 comments on commit f11eeeb

Please sign in to comment.