QGIS API Documentation  2.12.0-Lyon
qgsrelationadddlg.cpp
Go to the documentation of this file.
1 #include "qgsrelationadddlg.h"
2 #include "qgsvectorlayer.h"
3 
5  QDialog( parent )
6 {
7  setupUi( this );
8 
9  mTxtRelationId->setPlaceholderText( tr( "[Generated automatically]" ) );
10 }
11 
13 {
14  mCbxReferencingLayer->addItem( "", "" );
15  mCbxReferencedLayer->addItem( "", "" );
16 
17  Q_FOREACH ( QgsVectorLayer* layer, layers )
18  {
19  mCbxReferencingLayer->addItem( layer->name(), layer->id() );
20  mCbxReferencedLayer->addItem( layer->name(), layer->id() );
21 
22  mLayers.insert( layer->id(), layer );
23  }
24 }
25 
27 {
28  return mCbxReferencingLayer->itemData( mCbxReferencingLayer->currentIndex() ).toString();
29 }
30 
32 {
33  return mCbxReferencedLayer->itemData( mCbxReferencedLayer->currentIndex() ).toString();
34 }
35 
37 {
39 
40  QString referencingField = mCbxReferencingField->itemData( mCbxReferencingField->currentIndex() ).toString();
41  QString referencedField = mCbxReferencedField->itemData( mCbxReferencedField->currentIndex() ).toString();
42 
43  references.append( QPair<QString, QString> ( referencingField, referencedField ) );
44 
45  return references;
46 }
47 
49 {
50  return mTxtRelationId->text();
51 }
52 
54 {
55  return mTxtRelationName->text();
56 }
57 
58 void QgsRelationAddDlg::on_mCbxReferencingLayer_currentIndexChanged( int index )
59 {
60  loadLayerAttributes( mCbxReferencingField, mLayers[mCbxReferencingLayer->itemData( index ).toString()] );
61 }
62 
63 void QgsRelationAddDlg::on_mCbxReferencedLayer_currentIndexChanged( int index )
64 {
65  loadLayerAttributes( mCbxReferencedField, mLayers[mCbxReferencedLayer->itemData( index ).toString()] );
66 }
67 
68 void QgsRelationAddDlg::loadLayerAttributes( QComboBox* cbx, QgsVectorLayer* layer )
69 {
70  cbx->clear();
71 
72  if ( !layer )
73  {
74  return;
75  }
76 
77  Q_FOREACH ( const QgsField& fld, layer->fields().toList() )
78  {
79  cbx->addItem( fld.name(), fld.name() );
80  }
81 }
QList< QgsField > toList() const
Utility function to return a list of QgsField instances.
Definition: qgsfield.cpp:369
const QString & name() const
Gets the name of the field.
Definition: qgsfield.cpp:72
static unsigned index
void setupUi(QWidget *widget)
QgsFields fields() const
Returns the list of fields of this layer.
void clear()
QString tr(const char *sourceText, const char *disambiguation, int n)
void addItem(const QString &text, const QVariant &userData)
const QString & name() const
Get the display name of the layer.
QgsRelationAddDlg(QWidget *parent=0)
void append(const T &value)
void addLayers(const QList< QgsVectorLayer * > &layers)
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:40
QList< QPair< QString, QString > > references()
iterator insert(const Key &key, const T &value)
Represents a vector layer which manages a vector based data sets.