QGIS API Documentation  2.2.0-Valmiera
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
12 void QgsRelationAddDlg::addLayers( QList< QgsVectorLayer* > layers )
13 {
14  mCbxReferencingLayer->addItem( "", "" );
15  mCbxReferencedLayer->addItem( "", "" );
16 
17  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 
36 QList< QPair< QString, QString > > QgsRelationAddDlg::references()
37 {
38  QList< QPair< QString, QString > > references;
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 
59 {
60  loadLayerAttributes( mCbxReferencingField, mLayers[mCbxReferencingLayer->itemData( index ).toString()] );
61 }
62 
64 {
65  loadLayerAttributes( mCbxReferencedField, mLayers[mCbxReferencedLayer->itemData( index ).toString()] );
66 }
67 
69 {
70  cbx->clear();
71 
72  if ( !layer )
73  {
74  return;
75  }
76 
77  foreach ( QgsField fld, layer->pendingFields().toList() )
78  {
79  cbx->addItem( fld.name(), fld.name() );
80  }
81 }