Skip to content

Commit 44c7372

Browse files
committed
Prevent creating invalid join in add join dialog (fixes crash)
(cherry-picked from 693ead2)
1 parent 4baa0fb commit 44c7372

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/app/qgsjoindialog.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "qgsfieldcombobox.h"
2525

2626
#include <QStandardItemModel>
27+
#include <QPushButton>
2728

2829
QgsJoinDialog::QgsJoinDialog( QgsVectorLayer* layer, QList<QgsMapLayer*> alreadyJoinedLayers, QWidget * parent, Qt::WindowFlags f )
2930
: QDialog( parent, f )
@@ -53,6 +54,12 @@ QgsJoinDialog::QgsJoinDialog( QgsVectorLayer* layer, QList<QgsMapLayer*> already
5354
mJoinFieldComboBox->setLayer( joinLayer );
5455
joinedLayerChanged( joinLayer );
5556
}
57+
58+
connect( mJoinLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( checkDefinitionValid() ) );
59+
connect( mJoinFieldComboBox, SIGNAL( fieldChanged( QString ) ), this, SLOT( checkDefinitionValid() ) );
60+
connect( mTargetFieldComboBox, SIGNAL( fieldChanged( QString ) ), this, SLOT( checkDefinitionValid() ) );
61+
62+
checkDefinitionValid();
5663
}
5764

5865
QgsJoinDialog::~QgsJoinDialog()
@@ -98,7 +105,8 @@ void QgsJoinDialog::setJoinInfo( const QgsVectorJoinInfo& joinInfo )
98105
QgsVectorJoinInfo QgsJoinDialog::joinInfo() const
99106
{
100107
QgsVectorJoinInfo info;
101-
info.joinLayerId = mJoinLayerComboBox->currentLayer()->id();
108+
if ( mJoinLayerComboBox->currentLayer() )
109+
info.joinLayerId = mJoinLayerComboBox->currentLayer()->id();
102110
info.joinFieldName = mJoinFieldComboBox->currentField();
103111
info.targetFieldName = mTargetFieldComboBox->currentField();
104112
info.memoryCache = mCacheInMemoryCheckBox->isChecked();
@@ -173,3 +181,10 @@ void QgsJoinDialog::joinedLayerChanged( QgsMapLayer* layer )
173181
mCustomPrefix->setText( layer->name() + '_' );
174182
}
175183
}
184+
185+
void QgsJoinDialog::checkDefinitionValid()
186+
{
187+
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( mJoinLayerComboBox->currentIndex() != -1
188+
&& mJoinFieldComboBox->currentIndex() != -1
189+
&& mTargetFieldComboBox->currentIndex() != -1 );
190+
}

src/app/qgsjoindialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class APP_EXPORT QgsJoinDialog: public QDialog, private Ui::QgsJoinDialogBase
4242
private slots:
4343
void joinedLayerChanged( QgsMapLayer* layer );
4444

45+
void checkDefinitionValid();
46+
4547
private:
4648
/** Target layer*/
4749
QgsVectorLayer* mLayer;

0 commit comments

Comments
 (0)