Skip to content
Permalink
Browse files

UX improvements for comment editing

  • Loading branch information
nyalldawson committed Mar 4, 2020
1 parent 03fc033 commit 961557dacd4167603e850cc7a87b737ff1eb02e9
@@ -140,6 +140,29 @@ associated with the parameter.
Returns a new instance of a parameter definition, using the current settings defined in the dialog.

The ``name`` parameter specifies the name for the newly created parameter.
%End

void setComments( const QString &comments );
%Docstring
Sets the comments for the parameter.

.. seealso:: :py:func:`comments`

.. versionadded:: 3.14
%End

QString comments() const;
%Docstring
Returns the comments for the parameter.

.. seealso:: :py:func:`setComments`

.. versionadded:: 3.14
%End

void switchToCommentTab();
%Docstring
Switches the dialog to the comments tab.
%End

public slots:
@@ -831,10 +831,12 @@ def autogenerate_parameter_name(self, parameter):

def addInputOfType(self, paramType, pos=None):
new_param = None
comment = None
if ModelerParameterDefinitionDialog.use_legacy_dialog(paramType=paramType):
dlg = ModelerParameterDefinitionDialog(self.model, paramType)
if dlg.exec_():
new_param = dlg.param
comment = dlg.comments()
else:
# yay, use new API!
context = createContext()
@@ -846,6 +848,7 @@ def addInputOfType(self, paramType, pos=None):
if dlg.exec_():
new_param = dlg.createParameter()
self.autogenerate_parameter_name(new_param)
comment = dlg.comments()

if new_param is not None:
if pos is None:
@@ -855,6 +858,12 @@ def addInputOfType(self, paramType, pos=None):
component = QgsProcessingModelParameter(new_param.name())
component.setDescription(new_param.name())
component.setPosition(pos)

component.comment().setDescription(comment)
component.comment().setPosition(component.position() + QPointF(
component.size().width(),
-1.5 * component.size().height()))

self.model.addModelParameter(new_param, component)
self.repaintModel()
# self.view.ensureVisible(self.scene.getLastParameterItem())
@@ -903,6 +912,10 @@ def _addAlgorithm(self, alg, pos=None):
else:
alg.setPosition(pos)

alg.comment().setPosition(alg.position() + QPointF(
alg.size().width(),
-1.5 * alg.size().height()))

output_offset_x = alg.size().width()
output_offset_y = 1.5 * alg.size().height()
for out in alg.modelOutputs():
@@ -83,8 +83,13 @@ def edit(self, edit_comment=False):
widgetContext=widget_context,
definition=existing_param,
algorithm=self.model())
dlg.setComments(comment)
if edit_comment:
dlg.switchToCommentTab()

if dlg.exec_():
new_param = dlg.createParameter(existing_param.name())
comment = dlg.comments()

if new_param is not None:
self.model().removeModelParameter(self.component().parameterName())
@@ -139,11 +144,15 @@ def updateAlgorithm(self, alg):
alg.setPosition(existing_child.position())
alg.setLinksCollapsed(Qt.TopEdge, existing_child.linksCollapsed(Qt.TopEdge))
alg.setLinksCollapsed(Qt.BottomEdge, existing_child.linksCollapsed(Qt.BottomEdge))
alg.comment().setPosition(existing_child.comment().position())
alg.comment().setPosition(existing_child.comment().position() or
alg.position() + QPointF(
self.component().size().width(),
-1.5 * self.component().size().height())
)
alg.comment().setSize(existing_child.comment().size())
for i, out in enumerate(alg.modelOutputs().keys()):
alg.modelOutput(out).setPosition(existing_child.modelOutput(out).position()
or alg.position() + QPointF(
alg.modelOutput(out).setPosition(existing_child.modelOutput(out).position() or
alg.position() + QPointF(
self.component().size().width(),
(i + 1.5) * self.component().size().height()))
alg.modelOutput(out).comment().setDescription(existing_child.modelOutput(out).comment().description())
@@ -129,6 +129,8 @@ def closeEvent(self, event):

def switchToCommentTab(self):
self.tab.setCurrentIndex(1)
self.commentEdit.setFocus()
self.commentEdit.selectAll()

def setupUi(self):
type_metadata = QgsApplication.processingRegistry().parameterType(self.param.type() if self.param else self.paramType)
@@ -104,6 +104,8 @@ def closeEvent(self, event):

def switchToCommentTab(self):
self.tab.setCurrentIndex(1)
self.commentEdit.setFocus()
self.commentEdit.selectAll()

def setupUi(self):
self.checkBoxes = {}
@@ -29,6 +29,8 @@
#include <QDialog>
#include <QDialogButtonBox>
#include <QMessageBox>
#include <QTabWidget>
#include <QTextEdit>

QgsProcessingAbstractParameterDefinitionWidget::QgsProcessingAbstractParameterDefinitionWidget( QgsProcessingContext &,
const QgsProcessingParameterWidgetContext &,
@@ -130,11 +132,28 @@ QgsProcessingParameterDefinitionDialog::QgsProcessingParameterDefinitionDialog(
: QDialog( parent )
{
QVBoxLayout *vLayout = new QVBoxLayout();
mTabWidget = new QTabWidget();
vLayout->addWidget( mTabWidget );

QVBoxLayout *vLayout2 = new QVBoxLayout();
mWidget = new QgsProcessingParameterDefinitionWidget( type, context, widgetContext, definition, algorithm );
vLayout->addWidget( mWidget );
vLayout2->addWidget( mWidget );
QWidget *w = new QWidget();
w->setLayout( vLayout2 );
mTabWidget->addTab( w, tr( "Properties" ) );

QVBoxLayout *commentLayout = new QVBoxLayout();
mCommentEdit = new QTextEdit();
mCommentEdit->setAcceptRichText( false );
commentLayout->addWidget( mCommentEdit );
QWidget *w2 = new QWidget();
w2->setLayout( commentLayout );
mTabWidget->addTab( w2, tr( "Comments" ) );

QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
connect( bbox, &QDialogButtonBox::accepted, this, &QgsProcessingParameterDefinitionDialog::accept );
connect( bbox, &QDialogButtonBox::rejected, this, &QgsProcessingParameterDefinitionDialog::reject );

vLayout->addWidget( bbox );
setLayout( vLayout );
setWindowTitle( definition ? tr( "%1 Parameter Definition" ).arg( definition->description() )
@@ -149,6 +168,23 @@ QgsProcessingParameterDefinition *QgsProcessingParameterDefinitionDialog::create
return mWidget->createParameter( name );
}

void QgsProcessingParameterDefinitionDialog::setComments( const QString &comments )
{
mCommentEdit->setPlainText( comments );
}

QString QgsProcessingParameterDefinitionDialog::comments() const
{
return mCommentEdit->toPlainText();
}

void QgsProcessingParameterDefinitionDialog::switchToCommentTab()
{
mTabWidget->setCurrentIndex( 1 );
mCommentEdit->setFocus();
mCommentEdit->selectAll();
}

void QgsProcessingParameterDefinitionDialog::accept()
{
if ( mWidget->mDescriptionLineEdit->text().isEmpty() )
@@ -29,6 +29,8 @@
class QgsProcessingParameterWidgetContext;
class QLineEdit;
class QCheckBox;
class QTabWidget;
class QTextEdit;

/**
* Abstract base class for widgets which allow users to specify the properties of a
@@ -167,11 +169,32 @@ class GUI_EXPORT QgsProcessingParameterDefinitionDialog: public QDialog
*/
QgsProcessingParameterDefinition *createParameter( const QString &name = QString() ) const SIP_FACTORY;

/**
* Sets the comments for the parameter.
* \see comments()
* \since QGIS 3.14
*/
void setComments( const QString &comments );

/**
* Returns the comments for the parameter.
* \see setComments()
* \since QGIS 3.14
*/
QString comments() const;

/**
* Switches the dialog to the comments tab.
*/
void switchToCommentTab();

public slots:
void accept() override;

private:

QTabWidget *mTabWidget = nullptr;
QTextEdit *mCommentEdit = nullptr;
QgsProcessingParameterDefinitionWidget *mWidget = nullptr;

};

0 comments on commit 961557d

Please sign in to comment.
You can’t perform that action at this time.