Skip to content

Commit

Permalink
[needs-doc] Add a new button in property menu to create auxiliary fields
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Oct 9, 2017
1 parent fa4777e commit 1cfa215
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/gui/qgspropertyoverridebutton.sip
Expand Up @@ -190,6 +190,11 @@ Emitted when property definition changes
void activated( bool isActive );
%Docstring
Emitted when the activated status of the widget changes
%End

void createAuxiliaryField();
%Docstring
Emitted when creating a new auxiliary field
%End

protected:
Expand Down
21 changes: 21 additions & 0 deletions src/gui/qgspropertyoverridebutton.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgsvectorlayer.h"
#include "qgspanelwidget.h"
#include "qgspropertyassistantwidget.h"
#include "qgsauxiliarystorage.h"

#include <QClipboard>
#include <QMenu>
Expand Down Expand Up @@ -66,6 +67,8 @@ QgsPropertyOverrideButton::QgsPropertyOverrideButton( QWidget *parent,

mActionDescription = new QAction( tr( "Description..." ), this );

mActionCreateAuxiliaryField = new QAction( tr( "Store data in the project" ), this );

mActionExpDialog = new QAction( tr( "Edit..." ), this );
mActionExpression = nullptr;
mActionPasteExpr = new QAction( tr( "Paste" ), this );
Expand Down Expand Up @@ -329,6 +332,20 @@ void QgsPropertyOverrideButton::aboutToShowMenu()

mDefineMenu->addSeparator();

// deactivate button if field yet exists
mDefineMenu->addAction( mActionCreateAuxiliaryField );

const QgsAuxiliaryLayer *alayer = mVectorLayer->auxiliaryLayer();

if ( alayer && alayer->exists( mDefinition ) )
{
mActionCreateAuxiliaryField->setEnabled( false );
}
else
{
mActionCreateAuxiliaryField->setEnabled( true );
}

bool fieldActive = false;
if ( !mDataTypesString.isEmpty() )
{
Expand Down Expand Up @@ -507,6 +524,10 @@ void QgsPropertyOverrideButton::menuActionTriggered( QAction *action )
{
showAssistant();
}
else if ( action == mActionCreateAuxiliaryField )
{
emit createAuxiliaryField();
}
else if ( mFieldsMenu->actions().contains( action ) ) // a field name clicked
{
if ( action->isEnabled() )
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgspropertyoverridebutton.h
Expand Up @@ -203,6 +203,9 @@ class GUI_EXPORT QgsPropertyOverrideButton: public QToolButton
//! Emitted when the activated status of the widget changes
void activated( bool isActive );

//! Emitted when creating a new auxiliary field
void createAuxiliaryField();

protected:
void mouseReleaseEvent( QMouseEvent *event ) override;

Expand Down Expand Up @@ -246,6 +249,7 @@ class GUI_EXPORT QgsPropertyOverrideButton: public QToolButton
QAction *mActionCopyExpr = nullptr;
QAction *mActionClearExpr = nullptr;
QAction *mActionAssistant = nullptr;
QAction *mActionCreateAuxiliaryField = nullptr;

QgsPropertyDefinition mDefinition;

Expand Down

0 comments on commit 1cfa215

Please sign in to comment.