Skip to content

Commit

Permalink
[processing] Add a 'New Model' action to model designer dialog
Browse files Browse the repository at this point in the history
The dialog had all the standard open/save/save as actions, but was
missing the ability to directly create a new model within the
dialog itself.
  • Loading branch information
nyalldawson committed Feb 7, 2022
1 parent 8f34557 commit b8cd9c1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ QgsModelDesignerDialog::QgsModelDesignerDialog( QWidget *parent, Qt::WindowFlags
QgsSettings settings;

connect( mActionClose, &QAction::triggered, this, &QWidget::close );
connect( mActionNew, &QAction::triggered, this, &QgsModelDesignerDialog::newModel );
connect( mActionZoomIn, &QAction::triggered, this, &QgsModelDesignerDialog::zoomIn );
connect( mActionZoomOut, &QAction::triggered, this, &QgsModelDesignerDialog::zoomOut );
connect( mActionZoomActual, &QAction::triggered, this, &QgsModelDesignerDialog::zoomActual );
Expand Down Expand Up @@ -636,6 +637,16 @@ void QgsModelDesignerDialog::zoomFull()
mView->fitInView( totalRect, Qt::KeepAspectRatio );
}

void QgsModelDesignerDialog::newModel()
{
if ( !checkForUnsavedChanges() )
return;

std::unique_ptr< QgsProcessingModelAlgorithm > alg = std::make_unique< QgsProcessingModelAlgorithm >();
alg->setProvider( QgsApplication::processingRegistry()->providerById( QStringLiteral( "model" ) ) );
setModel( alg.release() );
}

void QgsModelDesignerDialog::exportToImage()
{
QString filename = QFileDialog::getSaveFileName( this, tr( "Save Model as Image" ), tr( "PNG files (*.png *.PNG)" ) );
Expand Down
1 change: 1 addition & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode
void zoomOut();
void zoomActual();
void zoomFull();
void newModel();
void exportToImage();
void exportToPdf();
void exportToSvg();
Expand Down
11 changes: 11 additions & 0 deletions src/ui/processing/qgsmodeldesignerdialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<addaction name="mActionRun"/>
<addaction name="mActionReorderInputs"/>
<addaction name="separator"/>
<addaction name="mActionNew"/>
<addaction name="mActionOpen"/>
<addaction name="mActionSave"/>
<addaction name="mActionSaveAs"/>
Expand Down Expand Up @@ -112,6 +113,7 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionNew"/>
<addaction name="mActionOpen"/>
<addaction name="mActionSave"/>
<addaction name="mActionSaveAs"/>
Expand Down Expand Up @@ -745,6 +747,15 @@
<string>V</string>
</property>
</action>
<action name="mActionNew">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFileNew.svg</normaloff>:/images/themes/default/mActionFileNew.svg</iconset>
</property>
<property name="text">
<string>New Model…</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down

0 comments on commit b8cd9c1

Please sign in to comment.