17#include "moc_qgsmodelinputreorderwidget.cpp"
20#include <QDialogButtonBox>
21#include <QStandardItemModel>
24QgsModelInputReorderWidget::QgsModelInputReorderWidget( QWidget *parent )
29 mItemModel =
new QStandardItemModel( 0, 1,
this );
30 mInputsList->setModel( mItemModel );
32 mInputsList->setDropIndicatorShown(
true );
33 mInputsList->setDragDropOverwriteMode(
false );
34 mInputsList->setDragEnabled(
true );
35 mInputsList->setDragDropMode( QAbstractItemView::InternalMove );
37 connect( mButtonUp, &QPushButton::clicked,
this, [ = ]
39 int currentRow = mInputsList->currentIndex().row();
40 if ( currentRow == 0 )
43 mItemModel->insertRow( currentRow - 1, mItemModel->takeRow( currentRow ) );
44 mInputsList->setCurrentIndex( mItemModel->index( currentRow - 1, 0 ) );
47 connect( mButtonDown, &QPushButton::clicked,
this, [ = ]
49 int currentRow = mInputsList->currentIndex().row();
50 if ( currentRow == mItemModel->rowCount() - 1 )
53 mItemModel->insertRow( currentRow + 1, mItemModel->takeRow( currentRow ) );
54 mInputsList->setCurrentIndex( mItemModel->index( currentRow + 1, 0 ) );
59void QgsModelInputReorderWidget::setModel( QgsProcessingModelAlgorithm *model )
62 mParameters = mModel->orderedParameters();
64 for (
const QgsProcessingModelParameter ¶m : std::as_const( mParameters ) )
66 QStandardItem *item =
new QStandardItem( mModel->parameterDefinition( param.parameterName() )->description() );
67 item->setData( param.parameterName() );
68 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
69 mItemModel->appendRow( item );
73QStringList QgsModelInputReorderWidget::inputOrder()
const
76 order.reserve( mItemModel->rowCount( ) );
77 for (
int row = 0; row < mItemModel->rowCount(); ++row )
79 order << mItemModel->data( mItemModel->index( row, 0 ), Qt::UserRole + 1 ).toString();
85QgsModelInputReorderDialog::QgsModelInputReorderDialog( QWidget *parent )
88 setWindowTitle( tr(
"Reorder Model Inputs" ) );
89 mWidget =
new QgsModelInputReorderWidget();
90 QVBoxLayout *vl =
new QVBoxLayout();
91 vl->addWidget( mWidget, 1 );
92 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
93 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
94 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
95 vl->addWidget( buttonBox );
99void QgsModelInputReorderDialog::setModel( QgsProcessingModelAlgorithm *model )
101 mWidget->setModel( model );
104QStringList QgsModelInputReorderDialog::inputOrder()
const
106 return mWidget->inputOrder();