From dfd8b818573a50dfd78822c53ab483f570fdd4f6 Mon Sep 17 00:00:00 2001 From: Giuseppe Sucameli Date: Sat, 31 Mar 2012 16:02:49 +0200 Subject: [PATCH] [FEATURE] allow multiline feature actions --- src/app/qgisapp.cpp | 2 +- src/app/qgsattributeactiondialog.cpp | 22 +++++++++++----------- src/core/qgsattributeaction.cpp | 2 +- src/python/qgspythonutils.h | 2 +- src/python/qgspythonutilsimpl.cpp | 4 ++-- src/python/qgspythonutilsimpl.h | 2 +- src/ui/qgsattributeactiondialogbase.ui | 17 ++++++++++++++--- 7 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index f5a71e8de6e..2897b48cff2 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -4838,7 +4838,7 @@ class QgsPythonRunnerImpl : public QgsPythonRunner { if ( mPythonUtils && mPythonUtils->isEnabled() ) { - return mPythonUtils->runString( command, messageOnError ); + return mPythonUtils->runString( command, messageOnError, false ); } return false; } diff --git a/src/app/qgsattributeactiondialog.cpp b/src/app/qgsattributeactiondialog.cpp index 3a076e7510e..7a6554242c4 100644 --- a/src/app/qgsattributeactiondialog.cpp +++ b/src/app/qgsattributeactiondialog.cpp @@ -45,7 +45,7 @@ QgsAttributeActionDialog::QgsAttributeActionDialog( QgsAttributeAction* actions, connect( attributeActionTable, SIGNAL( itemSelectionChanged() ), this, SLOT( itemSelectionChanged() ) ); connect( actionName, SIGNAL( textChanged( QString ) ), this, SLOT( updateButtons() ) ); - connect( actionAction, SIGNAL( textChanged( QString ) ), this, SLOT( updateButtons() ) ); + connect( actionAction, SIGNAL( textChanged() ), this, SLOT( updateButtons() ) ); connect( moveUpButton, SIGNAL( clicked() ), this, SLOT( moveUp() ) ); connect( moveDownButton, SIGNAL( clicked() ), this, SLOT( moveDown() ) ); @@ -159,16 +159,16 @@ void QgsAttributeActionDialog::browse() this, tr( "Select an action", "File dialog window title" ) ); if ( !action.isNull() ) - actionAction->insert( action ); + actionAction->insertPlainText( action ); } void QgsAttributeActionDialog::insertExpression() { - QString selText = actionAction->selectedText(); + QString selText = actionAction->textCursor().selectedText(); // edit the selected expression if there's one if ( selText.startsWith( "[%" ) && selText.endsWith( "%]" ) ) - selText = selText.mid( 2, selText.size() - 3 ); + selText = selText.mid( 2, selText.size() - 4 ); // display the expression builder QgsExpressionBuilderDialog dlg( mActions->layer(), selText, this ); @@ -179,7 +179,7 @@ void QgsAttributeActionDialog::insertExpression() //Only add the expression if the user has entered some text. if ( !expression.isEmpty() ) { - actionAction->insert( "[%" + expression + "%]" ); + actionAction->insertPlainText( "[%" + expression + "%]" ); } } } @@ -214,7 +214,7 @@ void QgsAttributeActionDialog::insert( int pos ) // Check to see if the action name and the action have been specified // before proceeding - if ( actionName->text().isEmpty() || actionAction->text().isEmpty() ) + if ( actionName->text().isEmpty() || actionAction->toPlainText().isEmpty() ) { QMessageBox::warning( this, tr( "Missing Information" ), tr( "To create an attribute action, you must provide both a name and the action to perform." ) ); @@ -240,14 +240,14 @@ void QgsAttributeActionDialog::insert( int pos ) if ( pos >= numRows ) { // Expand the table to have a row with index pos - insertRow( pos, ( QgsAction::ActionType ) actionType->currentIndex(), name, actionAction->text(), captureCB->isChecked() ); + insertRow( pos, ( QgsAction::ActionType ) actionType->currentIndex(), name, actionAction->toPlainText(), captureCB->isChecked() ); } else { // Update existing row attributeActionTable->item( pos, 0 )->setText( actionType->currentText() ); attributeActionTable->item( pos, 1 )->setText( name ); - attributeActionTable->item( pos, 2 )->setText( actionAction->text() ); + attributeActionTable->item( pos, 2 )->setText( actionAction->toPlainText() ); attributeActionTable->item( pos, 3 )->setCheckState( captureCB->isChecked() ? Qt::Checked : Qt::Unchecked ); } } @@ -266,7 +266,7 @@ void QgsAttributeActionDialog::update() void QgsAttributeActionDialog::updateButtons() { - bool validNewAction = !actionName->text().isEmpty() && !actionAction->text().isEmpty(); + bool validNewAction = !actionName->text().isEmpty() && !actionAction->toPlainText().isEmpty(); QList selection = attributeActionTable->selectedItems(); bool hasSelection = !selection.isEmpty(); @@ -299,7 +299,7 @@ void QgsAttributeActionDialog::insertField() QString field = "[% \""; field += fieldComboBox->currentText(); field += "\" %]"; - actionAction->insert( field ); + actionAction->insertPlainText( field ); } } @@ -358,7 +358,7 @@ void QgsAttributeActionDialog::rowSelected( int row ) // Only if a populated row was selected actionType->setCurrentIndex( actionType->findText( attributeActionTable->item( row, 0 )->text() ) ); actionName->setText( attributeActionTable->item( row, 1 )->text() ); - actionAction->setText( attributeActionTable->item( row, 2 )->text() ); + actionAction->setPlainText( attributeActionTable->item( row, 2 )->text() ); captureCB->setChecked( attributeActionTable->item( row, 3 )->checkState() == Qt::Checked ); } } diff --git a/src/core/qgsattributeaction.cpp b/src/core/qgsattributeaction.cpp index db17782c8bc..71a4ee3f0df 100644 --- a/src/core/qgsattributeaction.cpp +++ b/src/core/qgsattributeaction.cpp @@ -128,7 +128,7 @@ void QgsAttributeAction::runAction( const QgsAction &action, void ( *executePyth } else { - // TODO: capture output from QgsPythonRunner + // TODO: capture output from QgsPythonRunner (like QgsRunProcess does) QgsPythonRunner::run( action.action() ); } } diff --git a/src/python/qgspythonutils.h b/src/python/qgspythonutils.h index c5bea2b55ab..375a68f8c27 100644 --- a/src/python/qgspythonutils.h +++ b/src/python/qgspythonutils.h @@ -51,7 +51,7 @@ class PYTHON_EXPORT QgsPythonUtils //! run a statement, show an error message on error //! @return true if no error occured - virtual bool runString( const QString& command, QString msgOnError = QString() ) = 0; + virtual bool runString( const QString& command, QString msgOnError = QString(), bool single = true ) = 0; //! run a statement, error reporting is not done //! @return true if no error occured diff --git a/src/python/qgspythonutilsimpl.cpp b/src/python/qgspythonutilsimpl.cpp index 13b90a73e00..f76f9d85d49 100644 --- a/src/python/qgspythonutilsimpl.cpp +++ b/src/python/qgspythonutilsimpl.cpp @@ -172,9 +172,9 @@ bool QgsPythonUtilsImpl::runStringUnsafe( const QString& command, bool single ) return res; } -bool QgsPythonUtilsImpl::runString( const QString& command, QString msgOnError ) +bool QgsPythonUtilsImpl::runString( const QString& command, QString msgOnError, bool single ) { - bool res = runStringUnsafe( command ); + bool res = runStringUnsafe( command, single ); if ( res ) return true; diff --git a/src/python/qgspythonutilsimpl.h b/src/python/qgspythonutilsimpl.h index cee957c5695..1578af8d1a7 100644 --- a/src/python/qgspythonutilsimpl.h +++ b/src/python/qgspythonutilsimpl.h @@ -52,7 +52,7 @@ class QgsPythonUtilsImpl : public QgsPythonUtils //! this command is more advanced as enables error checking etc. //! when an exception is raised, it shows dialog with exception details //! @return true if no error occured - bool runString( const QString& command, QString msgOnError = QString() ); + bool runString( const QString& command, QString msgOnError = QString(), bool single = true ); //! run a statement, error reporting is not done //! @return true if no error occured diff --git a/src/ui/qgsattributeactiondialogbase.ui b/src/ui/qgsattributeactiondialogbase.ui index 4c033ba24de..5e91dd859dd 100644 --- a/src/ui/qgsattributeactiondialogbase.ui +++ b/src/ui/qgsattributeactiondialogbase.ui @@ -236,12 +236,18 @@ - + + + + 0 + 0 + + Enter the action command here - Enter the action here. This can be any program, script or command that is available on your system. When the action is invoked any set of characters that start with a % and then have the name of a field will be replaced by the value of that field. The special characters %% will be replaced by the value of the field that was selected. Double quote marks group text into single arguments to the program, script or command. Double quotes will be ignored if prefixed with a backslash + Enter the action here. This can be any program, script or command that is available on your system. When the action is invoked any set of characters within [% and %] will be evaluated as expression and replaced by its result. Double quote marks group text into single arguments to the program, script or command. Double quotes will be ignored if prefixed with a backslash @@ -380,14 +386,19 @@ attributeActionTable + moveUpButton + moveDownButton removeButton actionType + captureCB actionName actionAction browseButton - captureCB + insertExpressionButton fieldComboBox insertFieldButton + insertButton + updateButton