From 693ead28bbb8f7837d8d211c1472eb32069084d9 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 13 Jun 2016 09:18:59 +1000 Subject: [PATCH] Prevent creating invalid join in add join dialog (fixes crash) --- src/app/qgsjoindialog.cpp | 17 ++++++++++++++++- src/app/qgsjoindialog.h | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/app/qgsjoindialog.cpp b/src/app/qgsjoindialog.cpp index abea563def7b..7c9e5ffb47b4 100644 --- a/src/app/qgsjoindialog.cpp +++ b/src/app/qgsjoindialog.cpp @@ -24,6 +24,7 @@ #include "qgsfieldcombobox.h" #include +#include QgsJoinDialog::QgsJoinDialog( QgsVectorLayer* layer, QList alreadyJoinedLayers, QWidget * parent, Qt::WindowFlags f ) : QDialog( parent, f ) @@ -53,6 +54,12 @@ QgsJoinDialog::QgsJoinDialog( QgsVectorLayer* layer, QList already mJoinFieldComboBox->setLayer( joinLayer ); joinedLayerChanged( joinLayer ); } + + connect( mJoinLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( checkDefinitionValid() ) ); + connect( mJoinFieldComboBox, SIGNAL( fieldChanged( QString ) ), this, SLOT( checkDefinitionValid() ) ); + connect( mTargetFieldComboBox, SIGNAL( fieldChanged( QString ) ), this, SLOT( checkDefinitionValid() ) ); + + checkDefinitionValid(); } QgsJoinDialog::~QgsJoinDialog() @@ -98,7 +105,8 @@ void QgsJoinDialog::setJoinInfo( const QgsVectorJoinInfo& joinInfo ) QgsVectorJoinInfo QgsJoinDialog::joinInfo() const { QgsVectorJoinInfo info; - info.joinLayerId = mJoinLayerComboBox->currentLayer()->id(); + if ( mJoinLayerComboBox->currentLayer() ) + info.joinLayerId = mJoinLayerComboBox->currentLayer()->id(); info.joinFieldName = mJoinFieldComboBox->currentField(); info.targetFieldName = mTargetFieldComboBox->currentField(); info.memoryCache = mCacheInMemoryCheckBox->isChecked(); @@ -172,3 +180,10 @@ void QgsJoinDialog::joinedLayerChanged( QgsMapLayer* layer ) mCustomPrefix->setText( layer->name() + '_' ); } } + +void QgsJoinDialog::checkDefinitionValid() +{ + buttonBox->button( QDialogButtonBox::Ok )->setEnabled( mJoinLayerComboBox->currentIndex() != -1 + && mJoinFieldComboBox->currentIndex() != -1 + && mTargetFieldComboBox->currentIndex() != -1 ); +} diff --git a/src/app/qgsjoindialog.h b/src/app/qgsjoindialog.h index 71f800d367b1..3a48bb0300ea 100644 --- a/src/app/qgsjoindialog.h +++ b/src/app/qgsjoindialog.h @@ -42,6 +42,8 @@ class APP_EXPORT QgsJoinDialog: public QDialog, private Ui::QgsJoinDialogBase private slots: void joinedLayerChanged( QgsMapLayer* layer ); + void checkDefinitionValid(); + private: /** Target layer*/ QgsVectorLayer* mLayer;