Skip to content
Permalink
Browse files

Add editor widget for editing QgsExpressionContextScope variables

  • Loading branch information
nyalldawson committed Aug 22, 2015
1 parent 05b15dc commit 1c7a5b2dba7118b0b636e8299ccd7bd71b257665
@@ -314,6 +314,7 @@
<file>themes/default/mIconClear.svg</file>
<file>themes/default/mIconClose.png</file>
<file>themes/default/mIconCollapse.png</file>
<file>themes/default/mIconCollapseSmall.svg</file>
<file>themes/default/mIconColorBox.svg</file>
<file>themes/default/mIconColorPicker.svg</file>
<file>themes/default/mIconColorSwatches.svg</file>
@@ -333,6 +334,7 @@
<file>themes/default/mIconEditable.png</file>
<file>themes/default/mIconEditableEdits.png</file>
<file>themes/default/mIconExpand.png</file>
<file>themes/default/mIconExpandSmall.svg</file>
<file>themes/default/mIconExpression.svg</file>
<file>themes/default/mIconExpressionEditorOpen.svg</file>
<file>themes/default/mIconExpressionFilter.svg</file>
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="14"
height="14"
id="svg2"
version="1.1"
inkscape:version="0.48.5 r10040"
sodipodi:docname="New document 1">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="22.627417"
inkscape:cx="9.8576035"
inkscape:cy="9.6322253"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
showguides="false"
inkscape:snap-global="false"
inkscape:window-width="1114"
inkscape:window-height="630"
inkscape:window-x="190"
inkscape:window-y="52"
inkscape:window-maximized="0">
<inkscape:grid
type="xygrid"
id="grid2985"
empspacing="5"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-1038.3622)">
<path
style="fill:#4d4d4d;stroke:none"
d="m 2.032932,1042.3744 10.032077,0 0,0.9722 -4.9939412,6.0546 -5.0381358,-6.0546 z"
id="path2998"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccc" />
<path
style="fill:#808080;stroke:none"
d="m 3.4029514,1043.3908 7.3804266,0 -3.7123102,4.4636 z"
id="path3768"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccc" />
</g>
</svg>
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="14"
height="14"
id="svg2"
version="1.1"
inkscape:version="0.48.5 r10040"
sodipodi:docname="mIconCollapseSmall.svg">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="22.627417"
inkscape:cx="9.8576035"
inkscape:cy="9.6322253"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
showguides="false"
inkscape:snap-global="false"
inkscape:window-width="1114"
inkscape:window-height="630"
inkscape:window-x="190"
inkscape:window-y="52"
inkscape:window-maximized="0">
<inkscape:grid
type="xygrid"
id="grid2985"
empspacing="5"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-1038.3622)">
<path
style="fill:#4d4d4d;stroke:none"
d="m 3.9775122,1050.3735 0,-10.032 0.9722,0 6.0546008,4.9939 -6.0546008,5.0381 z"
id="path2998"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccc" />
<path
style="fill:#808080;stroke:none"
d="m 4.9939122,1049.0035 0,-7.3804 4.4636,3.7123 z"
id="path3768"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccc" />
</g>
</svg>
@@ -118,6 +118,7 @@
%Include qgssvgannotationitem.sip
%Include qgstextannotationitem.sip
%Include qgsuserinputdockwidget.sip
%Include qgsvariableeditorwidget.sip
%Include qgsvectorlayertools.sip
%Include qgsvertexmarker.sip

@@ -0,0 +1,90 @@
/** \ingroup gui
* \class QgsVariableEditorWidget
* A tree based widget for editing expression context scope variables. The widget allows editing
* variables from a QgsExpressionContextScope, and can optionally also show inherited
* variables from a QgsExpressionContext.
* \note added in QGIS 2.12
*/

class QgsVariableEditorWidget : QWidget
{
%TypeHeaderCode
#include <qgsvariableeditorwidget.h>
%End

public:

/** Constructor for QgsVariableEditorWidget.
* @param parent parent widget
*/
QgsVariableEditorWidget( QWidget *parent /TransferThis/ = 0 );

~QgsVariableEditorWidget();

/** Overwrites the QgsExpressionContext for the widget. Setting a context
* allows the widget to show all inherited variables for the context,
* and highlight any overriden variables within scopes.
* @param context expression context
* @see context()
*/
void setContext( QgsExpressionContext* context );

/** Returns the current expression context for the widget. QgsVariableEditorWidget widgets
* are created with an empty context by default.
* @see setContext()
*/
QgsExpressionContext* context() const;

/** Reloads all scopes from the editor's current context. This method should be called
* after adding or removing scopes from the attached context.
* @see context()
*/
void reloadContext();

/** Sets the editable scope for the widget. Only variables from the editable scope can
* be modified by users.
* @param scopeIndex index of current editable scope. Set to -1 to disable
* editing and make the widget read-only.
* @see editableScope()
*/
void setEditableScopeIndex( int scopeIndex );

/** Returns the current editable scope for the widget.
* @returns editable scope, or 0 if no editable scope is set
* @see setEditableScopeIndex()
*/
QgsExpressionContextScope* editableScope() const;

/** Sets the setting group for the widget. QgsVariableEditorWidget widgets with
* the same setting group will synchronise their settings, eg the size
* of columns in the tree widget.
* @param group setting group
* @see settingGroup()
*/
void setSettingGroup( const QString &group );

/** Returns the setting group for the widget. QgsVariableEditorWidget widgets with
* the same setting group will synchronise their settings, eg the size
* of columns in the tree widget.
* @returns setting group name
* @see setSettingGroup()
*/
QString settingGroup() const;

/** Returns a map variables set within the editable scope. Read only variables are not
* returned. This method can be used to retrieve the variables edited an added by
* users via the widget.
*/
QgsStringMap variablesInActiveScope() const;

signals:

/** Emitted when the user has modified a scope using the widget.
*/
void scopeChanged();

protected:

void showEvent( QShowEvent *event );

};
@@ -39,6 +39,7 @@
#include "qgscolorschemeregistry.h"
#include "qgssymbollayerv2utils.h"
#include "qgscolordialog.h"
#include "qgsexpressioncontext.h"

#include <QInputDialog>
#include <QFileDialog>
@@ -838,6 +839,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
// load gdal driver list only when gdal tab is first opened
mLoadedGdalDriverList = false;

mVariableEditor->context()->appendScope( QgsExpressionContextUtils::globalScope() );
mVariableEditor->reloadContext();
mVariableEditor->setEditableScopeIndex( 0 );

// restore window and widget geometry/state
restoreOptionsBaseUi();
}
@@ -1333,6 +1338,9 @@ void QgsOptions::saveOptions()
// TODO[MD] QgisApp::instance()->legend()->updateLegendItemSymbologies();
}

//save variables
QgsExpressionContextUtils::setGlobalVariables( mVariableEditor->variablesInActiveScope() );

// save app stylesheet last (in case reset becomes necessary)
if ( mStyleSheetNewOpts != mStyleSheetOldOpts )
{
@@ -29,6 +29,8 @@

#include <QList>

class QgsExpressionContext;

/**
* \class QgsOptions
* \brief Set user options and preferences
@@ -48,6 +48,7 @@
#include "qgscolorschemeregistry.h"
#include "qgssymbollayerv2utils.h"
#include "qgscolordialog.h"
#include "qgsexpressioncontext.h"

//qt includes
#include <QInputDialog>
@@ -524,6 +525,11 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
on_cbxProjectionEnabled_toggled( myProjectionEnabled );
}

mVariableEditor->context()->appendScope( QgsExpressionContextUtils::globalScope() );
mVariableEditor->context()->appendScope( QgsExpressionContextUtils::projectScope() );
mVariableEditor->reloadContext();
mVariableEditor->setEditableScopeIndex( 1 );

projectionSelectorInitialized();
restoreOptionsBaseUi();
restoreState();
@@ -919,6 +925,9 @@ void QgsProjectProperties::apply()

QgsProject::instance()->relationManager()->setRelations( mRelationManagerDlg->relations() );

//save variables
QgsExpressionContextUtils::setProjectVariables( mVariableEditor->variablesInActiveScope() );

emit refresh();
}

@@ -26,6 +26,7 @@
class QgsMapCanvas;
class QgsRelationManagerDialog;
class QgsStyleV2;
class QgsExpressionContext;

/** Dialog to set project level properties
@@ -234,6 +234,7 @@ SET(QGIS_GUI_SRCS
qgssvgannotationitem.cpp
qgstextannotationitem.cpp
qgsuserinputdockwidget.cpp
qgsvariableeditorwidget.cpp
qgsvertexmarker.cpp
qgsunitselectionwidget.cpp
)
@@ -351,6 +352,7 @@ SET(QGIS_GUI_MOC_HDRS
qgssearchquerybuilder.h
qgsslider.h
qgssublayersdialog.h
qgsvariableeditorwidget.h
qgsunitselectionwidget.h
qgsuserinputdockwidget.h

0 comments on commit 1c7a5b2

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