18 #include "qgsprocessingmodelalgorithm.h" 
   19 #include <QDialogButtonBox> 
   20 #include <QStandardItemModel> 
   23 QgsModelInputReorderWidget::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 ) );
 
   58 void QgsModelInputReorderWidget::setModel( QgsProcessingModelAlgorithm *model )
 
   61   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 );
 
   73 QStringList 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();
 
   85 QgsModelInputReorderDialog::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 );
 
   99 void QgsModelInputReorderDialog::setModel( QgsProcessingModelAlgorithm *model )
 
  101   mWidget->setModel( model );
 
  104 QStringList QgsModelInputReorderDialog::inputOrder()
 const 
  106   return mWidget->inputOrder();