Skip to content
Permalink
Browse files

Fix crash in relation manager

When clicking ok with invalid definitions.

Fixes #14869
  • Loading branch information
m-kuhn committed May 25, 2016
1 parent f300715 commit b762694b224ee2b26563b1fe9c7e867976114ef8
Showing with 38 additions and 4 deletions.
  1. +32 −0 src/app/qgsrelationadddlg.cpp
  2. +2 −0 src/app/qgsrelationadddlg.h
  3. +4 −4 src/ui/qgsrelationadddlgbase.ui
@@ -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 )
@@ -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();
@@ -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 );

@@ -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>
@@ -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>
@@ -114,7 +114,7 @@
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<sender>mButtonBox</sender>
<signal>rejected()</signal>
<receiver>QgsRelationAddDlgBase</receiver>
<slot>reject()</slot>

0 comments on commit b762694

Please sign in to comment.
You can’t perform that action at this time.