Skip to content

Commit

Permalink
Merge pull request #3788 from nyalldawson/rel_dialog
Browse files Browse the repository at this point in the history
Add relation dialog improvements
  • Loading branch information
nyalldawson committed Nov 20, 2016
2 parents 9679b6a + b4533cd commit 2270603
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 98 deletions.
65 changes: 19 additions & 46 deletions src/app/qgsrelationadddlg.cpp
Expand Up @@ -16,6 +16,7 @@

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

#include <QPushButton>

Expand All @@ -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 ) );

Expand All @@ -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()
{
Expand All @@ -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() );
}
}
9 changes: 0 additions & 9 deletions src/app/qgsrelationadddlg.h
Expand Up @@ -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();
Expand All @@ -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
3 changes: 1 addition & 2 deletions src/app/qgsrelationmanagerdialog.cpp
Expand Up @@ -84,7 +84,6 @@ void QgsRelationManagerDialog::addRelation( const QgsRelation &rel )
void QgsRelationManagerDialog::on_mBtnAddRelation_clicked()
{
QgsRelationAddDlg addDlg;
addDlg.addLayers( mLayers );

if ( addDlg.exec() )
{
Expand Down Expand Up @@ -164,4 +163,4 @@ QList< QgsRelation > QgsRelationManagerDialog::relations()
void QgsRelationManagerDialog::onSelectionChanged()
{
mBtnRemoveRelation->setEnabled( mRelationsTable->selectionModel()->hasSelection() );
}
}
93 changes: 52 additions & 41 deletions src/ui/qgsrelationadddlgbase.ui
Expand Up @@ -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>
Expand Down

0 comments on commit 2270603

Please sign in to comment.