17#include "moc_qgsmodeloutputreorderwidget.cpp"
20#include <QDialogButtonBox>
21#include <QStandardItemModel>
24QgsModelOutputReorderWidget::QgsModelOutputReorderWidget( QWidget *parent )
29 mItemModel =
new QStandardItemModel( 0, 1,
this );
30 mOutputsList->setModel( mItemModel );
32 mOutputsList->setDropIndicatorShown(
true );
33 mOutputsList->setDragDropOverwriteMode(
false );
34 mOutputsList->setDragEnabled(
true );
35 mOutputsList->setDragDropMode( QAbstractItemView::InternalMove );
37 connect( mButtonUp, &QPushButton::clicked,
this, [ = ]
39 int currentRow = mOutputsList->currentIndex().row();
40 if ( currentRow == 0 )
43 mItemModel->insertRow( currentRow - 1, mItemModel->takeRow( currentRow ) );
44 mOutputsList->setCurrentIndex( mItemModel->index( currentRow - 1, 0 ) );
47 connect( mButtonDown, &QPushButton::clicked,
this, [ = ]
49 int currentRow = mOutputsList->currentIndex().row();
50 if ( currentRow == mItemModel->rowCount() - 1 )
53 mItemModel->insertRow( currentRow + 1, mItemModel->takeRow( currentRow ) );
54 mOutputsList->setCurrentIndex( mItemModel->index( currentRow + 1, 0 ) );
59void QgsModelOutputReorderWidget::setModel( QgsProcessingModelAlgorithm *model )
62 mOutputs = mModel->orderedOutputs();
64 for (
const QgsProcessingModelOutput &output : std::as_const( mOutputs ) )
66 QStandardItem *item =
new QStandardItem( output.name() );
67 item->setData( QStringLiteral(
"%1:%2" ).arg( output.childId(), output.childOutputName() ), Qt::UserRole + 1 );
68 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
70 mItemModel->insertRow( 0, item );
73 mPlaceInGroupCheck->setChecked( !model->outputGroup().isEmpty() );
74 mGroupNameEdit->setText( model->outputGroup() );
77QStringList QgsModelOutputReorderWidget::outputOrder()
const
80 order.reserve( mItemModel->rowCount( ) );
82 for (
int row = mItemModel->rowCount() - 1; row >= 0; --row )
84 order << mItemModel->data( mItemModel->index( row, 0 ), Qt::UserRole + 1 ).toString();
89QString QgsModelOutputReorderWidget::outputGroup()
const
91 return mPlaceInGroupCheck->isChecked() ? mGroupNameEdit->text() : QString();
95QgsModelOutputReorderDialog::QgsModelOutputReorderDialog( QWidget *parent )
98 setWindowTitle( tr(
"Reorder Output Layers" ) );
99 mWidget =
new QgsModelOutputReorderWidget();
100 QVBoxLayout *vl =
new QVBoxLayout();
101 vl->addWidget( mWidget, 1 );
102 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
103 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
104 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
105 vl->addWidget( buttonBox );
109void QgsModelOutputReorderDialog::setModel( QgsProcessingModelAlgorithm *model )
111 mWidget->setModel( model );
114QStringList QgsModelOutputReorderDialog::outputOrder()
const
116 return mWidget->outputOrder();
119QString QgsModelOutputReorderDialog::outputGroup()
const
121 return mWidget->outputGroup();