Skip to content
Permalink
Browse files

Merge pull request #2167 from vmora/keep_data_defined_at_marker_level…

…_on_property_change

fix loss of expression when subsymbol is changed
  • Loading branch information
vmora committed Jun 26, 2015
2 parents 04439fe + c62b52b commit ab0aa0448f8e305df3254c61a10f2ac585ce005f
@@ -46,6 +46,70 @@

static const int SymbolLayerItemType = QStandardItem::UserType + 1;

DataDefinedRestorer::DataDefinedRestorer( QgsSymbolV2* symbol, const QgsSymbolLayerV2* symbolLayer )
: mMarker( NULL )
, mMarkerSymbolLayer( NULL )
, mLine( NULL )
, mLineSymbolLayer( NULL )
{
if ( symbolLayer->type() == QgsSymbolV2::Marker && symbol->type() == QgsSymbolV2::Marker )
{
Q_ASSERT( symbol->type() == QgsSymbolV2::Marker );
mMarker = static_cast<QgsMarkerSymbolV2*>( symbol );
mMarkerSymbolLayer = static_cast<const QgsMarkerSymbolLayerV2*>( symbolLayer );
mDDSize = mMarker->dataDefinedSize();
mDDAngle = mMarker->dataDefinedAngle();
// check if restore is actually needed
if ( mDDSize == QgsDataDefined() && mDDAngle == QgsDataDefined() )
mMarker = NULL;
}
else if( symbolLayer->type() == QgsSymbolV2::Line && symbol->type() == QgsSymbolV2::Line )
{
mLine = static_cast<QgsLineSymbolV2*>( symbol );
mLineSymbolLayer = static_cast<const QgsLineSymbolLayerV2*>( symbolLayer );
mDDWidth = mLine->dataDefinedWidth();
// check if restore is actually needed
if ( mDDWidth == QgsDataDefined() )
mLine = NULL;
}
save();
}

void DataDefinedRestorer::save()
{
if ( mMarker )
{
mSize = mMarkerSymbolLayer->size();
mAngle = mMarkerSymbolLayer->angle();
mMarkerOffset = mMarkerSymbolLayer->offset();
}
else if ( mLine )
{
mWidth = mLineSymbolLayer->width();
mLineOffset = mLineSymbolLayer->offset();
}
}

void DataDefinedRestorer::restore()
{
if ( mMarker )
{
if ( mDDSize != QgsDataDefined() &&
(mSize != mMarkerSymbolLayer->size() || mMarkerOffset != mMarkerSymbolLayer->offset()) )
mMarker->setDataDefinedSize( mDDSize );
if ( mDDAngle != QgsDataDefined() &&
mAngle != mMarkerSymbolLayer->angle() )
mMarker->setDataDefinedAngle( mDDAngle );
}
else if ( mLine )
{
if ( mDDWidth != QgsDataDefined() &&
(mWidth != mLineSymbolLayer->width() || mLineOffset != mLineSymbolLayer->offset()) )
mLine->setDataDefinedWidth( mDDWidth );
}
save();
}

// Hybrid item which may represent a symbol or a layer
// Check using item->isLayer()
class SymbolLayerItem : public QStandardItem
@@ -325,14 +389,17 @@ void QgsSymbolV2SelectorDialog::layerChanged()
if ( currentItem->isLayer() )
{
SymbolLayerItem *parent = static_cast<SymbolLayerItem*>( currentItem->parent() );
mDataDefineRestorer.reset( new DataDefinedRestorer( parent->symbol(), currentItem->layer() ) );
QWidget *layerProp = new QgsLayerPropertiesWidget( currentItem->layer(), parent->symbol(), mVectorLayer );
setWidget( layerProp );
connect( layerProp, SIGNAL( changed() ), mDataDefineRestorer.data(), SLOT( restore() ) );
connect( layerProp, SIGNAL( changed() ), this, SLOT( updateLayerPreview() ) );
// This connection when layer type is changed
connect( layerProp, SIGNAL( changeLayer( QgsSymbolLayerV2* ) ), this, SLOT( changeLayer( QgsSymbolLayerV2* ) ) );
}
else
{
mDataDefineRestorer.reset();
// then it must be a symbol
currentItem->symbol()->setLayer( mVectorLayer );
// Now populate symbols of that type using the symbols list widget:
@@ -20,7 +20,10 @@

#include "ui_qgssymbolv2selectordialogbase.h"

#include "qgsdatadefined.h"

#include <QStandardItemModel>
#include <QScopedPointer>

class QgsStyleV2;
class QgsSymbolV2;
@@ -31,6 +34,37 @@ class QMenu;
class QWidget;

class SymbolLayerItem;
class QgsMarkerSymbolV2;
class QgsLineSymbolV2;
class QgsMarkerSymbolLayerV2;
class QgsLineSymbolLayerV2;

class DataDefinedRestorer: public QObject
{
Q_OBJECT
public:
DataDefinedRestorer( QgsSymbolV2* symbol, const QgsSymbolLayerV2* symbolLayer);

public slots:
void restore();

private:
QgsMarkerSymbolV2* mMarker;
const QgsMarkerSymbolLayerV2* mMarkerSymbolLayer;
double mSize;
double mAngle;
QPointF mMarkerOffset;
QgsDataDefined mDDSize;
QgsDataDefined mDDAngle;

QgsLineSymbolV2* mLine;
const QgsLineSymbolLayerV2* mLineSymbolLayer;
double mWidth;
double mLineOffset;
QgsDataDefined mDDWidth;

void save();
};

class GUI_EXPORT QgsSymbolV2SelectorDialog : public QDialog, private Ui::QgsSymbolV2SelectorDialogBase
{
@@ -95,6 +129,9 @@ class GUI_EXPORT QgsSymbolV2SelectorDialog : public QDialog, private Ui::QgsSymb

QStandardItemModel* model;
QWidget *mPresentWidget;

private:
QScopedPointer<DataDefinedRestorer> mDataDefineRestorer;
};

#endif

0 comments on commit ab0aa04

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