Skip to content
Permalink
Browse files

Add assistant support to QgsDataDefinedButton

  • Loading branch information
vmora authored and nyalldawson committed Apr 27, 2015
1 parent cf3a712 commit 6a8526f91c09b013e135fe4a2648320fd8a70a45
Showing with 93 additions and 3 deletions.
  1. +30 −1 python/gui/qgsdatadefinedbutton.sip
  2. +35 −0 src/gui/qgsdatadefinedbutton.cpp
  3. +28 −2 src/gui/qgsdatadefinedbutton.h
@@ -1,4 +1,24 @@
class QgsDataDefinedButton : QToolButton
/** \ingroup gui
* \class QgsDataDefinedAssistant
* An assistant (wizard) dialog, accessible from a QgsDataDefinedButton.
* Can be used to guide users through creation of an expression for the
* data defined button.
* @note added in 2.10
*/
class QgsDataDefinedAssistant: QDialog
{
%TypeHeaderCode
#include <qgsdatadefinedbutton.h>
%End
public:
virtual QgsDataDefined* dataDefined() const = 0 /Factory/;
};

/** \ingroup gui
* \class QgsDataDefinedButton
* A button for defining data source field mappings or expressions.
*/
class QgsDataDefinedButton : QToolButton
{
%TypeHeaderCode
#include <qgsdatadefinedbutton.h>
@@ -135,6 +155,15 @@ class QgsDataDefinedButton : QToolButton
*/
void clearCheckedWidgets();

/**
* Sets an assistant used to define the data defined object properties.
* Ownership of the assistant is transferred to the widget.
* @param assistant data defined assistant. Set to null to remove the assistant
* option from the button.
* @note added in 2.10
*/
void setAssistant( QgsDataDefinedAssistant * assistant /Transfer/ );

/**
* Common descriptions for expected input values
*/
@@ -84,6 +84,7 @@ QgsDataDefinedButton::QgsDataDefinedButton( QWidget* parent,
mActionPasteExpr = new QAction( tr( "Paste" ), this );
mActionCopyExpr = new QAction( tr( "Copy" ), this );
mActionClearExpr = new QAction( tr( "Clear" ), this );
mActionAssistant = new QAction( tr( "Assistant..." ), this );

// set up sibling widget connections
connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( disableEnabledWidgets( bool ) ) );
@@ -322,6 +323,11 @@ void QgsDataDefinedButton::aboutToShowMenu()
mDefineMenu->addAction( mActionPasteExpr );
}

if ( mAssistant.data() )
{
mDefineMenu->addSeparator();
mDefineMenu->addAction( mActionAssistant );
}
}

void QgsDataDefinedButton::menuActionTriggered( QAction* action )
@@ -371,6 +377,10 @@ void QgsDataDefinedButton::menuActionTriggered( QAction* action )
setExpression( QString( "" ) );
updateGui();
}
else if ( action == mActionAssistant )
{
showAssistant();
}
else if ( mFieldsMenu->actions().contains( action ) ) // a field name clicked
{
if ( action->isEnabled() )
@@ -394,6 +404,25 @@ void QgsDataDefinedButton::showDescriptionDialog()
mv->exec();
}

void QgsDataDefinedButton::showAssistant()
{
if ( !mAssistant.data() )
return;

if ( mAssistant->exec() == QDialog::Accepted )
{
QScopedPointer<QgsDataDefined> dd( mAssistant->dataDefined() );
setUseExpression( dd->useExpression() );
setActive( dd->isActive() );
if ( dd->isActive() && dd->useExpression() )
setExpression( dd->expressionString() );
else if ( dd->isActive() )
setField( dd->field() );
updateGui();
}
activateWindow(); // reset focus to parent window
}

void QgsDataDefinedButton::showExpressionDialog()
{
QgsExpressionBuilderDialog d( const_cast<QgsVectorLayer*>( mVectorLayer ), getExpression() );
@@ -576,6 +605,12 @@ QList<QWidget*> QgsDataDefinedButton::registeredCheckedWidgets()
return wdgtList;
}

void QgsDataDefinedButton::setAssistant( QgsDataDefinedAssistant *assistant )
{
mAssistant.reset( assistant );
mAssistant.data()->setParent( this, Qt::Dialog );
}

void QgsDataDefinedButton::checkCheckedWidgets( bool check )
{
// don't uncheck, only set to checked
@@ -15,15 +15,29 @@
#ifndef QGSDATADEFINEDBUTTON_H
#define QGSDATADEFINEDBUTTON_H

#include "qgsfield.h"
#include <QDialog>
#include <QFlags>
#include <QMap>
#include <QPointer>
#include <QToolButton>
#include <QScopedPointer>

class QgsVectorLayer;
class QgsDataDefined;

/** \ingroup gui
* \class QgsDataDefinedAssistant
* An assistant (wizard) dialog, accessible from a QgsDataDefinedButton.
* Can be used to guide users through creation of an expression for the
* data defined button.
* @note added in 2.10
*/
class GUI_EXPORT QgsDataDefinedAssistant: public QDialog
{
public:
virtual QgsDataDefined* dataDefined() const = 0;
};

/** \ingroup gui
* \class QgsDataDefinedButton
* A button for defining data source field mappings or expressions.
@@ -166,6 +180,15 @@ class GUI_EXPORT QgsDataDefinedButton: public QToolButton
*/
void clearCheckedWidgets() { mCheckedWidgets.clear(); }

/**
* Sets an assistant used to define the data defined object properties.
* Ownership of the assistant is transferred to the widget.
* @param assistant data defined assistant. Set to null to remove the assistant
* option from the button.
* @note added in 2.10
*/
void setAssistant( QgsDataDefinedAssistant * assistant );

/**
* Common descriptions for expected input values
*/
@@ -254,10 +277,10 @@ class GUI_EXPORT QgsDataDefinedButton: public QToolButton
private:
void showDescriptionDialog();
void showExpressionDialog();
void showAssistant();
void updateGui();

const QgsVectorLayer* mVectorLayer;
QgsFields mFields;
QStringList mFieldNameList;
QStringList mFieldTypeList;
QMap< QString, QString > mProperty;
@@ -275,6 +298,7 @@ class GUI_EXPORT QgsDataDefinedButton: public QToolButton
QAction* mActionPasteExpr;
QAction* mActionCopyExpr;
QAction* mActionClearExpr;
QAction* mActionAssistant;

DataTypes mDataTypes;
QString mDataTypesString;
@@ -283,6 +307,8 @@ class GUI_EXPORT QgsDataDefinedButton: public QToolButton
QString mUsageInfo;
QString mCurrentDefinition;

QScopedPointer<QgsDataDefinedAssistant> mAssistant;

static QIcon mIconDataDefine;
static QIcon mIconDataDefineOn;
static QIcon mIconDataDefineError;

0 comments on commit 6a8526f

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