Skip to content

Commit

Permalink
Prevent creating invalid join in add join dialog (fixes crash)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 12, 2016
1 parent e301cc8 commit 693ead2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/app/qgsjoindialog.cpp
Expand Up @@ -24,6 +24,7 @@
#include "qgsfieldcombobox.h"

#include <QStandardItemModel>
#include <QPushButton>

QgsJoinDialog::QgsJoinDialog( QgsVectorLayer* layer, QList<QgsMapLayer*> alreadyJoinedLayers, QWidget * parent, Qt::WindowFlags f )
: QDialog( parent, f )
Expand Down Expand Up @@ -53,6 +54,12 @@ QgsJoinDialog::QgsJoinDialog( QgsVectorLayer* layer, QList<QgsMapLayer*> 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()
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
}
2 changes: 2 additions & 0 deletions src/app/qgsjoindialog.h
Expand Up @@ -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;
Expand Down

0 comments on commit 693ead2

Please sign in to comment.