Skip to content
Permalink
Browse files

Merge pull request #35901 from alexbruy/remove-functions

[feature] ability to remove custom functions (fix #27513)
  • Loading branch information
alexbruy committed Apr 30, 2020
2 parents 765aa9c + 075b8eb commit 60d568485df919ba783bf3b32144a9ed3b9c08b2
Showing with 59 additions and 4 deletions.
  1. +36 −2 src/gui/qgsexpressionbuilderwidget.cpp
  2. +1 −0 src/gui/qgsexpressionbuilderwidget.h
  3. +22 −2 src/ui/qgsexpressionbuilder.ui
@@ -78,7 +78,8 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
setupUi( this );

connect( btnRun, &QToolButton::pressed, this, &QgsExpressionBuilderWidget::btnRun_pressed );
connect( btnNewFile, &QToolButton::pressed, this, &QgsExpressionBuilderWidget::btnNewFile_pressed );
connect( btnNewFile, &QPushButton::pressed, this, &QgsExpressionBuilderWidget::btnNewFile_pressed );
connect( btnRemoveFile, &QPushButton::pressed, this, &QgsExpressionBuilderWidget::btnRemoveFile_pressed );
connect( cmbFileNames, &QListWidget::currentItemChanged, this, &QgsExpressionBuilderWidget::cmbFileNames_currentItemChanged );
connect( txtExpressionString, &QgsCodeEditorExpression::textChanged, this, &QgsExpressionBuilderWidget::txtExpressionString_textChanged );
connect( txtPython, &QgsCodeEditorPython::textChanged, this, &QgsExpressionBuilderWidget::txtPython_textChanged );
@@ -150,7 +151,6 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
mShowHelpButton->setEnabled( functionsplit->sizes().at( 1 ) == 0 );
} );


QgsSettings settings;
splitter->restoreState( settings.value( QStringLiteral( "Windows/QgsExpressionBuilderWidget/splitter" ) ).toByteArray() );
editorSplit->restoreState( settings.value( QStringLiteral( "Windows/QgsExpressionBuilderWidget/editorsplitter" ) ).toByteArray() );
@@ -163,6 +163,7 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
{
QgsPythonRunner::eval( QStringLiteral( "qgis.user.expressionspath" ), mFunctionsPath );
updateFunctionFileList( mFunctionsPath );
btnRemoveFile->setEnabled( cmbFileNames->count() > 0 );
}
else
{
@@ -422,6 +423,39 @@ void QgsExpressionBuilderWidget::btnNewFile_pressed()
}
}

void QgsExpressionBuilderWidget::btnRemoveFile_pressed()
{
if ( QMessageBox::question( this, tr( "Remove File" ),
tr( "Are you sure you want to remove current functions file?" ),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) == QMessageBox::No )
return;

int currentRow = cmbFileNames->currentRow();
QString fileName = cmbFileNames->currentItem()->text();
if ( QFile::remove( mFunctionsPath + QDir::separator() + fileName.append( ".py" ) ) )
{
{
QListWidgetItem *itemToRemove = whileBlocking( cmbFileNames )->takeItem( currentRow );
delete itemToRemove;
}

if ( cmbFileNames->count() > 0 )
{
cmbFileNames->setCurrentRow( currentRow > 0 ? currentRow - 1 : 0 );
loadCodeFromFile( mFunctionsPath + QDir::separator() + cmbFileNames->currentItem()->text() );
}
else
{
btnRemoveFile->setEnabled( false );
txtPython->clear();
}
}
else
{
QMessageBox::warning( this, tr( "Remove file" ), tr( "Failed to remove function file '%1'." ).arg( fileName ) );
}
}

void QgsExpressionBuilderWidget::cmbFileNames_currentItemChanged( QListWidgetItem *item, QListWidgetItem *lastitem )
{
if ( lastitem )
@@ -340,6 +340,7 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
void operatorButtonClicked();
void btnRun_pressed();
void btnNewFile_pressed();
void btnRemoveFile_pressed();

/**
* Display a file dialog to choose where to store the exported expressions JSON file
@@ -35,7 +35,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<property name="documentMode">
<bool>true</bool>
@@ -835,7 +835,27 @@ Change the name of the script and save to allow QGIS to auto load on startup.</s
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/console/iconNewTabEditorConsole.svg</normaloff>:/images/themes/default/console/iconNewTabEditorConsole.svg</iconset>
<normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnRemoveFile">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Remove selected functions file.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyRemove.svg</normaloff>:/images/themes/default/symbologyRemove.svg</iconset>
</property>
<property name="iconSize">
<size>

0 comments on commit 60d5684

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