Skip to content
Permalink
Browse files

Use actual map canvas variables & values for symbology widgets

  • Loading branch information
nyalldawson committed Sep 17, 2015
1 parent 87ee7b3 commit a77935f49170bc639a649728125210cd4a76db8f
@@ -11,7 +11,24 @@ class QgsDataDefinedAssistant: QDialog
#include <qgsdatadefinedbutton.h>
%End
public:
QgsDataDefinedAssistant();

virtual QgsDataDefined dataDefined() const = 0;

/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
* map scale and other properties from the canvas.
* @param canvas map canvas
* @see mapCanvas()
* @note added in QGIS 2.12
*/
virtual void setMapCanvas( QgsMapCanvas* canvas );

/** Returns the map canvas associated with the widget.
* @see setMapCanvas
* @note added in QGIS 2.12
*/
const QgsMapCanvas* mapCanvas() const;

};

/** \ingroup gui
@@ -187,9 +204,16 @@ class QgsDataDefinedButton : QToolButton
* @param assistant data defined assistant. Set to null to remove the assistant
* option from the button.
* @note added in 2.10
* @see assistant()
*/
void setAssistant( const QString& title, QgsDataDefinedAssistant * assistant /Transfer/ );

/** Returns the assistant used to defined the data defined object properties, if set.
* @see setAssistant()
* @note added in QGIS 2.12
*/
QgsDataDefinedAssistant* assistant();

/**
* Common descriptions for expected input values
*/
@@ -356,6 +356,12 @@ class QgsMapCanvas : QGraphicsView
*/
QgsExpressionContextScope& expressionContextScope();

/** Returns a const reference to the expression context scope for the map canvas.
* @note added in QGIS 2.12
* @see setExpressionContextScope()
*/
// const QgsExpressionContextScope& expressionContextScope() const;

public slots:

/** Repaints the canvas map*/
@@ -18,10 +18,22 @@ class QgsRendererV2Widget : QWidget
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
* map scale and other properties from the canvas.
* @param canvas map canvas
* @see mapCanvas()
* @note added in QGIS 2.12
*/
virtual void setMapCanvas( QgsMapCanvas* canvas );

/** Returns the map canvas associated with the widget.
* @see setMapCanvas
* @note added in QGIS 2.12
*/
const QgsMapCanvas* mapCanvas() const;

/** Returns the vector layer associated with the widget.
* @note added in QGIS 2.12
*/
const QgsVectorLayer* vectorLayer() const;

protected:
/** Subclasses may provide the capability of changing multiple symbols at once by implementing the following two methods
and by connecting the slot contextMenuViewCategories(const QPoint&)*/
@@ -45,3 +57,105 @@ class QgsRendererV2Widget : QWidget
virtual void paste();

};


/**
Utility classes for "en masse" size definition
*/
class QgsDataDefinedValueDialog : QDialog
{
%TypeHeaderCode
#include <qgsrendererv2widget.h>
%End

public:
/** Constructor
* @param symbolList must not be empty
* @param layer must not be null
* @param label value label
*/
QgsDataDefinedValueDialog( const QList<QgsSymbolV2*>& symbolList, QgsVectorLayer * layer, const QString & label );
virtual ~QgsDataDefinedValueDialog();

/** Sets the map canvas associated with the dialog. This allows the dialog to retrieve the current
* map scale and other properties from the canvas.
* @param canvas map canvas
* @see mapCanvas()
* @note added in QGIS 2.12
*/
virtual void setMapCanvas( QgsMapCanvas* canvas );

/** Returns the map canvas associated with the widget.
* @see setMapCanvas
* @note added in QGIS 2.12
*/
const QgsMapCanvas* mapCanvas() const;

/** Returns the vector layer associated with the widget.
* @note added in QGIS 2.12
*/
const QgsVectorLayer* vectorLayer() const;

public slots:
void dataDefinedChanged();

protected:
QgsDataDefined symbolDataDefined() const;
void init( const QString & description ); // needed in children ctor to call virtual

virtual QgsDataDefined symbolDataDefined( const QgsSymbolV2 * ) const = 0;
virtual double value( const QgsSymbolV2 * ) const = 0;
virtual void setDataDefined( QgsSymbolV2* symbol, const QgsDataDefined& dd ) = 0;
};

class QgsDataDefinedSizeDialog : QgsDataDefinedValueDialog
{
%TypeHeaderCode
#include <qgsrendererv2widget.h>
%End

public:
QgsDataDefinedSizeDialog( const QList<QgsSymbolV2*>& symbolList, QgsVectorLayer * layer );

protected:
QgsDataDefined symbolDataDefined( const QgsSymbolV2 * symbol ) const;

double value( const QgsSymbolV2 * symbol ) const;

void setDataDefined( QgsSymbolV2* symbol, const QgsDataDefined& dd );
};

class QgsDataDefinedRotationDialog : QgsDataDefinedValueDialog
{
%TypeHeaderCode
#include <qgsrendererv2widget.h>
%End

public:
QgsDataDefinedRotationDialog( const QList<QgsSymbolV2*>& symbolList, QgsVectorLayer * layer );

protected:
QgsDataDefined symbolDataDefined( const QgsSymbolV2 * symbol ) const;

double value( const QgsSymbolV2 * symbol ) const;

void setDataDefined( QgsSymbolV2* symbol, const QgsDataDefined& dd );
};


class QgsDataDefinedWidthDialog : QgsDataDefinedValueDialog
{
%TypeHeaderCode
#include <qgsrendererv2widget.h>
%End

public:
QgsDataDefinedWidthDialog( const QList<QgsSymbolV2*>& symbolList, QgsVectorLayer * layer );

protected:
QgsDataDefined symbolDataDefined( const QgsSymbolV2 * symbol ) const;

double value( const QgsSymbolV2 * symbol ) const;

void setDataDefined( QgsSymbolV2* symbol, const QgsDataDefined& dd );
};
@@ -8,6 +8,11 @@ class QgsSizeScaleWidget : QgsDataDefinedAssistant

QgsDataDefined dataDefined() const;

/** Returns the vector layer associated with the widget.
* @note added in QGIS 2.12
*/
const QgsVectorLayer* layer() const;

protected:

virtual void showEvent( QShowEvent * );
@@ -23,10 +23,17 @@ class QgsSymbolLayerV2Widget : QWidget
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
* map scale and other properties from the canvas.
* @param canvas map canvas
* @see mapCanvas()
* @note added in QGIS 2.12
*/
virtual void setMapCanvas( QgsMapCanvas* canvas );

/** Returns the map canvas associated with the widget.
* @see setMapCanvas
* @note added in QGIS 2.12
*/
const QgsMapCanvas* mapCanvas() const;

/** Returns the vector layer associated with the widget.
* @note added in QGIS 2.12
*/
@@ -17,10 +17,17 @@ class QgsSymbolsListWidget : QWidget
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
* map scale and other properties from the canvas.
* @param canvas map canvas
* @see mapCanvas()
* @note added in QGIS 2.12
*/
virtual void setMapCanvas( QgsMapCanvas* canvas );

/** Returns the map canvas associated with the widget.
* @see setMapCanvas
* @note added in QGIS 2.12
*/
const QgsMapCanvas* mapCanvas() const;

/** Returns the vector layer associated with the widget.
* @note added in QGIS 2.12
*/
@@ -698,6 +698,11 @@ void QgsDataDefinedButton::setAssistant( const QString& title, QgsDataDefinedAss
mAssistant.data()->setParent( this, Qt::Dialog );
}

QgsDataDefinedAssistant *QgsDataDefinedButton::assistant()
{
return mAssistant.data();
}

void QgsDataDefinedButton::checkCheckedWidgets( bool check )
{
// don't uncheck, only set to checked
@@ -25,6 +25,7 @@

class QgsVectorLayer;
class QgsDataDefined;
class QgsMapCanvas;

/** \ingroup gui
* \class QgsDataDefinedAssistant
@@ -36,7 +37,27 @@ class QgsDataDefined;
class GUI_EXPORT QgsDataDefinedAssistant: public QDialog
{
public:
QgsDataDefinedAssistant() : mMapCanvas( 0 ) {}

virtual QgsDataDefined dataDefined() const = 0;

/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
* map scale and other properties from the canvas.
* @param canvas map canvas
* @see mapCanvas()
* @note added in QGIS 2.12
*/
virtual void setMapCanvas( QgsMapCanvas* canvas ) { mMapCanvas = canvas; }

/** Returns the map canvas associated with the widget.
* @see setMapCanvas
* @note added in QGIS 2.12
*/
const QgsMapCanvas* mapCanvas() const { return mMapCanvas; }

protected:

QgsMapCanvas* mMapCanvas;
};

/** \ingroup gui
@@ -214,9 +235,16 @@ class GUI_EXPORT QgsDataDefinedButton: public QToolButton
* @param assistant data defined assistant. Set to null to remove the assistant
* option from the button.
* @note added in 2.10
* @see assistant()
*/
void setAssistant( const QString& title, QgsDataDefinedAssistant * assistant );

/** Returns the assistant used to defined the data defined object properties, if set.
* @see setAssistant()
* @note added in QGIS 2.12
*/
QgsDataDefinedAssistant* assistant();

/**
* Common descriptions for expected input values
*/
@@ -428,6 +428,12 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
*/
QgsExpressionContextScope& expressionContextScope() { return mExpressionContextScope; }

/** Returns a const reference to the expression context scope for the map canvas.
* @note added in QGIS 2.12
* @see setExpressionContextScope()
*/
const QgsExpressionContextScope& expressionContextScope() const { return mExpressionContextScope; }

public slots:

/** Repaints the canvas map*/
@@ -29,6 +29,7 @@

#include "qgsproject.h"
#include "qgsexpression.h"
#include "qgsmapcanvas.h"

#include <QKeyEvent>
#include <QMenu>
@@ -372,16 +373,25 @@ QgsRendererV2Widget* QgsCategorizedSymbolRendererV2Widget::create( QgsVectorLaye

static QgsExpressionContext _getExpressionContext( const void* context )
{
const QgsCategorizedSymbolRendererV2Widget* widget = ( const QgsCategorizedSymbolRendererV2Widget* ) context;

QgsExpressionContext expContext;
expContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
//TODO - use actual map canvas settings
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );
<< QgsExpressionContextUtils::atlasScope( 0 );

if ( widget->mapCanvas() )
{
expContext << QgsExpressionContextUtils::mapSettingsScope( widget->mapCanvas()->mapSettings() )
<< new QgsExpressionContextScope( widget->mapCanvas()->expressionContextScope() );
}
else
{
expContext << QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );
}

const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
if ( layer )
expContext << QgsExpressionContextUtils::layerScope( layer );
if ( widget->vectorLayer() )
expContext << QgsExpressionContextUtils::layerScope( widget->vectorLayer() );

return expContext;
}
@@ -468,7 +478,7 @@ QgsCategorizedSymbolRendererV2Widget::QgsCategorizedSymbolRendererV2Widget( QgsV

btnAdvanced->setMenu( advMenu );

mExpressionWidget->registerGetExpressionContextCallback( &_getExpressionContext, layer );
mExpressionWidget->registerGetExpressionContextCallback( &_getExpressionContext, this );
}

QgsCategorizedSymbolRendererV2Widget::~QgsCategorizedSymbolRendererV2Widget()

0 comments on commit a77935f

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