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
39 QgsProcessingHelpEditorTreeItem(
const QString &name,
const QString &description )
42 , description( description )
44 setText( 0, description );
53QgsProcessingHelpEditorWidget::QgsProcessingHelpEditorWidget( QWidget *parent )
55 , mCurrentName( ALGORITHM_DESCRIPTION )
59 connect( mElementTree, &QTreeWidget::currentItemChanged,
this, &QgsProcessingHelpEditorWidget::changeItem );
60 connect( mTextEdit, &QTextEdit::textChanged,
this, [ = ]
62 if ( !mCurrentName.isEmpty() )
64 if ( mEditStackedWidget->currentWidget() == mPagePlainText )
66 mHelpContent[ mCurrentName] = mTextEdit->toPlainText();
74 if ( !mCurrentName.isEmpty() )
76 if ( mEditStackedWidget->currentWidget() == mPageRichEdit )
78 mHelpContent[ mCurrentName] = mRichTextEdit->toHtml();
85QgsProcessingHelpEditorWidget::~QgsProcessingHelpEditorWidget() =
default;
94 if (
const QgsProcessingModelAlgorithm *model =
dynamic_cast< const QgsProcessingModelAlgorithm *
>( mAlgorithm.get() ) )
96 mHelpContent = model->helpContent();
99 mEditStackedWidget->setCurrentWidget( mPageRichEdit );
100 if ( mHelpContent.contains( ALGORITHM_DESCRIPTION ) )
102 mRichTextEdit->setText( mHelpContent.value( ALGORITHM_DESCRIPTION ).toString() );
105 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_DESCRIPTION, tr(
"Algorithm description" ) ) );
106 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_SHORT_DESCRIPTION, tr(
"Short description" ) ) );
108 QgsProcessingHelpEditorTreeItem *parametersItem =
new QgsProcessingHelpEditorTreeItem( QString(), tr(
"Input parameters" ) );
109 mElementTree->addTopLevelItem( parametersItem );
111 const QList< const QgsProcessingParameterDefinition * > definitions = mAlgorithm->parameterDefinitions();
117 parametersItem->addChild(
new QgsProcessingHelpEditorTreeItem( definition->name(), definition->description() ) );
120 QgsProcessingHelpEditorTreeItem *outputsItem =
new QgsProcessingHelpEditorTreeItem( QString(), tr(
"Outputs" ) );
121 mElementTree->addTopLevelItem( outputsItem );
122 const QList< const QgsProcessingOutputDefinition * > outputs = mAlgorithm->outputDefinitions();
125 outputsItem->addChild(
new QgsProcessingHelpEditorTreeItem( output->name(), output->description() ) );
128 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_EXAMPLES, tr(
"Examples" ) ) );
130 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_CREATOR, tr(
"Algorithm author" ) ) );
131 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_HELP_CREATOR, tr(
"Help author" ) ) );
132 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_VERSION, tr(
"Algorithm version" ) ) );
133 mElementTree->addTopLevelItem(
new QgsProcessingHelpEditorTreeItem( ALGORITHM_HELP_URL, tr(
"Documentation help URL (for help button)" ) ) );
138QVariantMap QgsProcessingHelpEditorWidget::helpContent()
144void QgsProcessingHelpEditorWidget::updateHtmlView()
146 mTextPreview->setHtml( formattedHelp() );
149void QgsProcessingHelpEditorWidget::changeItem( QTreeWidgetItem *, QTreeWidgetItem * )
151 if ( QgsProcessingHelpEditorTreeItem *item =
dynamic_cast< QgsProcessingHelpEditorTreeItem *
>( mElementTree->currentItem() ) )
155 const QString name = item->name;
156 if ( !name.isEmpty() )
158 mTextEdit->setEnabled(
true );
159 mRichTextEdit->setEnabled(
true );
164 const bool useRichTextEdit = name == ALGORITHM_EXAMPLES || name == ALGORITHM_DESCRIPTION;
165 if ( useRichTextEdit )
167 mEditStackedWidget->setCurrentWidget( mPageRichEdit );
168 if ( mHelpContent.contains( name ) )
169 mRichTextEdit->setText( mHelpContent.value( name ).toString() );
171 mRichTextEdit->setText( QString() );
175 mEditStackedWidget->setCurrentWidget( mPagePlainText );
176 if ( mHelpContent.contains( name ) )
177 mTextEdit->setText( mHelpContent.value( name ).toString() );
184 mCurrentName.clear();
186 mRichTextEdit->setText( QString() );
187 mTextEdit->setEnabled(
false );
188 mRichTextEdit->setEnabled(
false );
189 mEditStackedWidget->setCurrentWidget( mPagePlainText );
195QString QgsProcessingHelpEditorWidget::formattedHelp()
const
203void QgsProcessingHelpEditorWidget::storeCurrentValue()
205 if ( !mCurrentName.isEmpty() )
207 if ( mEditStackedWidget->currentWidget() == mPagePlainText )
208 mHelpContent[ mCurrentName] = mTextEdit->toPlainText();
210 mHelpContent[ mCurrentName] = mRichTextEdit->toHtml();
214QgsProcessingHelpEditorDialog::QgsProcessingHelpEditorDialog( QWidget *parent, Qt::WindowFlags flags )
215 : QDialog( parent, flags )
217 setObjectName( QStringLiteral(
"QgsProcessingHelpEditorDialog" ) );
219 QVBoxLayout *vLayout =
new QVBoxLayout();
220 mWidget =
new QgsProcessingHelpEditorWidget();
221 vLayout->addWidget( mWidget, 1 );
223 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
224 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
225 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
226 vLayout->addWidget( buttonBox );
227 setLayout( vLayout );
237QVariantMap QgsProcessingHelpEditorDialog::helpContent()
239 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