mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-06 00:03:16 -05:00
Move some model designer code to c++
This commit is contained in:
parent
7f4fe65bee
commit
133bad76ee
@ -94,6 +94,8 @@ Raise, unminimize and activate this window.
|
|||||||
|
|
||||||
virtual bool saveModel( bool saveAs = false ) = 0;
|
virtual bool saveModel( bool saveAs = false ) = 0;
|
||||||
|
|
||||||
|
virtual QgsProcessingAlgorithmDialogBase *createExecutionDialog() = 0 /TransferBack/;
|
||||||
|
|
||||||
QToolBar *toolbar();
|
QToolBar *toolbar();
|
||||||
QAction *actionOpen();
|
QAction *actionOpen();
|
||||||
QAction *actionSaveInProject();
|
QAction *actionSaveInProject();
|
||||||
|
|||||||
@ -94,6 +94,8 @@ Raise, unminimize and activate this window.
|
|||||||
|
|
||||||
virtual bool saveModel( bool saveAs = false ) = 0;
|
virtual bool saveModel( bool saveAs = false ) = 0;
|
||||||
|
|
||||||
|
virtual QgsProcessingAlgorithmDialogBase *createExecutionDialog() = 0 /TransferBack/;
|
||||||
|
|
||||||
QToolBar *toolbar();
|
QToolBar *toolbar();
|
||||||
QAction *actionOpen();
|
QAction *actionOpen();
|
||||||
QAction *actionSaveInProject();
|
QAction *actionSaveInProject();
|
||||||
|
|||||||
@ -100,7 +100,6 @@ class ModelerDialog(QgsModelDesignerDialog):
|
|||||||
|
|
||||||
self.actionOpen().triggered.connect(self.openModel)
|
self.actionOpen().triggered.connect(self.openModel)
|
||||||
self.actionSaveInProject().triggered.connect(self.saveInProject)
|
self.actionSaveInProject().triggered.connect(self.saveInProject)
|
||||||
self.actionRun().triggered.connect(self.runModel)
|
|
||||||
|
|
||||||
if model is not None:
|
if model is not None:
|
||||||
_model = model.create()
|
_model = model.create()
|
||||||
@ -122,37 +121,9 @@ class ModelerDialog(QgsModelDesignerDialog):
|
|||||||
|
|
||||||
self.context_generator = ContextGenerator(self.processing_context)
|
self.context_generator = ContextGenerator(self.processing_context)
|
||||||
|
|
||||||
def runModel(self):
|
def createExecutionDialog(self):
|
||||||
valid, errors = self.model().validate()
|
|
||||||
if not valid:
|
|
||||||
message_box = QMessageBox()
|
|
||||||
message_box.setWindowTitle(self.tr('Model is Invalid'))
|
|
||||||
message_box.setIcon(QMessageBox.Icon.Warning)
|
|
||||||
message_box.setText(self.tr('This model is not valid and contains one or more issues. Are you sure you want to run it in this state?'))
|
|
||||||
message_box.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.Cancel)
|
|
||||||
message_box.setDefaultButton(QMessageBox.StandardButton.Cancel)
|
|
||||||
|
|
||||||
error_string = ''
|
|
||||||
for e in errors:
|
|
||||||
e = re.sub(r'<[^>]*>', '', e)
|
|
||||||
error_string += f'• {e}\n'
|
|
||||||
|
|
||||||
message_box.setDetailedText(error_string)
|
|
||||||
if message_box.exec() == QMessageBox.StandardButton.Cancel:
|
|
||||||
return
|
|
||||||
|
|
||||||
def on_finished(successful, results):
|
|
||||||
self.setLastRunChildAlgorithmResults(dlg.results().get('CHILD_RESULTS', {}))
|
|
||||||
self.setLastRunChildAlgorithmInputs(dlg.results().get('CHILD_INPUTS', {}))
|
|
||||||
|
|
||||||
dlg = AlgorithmDialog(self.model().create(), parent=self)
|
dlg = AlgorithmDialog(self.model().create(), parent=self)
|
||||||
dlg.setLogLevel(QgsProcessingContext.LogLevel.ModelDebug)
|
return dlg
|
||||||
dlg.setParameters(self.model().designerParameterValues())
|
|
||||||
dlg.algorithmFinished.connect(on_finished)
|
|
||||||
dlg.exec()
|
|
||||||
|
|
||||||
if dlg.wasExecuted():
|
|
||||||
self.model().setDesignerParameterValues(dlg.createProcessingParameters(flags=QgsProcessingParametersGenerator.Flags(QgsProcessingParametersGenerator.Flag.SkipDefaultValueParameters)))
|
|
||||||
|
|
||||||
def saveInProject(self):
|
def saveInProject(self):
|
||||||
if not self.validateSave(QgsModelDesignerDialog.SaveAction.SaveInProject):
|
if not self.validateSave(QgsModelDesignerDialog.SaveAction.SaveInProject):
|
||||||
|
|||||||
@ -38,7 +38,7 @@
|
|||||||
#include "qgsprocessinghelpeditorwidget.h"
|
#include "qgsprocessinghelpeditorwidget.h"
|
||||||
#include "qgsscreenhelper.h"
|
#include "qgsscreenhelper.h"
|
||||||
#include "qgsmessagelog.h"
|
#include "qgsmessagelog.h"
|
||||||
|
#include "qgsprocessingalgorithmdialogbase.h"
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
@ -157,6 +157,7 @@ QgsModelDesignerDialog::QgsModelDesignerDialog( QWidget *parent, Qt::WindowFlags
|
|||||||
connect( mActionReorderOutputs, &QAction::triggered, this, &QgsModelDesignerDialog::reorderOutputs );
|
connect( mActionReorderOutputs, &QAction::triggered, this, &QgsModelDesignerDialog::reorderOutputs );
|
||||||
connect( mActionEditHelp, &QAction::triggered, this, &QgsModelDesignerDialog::editHelp );
|
connect( mActionEditHelp, &QAction::triggered, this, &QgsModelDesignerDialog::editHelp );
|
||||||
connect( mReorderInputsButton, &QPushButton::clicked, this, &QgsModelDesignerDialog::reorderInputs );
|
connect( mReorderInputsButton, &QPushButton::clicked, this, &QgsModelDesignerDialog::reorderInputs );
|
||||||
|
connect( mActionRun, &QAction::triggered, this, &QgsModelDesignerDialog::run );
|
||||||
|
|
||||||
mActionSnappingEnabled->setChecked( settings.value( QStringLiteral( "/Processing/Modeler/enableSnapToGrid" ), false ).toBool() );
|
mActionSnappingEnabled->setChecked( settings.value( QStringLiteral( "/Processing/Modeler/enableSnapToGrid" ), false ).toBool() );
|
||||||
connect( mActionSnappingEnabled, &QAction::toggled, this, [ = ]( bool enabled )
|
connect( mActionSnappingEnabled, &QAction::toggled, this, [ = ]( bool enabled )
|
||||||
@ -994,6 +995,52 @@ void QgsModelDesignerDialog::editHelp()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsModelDesignerDialog::run()
|
||||||
|
{
|
||||||
|
QStringList errors;
|
||||||
|
const bool isValid = model()->validate( errors );
|
||||||
|
if ( !isValid )
|
||||||
|
{
|
||||||
|
QMessageBox messageBox;
|
||||||
|
messageBox.setWindowTitle( tr( "Model is Invalid" ) );
|
||||||
|
messageBox.setIcon( QMessageBox::Icon::Warning );
|
||||||
|
messageBox.setText( tr( "This model is not valid and contains one or more issues. Are you sure you want to run it in this state?" ) );
|
||||||
|
messageBox.setStandardButtons( QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::Cancel );
|
||||||
|
messageBox.setDefaultButton( QMessageBox::StandardButton::Cancel );
|
||||||
|
|
||||||
|
QString errorString;
|
||||||
|
for ( const QString &error : std::as_const( errors ) )
|
||||||
|
{
|
||||||
|
QString cleanedError = error;
|
||||||
|
const thread_local QRegularExpression re( QStringLiteral( "<[^>]*>" ) );
|
||||||
|
cleanedError.replace( re, QString() );
|
||||||
|
errorString += QStringLiteral( "• %1\n" ).arg( cleanedError );
|
||||||
|
}
|
||||||
|
|
||||||
|
messageBox.setDetailedText( errorString );
|
||||||
|
if ( messageBox.exec() == QMessageBox::StandardButton::Cancel )
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr< QgsProcessingAlgorithmDialogBase > dialog( createExecutionDialog() );
|
||||||
|
if ( !dialog )
|
||||||
|
return;
|
||||||
|
|
||||||
|
dialog->setLogLevel( Qgis::ProcessingLogLevel::ModelDebug );
|
||||||
|
dialog->setParameters( mModel->designerParameterValues() );
|
||||||
|
|
||||||
|
connect( dialog.get(), &QgsProcessingAlgorithmDialogBase::algorithmFinished, this, [this, &dialog]( bool, const QVariantMap & )
|
||||||
|
{
|
||||||
|
const QVariantMap dialogResults = dialog->results();
|
||||||
|
setLastRunChildAlgorithmResults( dialogResults.value( QStringLiteral( "CHILD_RESULTS" ), QVariantMap() ).toMap() );
|
||||||
|
setLastRunChildAlgorithmInputs( dialogResults.value( QStringLiteral( "CHILD_INPUTS" ), QVariantMap() ).toMap() );
|
||||||
|
|
||||||
|
mModel->setDesignerParameterValues( dialog->createProcessingParameters( QgsProcessingParametersGenerator::Flag::SkipDefaultValueParameters ) );
|
||||||
|
} );
|
||||||
|
|
||||||
|
dialog->exec();
|
||||||
|
}
|
||||||
|
|
||||||
void QgsModelDesignerDialog::validate()
|
void QgsModelDesignerDialog::validate()
|
||||||
{
|
{
|
||||||
QStringList issues;
|
QStringList issues;
|
||||||
|
|||||||
@ -30,6 +30,7 @@ class QUndoView;
|
|||||||
class QgsModelViewToolPan;
|
class QgsModelViewToolPan;
|
||||||
class QgsModelViewToolSelect;
|
class QgsModelViewToolSelect;
|
||||||
class QgsScreenHelper;
|
class QgsScreenHelper;
|
||||||
|
class QgsProcessingAlgorithmDialogBase;
|
||||||
|
|
||||||
///@cond NOT_STABLE
|
///@cond NOT_STABLE
|
||||||
|
|
||||||
@ -126,6 +127,8 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode
|
|||||||
virtual void exportAsScriptAlgorithm() = 0;
|
virtual void exportAsScriptAlgorithm() = 0;
|
||||||
// cppcheck-suppress pureVirtualCall
|
// cppcheck-suppress pureVirtualCall
|
||||||
virtual bool saveModel( bool saveAs = false ) = 0;
|
virtual bool saveModel( bool saveAs = false ) = 0;
|
||||||
|
// cppcheck-suppress pureVirtualCall
|
||||||
|
virtual QgsProcessingAlgorithmDialogBase *createExecutionDialog() = 0 SIP_TRANSFERBACK;
|
||||||
|
|
||||||
QToolBar *toolbar() { return mToolbar; }
|
QToolBar *toolbar() { return mToolbar; }
|
||||||
QAction *actionOpen() { return mActionOpen; }
|
QAction *actionOpen() { return mActionOpen; }
|
||||||
@ -186,6 +189,7 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode
|
|||||||
void reorderOutputs();
|
void reorderOutputs();
|
||||||
void setPanelVisibility( bool hidden );
|
void setPanelVisibility( bool hidden );
|
||||||
void editHelp();
|
void editHelp();
|
||||||
|
void run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user