QGIS API Documentation  2.5.0-Master
 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 }
QList< QgsField > toList() const
Utility function to return a list of QgsField instances.
Definition: qgsfield.cpp:178
const QString & name() const
Gets the name of the field.
Definition: qgsfield.cpp:58
static unsigned index
QMap< QString, QgsVectorLayer * > mLayers
void on_mCbxReferencingLayer_currentIndexChanged(int index)
const QString & name() const
Get the display name of the layer.
QgsRelationAddDlg(QWidget *parent=0)
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
Definition: qgsmaplayer.cpp:95
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:33
QList< QPair< QString, QString > > references()
void on_mCbxReferencedLayer_currentIndexChanged(int index)
void addLayers(QList< QgsVectorLayer * > layers)
void loadLayerAttributes(QComboBox *cbx, QgsVectorLayer *layer)
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
Represents a vector layer which manages a vector based data sets.
#define tr(sourceText)