19#include <QDialogButtonBox>
20#include <QStandardItemModel>
23QgsModelInputReorderWidget::QgsModelInputReorderWidget( QWidget *parent )
28 mItemModel =
new QStandardItemModel( 0, 1,
this );
29 mInputsList->setModel( mItemModel );
31 mInputsList->setDropIndicatorShown(
true );
32 mInputsList->setDragDropOverwriteMode(
false );
33 mInputsList->setDragEnabled(
true );
34 mInputsList->setDragDropMode( QAbstractItemView::InternalMove );
36 connect( mButtonUp, &QPushButton::clicked,
this, [ = ]
38 int currentRow = mInputsList->currentIndex().row();
39 if ( currentRow == 0 )
42 mItemModel->insertRow( currentRow - 1, mItemModel->takeRow( currentRow ) );
43 mInputsList->setCurrentIndex( mItemModel->index( currentRow - 1, 0 ) );
46 connect( mButtonDown, &QPushButton::clicked,
this, [ = ]
48 int currentRow = mInputsList->currentIndex().row();
49 if ( currentRow == mItemModel->rowCount() - 1 )
52 mItemModel->insertRow( currentRow + 1, mItemModel->takeRow( currentRow ) );
53 mInputsList->setCurrentIndex( mItemModel->index( currentRow + 1, 0 ) );
58void QgsModelInputReorderWidget::setModel( QgsProcessingModelAlgorithm *model )
61 mParameters = mModel->orderedParameters();
63 for (
const QgsProcessingModelParameter ¶m : std::as_const( mParameters ) )
65 QStandardItem *item =
new QStandardItem( mModel->parameterDefinition( param.parameterName() )->description() );
66 item->setData( param.parameterName() );
67 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
68 mItemModel->appendRow( item );
72QStringList QgsModelInputReorderWidget::inputOrder()
const
75 order.reserve( mItemModel->rowCount( ) );
76 for (
int row = 0; row < mItemModel->rowCount(); ++row )
78 order << mItemModel->data( mItemModel->index( row, 0 ), Qt::UserRole + 1 ).toString();
84QgsModelInputReorderDialog::QgsModelInputReorderDialog( QWidget *parent )
87 setWindowTitle( tr(
"Reorder Model Inputs" ) );
88 mWidget =
new QgsModelInputReorderWidget();
89 QVBoxLayout *vl =
new QVBoxLayout();
90 vl->addWidget( mWidget, 1 );
91 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
92 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
93 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
94 vl->addWidget( buttonBox );
98void QgsModelInputReorderDialog::setModel( QgsProcessingModelAlgorithm *model )
100 mWidget->setModel( model );
103QStringList QgsModelInputReorderDialog::inputOrder()
const
105 return mWidget->inputOrder();