Skip to content

Commit

Permalink
Fix crash in relation manager
Browse files Browse the repository at this point in the history
When clicking ok with invalid definitions.

Fixes #14869
  • Loading branch information
m-kuhn committed May 25, 2016
1 parent f300715 commit b762694
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
32 changes: 32 additions & 0 deletions src/app/qgsrelationadddlg.cpp
@@ -1,12 +1,36 @@
/***************************************************************************
qgsrelationadddlg.cpp - QgsRelationAddDlg
---------------------------------
begin : 4.10.2013
copyright : (C) 2013 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsrelationadddlg.h"
#include "qgsvectorlayer.h"

#include <QPushButton>

QgsRelationAddDlg::QgsRelationAddDlg( QWidget *parent )
: QDialog( parent )
{
setupUi( this );

mTxtRelationId->setPlaceholderText( tr( "[Generated automatically]" ) );
checkDefinitionValid();

connect( mCbxReferencingLayer, SIGNAL( currentIndexChanged( int ) ), this, SLOT( checkDefinitionValid() ) );
connect( mCbxReferencingField, SIGNAL( currentIndexChanged( int ) ), this, SLOT( checkDefinitionValid() ) );
connect( mCbxReferencedLayer, SIGNAL( currentIndexChanged( int ) ), this, SLOT( checkDefinitionValid() ) );
connect( mCbxReferencedField, SIGNAL( currentIndexChanged( int ) ), this, SLOT( checkDefinitionValid() ) );
}

void QgsRelationAddDlg::addLayers( const QList< QgsVectorLayer* >& layers )
Expand Down Expand Up @@ -65,6 +89,14 @@ void QgsRelationAddDlg::on_mCbxReferencedLayer_currentIndexChanged( int index )
loadLayerAttributes( mCbxReferencedField, mLayers[mCbxReferencedLayer->itemData( index ).toString()] );
}

void QgsRelationAddDlg::checkDefinitionValid()
{
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( mCbxReferencedLayer->currentIndex() != -1
&& mCbxReferencedField->currentIndex() != -1
&& mCbxReferencingLayer->currentIndex() != -1
&& mCbxReferencingField->currentIndex() != -1 );
}

void QgsRelationAddDlg::loadLayerAttributes( QComboBox* cbx, QgsVectorLayer* layer )
{
cbx->clear();
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsrelationadddlg.h
Expand Up @@ -40,6 +40,8 @@ class APP_EXPORT QgsRelationAddDlg : public QDialog, private Ui::QgsRelationAddD
void on_mCbxReferencingLayer_currentIndexChanged( int index );
void on_mCbxReferencedLayer_currentIndexChanged( int index );

void checkDefinitionValid();

private:
void loadLayerAttributes( QComboBox* cbx, QgsVectorLayer* layer );

Expand Down
8 changes: 4 additions & 4 deletions src/ui/qgsrelationadddlgbase.ui
Expand Up @@ -62,7 +62,7 @@
</widget>
</item>
<item row="14" column="0" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand Down Expand Up @@ -93,12 +93,12 @@
<tabstop>mCbxReferencedLayer</tabstop>
<tabstop>mCbxReferencedField</tabstop>
<tabstop>mTxtRelationId</tabstop>
<tabstop>buttonBox</tabstop>
<tabstop>mButtonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<sender>mButtonBox</sender>
<signal>accepted()</signal>
<receiver>QgsRelationAddDlgBase</receiver>
<slot>accept()</slot>
Expand All @@ -114,7 +114,7 @@
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<sender>mButtonBox</sender>
<signal>rejected()</signal>
<receiver>QgsRelationAddDlgBase</receiver>
<slot>reject()</slot>
Expand Down

0 comments on commit b762694

Please sign in to comment.