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, [=] {
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, [=] {
47 int currentRow = mOutputsList->currentIndex().row();
48 if ( currentRow == mItemModel->rowCount() - 1 )
51 mItemModel->insertRow( currentRow + 1, mItemModel->takeRow( currentRow ) );
52 mOutputsList->setCurrentIndex( mItemModel->index( currentRow + 1, 0 ) );
56void QgsModelOutputReorderWidget::setModel( QgsProcessingModelAlgorithm *model )
59 mOutputs = mModel->orderedOutputs();
61 for (
const QgsProcessingModelOutput &output : std::as_const( mOutputs ) )
63 QStandardItem *item =
new QStandardItem( output.name() );
64 item->setData( QStringLiteral(
"%1:%2" ).arg( output.childId(), output.childOutputName() ), Qt::UserRole + 1 );
65 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
67 mItemModel->insertRow( 0, item );
70 mPlaceInGroupCheck->setChecked( !model->outputGroup().isEmpty() );
71 mGroupNameEdit->setText( model->outputGroup() );
74QStringList QgsModelOutputReorderWidget::outputOrder()
const
77 order.reserve( mItemModel->rowCount() );
79 for (
int row = mItemModel->rowCount() - 1; row >= 0; --row )
81 order << mItemModel->data( mItemModel->index( row, 0 ), Qt::UserRole + 1 ).toString();
86QString QgsModelOutputReorderWidget::outputGroup()
const
88 return mPlaceInGroupCheck->isChecked() ? mGroupNameEdit->text() : QString();
92QgsModelOutputReorderDialog::QgsModelOutputReorderDialog( QWidget *parent )
95 setWindowTitle( tr(
"Reorder Output Layers" ) );
96 mWidget =
new QgsModelOutputReorderWidget();
97 QVBoxLayout *vl =
new QVBoxLayout();
98 vl->addWidget( mWidget, 1 );
99 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
100 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
101 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
102 vl->addWidget( buttonBox );
106void QgsModelOutputReorderDialog::setModel( QgsProcessingModelAlgorithm *model )
108 mWidget->setModel( model );
111QStringList QgsModelOutputReorderDialog::outputOrder()
const
113 return mWidget->outputOrder();
116QString QgsModelOutputReorderDialog::outputGroup()
const
118 return mWidget->outputGroup();