Skip to content

Commit

Permalink
[processing] Matrix configuration dialog should open as an inline
Browse files Browse the repository at this point in the history
panel, not a dialog
  • Loading branch information
nyalldawson committed Jun 11, 2020
1 parent 2bb4aad commit 14ee228
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 55 deletions.
44 changes: 31 additions & 13 deletions src/gui/processing/qgsprocessingmatrixparameterdialog.cpp
Expand Up @@ -23,8 +23,8 @@

///@cond NOT_STABLE

QgsProcessingMatrixParameterDialog::QgsProcessingMatrixParameterDialog( QWidget *parent, Qt::WindowFlags flags, const QgsProcessingParameterMatrix *param, const QVariantList &initialTable )
: QDialog( parent, flags )
QgsProcessingMatrixParameterPanelWidget::QgsProcessingMatrixParameterPanelWidget( QWidget *parent, const QgsProcessingParameterMatrix *param, const QVariantList &initialTable )
: QgsPanelWidget( parent )
, mParam( param )
{
setupUi( this );
Expand All @@ -43,9 +43,19 @@ QgsProcessingMatrixParameterDialog::QgsProcessingMatrixParameterDialog( QWidget
mButtonRemoveAll = new QPushButton( tr( "Remove All" ) );
mButtonBox->addButton( mButtonRemoveAll, QDialogButtonBox::ActionRole );

connect( mButtonAdd, &QPushButton::clicked, this, &QgsProcessingMatrixParameterDialog::addRow );
connect( mButtonRemove, &QPushButton::clicked, this, &QgsProcessingMatrixParameterDialog::deleteRow );
connect( mButtonRemoveAll, &QPushButton::clicked, this, &QgsProcessingMatrixParameterDialog::deleteAllRows );
connect( mButtonBox->button( QDialogButtonBox::Ok ), &QPushButton::clicked, this, [ = ]
{
emit widgetChanged();
acceptPanel();
} );
connect( mButtonBox->button( QDialogButtonBox::Cancel ), &QPushButton::clicked, this, [ = ]
{
acceptPanel();
} );

connect( mButtonAdd, &QPushButton::clicked, this, &QgsProcessingMatrixParameterPanelWidget::addRow );
connect( mButtonRemove, &QPushButton::clicked, this, &QgsProcessingMatrixParameterPanelWidget::deleteRow );
connect( mButtonRemoveAll, &QPushButton::clicked, this, &QgsProcessingMatrixParameterPanelWidget::deleteAllRows );

if ( param && param->hasFixedNumberRows() )
{
Expand All @@ -57,7 +67,7 @@ QgsProcessingMatrixParameterDialog::QgsProcessingMatrixParameterDialog( QWidget
populateTable( initialTable );
}

QVariantList QgsProcessingMatrixParameterDialog::table() const
QVariantList QgsProcessingMatrixParameterPanelWidget::table() const
{
const int cols = mModel->columnCount();
const int rows = mModel->rowCount();
Expand All @@ -74,7 +84,7 @@ QVariantList QgsProcessingMatrixParameterDialog::table() const
return res;
}

void QgsProcessingMatrixParameterDialog::addRow()
void QgsProcessingMatrixParameterPanelWidget::addRow()
{
QList< QStandardItem * > items;
for ( int i = 0; i < mTblView->model()->columnCount(); ++i )
Expand All @@ -84,7 +94,7 @@ void QgsProcessingMatrixParameterDialog::addRow()
mModel->appendRow( items );
}

void QgsProcessingMatrixParameterDialog::deleteRow()
void QgsProcessingMatrixParameterPanelWidget::deleteRow()
{
QModelIndexList selected = mTblView->selectionModel()->selectedRows();
QSet< int > rows;
Expand All @@ -101,14 +111,14 @@ void QgsProcessingMatrixParameterDialog::deleteRow()
mTblView->setUpdatesEnabled( true );
}

void QgsProcessingMatrixParameterDialog::deleteAllRows()
void QgsProcessingMatrixParameterPanelWidget::deleteAllRows()
{
mModel->clear();
if ( mParam )
mModel->setHorizontalHeaderLabels( mParam->headers() );
}

void QgsProcessingMatrixParameterDialog::populateTable( const QVariantList &contents )
void QgsProcessingMatrixParameterPanelWidget::populateTable( const QVariantList &contents )
{
if ( !mParam )
return;
Expand Down Expand Up @@ -175,10 +185,18 @@ void QgsProcessingMatrixParameterPanel::setValue( const QVariantList &value )

void QgsProcessingMatrixParameterPanel::showDialog()
{
QgsProcessingMatrixParameterDialog dlg( this, nullptr, mParam, mTable );
if ( dlg.exec() )
if ( QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this ) )
{
setValue( dlg.table() );
QgsProcessingMatrixParameterPanelWidget *widget = new QgsProcessingMatrixParameterPanelWidget( this, mParam, mTable );

widget->setPanelTitle( mParam->description() );

panel->openPanel( widget );

connect( widget, &QgsPanelWidget::widgetChanged, this, [ = ]
{
setValue( widget->table() );
} );
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/gui/processing/qgsprocessingmatrixparameterdialog.h
Expand Up @@ -30,11 +30,11 @@ class QToolButton;

/**
* \ingroup gui
* \brief Dialog for configuration of a matrix (fixed table) parameter.
* \brief Panel widget for configuration of a matrix (fixed table) parameter.
* \note Not stable API
* \since QGIS 3.6
*/
class GUI_EXPORT QgsProcessingMatrixParameterDialog : public QDialog, private Ui::QgsProcessingMatrixParameterDialogBase
class GUI_EXPORT QgsProcessingMatrixParameterPanelWidget : public QgsPanelWidget, private Ui::QgsProcessingMatrixParameterDialogBase
{
Q_OBJECT

Expand All @@ -43,8 +43,8 @@ class GUI_EXPORT QgsProcessingMatrixParameterDialog : public QDialog, private Ui
/**
* Constructor for QgsProcessingMatrixParameterDialog.
*/
QgsProcessingMatrixParameterDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = nullptr, const QgsProcessingParameterMatrix *param = nullptr,
const QVariantList &initialTable = QVariantList() );
QgsProcessingMatrixParameterPanelWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QgsProcessingParameterMatrix *param = nullptr,
const QVariantList &initialTable = QVariantList() );

/**
* Returns the table's contents as a 1 dimensional array.
Expand Down
45 changes: 10 additions & 35 deletions src/ui/processing/qgsprocessingmatrixparameterdialogbase.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsProcessingMatrixParameterDialogBase</class>
<widget class="QDialog" name="QgsProcessingMatrixParameterDialogBase">
<widget class="QgsPanelWidget" name="QgsProcessingMatrixParameterDialogBase">
<property name="geometry">
<rect>
<x>0</x>
Expand Down Expand Up @@ -48,39 +48,14 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsPanelWidget</class>
<extends>QWidget</extends>
<header>qgspanelwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>mButtonBox</sender>
<signal>accepted()</signal>
<receiver>QgsProcessingMatrixParameterDialogBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>mButtonBox</sender>
<signal>rejected()</signal>
<receiver>QgsProcessingMatrixParameterDialogBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>
6 changes: 3 additions & 3 deletions tests/src/gui/testprocessinggui.cpp
Expand Up @@ -2367,23 +2367,23 @@ void TestProcessingGui::testRangeWrapper()
void TestProcessingGui::testMatrixDialog()
{
QgsProcessingParameterMatrix matrixParam( QString(), QString(), 3, false, QStringList() << QStringLiteral( "a" ) << QStringLiteral( "b" ) );
std::unique_ptr< QgsProcessingMatrixParameterDialog > dlg = qgis::make_unique< QgsProcessingMatrixParameterDialog>( nullptr, nullptr, &matrixParam );
std::unique_ptr< QgsProcessingMatrixParameterPanelWidget > dlg = qgis::make_unique< QgsProcessingMatrixParameterPanelWidget>( nullptr, &matrixParam );
// variable length table
QVERIFY( dlg->mButtonAdd->isEnabled() );
QVERIFY( dlg->mButtonRemove->isEnabled() );
QVERIFY( dlg->mButtonRemoveAll->isEnabled() );

QCOMPARE( dlg->table(), QVariantList() );

dlg = qgis::make_unique< QgsProcessingMatrixParameterDialog >( nullptr, nullptr, &matrixParam, QVariantList() << QStringLiteral( "a" ) << QStringLiteral( "b" ) << QStringLiteral( "c" ) << QStringLiteral( "d" ) << QStringLiteral( "e" ) << QStringLiteral( "f" ) );
dlg = qgis::make_unique< QgsProcessingMatrixParameterPanelWidget >( nullptr, &matrixParam, QVariantList() << QStringLiteral( "a" ) << QStringLiteral( "b" ) << QStringLiteral( "c" ) << QStringLiteral( "d" ) << QStringLiteral( "e" ) << QStringLiteral( "f" ) );
QCOMPARE( dlg->table(), QVariantList() << QStringLiteral( "a" ) << QStringLiteral( "b" ) << QStringLiteral( "c" ) << QStringLiteral( "d" ) << QStringLiteral( "e" ) << QStringLiteral( "f" ) );
dlg->addRow();
QCOMPARE( dlg->table(), QVariantList() << QStringLiteral( "a" ) << QStringLiteral( "b" ) << QStringLiteral( "c" ) << QStringLiteral( "d" ) << QStringLiteral( "e" ) << QStringLiteral( "f" ) << QString() << QString() );
dlg->deleteAllRows();
QCOMPARE( dlg->table(), QVariantList() );

QgsProcessingParameterMatrix matrixParam2( QString(), QString(), 3, true, QStringList() << QStringLiteral( "a" ) << QStringLiteral( "b" ) );
dlg = qgis::make_unique< QgsProcessingMatrixParameterDialog >( nullptr, nullptr, &matrixParam2, QVariantList() << QStringLiteral( "a" ) << QStringLiteral( "b" ) << QStringLiteral( "c" ) << QStringLiteral( "d" ) << QStringLiteral( "e" ) << QStringLiteral( "f" ) );
dlg = qgis::make_unique< QgsProcessingMatrixParameterPanelWidget >( nullptr, &matrixParam2, QVariantList() << QStringLiteral( "a" ) << QStringLiteral( "b" ) << QStringLiteral( "c" ) << QStringLiteral( "d" ) << QStringLiteral( "e" ) << QStringLiteral( "f" ) );
QVERIFY( !dlg->mButtonAdd->isEnabled() );
QVERIFY( !dlg->mButtonRemove->isEnabled() );
QVERIFY( !dlg->mButtonRemoveAll->isEnabled() );
Expand Down

0 comments on commit 14ee228

Please sign in to comment.