17#include "moc_qgsprocessinghelpeditorwidget.cpp"
20#include <QTreeWidgetItem>
21#include <QDialogButtonBox>
26const QString QgsProcessingHelpEditorWidget::ALGORITHM_DESCRIPTION = QStringLiteral(
"ALG_DESC" );
27const QString QgsProcessingHelpEditorWidget::ALGORITHM_CREATOR = QStringLiteral(
"ALG_CREATOR" );
28const QString QgsProcessingHelpEditorWidget::ALGORITHM_HELP_CREATOR = QStringLiteral(
"ALG_HELP_CREATOR" );
29const QString QgsProcessingHelpEditorWidget::ALGORITHM_VERSION = QStringLiteral(
"ALG_VERSION" );
30const QString QgsProcessingHelpEditorWidget::ALGORITHM_SHORT_DESCRIPTION = QStringLiteral(
"SHORT_DESCRIPTION" );
31const QString QgsProcessingHelpEditorWidget::ALGORITHM_HELP_URL = QStringLiteral(
"HELP_URL" );
32const QString QgsProcessingHelpEditorWidget::ALGORITHM_EXAMPLES = QStringLiteral(
"EXAMPLES" );
35class QgsProcessingHelpEditorTreeItem :
public QTreeWidgetItem
38 QgsProcessingHelpEditorTreeItem(
const QString &name,
const QString &description )
41 , description( description )
43 setText( 0, description );
51QgsProcessingHelpEditorWidget::QgsProcessingHelpEditorWidget( QWidget *parent )
53 , mCurrentName( ALGORITHM_DESCRIPTION )
57 connect( mElementTree, &QTreeWidget::currentItemChanged,
this, &QgsProcessingHelpEditorWidget::changeItem );
58 connect( mTextEdit, &QTextEdit::textChanged,
this, [=] {
59 if ( !mCurrentName.isEmpty() )
61 if ( mEditStackedWidget->currentWidget() == mPagePlainText )
63 mHelpContent[mCurrentName] = mTextEdit->toPlainText();
70 if ( !mCurrentName.isEmpty() )
72 if ( mEditStackedWidget->currentWidget() == mPageRichEdit )
74 mHelpContent[mCurrentName] = mRichTextEdit->toHtml();
81QgsProcessingHelpEditorWidget::~QgsProcessingHelpEditorWidget() =
default;
90 if (
const QgsProcessingModelAlgorithm *model =
dynamic_cast<const QgsProcessingModelAlgorithm *
>( mAlgorithm.get() ) )
92 mHelpContent = model->helpContent();
95 mEditStackedWidget->setCurrentWidget( mPageRichEdit );
96 if ( mHelpContent.contains( ALGORITHM_DESCRIPTION ) )
98 mRichTextEdit->setText( mHelpContent.value( ALGORITHM_DESCRIPTION ).toString() );
101 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_DESCRIPTION, tr(
"Algorithm description" ) ) );
102 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_SHORT_DESCRIPTION, tr(
"Short description" ) ) );
104 QgsProcessingHelpEditorTreeItem *parametersItem =
new QgsProcessingHelpEditorTreeItem( QString(), tr(
"Input parameters" ) );
105 mElementTree->addTopLevelItem( parametersItem );
107 const QList<const QgsProcessingParameterDefinition *> definitions = mAlgorithm->parameterDefinitions();
113 parametersItem->addChild(
new QgsProcessingHelpEditorTreeItem( definition->name(), definition->description() ) );
116 QgsProcessingHelpEditorTreeItem *outputsItem =
new QgsProcessingHelpEditorTreeItem( QString(), tr(
"Outputs" ) );
117 mElementTree->addTopLevelItem( outputsItem );
118 const QList<const QgsProcessingOutputDefinition *> outputs = mAlgorithm->outputDefinitions();
121 outputsItem->addChild(
new QgsProcessingHelpEditorTreeItem( output->name(), output->description() ) );
124 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_EXAMPLES, tr(
"Examples" ) ) );
126 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_CREATOR, tr(
"Algorithm author" ) ) );
127 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_HELP_CREATOR, tr(
"Help author" ) ) );
128 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_VERSION, tr(
"Algorithm version" ) ) );
129 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_HELP_URL, tr(
"Documentation help URL (for help button)" ) ) );
134QVariantMap QgsProcessingHelpEditorWidget::helpContent()
140void QgsProcessingHelpEditorWidget::updateHtmlView()
142 mTextPreview->setHtml( formattedHelp() );
145void QgsProcessingHelpEditorWidget::changeItem( QTreeWidgetItem *, QTreeWidgetItem * )
147 if ( QgsProcessingHelpEditorTreeItem *item =
dynamic_cast<QgsProcessingHelpEditorTreeItem *
>( mElementTree->currentItem() ) )
151 const QString name = item->name;
152 if ( !name.isEmpty() )
154 mTextEdit->setEnabled(
true );
155 mRichTextEdit->setEnabled(
true );
160 const bool useRichTextEdit = name == ALGORITHM_EXAMPLES || name == ALGORITHM_DESCRIPTION;
161 if ( useRichTextEdit )
163 mEditStackedWidget->setCurrentWidget( mPageRichEdit );
164 if ( mHelpContent.contains( name ) )
165 mRichTextEdit->setText( mHelpContent.value( name ).toString() );
167 mRichTextEdit->setText( QString() );
171 mEditStackedWidget->setCurrentWidget( mPagePlainText );
172 if ( mHelpContent.contains( name ) )
173 mTextEdit->setText( mHelpContent.value( name ).toString() );
180 mCurrentName.clear();
182 mRichTextEdit->setText( QString() );
183 mTextEdit->setEnabled(
false );
184 mRichTextEdit->setEnabled(
false );
185 mEditStackedWidget->setCurrentWidget( mPagePlainText );
191QString QgsProcessingHelpEditorWidget::formattedHelp()
const
199void QgsProcessingHelpEditorWidget::storeCurrentValue()
201 if ( !mCurrentName.isEmpty() )
203 if ( mEditStackedWidget->currentWidget() == mPagePlainText )
204 mHelpContent[mCurrentName] = mTextEdit->toPlainText();
206 mHelpContent[mCurrentName] = mRichTextEdit->toHtml();
210QgsProcessingHelpEditorDialog::QgsProcessingHelpEditorDialog( QWidget *parent, Qt::WindowFlags flags )
211 : QDialog( parent, flags )
213 setObjectName( QStringLiteral(
"QgsProcessingHelpEditorDialog" ) );
215 QVBoxLayout *vLayout =
new QVBoxLayout();
216 mWidget =
new QgsProcessingHelpEditorWidget();
217 vLayout->addWidget( mWidget, 1 );
219 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
220 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
221 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
222 vLayout->addWidget( buttonBox );
223 setLayout( vLayout );
233QVariantMap QgsProcessingHelpEditorDialog::helpContent()
235 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.
QgsProcessingAlgorithm * create(const QVariantMap &configuration=QVariantMap()) const
Creates a copy of the algorithm, ready for execution.
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