Skip to content
Permalink
Browse files

Hookup toggle to hide comments from model designer

  • Loading branch information
nyalldawson committed Mar 6, 2020
1 parent 08b47a4 commit 0b3f7a58c197974a2d3681b839f054509949e95d
@@ -36,6 +36,7 @@ QGraphicsScene subclass representing the model designer.
enum Flag
{
FlagHideControls,
FlagHideComments,
};
typedef QFlags<QgsModelGraphicsScene::Flag> Flags;

@@ -38,10 +38,10 @@
QgsApplication,
QgsProcessing,
QgsProject,
QgsSettings,
QgsMessageLog,
QgsProcessingModelAlgorithm,
QgsProcessingModelParameter,
QgsSettings
)
from qgis.gui import (QgsProcessingParameterDefinitionDialog,
QgsProcessingParameterWidgetContext,
@@ -102,9 +102,6 @@ def __init__(self, model=None, parent=None):
self.actionEditHelp().triggered.connect(self.editHelp)
self.actionRun().triggered.connect(self.runModel)

# self.mActionShowComments.toggled.connect(self.showComments)
# self.mActionShowComments.setChecked(settings.value("/Processing/stateModeler", self.saveState())))

if model is not None:
self._model = model.create()
self._model.setSourceFilePath(model.sourceFilePath())
@@ -135,7 +132,7 @@ def runModel(self):
if len(self.model().childAlgorithms()) == 0:
self.messageBar().pushMessage("", self.tr(
"Model doesn't contain any algorithm and/or parameter and can't be executed"), level=Qgis.Warning,
duration=5)
duration=5)
return

dlg = AlgorithmDialog(self.model().create(), parent=self)
@@ -208,7 +205,7 @@ def saveModel(self, saveAs):
if saveAs:
self.messageBar().pushMessage("", self.tr("Model was correctly saved to <a href=\"{}\">{}</a>").format(
QUrl.fromLocalFile(filename).toString(), QDir.toNativeSeparators(filename)), level=Qgis.Success,
duration=5)
duration=5)
else:
self.messageBar().pushMessage("", self.tr("Model was correctly saved"), level=Qgis.Success, duration=5)

@@ -251,6 +248,10 @@ def repaintModel(self, showControls=True):
if not showControls:
self.scene.setFlag(QgsModelGraphicsScene.FlagHideControls)

showComments = QgsSettings().value("/Processing/Modeler/ShowComments", True, bool)
if not showComments:
self.scene.setFlag(QgsModelGraphicsScene.FlagHideComments)

context = createContext()
self.scene.createItems(self.model(), context)
self.view().setScene(self.scene)
@@ -161,6 +161,9 @@ QgsModelDesignerDialog::QgsModelDesignerDialog( QWidget *parent, Qt::WindowFlags
toolbuttonExportToScript->setDefaultAction( mActionExportAsScriptAlgorithm );
mToolbar->insertWidget( mActionExportImage, toolbuttonExportToScript );
connect( mActionExportAsScriptAlgorithm, &QAction::triggered, this, &QgsModelDesignerDialog::exportAsScriptAlgorithm );

mActionShowComments->setChecked( settings.value( QStringLiteral( "/Processing/Modeler/ShowComments" ), true ).toBool() );
connect( mActionShowComments, &QAction::toggled, this, &QgsModelDesignerDialog::toggleComments );
}

void QgsModelDesignerDialog::closeEvent( QCloseEvent *event )
@@ -219,7 +222,6 @@ void QgsModelDesignerDialog::zoomIn()
const double factor = settings.value( QStringLiteral( "/qgis/zoom_favor" ), 2.0 ).toDouble();
mView->scale( factor, factor );
mView->centerOn( point );
repaintModel();
}

void QgsModelDesignerDialog::zoomOut()
@@ -230,7 +232,6 @@ void QgsModelDesignerDialog::zoomOut()
const double factor = 1.0 / settings.value( QStringLiteral( "/qgis/zoom_favor" ), 2.0 ).toDouble();
mView->scale( factor, factor );
mView->centerOn( point );
repaintModel();
}

void QgsModelDesignerDialog::zoomActual()
@@ -355,6 +356,13 @@ void QgsModelDesignerDialog::exportAsPython()
mMessageBar->pushMessage( QString(), tr( "Successfully exported model as Python script to <a href=\"{}\">{}</a>" ).arg( QUrl::fromLocalFile( filename ).toString(), QDir::toNativeSeparators( filename ) ), Qgis::Success, 5 );
}

void QgsModelDesignerDialog::toggleComments( bool show )
{
QgsSettings().setValue( QStringLiteral( "/Processing/Modeler/ShowComments" ), show );

repaintModel( true );
}

void QgsModelDesignerDialog::fillInputsTree()
{
const QIcon icon = QgsApplication::getThemeIcon( QStringLiteral( "mIconModelInput.svg" ) );
@@ -87,6 +87,7 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode
void exportToPdf();
void exportToSvg();
void exportAsPython();
void toggleComments( bool show );

private:

@@ -257,7 +257,7 @@ QList<QgsModelGraphicsScene::LinkSource> QgsModelGraphicsScene::linkSourcesForPa

void QgsModelGraphicsScene::addCommentItemForComponent( QgsProcessingModelAlgorithm *model, const QgsProcessingModelComponent &component, QgsModelComponentGraphicItem *parentItem )
{
if ( !component.comment() || component.comment()->description().isEmpty() )
if ( mFlags & FlagHideComments || !component.comment() || component.comment()->description().isEmpty() )
return;

QgsModelComponentGraphicItem *commentItem = createCommentGraphicItem( model, component.comment()->clone(), parentItem );
@@ -54,6 +54,7 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
enum Flag
{
FlagHideControls = 1 << 1, //!< If set, item interactive controls will be hidden
FlagHideComments = 1 << 2, //!< If set, comments will be hidden
};
Q_DECLARE_FLAGS( Flags, Flag )

0 comments on commit 0b3f7a5

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