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, [=] {
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, [=] {
47 int currentRow = mInputsList->currentIndex().row();
48 if ( currentRow == mItemModel->rowCount() - 1 )
51 mItemModel->insertRow( currentRow + 1, mItemModel->takeRow( currentRow ) );
52 mInputsList->setCurrentIndex( mItemModel->index( currentRow + 1, 0 ) );
56void QgsModelInputReorderWidget::setModel( QgsProcessingModelAlgorithm *model )
59 mParameters = mModel->orderedParameters();
61 for (
const QgsProcessingModelParameter ¶m : std::as_const( mParameters ) )
63 QStandardItem *item =
new QStandardItem( mModel->parameterDefinition( param.parameterName() )->description() );
64 item->setData( param.parameterName() );
65 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
66 mItemModel->appendRow( item );
70QStringList QgsModelInputReorderWidget::inputOrder()
const
73 order.reserve( mItemModel->rowCount() );
74 for (
int row = 0; row < mItemModel->rowCount(); ++row )
76 order << mItemModel->data( mItemModel->index( row, 0 ), Qt::UserRole + 1 ).toString();
82QgsModelInputReorderDialog::QgsModelInputReorderDialog( QWidget *parent )
85 setWindowTitle( tr(
"Reorder Model Inputs" ) );
86 mWidget =
new QgsModelInputReorderWidget();
87 QVBoxLayout *vl =
new QVBoxLayout();
88 vl->addWidget( mWidget, 1 );
89 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
90 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
91 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
92 vl->addWidget( buttonBox );
96void QgsModelInputReorderDialog::setModel( QgsProcessingModelAlgorithm *model )
98 mWidget->setModel( model );
101QStringList QgsModelInputReorderDialog::inputOrder()
const
103 return mWidget->inputOrder();