Skip to content

Commit

Permalink
Hookup toggle to hide comments from model designer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 6, 2020
1 parent 08b47a4 commit 0b3f7a5
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
Expand Up @@ -36,6 +36,7 @@ QGraphicsScene subclass representing the model designer.
enum Flag
{
FlagHideControls,
FlagHideComments,
};
typedef QFlags<QgsModelGraphicsScene::Flag> Flags;

Expand Down
13 changes: 7 additions & 6 deletions python/plugins/processing/modeler/ModelerDialog.py
Expand Up @@ -38,10 +38,10 @@
QgsApplication,
QgsProcessing,
QgsProject,
QgsSettings,
QgsMessageLog,
QgsProcessingModelAlgorithm,
QgsProcessingModelParameter,
QgsSettings
)
from qgis.gui import (QgsProcessingParameterDefinitionDialog,
QgsProcessingParameterWidgetContext,
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions src/gui/processing/models/qgsmodeldesignerdialog.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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" ) );
Expand Down
1 change: 1 addition & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.h
Expand Up @@ -87,6 +87,7 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode
void exportToPdf();
void exportToSvg();
void exportAsPython();
void toggleComments( bool show );

private:

Expand Down
2 changes: 1 addition & 1 deletion src/gui/processing/models/qgsmodelgraphicsscene.cpp
Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/gui/processing/models/qgsmodelgraphicsscene.h
Expand Up @@ -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 )

Expand Down

0 comments on commit 0b3f7a5

Please sign in to comment.