Skip to content

Commit b762694

Browse files
committed
Fix crash in relation manager
When clicking ok with invalid definitions. Fixes #14869
1 parent f300715 commit b762694

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

src/app/qgsrelationadddlg.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
1+
/***************************************************************************
2+
qgsrelationadddlg.cpp - QgsRelationAddDlg
3+
---------------------------------
4+
5+
begin : 4.10.2013
6+
copyright : (C) 2013 by Matthias Kuhn
7+
email : matthias@opengis.ch
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
117
#include "qgsrelationadddlg.h"
218
#include "qgsvectorlayer.h"
319

20+
#include <QPushButton>
21+
422
QgsRelationAddDlg::QgsRelationAddDlg( QWidget *parent )
523
: QDialog( parent )
624
{
725
setupUi( this );
826

927
mTxtRelationId->setPlaceholderText( tr( "[Generated automatically]" ) );
28+
checkDefinitionValid();
29+
30+
connect( mCbxReferencingLayer, SIGNAL( currentIndexChanged( int ) ), this, SLOT( checkDefinitionValid() ) );
31+
connect( mCbxReferencingField, SIGNAL( currentIndexChanged( int ) ), this, SLOT( checkDefinitionValid() ) );
32+
connect( mCbxReferencedLayer, SIGNAL( currentIndexChanged( int ) ), this, SLOT( checkDefinitionValid() ) );
33+
connect( mCbxReferencedField, SIGNAL( currentIndexChanged( int ) ), this, SLOT( checkDefinitionValid() ) );
1034
}
1135

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

92+
void QgsRelationAddDlg::checkDefinitionValid()
93+
{
94+
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( mCbxReferencedLayer->currentIndex() != -1
95+
&& mCbxReferencedField->currentIndex() != -1
96+
&& mCbxReferencingLayer->currentIndex() != -1
97+
&& mCbxReferencingField->currentIndex() != -1 );
98+
}
99+
68100
void QgsRelationAddDlg::loadLayerAttributes( QComboBox* cbx, QgsVectorLayer* layer )
69101
{
70102
cbx->clear();

src/app/qgsrelationadddlg.h

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class APP_EXPORT QgsRelationAddDlg : public QDialog, private Ui::QgsRelationAddD
4040
void on_mCbxReferencingLayer_currentIndexChanged( int index );
4141
void on_mCbxReferencedLayer_currentIndexChanged( int index );
4242

43+
void checkDefinitionValid();
44+
4345
private:
4446
void loadLayerAttributes( QComboBox* cbx, QgsVectorLayer* layer );
4547

src/ui/qgsrelationadddlgbase.ui

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</widget>
6363
</item>
6464
<item row="14" column="0" colspan="3">
65-
<widget class="QDialogButtonBox" name="buttonBox">
65+
<widget class="QDialogButtonBox" name="mButtonBox">
6666
<property name="orientation">
6767
<enum>Qt::Horizontal</enum>
6868
</property>
@@ -93,12 +93,12 @@
9393
<tabstop>mCbxReferencedLayer</tabstop>
9494
<tabstop>mCbxReferencedField</tabstop>
9595
<tabstop>mTxtRelationId</tabstop>
96-
<tabstop>buttonBox</tabstop>
96+
<tabstop>mButtonBox</tabstop>
9797
</tabstops>
9898
<resources/>
9999
<connections>
100100
<connection>
101-
<sender>buttonBox</sender>
101+
<sender>mButtonBox</sender>
102102
<signal>accepted()</signal>
103103
<receiver>QgsRelationAddDlgBase</receiver>
104104
<slot>accept()</slot>
@@ -114,7 +114,7 @@
114114
</hints>
115115
</connection>
116116
<connection>
117-
<sender>buttonBox</sender>
117+
<sender>mButtonBox</sender>
118118
<signal>rejected()</signal>
119119
<receiver>QgsRelationAddDlgBase</receiver>
120120
<slot>reject()</slot>

0 commit comments

Comments
 (0)