Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] allow multiline feature actions
  • Loading branch information
brushtyler committed Mar 31, 2012
1 parent f9ed6d4 commit dfd8b81
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -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;
}
Expand Down
22 changes: 11 additions & 11 deletions src/app/qgsattributeactiondialog.cpp
Expand Up @@ -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() ) );
Expand Down Expand Up @@ -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 );
Expand All @@ -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 + "%]" );
}
}
}
Expand Down Expand Up @@ -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." ) );
Expand All @@ -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 );
}
}
Expand All @@ -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<QTableWidgetItem *> selection = attributeActionTable->selectedItems();
bool hasSelection = !selection.isEmpty();
Expand Down Expand Up @@ -299,7 +299,7 @@ void QgsAttributeActionDialog::insertField()
QString field = "[% \"";
field += fieldComboBox->currentText();
field += "\" %]";
actionAction->insert( field );
actionAction->insertPlainText( field );
}
}

Expand Down Expand Up @@ -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 );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsattributeaction.cpp
Expand Up @@ -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() );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/python/qgspythonutils.h
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/python/qgspythonutilsimpl.cpp
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/python/qgspythonutilsimpl.h
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions src/ui/qgsattributeactiondialogbase.ui
Expand Up @@ -236,12 +236,18 @@
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="actionAction">
<widget class="QPlainTextEdit" name="actionAction">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Enter the action command here</string>
</property>
<property name="whatsThis">
<string>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</string>
<string>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</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -380,14 +386,19 @@
<layoutdefault spacing="6" margin="11"/>
<tabstops>
<tabstop>attributeActionTable</tabstop>
<tabstop>moveUpButton</tabstop>
<tabstop>moveDownButton</tabstop>
<tabstop>removeButton</tabstop>
<tabstop>actionType</tabstop>
<tabstop>captureCB</tabstop>
<tabstop>actionName</tabstop>
<tabstop>actionAction</tabstop>
<tabstop>browseButton</tabstop>
<tabstop>captureCB</tabstop>
<tabstop>insertExpressionButton</tabstop>
<tabstop>fieldComboBox</tabstop>
<tabstop>insertFieldButton</tabstop>
<tabstop>insertButton</tabstop>
<tabstop>updateButton</tabstop>
</tabstops>
<resources/>
<connections/>
Expand Down

0 comments on commit dfd8b81

Please sign in to comment.