19#include <QDialogButtonBox>
20#include <QStandardItemModel>
23QgsModelOutputReorderWidget::QgsModelOutputReorderWidget( QWidget *parent )
28 mItemModel =
new QStandardItemModel( 0, 1,
this );
29 mOutputsList->setModel( mItemModel );
31 mOutputsList->setDropIndicatorShown(
true );
32 mOutputsList->setDragDropOverwriteMode(
false );
33 mOutputsList->setDragEnabled(
true );
34 mOutputsList->setDragDropMode( QAbstractItemView::InternalMove );
36 connect( mButtonUp, &QPushButton::clicked,
this, [ = ]
38 int currentRow = mOutputsList->currentIndex().row();
39 if ( currentRow == 0 )
42 mItemModel->insertRow( currentRow - 1, mItemModel->takeRow( currentRow ) );
43 mOutputsList->setCurrentIndex( mItemModel->index( currentRow - 1, 0 ) );
46 connect( mButtonDown, &QPushButton::clicked,
this, [ = ]
48 int currentRow = mOutputsList->currentIndex().row();
49 if ( currentRow == mItemModel->rowCount() - 1 )
52 mItemModel->insertRow( currentRow + 1, mItemModel->takeRow( currentRow ) );
53 mOutputsList->setCurrentIndex( mItemModel->index( currentRow + 1, 0 ) );
58void QgsModelOutputReorderWidget::setModel( QgsProcessingModelAlgorithm *model )
61 mOutputs = mModel->orderedOutputs();
63 for (
const QgsProcessingModelOutput &output : std::as_const( mOutputs ) )
65 QStandardItem *item =
new QStandardItem( output.name() );
66 item->setData( QStringLiteral(
"%1:%2" ).arg( output.childId(), output.childOutputName() ), Qt::UserRole + 1 );
67 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
69 mItemModel->insertRow( 0, item );
72 mPlaceInGroupCheck->setChecked( !model->outputGroup().isEmpty() );
73 mGroupNameEdit->setText( model->outputGroup() );
76QStringList QgsModelOutputReorderWidget::outputOrder()
const
79 order.reserve( mItemModel->rowCount( ) );
81 for (
int row = mItemModel->rowCount() - 1; row >= 0; --row )
83 order << mItemModel->data( mItemModel->index( row, 0 ), Qt::UserRole + 1 ).toString();
88QString QgsModelOutputReorderWidget::outputGroup()
const
90 return mPlaceInGroupCheck->isChecked() ? mGroupNameEdit->text() : QString();
94QgsModelOutputReorderDialog::QgsModelOutputReorderDialog( QWidget *parent )
97 setWindowTitle( tr(
"Reorder Output Layers" ) );
98 mWidget =
new QgsModelOutputReorderWidget();
99 QVBoxLayout *vl =
new QVBoxLayout();
100 vl->addWidget( mWidget, 1 );
101 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
102 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
103 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
104 vl->addWidget( buttonBox );
108void QgsModelOutputReorderDialog::setModel( QgsProcessingModelAlgorithm *model )
110 mWidget->setModel( model );
113QStringList QgsModelOutputReorderDialog::outputOrder()
const
115 return mWidget->outputOrder();
118QString QgsModelOutputReorderDialog::outputGroup()
const
120 return mWidget->outputGroup();