28 #include <QHBoxLayout>
37 , mInitialized( false )
39 QVBoxLayout* topLayout =
new QVBoxLayout(
this );
40 topLayout->setContentsMargins( 0, 9, 0, 0 );
41 setLayout( topLayout );
44 QHBoxLayout* buttonLayout =
new QHBoxLayout();
45 buttonLayout->setContentsMargins( 0, 0, 0, 0 );
47 mToggleEditingButton =
new QToolButton(
this );
49 mToggleEditingButton->setText(
tr(
"Toggle editing" ) );
50 mToggleEditingButton->setEnabled(
false );
51 mToggleEditingButton->setCheckable(
true );
52 buttonLayout->addWidget( mToggleEditingButton );
54 mSaveEditsButton =
new QToolButton(
this );
56 mSaveEditsButton->setText(
tr(
"Save layer edits" ) );
57 mSaveEditsButton->setEnabled(
true );
58 buttonLayout->addWidget( mSaveEditsButton );
60 mAddFeatureButton =
new QToolButton(
this );
62 mAddFeatureButton->setText(
tr(
"Add feature" ) );
63 buttonLayout->addWidget( mAddFeatureButton );
65 mDeleteFeatureButton =
new QToolButton(
this );
67 mDeleteFeatureButton->setText(
tr(
"Delete feature" ) );
68 buttonLayout->addWidget( mDeleteFeatureButton );
70 mLinkFeatureButton =
new QToolButton(
this );
72 mLinkFeatureButton->setText(
tr(
"Link feature" ) );
73 buttonLayout->addWidget( mLinkFeatureButton );
75 mUnlinkFeatureButton =
new QToolButton(
this );
77 mUnlinkFeatureButton->setText(
tr(
"Unlink feature" ) );
78 buttonLayout->addWidget( mUnlinkFeatureButton );
80 buttonLayout->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding ) );
82 mFormViewButton =
new QToolButton(
this );
83 mFormViewButton->setText(
tr(
"Form view" ) );
85 mFormViewButton->setCheckable(
true );
87 buttonLayout->addWidget( mFormViewButton );
89 mTableViewButton =
new QToolButton(
this );
90 mTableViewButton->setText(
tr(
"Table view" ) );
92 mTableViewButton->setCheckable(
true );
94 buttonLayout->addWidget( mTableViewButton );
96 mViewModeButtonGroup =
new QButtonGroup(
this );
101 topLayout->addLayout( buttonLayout );
104 referencingLayerEditingToggled();
106 mRelationLayout =
new QGridLayout();
107 mRelationLayout->setContentsMargins( 0, 0, 0, 0 );
108 topLayout->addLayout( mRelationLayout );
111 mDualView->
setView( mViewMode );
115 mRelationLayout->addWidget( mDualView );
117 connect(
this, SIGNAL(
collapsedStateChanged(
bool ) ),
this, SLOT( onCollapsedStateChanged(
bool ) ) );
118 connect( mViewModeButtonGroup, SIGNAL( buttonClicked(
int ) ),
this, SLOT(
setViewMode(
int ) ) );
119 connect( mToggleEditingButton, SIGNAL( clicked(
bool ) ),
this, SLOT( toggleEditing(
bool ) ) );
120 connect( mSaveEditsButton, SIGNAL( clicked() ),
this, SLOT( saveEdits() ) );
121 connect( mAddFeatureButton, SIGNAL( clicked() ),
this, SLOT( addFeature() ) );
122 connect( mDeleteFeatureButton, SIGNAL( clicked() ),
this, SLOT( deleteFeature() ) );
123 connect( mLinkFeatureButton, SIGNAL( clicked() ),
this, SLOT( linkFeature() ) );
124 connect( mUnlinkFeatureButton, SIGNAL( clicked() ),
this, SLOT( unlinkFeature() ) );
131 disconnect( mRelation.
referencingLayer(), SIGNAL( editingStarted() ),
this, SLOT( referencingLayerEditingToggled() ) );
132 disconnect( mRelation.
referencingLayer(), SIGNAL( editingStopped() ),
this, SLOT( referencingLayerEditingToggled() ) );
135 mRelation = relation;
138 connect( mRelation.
referencingLayer(), SIGNAL( editingStarted() ),
this, SLOT( referencingLayerEditingToggled() ) );
139 connect( mRelation.
referencingLayer(), SIGNAL( editingStopped() ),
this, SLOT( referencingLayerEditingToggled() ) );
141 setTitle( relation.
name() );
146 if ( canChangeAttributes && !lyr->isReadOnly() )
148 mToggleEditingButton->setEnabled(
true );
149 referencingLayerEditingToggled();
153 mToggleEditingButton->setEnabled(
false );
170 mEditorContext = context;
179 void QgsRelationEditorWidget::referencingLayerEditingToggled()
181 bool editable =
false;
187 mAddFeatureButton->setEnabled( editable );
188 mLinkFeatureButton->setEnabled( editable );
189 mDeleteFeatureButton->setEnabled( editable );
190 mUnlinkFeatureButton->setEnabled( editable );
191 mToggleEditingButton->setChecked( editable );
192 mSaveEditsButton->setEnabled( editable );
195 void QgsRelationEditorWidget::addFeature()
209 void QgsRelationEditorWidget::linkFeature()
213 if ( selectionDlg.exec() )
215 QMap<int, QVariant> keys;
220 keys.insert( idx, val );
223 Q_FOREACH (
QgsFeatureId fid, selectionDlg.selectedFeatures() )
225 QMapIterator<int, QVariant> it( keys );
226 while ( it.hasNext() )
235 void QgsRelationEditorWidget::deleteFeature()
243 void QgsRelationEditorWidget::unlinkFeature()
245 QMap<int, QgsField> keyFields;
255 keyFields.insert( idx, fld );
260 QMapIterator<int, QgsField> it( keyFields );
261 while ( it.hasNext() )
269 void QgsRelationEditorWidget::toggleEditing(
bool state )
281 void QgsRelationEditorWidget::saveEdits()
286 void QgsRelationEditorWidget::onCollapsedStateChanged(
bool collapsed )
288 if ( !mInitialized && !collapsed && mRelation.
isValid() )