Skip to content

Commit

Permalink
[FEATURE] Add action to manually validate a processing model
Browse files Browse the repository at this point in the history
Allows users to run a validation over their model, listing any issues
found with the model
  • Loading branch information
nyalldawson committed Apr 14, 2020
1 parent acc6844 commit fd98158
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.cpp
Expand Up @@ -28,6 +28,8 @@
#include "qgsmodelgraphicsscene.h"
#include "qgsmodelcomponentgraphicitem.h"
#include "processing/models/qgsprocessingmodelgroupbox.h"
#include "qgsmessageviewer.h"
#include "qgsmessagebaritem.h"

#include <QShortcut>
#include <QDesktopWidget>
Expand All @@ -39,6 +41,7 @@
#include <QCloseEvent>
#include <QMessageBox>
#include <QUndoView>
#include <QPushButton>

///@cond NOT_STABLE

Expand Down Expand Up @@ -134,6 +137,7 @@ QgsModelDesignerDialog::QgsModelDesignerDialog( QWidget *parent, Qt::WindowFlags
connect( mActionSaveAs, &QAction::triggered, this, [ = ] { saveModel( true ); } );
connect( mActionDeleteComponents, &QAction::triggered, this, &QgsModelDesignerDialog::deleteSelected );
connect( mActionSnapSelected, &QAction::triggered, mView, &QgsModelGraphicsView::snapSelected );
connect( mActionValidate, &QAction::triggered, this, &QgsModelDesignerDialog::validate );

mActionSnappingEnabled->setChecked( settings.value( QStringLiteral( "/Processing/Modeler/enableSnapToGrid" ), false ).toBool() );
connect( mActionSnappingEnabled, &QAction::toggled, this, [ = ]( bool enabled )
Expand Down Expand Up @@ -777,6 +781,38 @@ void QgsModelDesignerDialog::populateZoomToMenu()
}
}

void QgsModelDesignerDialog::validate()
{
QStringList issues;
if ( model()->validate( issues ) )
{
mMessageBar->pushSuccess( QString(), tr( "Model is valid!" ) );
}
else
{
QgsMessageBarItem *messageWidget = mMessageBar->createMessage( QString(), tr( "Model is invalid!" ) );
QPushButton *detailsButton = new QPushButton( tr( "Details" ) );
connect( detailsButton, &QPushButton::clicked, detailsButton, [ = ]
{
QgsMessageViewer *dialog = new QgsMessageViewer( detailsButton );
dialog->setTitle( tr( "Model is Invalid" ) );

QString longMessage = tr( "<p>This model is not valid:</p>" ) + QStringLiteral( "<ul>" );
for ( const QString &issue : issues )
{
longMessage += QStringLiteral( "<li>%1</li>" ).arg( issue );
}
longMessage += QStringLiteral( "</ul>" );

dialog->setMessage( longMessage, QgsMessageOutput::MessageHtml );
dialog->showMessage();
} );
messageWidget->layout()->addWidget( detailsButton );
mMessageBar->clearWidgets();
mMessageBar->pushWidget( messageWidget, Qgis::Warning, 0 );
}
}

bool QgsModelDesignerDialog::isDirty() const
{
return mHasChanged && mUndoStack->index() != -1;
Expand Down
1 change: 1 addition & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.h
Expand Up @@ -143,6 +143,7 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode
void updateWindowTitle();
void deleteSelected();
void populateZoomToMenu();
void validate();

private:

Expand Down
10 changes: 10 additions & 0 deletions src/ui/processing/qgsmodeldesignerdialogbase.ui
Expand Up @@ -58,6 +58,7 @@
<addaction name="separator"/>
<addaction name="mActionExportPython"/>
</widget>
<addaction name="mActionValidate"/>
<addaction name="mActionRun"/>
<addaction name="separator"/>
<addaction name="mActionOpen"/>
Expand Down Expand Up @@ -647,6 +648,15 @@
<string>Add Group Box</string>
</property>
</action>
<action name="mActionValidate">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mIconSuccess.svg</normaloff>:/images/themes/default/mIconSuccess.svg</iconset>
</property>
<property name="text">
<string>Validate Model</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down

0 comments on commit fd98158

Please sign in to comment.