Skip to content

Commit

Permalink
Show description in model input reorder dialog, not raw parameter name
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 22, 2020
1 parent 888819c commit 947aedb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/gui/processing/models/qgsmodeldesignerdialog.cpp
Expand Up @@ -821,7 +821,7 @@ void QgsModelDesignerDialog::validate()
void QgsModelDesignerDialog::reorderInputs()
{
QgsModelInputReorderDialog dlg( this );
dlg.setInputs( mModel->orderedParameters() );
dlg.setModel( mModel.get() );
if ( dlg.exec() )
{
const QStringList inputOrder = dlg.inputOrder();
Expand Down
52 changes: 22 additions & 30 deletions src/gui/processing/models/qgsmodelinputreorderwidget.cpp
Expand Up @@ -15,6 +15,7 @@

#include "qgsmodelinputreorderwidget.h"
#include "qgsgui.h"
#include "qgsprocessingmodelalgorithm.h"
#include <QDialogButtonBox>
#include <QStandardItemModel>
///@cond NOT_STABLE
Expand All @@ -24,8 +25,8 @@ QgsModelInputReorderWidget::QgsModelInputReorderWidget( QWidget *parent )
{
setupUi( this );

mModel = new QStandardItemModel( 0, 1, this );
mInputsList->setModel( mModel );
mItemModel = new QStandardItemModel( 0, 1, this );
mInputsList->setModel( mItemModel );

mInputsList->setDropIndicatorShown( true );
mInputsList->setDragDropOverwriteMode( false );
Expand All @@ -38,55 +39,46 @@ QgsModelInputReorderWidget::QgsModelInputReorderWidget( QWidget *parent )
if ( currentRow == 0 )
return;

mModel->insertRow( currentRow - 1, mModel->takeRow( currentRow ) );
mInputsList->setCurrentIndex( mModel->index( currentRow - 1, 0 ) );
mItemModel->insertRow( currentRow - 1, mItemModel->takeRow( currentRow ) );
mInputsList->setCurrentIndex( mItemModel->index( currentRow - 1, 0 ) );
} );

connect( mButtonDown, &QPushButton::clicked, this, [ = ]
{
int currentRow = mInputsList->currentIndex().row();
if ( currentRow == mModel->rowCount() - 1 )
if ( currentRow == mItemModel->rowCount() - 1 )
return;

mModel->insertRow( currentRow + 1, mModel->takeRow( currentRow ) );
mInputsList->setCurrentIndex( mModel->index( currentRow + 1, 0 ) );
mItemModel->insertRow( currentRow + 1, mItemModel->takeRow( currentRow ) );
mInputsList->setCurrentIndex( mItemModel->index( currentRow + 1, 0 ) );
} );

}

void QgsModelInputReorderWidget::setInputs( const QList<QgsProcessingModelParameter> &inputs )
void QgsModelInputReorderWidget::setModel( QgsProcessingModelAlgorithm *model )
{
mParameters = inputs;
mModel = model;
mParameters = mModel->orderedParameters();
QStringList res;
mModel->clear();
for ( const QgsProcessingModelParameter &param : inputs )
mItemModel->clear();
for ( const QgsProcessingModelParameter &param : qgis::as_const( mParameters ) )
{
QStandardItem *item = new QStandardItem( param.description() );
QStandardItem *item = new QStandardItem( mModel->parameterDefinition( param.parameterName() )->description() );
item->setData( param.parameterName() );
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
mModel->appendRow( item );
mItemModel->appendRow( item );
}
}

QStringList QgsModelInputReorderWidget::inputOrder() const
{
QStringList order;
order.reserve( mModel->rowCount( ) );
for ( int row = 0; row < mModel->rowCount(); ++row )
order.reserve( mItemModel->rowCount( ) );
for ( int row = 0; row < mItemModel->rowCount(); ++row )
{
order << mModel->data( mModel->index( row, 0 ) ).toString();
order << mItemModel->data( mItemModel->index( row, 0 ), Qt::UserRole + 1 ).toString();
}
QStringList res;
for ( const QString &description : order )
{
for ( auto it = mParameters.constBegin(); it != mParameters.constEnd(); ++it )
{
if ( it->description() == description )
{
res << it->parameterName();
}
}
}
return res;
return order;
}


Expand All @@ -104,9 +96,9 @@ QgsModelInputReorderDialog::QgsModelInputReorderDialog( QWidget *parent )
setLayout( vl );
}

void QgsModelInputReorderDialog::setInputs( const QList<QgsProcessingModelParameter> &inputs )
void QgsModelInputReorderDialog::setModel( QgsProcessingModelAlgorithm *model )
{
mWidget->setInputs( inputs );
mWidget->setModel( model );
}

QStringList QgsModelInputReorderDialog::inputOrder() const
Expand Down
12 changes: 7 additions & 5 deletions src/gui/processing/models/qgsmodelinputreorderwidget.h
Expand Up @@ -25,6 +25,7 @@
#include <QDialog>

class QStandardItemModel;
class QgsProcessingModelAlgorithm;

///@cond PRIVATE

Expand All @@ -46,9 +47,9 @@ class GUI_EXPORT QgsModelInputReorderWidget : public QWidget, private Ui::QgsMod
QgsModelInputReorderWidget( QWidget *parent = nullptr );

/**
* Sets the list of \a inputs to show, in their initial order.
* Sets the source \a model from which to obtain the list of inputs.
*/
void setInputs( const QList< QgsProcessingModelParameter > &inputs );
void setModel( QgsProcessingModelAlgorithm *model );

/**
* Returns the ordered list of inputs (by name).
Expand All @@ -57,8 +58,9 @@ class GUI_EXPORT QgsModelInputReorderWidget : public QWidget, private Ui::QgsMod

private:

QgsProcessingModelAlgorithm *mModel;
QList< QgsProcessingModelParameter > mParameters;
QStandardItemModel *mModel = nullptr;
QStandardItemModel *mItemModel = nullptr;
};


Expand All @@ -79,9 +81,9 @@ class GUI_EXPORT QgsModelInputReorderDialog : public QDialog
QgsModelInputReorderDialog( QWidget *parent = nullptr );

/**
* Sets the list of \a inputs to show, in their initial order.
* Sets the source \a model from which to obtain the list of inputs.
*/
void setInputs( const QList< QgsProcessingModelParameter > &inputs );
void setModel( QgsProcessingModelAlgorithm *model );

/**
* Returns the ordered list of inputs (by name).
Expand Down

0 comments on commit 947aedb

Please sign in to comment.