Skip to content
Permalink
Browse files

Fix a bunch of crashes in renderer widgets when used with a rule

based rule which has no symbol
  • Loading branch information
nyalldawson committed Dec 18, 2015
1 parent e9cd829 commit d91c9cd23c5cb111f9307e05820fb867f19f6b81
@@ -1324,6 +1324,8 @@ void QgsLineSymbolV2::setWidth( double w )
double QgsLineSymbolV2::width() const
{
double maxWidth = 0;
if ( mLayers.isEmpty() )
return maxWidth;

Q_FOREACH ( QgsSymbolLayerV2* symbolLayer, mLayers )
{
@@ -61,18 +61,30 @@ void QgsRendererV2Widget::contextMenuViewCategories( const QPoint & )
void QgsRendererV2Widget::changeSymbolColor()
{
QList<QgsSymbolV2*> symbolList = selectedSymbols();
if ( symbolList.size() < 1 )
if ( symbolList.isEmpty() )
{
return;
}

QColor color = QgsColorDialogV2::getColor( symbolList.at( 0 )->color(), this, "Change Symbol Color", true );
QgsSymbolV2* firstSymbol = nullptr;
Q_FOREACH ( QgsSymbolV2* symbol, symbolList )
{
if ( symbol )
{
firstSymbol = symbol;
break;
}
}
if ( !firstSymbol )
return;

QColor color = QgsColorDialogV2::getColor( firstSymbol->color(), this, "Change Symbol Color", true );
if ( color.isValid() )
{
QList<QgsSymbolV2*>::iterator symbolIt = symbolList.begin();
for ( ; symbolIt != symbolList.end(); ++symbolIt )
Q_FOREACH ( QgsSymbolV2* symbol, symbolList )
{
( *symbolIt )->setColor( color );
if ( symbol )
symbol->setColor( color );
}
refreshSymbolView();
}
@@ -81,20 +93,32 @@ void QgsRendererV2Widget::changeSymbolColor()
void QgsRendererV2Widget::changeSymbolTransparency()
{
QList<QgsSymbolV2*> symbolList = selectedSymbols();
if ( symbolList.size() < 1 )
if ( symbolList.isEmpty() )
{
return;
}

QgsSymbolV2* firstSymbol = nullptr;
Q_FOREACH ( QgsSymbolV2* symbol, symbolList )
{
if ( symbol )
{
firstSymbol = symbol;
break;
}
}
if ( !firstSymbol )
return;

bool ok;
double oldTransparency = ( 1 - symbolList.at( 0 )->alpha() ) * 100; // convert to percents
double oldTransparency = ( 1 - firstSymbol->alpha() ) * 100; // convert to percents
double transparency = QInputDialog::getDouble( this, tr( "Transparency" ), tr( "Change symbol transparency [%]" ), oldTransparency, 0.0, 100.0, 0, &ok );
if ( ok )
{
QList<QgsSymbolV2*>::iterator symbolIt = symbolList.begin();
for ( ; symbolIt != symbolList.end(); ++symbolIt )
Q_FOREACH ( QgsSymbolV2* symbol, symbolList )
{
( *symbolIt )->setAlpha( 1 - transparency / 100 );
if ( symbol )
symbol->setAlpha( 1 - transparency / 100 );
}
refreshSymbolView();
}
@@ -103,22 +127,34 @@ void QgsRendererV2Widget::changeSymbolTransparency()
void QgsRendererV2Widget::changeSymbolUnit()
{
QList<QgsSymbolV2*> symbolList = selectedSymbols();
if ( symbolList.size() < 1 )
if ( symbolList.isEmpty() )
{
return;
}

QgsSymbolV2* firstSymbol = nullptr;
Q_FOREACH ( QgsSymbolV2* symbol, symbolList )
{
if ( symbol )
{
firstSymbol = symbol;
break;
}
}
if ( !firstSymbol )
return;

bool ok;
int currentUnit = ( symbolList.at( 0 )->outputUnit() == QgsSymbolV2::MM ) ? 0 : 1;
int currentUnit = ( firstSymbol->outputUnit() == QgsSymbolV2::MM ) ? 0 : 1;
QString item = QInputDialog::getItem( this, tr( "Symbol unit" ), tr( "Select symbol unit" ), QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), currentUnit, false, &ok );
if ( ok )
{
QgsSymbolV2::OutputUnit unit = ( item.compare( tr( "Millimeter" ) ) == 0 ) ? QgsSymbolV2::MM : QgsSymbolV2::MapUnit;

QList<QgsSymbolV2*>::iterator symbolIt = symbolList.begin();
for ( ; symbolIt != symbolList.end(); ++symbolIt )
Q_FOREACH ( QgsSymbolV2* symbol, symbolList )
{
( *symbolIt )->setOutputUnit( unit );
if ( symbol )
symbol->setOutputUnit( unit );
}
refreshSymbolView();
}
@@ -127,7 +163,7 @@ void QgsRendererV2Widget::changeSymbolUnit()
void QgsRendererV2Widget::changeSymbolWidth()
{
QList<QgsSymbolV2*> symbolList = selectedSymbols();
if ( symbolList.size() < 1 )
if ( symbolList.isEmpty() )
{
return;
}
@@ -139,11 +175,13 @@ void QgsRendererV2Widget::changeSymbolWidth()
{
if ( !dlg.mDDBtn->isActive() )
{
QList<QgsSymbolV2*>::iterator symbolIt = symbolList.begin();
for ( ; symbolIt != symbolList.end(); ++symbolIt )
Q_FOREACH ( QgsSymbolV2* symbol, symbolList )
{
if (( *symbolIt )->type() == QgsSymbolV2::Line )
static_cast<QgsLineSymbolV2*>( *symbolIt )->setWidth( dlg.mSpinBox->value() );
if ( !symbol )
continue;

if ( symbol->type() == QgsSymbolV2::Line )
static_cast<QgsLineSymbolV2*>( symbol )->setWidth( dlg.mSpinBox->value() );
}
}
refreshSymbolView();
@@ -153,7 +191,7 @@ void QgsRendererV2Widget::changeSymbolWidth()
void QgsRendererV2Widget::changeSymbolSize()
{
QList<QgsSymbolV2*> symbolList = selectedSymbols();
if ( symbolList.size() < 1 )
if ( symbolList.isEmpty() )
{
return;
}
@@ -165,11 +203,13 @@ void QgsRendererV2Widget::changeSymbolSize()
{
if ( !dlg.mDDBtn->isActive() )
{
QList<QgsSymbolV2*>::iterator symbolIt = symbolList.begin();
for ( ; symbolIt != symbolList.end(); ++symbolIt )
Q_FOREACH ( QgsSymbolV2* symbol, symbolList )
{
if (( *symbolIt )->type() == QgsSymbolV2::Marker )
static_cast<QgsMarkerSymbolV2*>( *symbolIt )->setSize( dlg.mSpinBox->value() );
if ( !symbol )
continue;

if ( symbol->type() == QgsSymbolV2::Marker )
static_cast<QgsMarkerSymbolV2*>( symbol )->setSize( dlg.mSpinBox->value() );
}
}
refreshSymbolView();
@@ -179,7 +219,7 @@ void QgsRendererV2Widget::changeSymbolSize()
void QgsRendererV2Widget::changeSymbolAngle()
{
QList<QgsSymbolV2*> symbolList = selectedSymbols();
if ( symbolList.size() < 1 )
if ( symbolList.isEmpty() )
{
return;
}
@@ -191,11 +231,13 @@ void QgsRendererV2Widget::changeSymbolAngle()
{
if ( !dlg.mDDBtn->isActive() )
{
QList<QgsSymbolV2*>::iterator symbolIt = symbolList.begin();
for ( ; symbolIt != symbolList.end(); ++symbolIt )
Q_FOREACH ( QgsSymbolV2* symbol, symbolList )
{
if (( *symbolIt )->type() == QgsSymbolV2::Marker )
static_cast<QgsMarkerSymbolV2*>( *symbolIt )->setAngle( dlg.mSpinBox->value() );
if ( !symbol )
continue;

if ( symbol->type() == QgsSymbolV2::Marker )
static_cast<QgsMarkerSymbolV2*>( symbol )->setAngle( dlg.mSpinBox->value() );
}
}
refreshSymbolView();
@@ -460,17 +502,30 @@ void QgsDataDefinedValueDialog::init( const QString & description )
QgsDataDefined dd = symbolDataDefined();
mDDBtn->init( mLayer, &dd, QgsDataDefinedButton::Double, description );
mDDBtn->registerGetExpressionContextCallback( &_getExpressionContext, this );
mSpinBox->setValue( value( mSymbolList.back() ) );

QgsSymbolV2* initialSymbol = nullptr;
Q_FOREACH ( QgsSymbolV2* symbol, mSymbolList )
{
if ( symbol )
{
initialSymbol = symbol;
}
}
mSpinBox->setValue( initialSymbol ? value( initialSymbol ) : 0 );
mSpinBox->setEnabled( !mDDBtn->isActive() );
}

QgsDataDefined QgsDataDefinedValueDialog::symbolDataDefined() const
{
if ( mSymbolList.isEmpty() || !mSymbolList.back() )
return QgsDataDefined();

// check that all symbols share the same size expression
QgsDataDefined dd = symbolDataDefined( mSymbolList.back() );
Q_FOREACH ( QgsSymbolV2 * it, mSymbolList )
{
if ( symbolDataDefined( it ) != dd ) return QgsDataDefined();
if ( !it || symbolDataDefined( it ) != dd )
return QgsDataDefined();
}
return dd;
}
@@ -215,8 +215,8 @@ class GUI_EXPORT QgsDataDefinedSizeDialog : public QgsDataDefinedValueDialog
: QgsDataDefinedValueDialog( symbolList, layer, tr( "Size" ) )
{
init( tr( "Symbol size" ) );
if ( !symbolList.isEmpty() && mLayer )
mDDBtn->setAssistant( tr( "Size Assistant..." ), new QgsSizeScaleWidget( mLayer, static_cast<const QgsMarkerSymbolV2*>( symbolList[0] ) ) );
if ( !symbolList.isEmpty() && symbolList.at( 0 ) && mLayer )
mDDBtn->setAssistant( tr( "Size Assistant..." ), new QgsSizeScaleWidget( mLayer, static_cast<const QgsMarkerSymbolV2*>( symbolList.at( 0 ) ) ) );
}

protected:

0 comments on commit d91c9cd

Please sign in to comment.
You can’t perform that action at this time.