mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Use actual map canvas variables & values for symbology widgets
This commit is contained in:
parent
87ee7b3692
commit
a77935f491
@ -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 );
|
||||
|
||||
const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
|
||||
if ( layer )
|
||||
expContext << QgsExpressionContextUtils::layerScope( layer );
|
||||
if ( widget->mapCanvas() )
|
||||
{
|
||||
expContext << QgsExpressionContextUtils::mapSettingsScope( widget->mapCanvas()->mapSettings() )
|
||||
<< new QgsExpressionContextScope( widget->mapCanvas()->expressionContextScope() );
|
||||
}
|
||||
else
|
||||
{
|
||||
expContext << QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );
|
||||
}
|
||||
|
||||
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()
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "qgsludialog.h"
|
||||
|
||||
#include "qgsproject.h"
|
||||
#include "qgsmapcanvas.h"
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QMenu>
|
||||
@ -381,16 +382,25 @@ QgsRendererV2Widget* QgsGraduatedSymbolRendererV2Widget::create( QgsVectorLayer*
|
||||
|
||||
static QgsExpressionContext _getExpressionContext( const void* context )
|
||||
{
|
||||
const QgsGraduatedSymbolRendererV2Widget* widget = ( const QgsGraduatedSymbolRendererV2Widget* ) context;
|
||||
|
||||
QgsExpressionContext expContext;
|
||||
expContext << QgsExpressionContextUtils::globalScope()
|
||||
<< QgsExpressionContextUtils::projectScope()
|
||||
<< QgsExpressionContextUtils::atlasScope( 0 )
|
||||
//TODO - use actual map canvas settings
|
||||
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );
|
||||
<< QgsExpressionContextUtils::atlasScope( 0 );
|
||||
|
||||
const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
|
||||
if ( layer )
|
||||
expContext << QgsExpressionContextUtils::layerScope( layer );
|
||||
if ( widget->mapCanvas() )
|
||||
{
|
||||
expContext << QgsExpressionContextUtils::mapSettingsScope( widget->mapCanvas()->mapSettings() )
|
||||
<< new QgsExpressionContextScope( widget->mapCanvas()->expressionContextScope() );
|
||||
}
|
||||
else
|
||||
{
|
||||
expContext << QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );
|
||||
}
|
||||
|
||||
if ( widget->vectorLayer() )
|
||||
expContext << QgsExpressionContextUtils::layerScope( widget->vectorLayer() );
|
||||
|
||||
return expContext;
|
||||
}
|
||||
@ -489,7 +499,7 @@ QgsGraduatedSymbolRendererV2Widget::QgsGraduatedSymbolRendererV2Widget( QgsVecto
|
||||
connect( mHistogramWidget, SIGNAL( rangesModified( bool ) ), this, SLOT( refreshRanges( bool ) ) );
|
||||
connect( mExpressionWidget, SIGNAL( fieldChanged( QString ) ), mHistogramWidget, SLOT( setSourceFieldExp( QString ) ) );
|
||||
|
||||
mExpressionWidget->registerGetExpressionContextCallback( &_getExpressionContext, mLayer );
|
||||
mExpressionWidget->registerGetExpressionContextCallback( &_getExpressionContext, this );
|
||||
}
|
||||
|
||||
void QgsGraduatedSymbolRendererV2Widget::on_mSizeUnitWidget_changed()
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "qgsvectorcolorrampv2.h"
|
||||
#include "qgsstylev2.h"
|
||||
#include "qgsproject.h"
|
||||
#include "qgsmapcanvas.h"
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
|
||||
@ -33,16 +34,25 @@ QgsRendererV2Widget* QgsHeatmapRendererWidget::create( QgsVectorLayer* layer, Qg
|
||||
|
||||
static QgsExpressionContext _getExpressionContext( const void* context )
|
||||
{
|
||||
const QgsHeatmapRendererWidget* widget = ( const QgsHeatmapRendererWidget* ) context;
|
||||
|
||||
QgsExpressionContext expContext;
|
||||
expContext << QgsExpressionContextUtils::globalScope()
|
||||
<< QgsExpressionContextUtils::projectScope()
|
||||
<< QgsExpressionContextUtils::atlasScope( 0 )
|
||||
//TODO - use actual map canvas settings
|
||||
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );
|
||||
<< QgsExpressionContextUtils::atlasScope( 0 );
|
||||
|
||||
const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
|
||||
if ( layer )
|
||||
expContext << QgsExpressionContextUtils::layerScope( layer );
|
||||
if ( widget->mapCanvas() )
|
||||
{
|
||||
expContext << QgsExpressionContextUtils::mapSettingsScope( widget->mapCanvas()->mapSettings() )
|
||||
<< new QgsExpressionContextScope( widget->mapCanvas()->expressionContextScope() );
|
||||
}
|
||||
else
|
||||
{
|
||||
expContext << QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );
|
||||
}
|
||||
|
||||
if ( widget->vectorLayer() )
|
||||
expContext << QgsExpressionContextUtils::layerScope( widget->vectorLayer() );
|
||||
|
||||
return expContext;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "qgscolordialog.h"
|
||||
#include "qgssymbollevelsv2dialog.h"
|
||||
#include "qgsexpressionbuilderdialog.h"
|
||||
#include "qgsmapcanvas.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QInputDialog>
|
||||
@ -132,6 +133,7 @@ void QgsRendererV2Widget::changeSymbolWidth()
|
||||
}
|
||||
|
||||
QgsDataDefinedWidthDialog dlg( symbolList, mLayer );
|
||||
dlg.setMapCanvas( mMapCanvas );
|
||||
|
||||
if ( QDialog::Accepted == dlg.exec() )
|
||||
{
|
||||
@ -157,6 +159,7 @@ void QgsRendererV2Widget::changeSymbolSize()
|
||||
}
|
||||
|
||||
QgsDataDefinedSizeDialog dlg( symbolList, mLayer );
|
||||
dlg.setMapCanvas( mMapCanvas );
|
||||
|
||||
if ( QDialog::Accepted == dlg.exec() )
|
||||
{
|
||||
@ -182,6 +185,7 @@ void QgsRendererV2Widget::changeSymbolAngle()
|
||||
}
|
||||
|
||||
QgsDataDefinedRotationDialog dlg( symbolList, mLayer );
|
||||
dlg.setMapCanvas( mMapCanvas );
|
||||
|
||||
if ( QDialog::Accepted == dlg.exec() )
|
||||
{
|
||||
@ -215,6 +219,11 @@ void QgsRendererV2Widget::setMapCanvas( QgsMapCanvas *canvas )
|
||||
mMapCanvas = canvas;
|
||||
}
|
||||
|
||||
const QgsMapCanvas*QgsRendererV2Widget::mapCanvas() const
|
||||
{
|
||||
return mMapCanvas;
|
||||
}
|
||||
|
||||
|
||||
////////////
|
||||
|
||||
@ -397,6 +406,7 @@ void QgsRendererV2DataDefinedMenus::updateMenu( QActionGroup* actionGroup, QStri
|
||||
QgsDataDefinedValueDialog::QgsDataDefinedValueDialog( const QList<QgsSymbolV2*>& symbolList, QgsVectorLayer * layer, const QString & label )
|
||||
: mSymbolList( symbolList )
|
||||
, mLayer( layer )
|
||||
, mMapCanvas( 0 )
|
||||
{
|
||||
setupUi( this );
|
||||
setWindowFlags( Qt::WindowStaysOnTopHint );
|
||||
@ -406,18 +416,41 @@ QgsDataDefinedValueDialog::QgsDataDefinedValueDialog( const QList<QgsSymbolV2*>&
|
||||
|
||||
}
|
||||
|
||||
void QgsDataDefinedValueDialog::setMapCanvas( QgsMapCanvas *canvas )
|
||||
{
|
||||
mMapCanvas = canvas;
|
||||
Q_FOREACH ( QgsDataDefinedButton* ddButton, findChildren<QgsDataDefinedButton*>() )
|
||||
{
|
||||
if ( ddButton->assistant() )
|
||||
ddButton->assistant()->setMapCanvas( mMapCanvas );
|
||||
}
|
||||
}
|
||||
|
||||
const QgsMapCanvas *QgsDataDefinedValueDialog::mapCanvas() const
|
||||
{
|
||||
return mMapCanvas;
|
||||
}
|
||||
|
||||
static QgsExpressionContext _getExpressionContext( const void* context )
|
||||
{
|
||||
const QgsDataDefinedValueDialog* widget = ( const QgsDataDefinedValueDialog* ) 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;
|
||||
}
|
||||
@ -426,7 +459,7 @@ void QgsDataDefinedValueDialog::init( const QString & description )
|
||||
{
|
||||
QgsDataDefined dd = symbolDataDefined();
|
||||
mDDBtn->init( mLayer, &dd, QgsDataDefinedButton::Double, description );
|
||||
mDDBtn->registerGetExpressionContextCallback( &_getExpressionContext, const_cast< QgsVectorLayer* >( mLayer ) );
|
||||
mDDBtn->registerGetExpressionContextCallback( &_getExpressionContext, this );
|
||||
mSpinBox->setValue( value( mSymbolList.back() ) );
|
||||
mSpinBox->setEnabled( !mDDBtn->isActive() );
|
||||
}
|
||||
|
@ -53,10 +53,22 @@ class GUI_EXPORT QgsRendererV2Widget : public 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 { return mLayer; }
|
||||
|
||||
protected:
|
||||
QgsVectorLayer* mLayer;
|
||||
QgsStyleV2* mStyle;
|
||||
@ -159,6 +171,25 @@ class GUI_EXPORT QgsDataDefinedValueDialog : public QDialog, public Ui::QgsDataD
|
||||
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 { return mLayer; }
|
||||
|
||||
public slots:
|
||||
void dataDefinedChanged();
|
||||
|
||||
@ -172,6 +203,7 @@ class GUI_EXPORT QgsDataDefinedValueDialog : public QDialog, public Ui::QgsDataD
|
||||
|
||||
QList<QgsSymbolV2*> mSymbolList;
|
||||
QgsVectorLayer* mLayer;
|
||||
QgsMapCanvas* mMapCanvas;
|
||||
};
|
||||
|
||||
class GUI_EXPORT QgsDataDefinedSizeDialog : public QgsDataDefinedValueDialog
|
||||
|
@ -510,10 +510,17 @@ void QgsRuleBasedRendererV2Widget::countFeatures()
|
||||
QgsExpressionContext context;
|
||||
context << QgsExpressionContextUtils::globalScope()
|
||||
<< QgsExpressionContextUtils::projectScope()
|
||||
<< QgsExpressionContextUtils::atlasScope( 0 )
|
||||
//TODO - use actual map canvas settings
|
||||
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() )
|
||||
<< QgsExpressionContextUtils::layerScope( mLayer );
|
||||
<< QgsExpressionContextUtils::atlasScope( 0 );
|
||||
if ( mMapCanvas )
|
||||
{
|
||||
context << QgsExpressionContextUtils::mapSettingsScope( mMapCanvas->mapSettings() )
|
||||
<< new QgsExpressionContextScope( mMapCanvas->expressionContextScope() );
|
||||
}
|
||||
else
|
||||
{
|
||||
context << QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );
|
||||
}
|
||||
context << QgsExpressionContextUtils::layerScope( mLayer );
|
||||
|
||||
renderContext.setExpressionContext( context );
|
||||
|
||||
@ -637,10 +644,17 @@ void QgsRendererRulePropsDialog::buildExpression()
|
||||
QgsExpressionContext context;
|
||||
context << QgsExpressionContextUtils::globalScope()
|
||||
<< QgsExpressionContextUtils::projectScope()
|
||||
<< QgsExpressionContextUtils::atlasScope( 0 )
|
||||
//TODO - use actual map canvas settings
|
||||
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() )
|
||||
<< QgsExpressionContextUtils::layerScope( mLayer );
|
||||
<< QgsExpressionContextUtils::atlasScope( 0 );
|
||||
if ( mMapCanvas )
|
||||
{
|
||||
context << QgsExpressionContextUtils::mapSettingsScope( mMapCanvas->mapSettings() )
|
||||
<< new QgsExpressionContextScope( mMapCanvas->expressionContextScope() );
|
||||
}
|
||||
else
|
||||
{
|
||||
context << QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );
|
||||
}
|
||||
context << QgsExpressionContextUtils::layerScope( mLayer );
|
||||
|
||||
QgsExpressionBuilderDialog dlg( mLayer, editFilter->text(), this, "generic", context );
|
||||
|
||||
@ -660,10 +674,17 @@ void QgsRendererRulePropsDialog::testFilter()
|
||||
QgsExpressionContext context;
|
||||
context << QgsExpressionContextUtils::globalScope()
|
||||
<< QgsExpressionContextUtils::projectScope()
|
||||
<< QgsExpressionContextUtils::atlasScope( 0 )
|
||||
//TODO - use actual map canvas settings
|
||||
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() )
|
||||
<< QgsExpressionContextUtils::layerScope( mLayer );
|
||||
<< QgsExpressionContextUtils::atlasScope( 0 );
|
||||
if ( mMapCanvas )
|
||||
{
|
||||
context << QgsExpressionContextUtils::mapSettingsScope( mMapCanvas->mapSettings() )
|
||||
<< new QgsExpressionContextScope( mMapCanvas->expressionContextScope() );
|
||||
}
|
||||
else
|
||||
{
|
||||
context << QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );
|
||||
}
|
||||
context << QgsExpressionContextUtils::layerScope( mLayer );
|
||||
|
||||
if ( !filter.prepare( &context ) )
|
||||
{
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "qgssymbollayerv2utils.h"
|
||||
#include "qgsscaleexpression.h"
|
||||
#include "qgsdatadefined.h"
|
||||
#include "qgsmapcanvas.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
@ -80,16 +81,25 @@ void QgsSizeScaleWidget::setFromSymbol()
|
||||
|
||||
static QgsExpressionContext _getExpressionContext( const void* context )
|
||||
{
|
||||
const QgsSizeScaleWidget* widget = ( const QgsSizeScaleWidget* ) context;
|
||||
|
||||
QgsExpressionContext expContext;
|
||||
expContext << QgsExpressionContextUtils::globalScope()
|
||||
<< QgsExpressionContextUtils::projectScope()
|
||||
<< QgsExpressionContextUtils::atlasScope( 0 )
|
||||
//TODO - use actual map canvas settings
|
||||
<< QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );
|
||||
<< QgsExpressionContextUtils::atlasScope( 0 );
|
||||
|
||||
const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
|
||||
if ( layer )
|
||||
expContext << QgsExpressionContextUtils::layerScope( layer );
|
||||
if ( widget->mapCanvas() )
|
||||
{
|
||||
expContext << QgsExpressionContextUtils::mapSettingsScope( widget->mapCanvas()->mapSettings() )
|
||||
<< new QgsExpressionContextScope( widget->mapCanvas()->expressionContextScope() );
|
||||
}
|
||||
else
|
||||
{
|
||||
expContext << QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );
|
||||
}
|
||||
|
||||
if ( widget->layer() )
|
||||
expContext << QgsExpressionContextUtils::layerScope( widget->layer() );
|
||||
|
||||
return expContext;
|
||||
}
|
||||
@ -99,11 +109,12 @@ QgsSizeScaleWidget::QgsSizeScaleWidget( const QgsVectorLayer * layer, const QgsM
|
||||
// we just use the minimumValue and maximumValue from the layer, unfortunately they are
|
||||
// non const, so we get the layer from the registry instead
|
||||
, mLayer( layer ? dynamic_cast<QgsVectorLayer *>( QgsMapLayerRegistry::instance()->mapLayer( layer->id() ) ) : 0 )
|
||||
, mMapCanvas( 0 )
|
||||
{
|
||||
setupUi( this );
|
||||
setWindowFlags( Qt::WindowStaysOnTopHint );
|
||||
|
||||
mExpressionWidget->registerGetExpressionContextCallback( &_getExpressionContext, mLayer );
|
||||
mExpressionWidget->registerGetExpressionContextCallback( &_getExpressionContext, this );
|
||||
|
||||
if ( mLayer )
|
||||
{
|
||||
|
@ -28,6 +28,7 @@ class QgsMarkerSymbolV2;
|
||||
class QgsLayerTreeLayer;
|
||||
class QgsScaleExpression;
|
||||
class QgsDataDefined;
|
||||
class QgsMapCanvas;
|
||||
|
||||
class GUI_EXPORT QgsSizeScaleWidget : public QgsDataDefinedAssistant, private Ui_SizeScaleBase
|
||||
{
|
||||
@ -38,6 +39,11 @@ class GUI_EXPORT QgsSizeScaleWidget : public QgsDataDefinedAssistant, private Ui
|
||||
|
||||
QgsDataDefined dataDefined() const override;
|
||||
|
||||
/** Returns the vector layer associated with the widget.
|
||||
* @note added in QGIS 2.12
|
||||
*/
|
||||
const QgsVectorLayer* layer() const { return mLayer; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual void showEvent( QShowEvent * ) override;
|
||||
@ -53,6 +59,7 @@ class GUI_EXPORT QgsSizeScaleWidget : public QgsDataDefinedAssistant, private Ui
|
||||
QgsLayerTreeLayer* mLayerTreeLayer;
|
||||
QgsLayerTreeGroup mRoot;
|
||||
QStandardItemModel mPreviewList;
|
||||
QgsMapCanvas* mMapCanvas;
|
||||
|
||||
QgsScaleExpression* createExpression() const;
|
||||
void setFromSymbol();
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "qgsvectorgradientcolorrampv2dialog.h"
|
||||
#include "qgsdatadefined.h"
|
||||
#include "qgsstylev2.h" //for symbol selector dialog
|
||||
|
||||
#include "qgsmapcanvas.h"
|
||||
#include "qgsapplication.h"
|
||||
|
||||
#include "qgslogger.h"
|
||||
@ -57,9 +57,17 @@ static QgsExpressionContext _getExpressionContext( const void* 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 = widget->vectorLayer();
|
||||
if ( layer )
|
||||
@ -75,6 +83,16 @@ void QgsSymbolLayerV2Widget::setMapCanvas( QgsMapCanvas *canvas )
|
||||
{
|
||||
unitWidget->setMapCanvas( mMapCanvas );
|
||||
}
|
||||
Q_FOREACH ( QgsDataDefinedButton* ddButton, findChildren<QgsDataDefinedButton*>() )
|
||||
{
|
||||
if ( ddButton->assistant() )
|
||||
ddButton->assistant()->setMapCanvas( mMapCanvas );
|
||||
}
|
||||
}
|
||||
|
||||
const QgsMapCanvas* QgsSymbolLayerV2Widget::mapCanvas() const
|
||||
{
|
||||
return mMapCanvas;
|
||||
}
|
||||
|
||||
void QgsSymbolLayerV2Widget::registerDataDefinedButton( QgsDataDefinedButton * button, const QString & propertyName, QgsDataDefinedButton::DataType type, const QString & description )
|
||||
|
@ -47,10 +47,17 @@ class GUI_EXPORT QgsSymbolLayerV2Widget : public 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
|
||||
*/
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include "qgsstylev2.h"
|
||||
#include "qgssymbollayerv2utils.h"
|
||||
#include "qgsmarkersymbollayerv2.h"
|
||||
|
||||
#include "qgsmapcanvas.h"
|
||||
#include "qgsapplication.h"
|
||||
|
||||
#include <QString>
|
||||
@ -47,6 +47,7 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbolV2* symbol, QgsStyleV2* sty
|
||||
, mAdvancedMenu( 0 )
|
||||
, mClipFeaturesAction( 0 )
|
||||
, mLayer( layer )
|
||||
, mMapCanvas( 0 )
|
||||
, mPresetExpressionContext( 0 )
|
||||
{
|
||||
setupUi( this );
|
||||
@ -119,10 +120,21 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbolV2* symbol, QgsStyleV2* sty
|
||||
|
||||
void QgsSymbolsListWidget::setMapCanvas( QgsMapCanvas* canvas )
|
||||
{
|
||||
mMapCanvas = canvas;
|
||||
Q_FOREACH ( QgsUnitSelectionWidget* unitWidget, findChildren<QgsUnitSelectionWidget*>() )
|
||||
{
|
||||
unitWidget->setMapCanvas( canvas );
|
||||
}
|
||||
Q_FOREACH ( QgsDataDefinedButton* ddButton, findChildren<QgsDataDefinedButton*>() )
|
||||
{
|
||||
if ( ddButton->assistant() )
|
||||
ddButton->assistant()->setMapCanvas( mMapCanvas );
|
||||
}
|
||||
}
|
||||
|
||||
const QgsMapCanvas*QgsSymbolsListWidget::mapCanvas() const
|
||||
{
|
||||
return mMapCanvas;
|
||||
}
|
||||
|
||||
void QgsSymbolsListWidget::setExpressionContext( QgsExpressionContext *context )
|
||||
@ -385,9 +397,17 @@ static QgsExpressionContext _getExpressionContext( const void* 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 = widget->layer();
|
||||
if ( layer )
|
||||
|
@ -43,10 +43,17 @@ class GUI_EXPORT QgsSymbolsListWidget : public QWidget, private Ui::SymbolsListW
|
||||
/** 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
|
||||
*/
|
||||
@ -93,6 +100,7 @@ class GUI_EXPORT QgsSymbolsListWidget : public QWidget, private Ui::SymbolsListW
|
||||
QMenu* mAdvancedMenu;
|
||||
QAction* mClipFeaturesAction;
|
||||
const QgsVectorLayer* mLayer;
|
||||
QgsMapCanvas* mMapCanvas;
|
||||
|
||||
void populateSymbolView();
|
||||
void populateSymbols( QStringList symbols );
|
||||
|
Loading…
x
Reference in New Issue
Block a user