19#include <QTreeWidgetItem> 
   20#include <QDialogButtonBox> 
   25const QString QgsProcessingHelpEditorWidget::ALGORITHM_DESCRIPTION = QStringLiteral( 
"ALG_DESC" );
 
   26const QString QgsProcessingHelpEditorWidget::ALGORITHM_CREATOR = QStringLiteral( 
"ALG_CREATOR" );
 
   27const QString QgsProcessingHelpEditorWidget::ALGORITHM_HELP_CREATOR = QStringLiteral( 
"ALG_HELP_CREATOR" );
 
   28const QString QgsProcessingHelpEditorWidget::ALGORITHM_VERSION = QStringLiteral( 
"ALG_VERSION" );
 
   29const QString QgsProcessingHelpEditorWidget::ALGORITHM_SHORT_DESCRIPTION = QStringLiteral( 
"SHORT_DESCRIPTION" );
 
   30const QString QgsProcessingHelpEditorWidget::ALGORITHM_HELP_URL = QStringLiteral( 
"HELP_URL" );
 
   31const QString QgsProcessingHelpEditorWidget::ALGORITHM_EXAMPLES = QStringLiteral( 
"EXAMPLES" );
 
   34class QgsProcessingHelpEditorTreeItem : 
public QTreeWidgetItem
 
   38    QgsProcessingHelpEditorTreeItem( 
const QString &name, 
const QString &description )
 
   41      , description( description )
 
   43      setText( 0, description );
 
   52QgsProcessingHelpEditorWidget::QgsProcessingHelpEditorWidget( QWidget *parent )
 
   54  , mCurrentName( ALGORITHM_DESCRIPTION )
 
   58  connect( mElementTree, &QTreeWidget::currentItemChanged, 
this, &QgsProcessingHelpEditorWidget::changeItem );
 
   59  connect( mTextEdit, &QTextEdit::textChanged, 
this, [ = ]
 
   61    if ( !mCurrentName.isEmpty() )
 
   63      if ( mEditStackedWidget->currentWidget() == mPagePlainText )
 
   65        mHelpContent[ mCurrentName] = mTextEdit->toPlainText();
 
   73    if ( !mCurrentName.isEmpty() )
 
   75      if ( mEditStackedWidget->currentWidget() == mPageRichEdit )
 
   77        mHelpContent[ mCurrentName] = mRichTextEdit->toHtml();
 
   84QgsProcessingHelpEditorWidget::~QgsProcessingHelpEditorWidget() = 
default;
 
   93  if ( 
const QgsProcessingModelAlgorithm *model = 
dynamic_cast< const QgsProcessingModelAlgorithm *
>( mAlgorithm.get() ) )
 
   95    mHelpContent = model->helpContent();
 
   98  mEditStackedWidget->setCurrentWidget( mPageRichEdit );
 
   99  if ( mHelpContent.contains( ALGORITHM_DESCRIPTION ) )
 
  101    mRichTextEdit->setText( mHelpContent.value( ALGORITHM_DESCRIPTION ).toString() );
 
  104  mElementTree->addTopLevelItem( 
new QgsProcessingHelpEditorTreeItem( ALGORITHM_DESCRIPTION, tr( 
"Algorithm description" ) ) );
 
  105  mElementTree->addTopLevelItem( 
new QgsProcessingHelpEditorTreeItem( ALGORITHM_SHORT_DESCRIPTION, tr( 
"Short description" ) ) );
 
  107  QgsProcessingHelpEditorTreeItem *parametersItem = 
new QgsProcessingHelpEditorTreeItem( QString(), tr( 
"Input parameters" ) );
 
  108  mElementTree->addTopLevelItem( parametersItem );
 
  110  const QList< const QgsProcessingParameterDefinition * > definitions = mAlgorithm->parameterDefinitions();
 
  116    parametersItem->addChild( 
new QgsProcessingHelpEditorTreeItem( definition->name(), definition->description() ) );
 
  119  QgsProcessingHelpEditorTreeItem *outputsItem = 
new QgsProcessingHelpEditorTreeItem( QString(), tr( 
"Outputs" ) );
 
  120  mElementTree->addTopLevelItem( outputsItem );
 
  121  const QList< const QgsProcessingOutputDefinition * > outputs = mAlgorithm->outputDefinitions();
 
  124    outputsItem->addChild( 
new QgsProcessingHelpEditorTreeItem( output->name(), output->description() ) );
 
  127  mElementTree->addTopLevelItem( 
new QgsProcessingHelpEditorTreeItem( ALGORITHM_EXAMPLES, tr( 
"Examples" ) ) );
 
  129  mElementTree->addTopLevelItem( 
new QgsProcessingHelpEditorTreeItem( ALGORITHM_CREATOR, tr( 
"Algorithm author" ) ) );
 
  130  mElementTree->addTopLevelItem( 
new QgsProcessingHelpEditorTreeItem( ALGORITHM_HELP_CREATOR, tr( 
"Help author" ) ) );
 
  131  mElementTree->addTopLevelItem( 
new QgsProcessingHelpEditorTreeItem( ALGORITHM_VERSION, tr( 
"Algorithm version" ) ) );
 
  132  mElementTree->addTopLevelItem( 
new QgsProcessingHelpEditorTreeItem( ALGORITHM_HELP_URL, tr( 
"Documentation help URL (for help button)" ) ) );
 
  137QVariantMap QgsProcessingHelpEditorWidget::helpContent()
 
  143void QgsProcessingHelpEditorWidget::updateHtmlView()
 
  145  mTextPreview->setHtml( formattedHelp() );
 
  148void QgsProcessingHelpEditorWidget::changeItem( QTreeWidgetItem *, QTreeWidgetItem * )
 
  150  if ( QgsProcessingHelpEditorTreeItem *item = 
dynamic_cast< QgsProcessingHelpEditorTreeItem *
>( mElementTree->currentItem() ) )
 
  154    const QString name = item->name;
 
  155    if ( !name.isEmpty() )
 
  157      mTextEdit->setEnabled( 
true );
 
  158      mRichTextEdit->setEnabled( 
true );
 
  163      const bool useRichTextEdit = name == ALGORITHM_EXAMPLES || name == ALGORITHM_DESCRIPTION;
 
  164      if ( useRichTextEdit )
 
  166        mEditStackedWidget->setCurrentWidget( mPageRichEdit );
 
  167        if ( mHelpContent.contains( name ) )
 
  168          mRichTextEdit->setText( mHelpContent.value( name ).toString() );
 
  170          mRichTextEdit->setText( QString() );
 
  174        mEditStackedWidget->setCurrentWidget( mPagePlainText );
 
  175        if ( mHelpContent.contains( name ) )
 
  176          mTextEdit->setText( mHelpContent.value( name ).toString() );
 
  183      mCurrentName.clear();
 
  185      mRichTextEdit->setText( QString() );
 
  186      mTextEdit->setEnabled( 
false );
 
  187      mRichTextEdit->setEnabled( 
false );
 
  188      mEditStackedWidget->setCurrentWidget( mPagePlainText );
 
  194QString QgsProcessingHelpEditorWidget::formattedHelp()
 const 
  202void QgsProcessingHelpEditorWidget::storeCurrentValue()
 
  204  if ( !mCurrentName.isEmpty() )
 
  206    if ( mEditStackedWidget->currentWidget() == mPagePlainText )
 
  207      mHelpContent[ mCurrentName] = mTextEdit->toPlainText();
 
  209      mHelpContent[ mCurrentName] = mRichTextEdit->toHtml();
 
  213QgsProcessingHelpEditorDialog::QgsProcessingHelpEditorDialog( QWidget *parent, Qt::WindowFlags flags )
 
  214  : QDialog( parent, flags )
 
  216  setObjectName( QStringLiteral( 
"QgsProcessingHelpEditorDialog" ) );
 
  218  QVBoxLayout *vLayout = 
new QVBoxLayout();
 
  219  mWidget = 
new QgsProcessingHelpEditorWidget();
 
  220  vLayout->addWidget( mWidget, 1 );
 
  222  QDialogButtonBox *buttonBox = 
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
 
  223  connect( buttonBox, &QDialogButtonBox::accepted, 
this, &QDialog::accept );
 
  224  connect( buttonBox, &QDialogButtonBox::rejected, 
this, &QDialog::reject );
 
  225  vLayout->addWidget( buttonBox );
 
  226  setLayout( vLayout );
 
  236QVariantMap QgsProcessingHelpEditorDialog::helpContent()
 
  238  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