21#include <QDialogButtonBox>
23#include <QTreeWidgetItem>
26#include "moc_qgsprocessinghelpeditorwidget.cpp"
28using namespace Qt::StringLiterals;
32const QString QgsProcessingHelpEditorWidget::ALGORITHM_DESCRIPTION = u
"ALG_DESC"_s;
33const QString QgsProcessingHelpEditorWidget::ALGORITHM_CREATOR = u
"ALG_CREATOR"_s;
34const QString QgsProcessingHelpEditorWidget::ALGORITHM_HELP_CREATOR = u
"ALG_HELP_CREATOR"_s;
35const QString QgsProcessingHelpEditorWidget::ALGORITHM_VERSION = u
"ALG_VERSION"_s;
36const QString QgsProcessingHelpEditorWidget::ALGORITHM_SHORT_DESCRIPTION = u
"SHORT_DESCRIPTION"_s;
37const QString QgsProcessingHelpEditorWidget::ALGORITHM_HELP_URL = u
"HELP_URL"_s;
38const QString QgsProcessingHelpEditorWidget::ALGORITHM_EXAMPLES = u
"EXAMPLES"_s;
41class QgsProcessingHelpEditorTreeItem :
public QTreeWidgetItem
44 QgsProcessingHelpEditorTreeItem(
const QString &name,
const QString &description )
47 , description( description )
49 setText( 0, description );
57QgsProcessingHelpEditorWidget::QgsProcessingHelpEditorWidget( QWidget *parent )
59 , mCurrentName( ALGORITHM_DESCRIPTION )
63 connect( mElementTree, &QTreeWidget::currentItemChanged,
this, &QgsProcessingHelpEditorWidget::changeItem );
64 connect( mTextEdit, &QTextEdit::textChanged,
this, [
this] {
65 if ( !mCurrentName.isEmpty() )
67 if ( mEditStackedWidget->currentWidget() == mPagePlainText )
69 mHelpContent[mCurrentName] = mTextEdit->toPlainText();
76 if ( !mCurrentName.isEmpty() )
78 if ( mEditStackedWidget->currentWidget() == mPageRichEdit )
80 mHelpContent[mCurrentName] = mRichTextEdit->toHtml();
87QgsProcessingHelpEditorWidget::~QgsProcessingHelpEditorWidget() =
default;
96 if (
const QgsProcessingModelAlgorithm *model =
dynamic_cast<const QgsProcessingModelAlgorithm *
>( mAlgorithm.get() ) )
98 mHelpContent = model->helpContent();
101 mEditStackedWidget->setCurrentWidget( mPageRichEdit );
102 if ( mHelpContent.contains( ALGORITHM_DESCRIPTION ) )
104 mRichTextEdit->setText( mHelpContent.value( ALGORITHM_DESCRIPTION ).toString() );
107 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_DESCRIPTION, tr(
"Algorithm description" ) ) );
108 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_SHORT_DESCRIPTION, tr(
"Short description" ) ) );
110 QgsProcessingHelpEditorTreeItem *parametersItem =
new QgsProcessingHelpEditorTreeItem( QString(), tr(
"Input parameters" ) );
111 mElementTree->addTopLevelItem( parametersItem );
113 const QList<const QgsProcessingParameterDefinition *> definitions = mAlgorithm->parameterDefinitions();
119 parametersItem->addChild(
new QgsProcessingHelpEditorTreeItem( definition->name(), definition->description() ) );
122 QgsProcessingHelpEditorTreeItem *outputsItem =
new QgsProcessingHelpEditorTreeItem( QString(), tr(
"Outputs" ) );
123 mElementTree->addTopLevelItem( outputsItem );
124 const QList<const QgsProcessingOutputDefinition *> outputs = mAlgorithm->outputDefinitions();
127 outputsItem->addChild(
new QgsProcessingHelpEditorTreeItem( output->name(), output->description() ) );
130 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_EXAMPLES, tr(
"Examples" ) ) );
132 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_CREATOR, tr(
"Algorithm author" ) ) );
133 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_HELP_CREATOR, tr(
"Help author" ) ) );
134 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_VERSION, tr(
"Algorithm version" ) ) );
135 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_HELP_URL, tr(
"Documentation help URL (for help button)" ) ) );
140QVariantMap QgsProcessingHelpEditorWidget::helpContent()
146void QgsProcessingHelpEditorWidget::updateHtmlView()
148 mTextPreview->setHtml( formattedHelp() );
151void QgsProcessingHelpEditorWidget::changeItem( QTreeWidgetItem *, QTreeWidgetItem * )
153 if ( QgsProcessingHelpEditorTreeItem *item =
dynamic_cast<QgsProcessingHelpEditorTreeItem *
>( mElementTree->currentItem() ) )
157 const QString name = item->name;
158 if ( !name.isEmpty() )
160 mTextEdit->setEnabled(
true );
161 mRichTextEdit->setEnabled(
true );
166 const bool useRichTextEdit = name == ALGORITHM_EXAMPLES || name == ALGORITHM_DESCRIPTION;
167 if ( useRichTextEdit )
169 mEditStackedWidget->setCurrentWidget( mPageRichEdit );
170 if ( mHelpContent.contains( name ) )
171 mRichTextEdit->setText( mHelpContent.value( name ).toString() );
173 mRichTextEdit->setText( QString() );
177 mEditStackedWidget->setCurrentWidget( mPagePlainText );
178 if ( mHelpContent.contains( name ) )
179 mTextEdit->setText( mHelpContent.value( name ).toString() );
186 mCurrentName.clear();
188 mRichTextEdit->setText( QString() );
189 mTextEdit->setEnabled(
false );
190 mRichTextEdit->setEnabled(
false );
191 mEditStackedWidget->setCurrentWidget( mPagePlainText );
197QString QgsProcessingHelpEditorWidget::formattedHelp()
const
205void QgsProcessingHelpEditorWidget::storeCurrentValue()
207 if ( !mCurrentName.isEmpty() )
209 if ( mEditStackedWidget->currentWidget() == mPagePlainText )
210 mHelpContent[mCurrentName] = mTextEdit->toPlainText();
212 mHelpContent[mCurrentName] = mRichTextEdit->toHtml();
216QgsProcessingHelpEditorDialog::QgsProcessingHelpEditorDialog( QWidget *parent, Qt::WindowFlags flags )
217 : QDialog( parent, flags )
219 setObjectName( u
"QgsProcessingHelpEditorDialog"_s );
221 QVBoxLayout *vLayout =
new QVBoxLayout();
222 mWidget =
new QgsProcessingHelpEditorWidget();
223 vLayout->addWidget( mWidget, 1 );
225 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
226 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
227 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
228 vLayout->addWidget( buttonBox );
229 setLayout( vLayout );
239QVariantMap QgsProcessingHelpEditorDialog::helpContent()
241 return mWidget->helpContent();
@ Hidden
Parameter is hidden and should not be shown to users.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Abstract base class for processing algorithms.
Base class for the definition of processing outputs.
Base class for the definition of processing parameters.
static QString formatHelpMapAsHtml(const QVariantMap &map, const QgsProcessingAlgorithm *algorithm)
Returns a HTML formatted version of the help text encoded in a variant map for a specified algorithm.
void textChanged()
Emitted when the text contents are changed.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call