From d62d0b82e3d3ca54cc9e204e479252db060d38c7 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 28 Feb 2022 13:52:58 +1000 Subject: [PATCH] Port model help editor dialog to c++ --- .../models/qgsmodeldesignerdialog.sip.in | 1 - .../processing/gui/HelpEditionDialog.py | 178 --------------- .../processing/modeler/ModelerDialog.py | 11 - src/gui/CMakeLists.txt | 2 + .../models/qgsmodeldesignerdialog.cpp | 15 ++ .../models/qgsmodeldesignerdialog.h | 2 +- .../qgsprocessinghelpeditorwidget.cpp | 213 ++++++++++++++++++ .../qgsprocessinghelpeditorwidget.h | 122 ++++++++++ .../qgsprocessinghelpeditorwidgetbase.ui | 72 ++---- 9 files changed, 372 insertions(+), 244 deletions(-) delete mode 100644 python/plugins/processing/gui/HelpEditionDialog.py create mode 100644 src/gui/processing/qgsprocessinghelpeditorwidget.cpp create mode 100644 src/gui/processing/qgsprocessinghelpeditorwidget.h rename python/plugins/processing/ui/DlgHelpEdition.ui => src/ui/processing/qgsprocessinghelpeditorwidgetbase.ui (62%) diff --git a/python/gui/auto_generated/processing/models/qgsmodeldesignerdialog.sip.in b/python/gui/auto_generated/processing/models/qgsmodeldesignerdialog.sip.in index 713aa55ff57..c5cf803d4f7 100644 --- a/python/gui/auto_generated/processing/models/qgsmodeldesignerdialog.sip.in +++ b/python/gui/auto_generated/processing/models/qgsmodeldesignerdialog.sip.in @@ -93,7 +93,6 @@ Raise, unminimize and activate this window. QToolBar *toolbar(); QAction *actionOpen(); QAction *actionSaveInProject(); - QAction *actionEditHelp(); QAction *actionRun(); QgsMessageBar *messageBar(); QGraphicsView *view(); diff --git a/python/plugins/processing/gui/HelpEditionDialog.py b/python/plugins/processing/gui/HelpEditionDialog.py deleted file mode 100644 index d0086695c8c..00000000000 --- a/python/plugins/processing/gui/HelpEditionDialog.py +++ /dev/null @@ -1,178 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -*************************************************************************** - HelpEditionDialog.py - --------------------- - Date : August 2012 - Copyright : (C) 2012 by Victor Olaya - Email : volayaf at gmail dot com -*************************************************************************** -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -* * -*************************************************************************** -""" - -__author__ = 'Victor Olaya' -__date__ = 'August 2012' -__copyright__ = '(C) 2012, Victor Olaya' - -import os -import json -import warnings - -from qgis.PyQt import uic -from qgis.PyQt.QtWidgets import QDialog, QTreeWidgetItem - -from qgis.core import (Qgis, - QgsMessageLog, - QgsProcessingUtils, - QgsProcessingParameterDefinition, - QgsProcessingModelAlgorithm) - -pluginPath = os.path.split(os.path.dirname(__file__))[0] - -with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=DeprecationWarning) - WIDGET, BASE = uic.loadUiType( - os.path.join(pluginPath, 'ui', 'DlgHelpEdition.ui')) - - -class HelpEditionDialog(BASE, WIDGET): - ALG_DESC = 'ALG_DESC' - ALG_CREATOR = 'ALG_CREATOR' - ALG_HELP_CREATOR = 'ALG_HELP_CREATOR' - ALG_VERSION = 'ALG_VERSION' - SHORT_DESCRIPTION = 'SHORT_DESCRIPTION' - HELP_URL = 'HELP_URL' - - def __init__(self, alg): - super(HelpEditionDialog, self).__init__(None) - self.setupUi(self) - - self.alg = alg - self.descriptions = {} - if isinstance(self.alg, QgsProcessingModelAlgorithm): - self.descriptions = self.alg.helpContent() - else: - if self.alg.descriptionFile is not None: - helpfile = alg.descriptionFile + '.help' - if os.path.exists(helpfile): - try: - with open(helpfile) as f: - self.descriptions = json.load(f) - except Exception: - QgsMessageLog.logMessage(self.tr('Cannot open help file: {0}').format(helpfile), self.tr('Processing'), Qgis.Warning) - - self.currentName = self.ALG_DESC - if self.ALG_DESC in self.descriptions: - self.text.setText(self.descriptions[self.ALG_DESC]) - self.tree.itemClicked.connect(self.changeItem) - - self.fillTree() - self.updateHtmlView() - - def reject(self): - self.descriptions = None - QDialog.reject(self) - - def accept(self): - self.descriptions[self.currentName] = str(self.text.toPlainText()) - QDialog.accept(self) - - def getHtml(self): - s = '

' + self.getDescription(self.ALG_DESC) + '

\n' - inputs = "" - for param in self.alg.parameterDefinitions(): - if param.flags() & QgsProcessingParameterDefinition.FlagHidden or param.isDestination(): - continue - - if self.getDescription(param.name()): - inputs += '

' + param.description() + '

\n' - inputs += '

' + self.getDescription(param.name()) + '

\n' - if inputs: - s += '

' + self.tr('Input parameters') + '

\n' + inputs - outputs = "" - for out in self.alg.outputDefinitions(): - if self.getDescription(param.name()): - outputs += '

' + out.description() + '

\n' - outputs += '

' + self.getDescription(out.name()) + '

\n' - if outputs: - s += '

' + self.tr('Outputs') + '

\n' + outputs - s += '
' - if self.getDescription(self.ALG_CREATOR): - s += '

' + self.tr('Algorithm author:') + ' ' + self.getDescription(self.ALG_CREATOR) + '

' - if self.getDescription(self.ALG_HELP_CREATOR): - s += '

' + self.tr('Help author:') + ' ' + self.getDescription(self.ALG_HELP_CREATOR) + '

' - if self.getDescription(self.ALG_VERSION): - s += '

' + self.tr('Algorithm version:') + ' ' + self.getDescription(self.ALG_VERSION) + '

' - return s - - def fillTree(self): - item = TreeDescriptionItem(self.tr('Algorithm description'), self.ALG_DESC) - self.tree.addTopLevelItem(item) - item = TreeDescriptionItem(self.tr('Short description'), self.SHORT_DESCRIPTION) - self.tree.addTopLevelItem(item) - parametersItem = TreeDescriptionItem(self.tr('Input parameters'), None) - self.tree.addTopLevelItem(parametersItem) - for param in self.alg.parameterDefinitions(): - if param.flags() & QgsProcessingParameterDefinition.FlagHidden or param.isDestination(): - continue - - item = TreeDescriptionItem(param.description(), param.name()) - parametersItem.addChild(item) - outputsItem = TreeDescriptionItem(self.tr('Outputs'), None) - self.tree.addTopLevelItem(outputsItem) - for out in self.alg.outputDefinitions(): - item = TreeDescriptionItem(out.description(), out.name()) - outputsItem.addChild(item) - item = TreeDescriptionItem(self.tr('Algorithm author'), self.ALG_CREATOR) - self.tree.addTopLevelItem(item) - item = TreeDescriptionItem(self.tr('Help author'), self.ALG_HELP_CREATOR) - self.tree.addTopLevelItem(item) - item = TreeDescriptionItem(self.tr('Algorithm version'), self.ALG_VERSION) - self.tree.addTopLevelItem(item) - item = TreeDescriptionItem(self.tr('Documentation help URL (for help button)'), self.HELP_URL) - self.tree.addTopLevelItem(item) - - def changeItem(self): - item = self.tree.currentItem() - if isinstance(item, TreeDescriptionItem): - if self.currentName: - self.descriptions[self.currentName] = str(self.text.toPlainText()) - name = item.name - if name: - self.text.setEnabled(True) - self.updateHtmlView() - self.currentName = name - if name in self.descriptions: - self.text.setText(self.descriptions[name]) - else: - self.text.clear() - else: - self.currentName = None - self.text.clear() - self.text.setEnabled(False) - self.updateHtmlView() - - def updateHtmlView(self): - self.txtPreview.setHtml(self.getHtml()) - - def getDescription(self, name): - if name in self.descriptions: - return self.descriptions[name].replace('\n', '
') - else: - return '' - - -class TreeDescriptionItem(QTreeWidgetItem): - - def __init__(self, description, name): - QTreeWidgetItem.__init__(self) - self.name = name - self.description = description - self.setText(0, description) diff --git a/python/plugins/processing/modeler/ModelerDialog.py b/python/plugins/processing/modeler/ModelerDialog.py index c717e040a54..24d9da3510c 100644 --- a/python/plugins/processing/modeler/ModelerDialog.py +++ b/python/plugins/processing/modeler/ModelerDialog.py @@ -55,7 +55,6 @@ from qgis.gui import (QgsProcessingParameterDefinitionDialog, from qgis.utils import iface from processing.gui.AlgorithmDialog import AlgorithmDialog -from processing.gui.HelpEditionDialog import HelpEditionDialog from processing.modeler.ModelerParameterDefinitionDialog import ModelerParameterDefinitionDialog from processing.modeler.ModelerParametersDialog import ModelerParametersDialog from processing.modeler.ModelerScene import ModelerScene @@ -102,7 +101,6 @@ class ModelerDialog(QgsModelDesignerDialog): self.actionOpen().triggered.connect(self.openModel) self.actionSaveInProject().triggered.connect(self.saveInProject) - self.actionEditHelp().triggered.connect(self.editHelp) self.actionRun().triggered.connect(self.runModel) if model is not None: @@ -125,15 +123,6 @@ class ModelerDialog(QgsModelDesignerDialog): self.context_generator = ContextGenerator(self.processing_context) - def editHelp(self): - alg = self.model() - dlg = HelpEditionDialog(alg) - dlg.exec_() - if dlg.descriptions: - self.beginUndoCommand(self.tr('Edit Model Help')) - self.model().setHelpContent(dlg.descriptions) - self.endUndoCommand() - def runModel(self): valid, errors = self.model().validate() if not valid: diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 27ad4fdca2e..af629e3f881 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -329,6 +329,7 @@ set(QGIS_GUI_SRCS processing/qgsprocessingfeaturesourceoptionswidget.cpp processing/qgsprocessingfieldmapwidgetwrapper.cpp processing/qgsprocessingguiregistry.cpp + processing/qgsprocessinghelpeditorwidget.cpp processing/qgsprocessinghistoryprovider.cpp processing/qgsprocessingmaplayercombobox.cpp processing/qgsprocessingmatrixmodelerwidget.cpp @@ -1165,6 +1166,7 @@ set(QGIS_GUI_HDRS processing/qgsprocessingfieldmapwidgetwrapper.h processing/qgsprocessinggui.h processing/qgsprocessingguiregistry.h + processing/qgsprocessinghelpeditorwidget.h processing/qgsprocessinghistoryprovider.h processing/qgsprocessingmaplayercombobox.h processing/qgsprocessingmatrixmodelerwidget.h diff --git a/src/gui/processing/models/qgsmodeldesignerdialog.cpp b/src/gui/processing/models/qgsmodeldesignerdialog.cpp index 8d4afce8014..6e6dcc16075 100644 --- a/src/gui/processing/models/qgsmodeldesignerdialog.cpp +++ b/src/gui/processing/models/qgsmodeldesignerdialog.cpp @@ -34,6 +34,7 @@ #include "qgsmessagebaritem.h" #include "qgspanelwidget.h" #include "qgsprocessingmultipleselectiondialog.h" +#include "qgsprocessinghelpeditorwidget.h" #include #include @@ -149,6 +150,7 @@ QgsModelDesignerDialog::QgsModelDesignerDialog( QWidget *parent, Qt::WindowFlags connect( mActionSnapSelected, &QAction::triggered, mView, &QgsModelGraphicsView::snapSelected ); connect( mActionValidate, &QAction::triggered, this, &QgsModelDesignerDialog::validate ); connect( mActionReorderInputs, &QAction::triggered, this, &QgsModelDesignerDialog::reorderInputs ); + connect( mActionEditHelp, &QAction::triggered, this, &QgsModelDesignerDialog::editHelp ); connect( mReorderInputsButton, &QPushButton::clicked, this, &QgsModelDesignerDialog::reorderInputs ); mActionSnappingEnabled->setChecked( settings.value( QStringLiteral( "/Processing/Modeler/enableSnapToGrid" ), false ).toBool() ); @@ -926,6 +928,19 @@ void QgsModelDesignerDialog::setPanelVisibility( bool hidden ) } } +void QgsModelDesignerDialog::editHelp() +{ + QgsProcessingHelpEditorDialog dialog( this ); + dialog.setWindowTitle( tr( "Edit Model Help" ) ); + dialog.setAlgorithm( mModel.get() ); + if ( dialog.exec() ) + { + beginUndoCommand( tr( "Edit Model Help" ) ); + mModel->setHelpContent( dialog.helpContent() ); + endUndoCommand(); + } +} + void QgsModelDesignerDialog::validate() { QStringList issues; diff --git a/src/gui/processing/models/qgsmodeldesignerdialog.h b/src/gui/processing/models/qgsmodeldesignerdialog.h index ceb4a8d717e..dd692666356 100644 --- a/src/gui/processing/models/qgsmodeldesignerdialog.h +++ b/src/gui/processing/models/qgsmodeldesignerdialog.h @@ -127,7 +127,6 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode QToolBar *toolbar() { return mToolbar; } QAction *actionOpen() { return mActionOpen; } QAction *actionSaveInProject() { return mActionSaveInProject; } - QAction *actionEditHelp() { return mActionEditHelp; } QAction *actionRun() { return mActionRun; } QgsMessageBar *messageBar() { return mMessageBar; } QGraphicsView *view() { return mView; } @@ -182,6 +181,7 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode void validate(); void reorderInputs(); void setPanelVisibility( bool hidden ); + void editHelp(); private: diff --git a/src/gui/processing/qgsprocessinghelpeditorwidget.cpp b/src/gui/processing/qgsprocessinghelpeditorwidget.cpp new file mode 100644 index 00000000000..435351dfdba --- /dev/null +++ b/src/gui/processing/qgsprocessinghelpeditorwidget.cpp @@ -0,0 +1,213 @@ +/*************************************************************************** + qgsprocessinghelpeditorwidget.h + ------------------------ + Date : February 2022 + Copyright : (C) 2022 Nyall Dawson + Email : nyall dot dawson at gmail dot com + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgsprocessinghelpeditorwidget.h" +#include "qgsprocessingmodelalgorithm.h" +#include "qgsgui.h" +#include +#include +#include + +///@cond NOT_STABLE + +const QString QgsProcessingHelpEditorWidget::ALGORITHM_DESCRIPTION = QStringLiteral( "ALG_DESC" ); +const QString QgsProcessingHelpEditorWidget::ALGORITHM_CREATOR = QStringLiteral( "ALG_CREATOR" ); +const QString QgsProcessingHelpEditorWidget::ALGORITHM_HELP_CREATOR = QStringLiteral( "ALG_HELP_CREATOR" ); +const QString QgsProcessingHelpEditorWidget::ALGORITHM_VERSION = QStringLiteral( "ALG_VERSION" ); +const QString QgsProcessingHelpEditorWidget::ALGORITHM_SHORT_DESCRIPTION = QStringLiteral( "SHORT_DESCRIPTION" ); +const QString QgsProcessingHelpEditorWidget::ALGORITHM_HELP_URL = QStringLiteral( "HELP_URL" ); + + +class QgsProcessingHelpEditorTreeItem : public QTreeWidgetItem +{ + public: + + QgsProcessingHelpEditorTreeItem( const QString &name, const QString &description ) + : QTreeWidgetItem() + , name( name ) + , description( description ) + { + setText( 0, description ); + } + + QString name; + QString description; + +}; + + +QgsProcessingHelpEditorWidget::QgsProcessingHelpEditorWidget( QWidget *parent ) + : QWidget( parent ) + , mCurrentName( ALGORITHM_DESCRIPTION ) +{ + setupUi( this ); + + connect( mElementTree, &QTreeWidget::currentItemChanged, this, &QgsProcessingHelpEditorWidget::changeItem ); + connect( mTextEdit, &QTextEdit::textChanged, this, [ = ] + { + if ( !mCurrentName.isEmpty() ) + { + mHelpContent[ mCurrentName] = mTextEdit->toPlainText(); + updateHtmlView(); + } + } ); +} + +QgsProcessingHelpEditorWidget::~QgsProcessingHelpEditorWidget() = default; + +void QgsProcessingHelpEditorWidget::setAlgorithm( const QgsProcessingAlgorithm *algorithm ) +{ + if ( !algorithm ) + return; + + mAlgorithm.reset( algorithm->create() ); + + if ( const QgsProcessingModelAlgorithm *model = dynamic_cast< const QgsProcessingModelAlgorithm *>( mAlgorithm.get() ) ) + { + mHelpContent = model->helpContent(); + } + + if ( mHelpContent.contains( ALGORITHM_DESCRIPTION ) ) + { + mTextEdit->setText( mHelpContent.value( ALGORITHM_CREATOR ).toString() ); + } + + mElementTree->addTopLevelItem( new QgsProcessingHelpEditorTreeItem( ALGORITHM_DESCRIPTION, tr( "Algorithm description" ) ) ); + mElementTree->addTopLevelItem( new QgsProcessingHelpEditorTreeItem( ALGORITHM_SHORT_DESCRIPTION, tr( "Short description" ) ) ); + + QgsProcessingHelpEditorTreeItem *parametersItem = new QgsProcessingHelpEditorTreeItem( QString(), tr( "Input parameters" ) ); + mElementTree->addTopLevelItem( parametersItem ); + + const QList< const QgsProcessingParameterDefinition * > definitions = mAlgorithm->parameterDefinitions(); + for ( const QgsProcessingParameterDefinition *definition : definitions ) + { + if ( definition->flags() & QgsProcessingParameterDefinition::FlagHidden || definition->isDestination() ) + continue; + + parametersItem->addChild( new QgsProcessingHelpEditorTreeItem( definition->name(), definition->description() ) ); + } + + QgsProcessingHelpEditorTreeItem *outputsItem = new QgsProcessingHelpEditorTreeItem( QString(), tr( "Outputs" ) ); + mElementTree->addTopLevelItem( outputsItem ); + const QList< const QgsProcessingOutputDefinition * > outputs = mAlgorithm->outputDefinitions(); + for ( const QgsProcessingOutputDefinition *output : outputs ) + { + outputsItem->addChild( new QgsProcessingHelpEditorTreeItem( output->name(), output->description() ) ); + } + + mElementTree->addTopLevelItem( new QgsProcessingHelpEditorTreeItem( ALGORITHM_CREATOR, tr( "Algorithm author" ) ) ); + mElementTree->addTopLevelItem( new QgsProcessingHelpEditorTreeItem( ALGORITHM_HELP_CREATOR, tr( "Help author" ) ) ); + mElementTree->addTopLevelItem( new QgsProcessingHelpEditorTreeItem( ALGORITHM_VERSION, tr( "Algorithm version" ) ) ); + mElementTree->addTopLevelItem( new QgsProcessingHelpEditorTreeItem( ALGORITHM_HELP_URL, tr( "Documentation help URL (for help button)" ) ) ); + + updateHtmlView(); +} + +QVariantMap QgsProcessingHelpEditorWidget::helpContent() +{ + if ( !mCurrentName.isEmpty() ) + mHelpContent[ mCurrentName] = mTextEdit->toPlainText(); + + return mHelpContent; +} + +void QgsProcessingHelpEditorWidget::updateHtmlView() +{ + mTextPreview->setHtml( formattedHelp() ); +} + +void QgsProcessingHelpEditorWidget::changeItem( QTreeWidgetItem *, QTreeWidgetItem * ) +{ + if ( QgsProcessingHelpEditorTreeItem *item = dynamic_cast< QgsProcessingHelpEditorTreeItem *>( mElementTree->currentItem() ) ) + { + if ( !mCurrentName.isEmpty() ) + { + mHelpContent[ mCurrentName] = mTextEdit->toPlainText(); + } + + const QString name = item->name; + if ( !name.isEmpty() ) + { + mTextEdit->setEnabled( true ); + updateHtmlView(); + mCurrentName = name; + if ( mHelpContent.contains( name ) ) + mTextEdit->setText( mHelpContent[name].toString() ); + else + mTextEdit->clear(); + } + else + { + mCurrentName.clear(); + mTextEdit->clear(); + mTextEdit->setEnabled( false ); + updateHtmlView(); + } + } +} + +QString QgsProcessingHelpEditorWidget::formattedHelp() const +{ + if ( !mAlgorithm ) + return QString(); + + return QgsProcessingUtils::formatHelpMapAsHtml( mHelpContent, mAlgorithm.get() ); +} + +QString QgsProcessingHelpEditorWidget::helpComponent( const QString &name ) const +{ + if ( mHelpContent.contains( name ) ) + { + QString component = mHelpContent.value( name ).toString(); + component.replace( '\n', QStringLiteral( "
" ) ); + return component; + } + else + { + return QString(); + } +} + +QgsProcessingHelpEditorDialog::QgsProcessingHelpEditorDialog( QWidget *parent, Qt::WindowFlags flags ) + : QDialog( parent, flags ) +{ + setObjectName( QStringLiteral( "QgsProcessingHelpEditorDialog" ) ); + + QVBoxLayout *vLayout = new QVBoxLayout(); + mWidget = new QgsProcessingHelpEditorWidget(); + vLayout->addWidget( mWidget, 1 ); + + QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel ); + connect( buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept ); + connect( buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject ); + vLayout->addWidget( buttonBox ); + setLayout( vLayout ); + + QgsGui::enableAutoGeometryRestore( this ); +} + +void QgsProcessingHelpEditorDialog::setAlgorithm( const QgsProcessingAlgorithm *algorithm ) +{ + mWidget->setAlgorithm( algorithm ); +} + +QVariantMap QgsProcessingHelpEditorDialog::helpContent() +{ + return mWidget->helpContent(); +} + + +///@endcond + diff --git a/src/gui/processing/qgsprocessinghelpeditorwidget.h b/src/gui/processing/qgsprocessinghelpeditorwidget.h new file mode 100644 index 00000000000..32e12527ecc --- /dev/null +++ b/src/gui/processing/qgsprocessinghelpeditorwidget.h @@ -0,0 +1,122 @@ +/*************************************************************************** + qgsprocessinghelpeditorwidget.h + ------------------------ + Date : February 2022 + Copyright : (C) 2022 Nyall Dawson + Email : nyall dot dawson at gmail dot com + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef QGSPROCESSINGHELPEDITORWIDGET_H +#define QGSPROCESSINGHELPEDITORWIDGET_H + +#include "qgis.h" +#include "qgis_gui.h" +#include "ui_qgsprocessinghelpeditorwidgetbase.h" + +#include + +class QgsProcessingAlgorithm; + + + +///@cond NOT_STABLE + +#define SIP_NO_FILE + + +/** + * \ingroup gui + * \brief A widget for editing help for a Processing algorithm. + * \warning Not stable API + * \since QGIS 3.26 + */ +class GUI_EXPORT QgsProcessingHelpEditorWidget : public QWidget, public Ui::QgsProcessingHelpEditorWidgetBase +{ + Q_OBJECT + public: + + /** + * Constructor for QgsProcessingHelpEditorWidget, with the specified \a parent widget. + */ + QgsProcessingHelpEditorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr ); + ~QgsProcessingHelpEditorWidget() override; + + /** + * Sets the \a algorithm associated with the widget. + */ + void setAlgorithm( const QgsProcessingAlgorithm *algorithm ); + + /** + * Returns the current help content defined by the widget. + */ + QVariantMap helpContent(); + + private slots: + + void updateHtmlView(); + + void changeItem( QTreeWidgetItem *current, QTreeWidgetItem *previous ); + + private: + + QString formattedHelp() const; + QString helpComponent( const QString &name ) const; + + QVariantMap mHelpContent; + + QString mCurrentName; + + std::unique_ptr< QgsProcessingAlgorithm > mAlgorithm; + + static const QString ALGORITHM_DESCRIPTION; + static const QString ALGORITHM_CREATOR; + static const QString ALGORITHM_HELP_CREATOR; + static const QString ALGORITHM_VERSION; + static const QString ALGORITHM_SHORT_DESCRIPTION; + static const QString ALGORITHM_HELP_URL; + +}; + +/** + * \ingroup gui + * \brief A dialog for editing help for a Processing algorithm. + * \warning Not stable API + * \since QGIS 3.26 + */ +class GUI_EXPORT QgsProcessingHelpEditorDialog : public QDialog +{ + Q_OBJECT + + public: + + /** + * Constructor for QgsProcessingHelpEditorDialog, with the specified \a parent and \a flags. + */ + QgsProcessingHelpEditorDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() ); + + /** + * Sets the \a algorithm associated with the dialog. + */ + void setAlgorithm( const QgsProcessingAlgorithm *algorithm ); + + /** + * Returns the current help content defined by the dialog. + */ + QVariantMap helpContent(); + + private: + + QgsProcessingHelpEditorWidget *mWidget = nullptr; +}; + + +///@endcond + +#endif // QGSPROCESSINGHELPEDITORWIDGET_H diff --git a/python/plugins/processing/ui/DlgHelpEdition.ui b/src/ui/processing/qgsprocessinghelpeditorwidgetbase.ui similarity index 62% rename from python/plugins/processing/ui/DlgHelpEdition.ui rename to src/ui/processing/qgsprocessinghelpeditorwidgetbase.ui index a0ea657dee7..93a3438da59 100644 --- a/python/plugins/processing/ui/DlgHelpEdition.ui +++ b/src/ui/processing/qgsprocessinghelpeditorwidgetbase.ui @@ -1,7 +1,7 @@ - DlgHelpEdition - + QgsProcessingHelpEditorWidgetBase + 0 @@ -17,11 +17,20 @@ 6 - - 9 + + 0 + + + 0 + + + 0 + + + 0 - + @@ -32,7 +41,7 @@ Qt::Horizontal - + 2 @@ -45,7 +54,7 @@ - + 0 @@ -73,14 +82,14 @@ 2 - + Element description - + 0 @@ -94,51 +103,8 @@ - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - buttonBox - accepted() - DlgHelpEdition - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - DlgHelpEdition - reject() - - - 316 - 260 - - - 286 - 274 - - - - +