Skip to content
Permalink
Browse files

Merge pull request #3788 from nyalldawson/rel_dialog

Add relation dialog improvements
  • Loading branch information
nyalldawson committed Nov 20, 2016
2 parents 9679b6a + b4533cd commit 22706036dbe5fb4b1dee057bda53dccb152a229b
@@ -16,6 +16,7 @@

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

#include <QPushButton>

@@ -24,45 +25,41 @@ QgsRelationAddDlg::QgsRelationAddDlg( QWidget *parent )
{
setupUi( this );

mTxtRelationId->setPlaceholderText( tr( "[Generated automatically]" ) );
checkDefinitionValid();
connect( mCbxReferencingLayer, &QgsMapLayerComboBox::layerChanged, this, [=]( QgsMapLayer * layer ) { mCbxReferencingField->setLayer( layer ); }
);
connect( mCbxReferencedLayer, &QgsMapLayerComboBox::layerChanged, this, [=]( QgsMapLayer * layer ) { mCbxReferencedField->setLayer( layer ); }
);

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 )
{
mCbxReferencingLayer->addItem( QLatin1String( "" ), "" );
mCbxReferencedLayer->addItem( QLatin1String( "" ), "" );
mCbxReferencingLayer->setFilters( QgsMapLayerProxyModel::VectorLayer );
mCbxReferencingField->setLayer( mCbxReferencingLayer->currentLayer() );
mCbxReferencedLayer->setFilters( QgsMapLayerProxyModel::VectorLayer );
mCbxReferencedField->setLayer( mCbxReferencedLayer->currentLayer() );

Q_FOREACH ( QgsVectorLayer* layer, layers )
{
mCbxReferencingLayer->addItem( layer->name(), layer->id() );
mCbxReferencedLayer->addItem( layer->name(), layer->id() );
mTxtRelationId->setPlaceholderText( tr( "[Generated automatically]" ) );
checkDefinitionValid();

mLayers.insert( layer->id(), layer );
}
connect( mCbxReferencingLayer, &QgsMapLayerComboBox::layerChanged, this, &QgsRelationAddDlg::checkDefinitionValid );
connect( mCbxReferencingField, &QgsFieldComboBox::fieldChanged, this, &QgsRelationAddDlg::checkDefinitionValid );
connect( mCbxReferencedLayer, &QgsMapLayerComboBox::layerChanged, this, &QgsRelationAddDlg::checkDefinitionValid );
connect( mCbxReferencedField, &QgsFieldComboBox::fieldChanged, this, &QgsRelationAddDlg::checkDefinitionValid );
}

QString QgsRelationAddDlg::referencingLayerId()
{
return mCbxReferencingLayer->currentData().toString();
return mCbxReferencingLayer->currentLayer()->id();
}

QString QgsRelationAddDlg::referencedLayerId()
{
return mCbxReferencedLayer->currentData().toString();
return mCbxReferencedLayer->currentLayer()->id();
}

QList< QPair< QString, QString > > QgsRelationAddDlg::references()
{
QList< QPair< QString, QString > > references;

QString referencingField = mCbxReferencingField->currentData().toString();
QString referencedField = mCbxReferencedField->currentData().toString();
QString referencingField = mCbxReferencingField->currentField();
QString referencedField = mCbxReferencedField->currentField();

references.append( QPair<QString, QString> ( referencingField, referencedField ) );

@@ -79,15 +76,6 @@ QString QgsRelationAddDlg::relationName()
return mTxtRelationName->text();
}

void QgsRelationAddDlg::on_mCbxReferencingLayer_currentIndexChanged( int index )
{
loadLayerAttributes( mCbxReferencingField, mLayers[mCbxReferencingLayer->itemData( index ).toString()] );
}

void QgsRelationAddDlg::on_mCbxReferencedLayer_currentIndexChanged( int index )
{
loadLayerAttributes( mCbxReferencedField, mLayers[mCbxReferencedLayer->itemData( index ).toString()] );
}

void QgsRelationAddDlg::checkDefinitionValid()
{
@@ -96,18 +84,3 @@ void QgsRelationAddDlg::checkDefinitionValid()
&& mCbxReferencingLayer->currentIndex() != -1
&& mCbxReferencingField->currentIndex() != -1 );
}

void QgsRelationAddDlg::loadLayerAttributes( QComboBox* cbx, QgsVectorLayer* layer )
{
cbx->clear();

if ( !layer )
{
return;
}

Q_FOREACH ( const QgsField& fld, layer->fields().toList() )
{
cbx->addItem( fld.name(), fld.name() );
}
}
@@ -27,8 +27,6 @@ class APP_EXPORT QgsRelationAddDlg : public QDialog, private Ui::QgsRelationAddD
public:
explicit QgsRelationAddDlg( QWidget *parent = nullptr );

void addLayers( const QList<QgsVectorLayer*>& layers );

QString referencingLayerId();
QString referencedLayerId();
QList< QPair< QString, QString > > references();
@@ -37,16 +35,9 @@ class APP_EXPORT QgsRelationAddDlg : public QDialog, private Ui::QgsRelationAddD


private slots:
void on_mCbxReferencingLayer_currentIndexChanged( int index );
void on_mCbxReferencedLayer_currentIndexChanged( int index );

void checkDefinitionValid();

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

QMap< QString, QgsVectorLayer* > mLayers;

};

#endif // QGSRELATIONADDDLG_H
@@ -84,7 +84,6 @@ void QgsRelationManagerDialog::addRelation( const QgsRelation &rel )
void QgsRelationManagerDialog::on_mBtnAddRelation_clicked()
{
QgsRelationAddDlg addDlg;
addDlg.addLayers( mLayers );

if ( addDlg.exec() )
{
@@ -164,4 +163,4 @@ QList< QgsRelation > QgsRelationManagerDialog::relations()
void QgsRelationManagerDialog::onSelectionChanged()
{
mBtnRemoveRelation->setEnabled( mRelationsTable->selectionModel()->hasSelection() );
}
}
@@ -14,86 +14,97 @@
<string>Add relation</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="1" colspan="2">
<widget class="QComboBox" name="mCbxReferencingField"/>
</item>
<item row="3" column="1" colspan="2">
<widget class="QComboBox" name="mCbxReferencingLayer"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Referencing Field</string>
<string>Name</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_3">
<item row="4" column="1" colspan="2">
<widget class="QgsMapLayerComboBox" name="mCbxReferencingLayer"/>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Referenced Layer (Parent)</string>
<string>Id</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Referenced Field</string>
<item row="15" column="0" colspan="3">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<widget class="QComboBox" name="mCbxReferencedLayer"/>
</item>
<item row="6" column="1" colspan="2">
<widget class="QComboBox" name="mCbxReferencedField"/>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Referencing Layer (Child)</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<item row="5" column="1" colspan="2">
<widget class="QgsFieldComboBox" name="mCbxReferencingField"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Name</string>
<string>Referencing Field</string>
</property>
</widget>
</item>
<item row="14" column="0" colspan="3">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Referenced Layer (Parent)</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_5">
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Id</string>
<string>Referenced Field</string>
</property>
</widget>
</item>
<item row="8" column="1">
<item row="3" column="1" colspan="2">
<widget class="QgsFieldComboBox" name="mCbxReferencedField"/>
</item>
<item row="9" column="1" colspan="2">
<widget class="QLineEdit" name="mTxtRelationId"/>
</item>
<item row="1" column="1">
<item row="2" column="1" colspan="2">
<widget class="QgsMapLayerComboBox" name="mCbxReferencedLayer"/>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="mTxtRelationName"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsMapLayerComboBox</class>
<extends>QComboBox</extends>
<header location="global">qgsmaplayercombobox.h</header>
</customwidget>
<customwidget>
<class>QgsFieldComboBox</class>
<extends>QComboBox</extends>
<header location="global">qgsfieldcombobox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mTxtRelationName</tabstop>
<tabstop>mCbxReferencingLayer</tabstop>
<tabstop>mCbxReferencingField</tabstop>
<tabstop>mCbxReferencedLayer</tabstop>
<tabstop>mCbxReferencedField</tabstop>
<tabstop>mCbxReferencingLayer</tabstop>
<tabstop>mCbxReferencingField</tabstop>
<tabstop>mTxtRelationId</tabstop>
<tabstop>mButtonBox</tabstop>
</tabstops>
<resources/>
<connections>

0 comments on commit 2270603

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