Skip to content

Commit be8c7da

Browse files
committed
Merge pull request #2449 from elpaso/bugfix-11517
Fix attribute sync to layer for python init code and make QgsAttributeDialog reachable form python
2 parents c483411 + ad2caed commit be8c7da

File tree

4 files changed

+31
-36
lines changed

4 files changed

+31
-36
lines changed

src/app/qgsfieldsproperties.cpp

+25-30
Original file line numberDiff line numberDiff line change
@@ -115,34 +115,6 @@ QgsFieldsProperties::QgsFieldsProperties( QgsVectorLayer *layer, QWidget* parent
115115
mRelationsList->setHorizontalHeaderItem( RelFieldCol, new QTableWidgetItem( tr( "Field" ) ) );
116116
mRelationsList->verticalHeader()->hide();
117117

118-
// Python init function and code
119-
leEditForm->setText( layer->editForm() );
120-
leEditFormInit->setText( layer->editFormInit() );
121-
leEditFormInitUseCode->setChecked( layer->editFormInitUseCode() );
122-
QString code( layer->editFormInitCode() );
123-
if ( code.isEmpty( ) )
124-
{
125-
code.append( tr( "# -*- coding: utf-8 -*-\n\"\"\"\n"
126-
"QGIS forms can have a Python function that is called when the form is\n"
127-
"opened.\n"
128-
"\n"
129-
"Use this function to add extra logic to your forms.\n"
130-
"\n"
131-
"Enter the name of the function in the \"Python Init function\"\n"
132-
"field.\n"
133-
"An example follows:\n"
134-
"\"\"\"\n"
135-
"from PyQt4.QtGui import QWidget\n\n"
136-
"def my_form_open(dialog, layer, feature):\n"
137-
"\tgeom = feature.geometry()\n"
138-
"\tcontrol = dialog.findChild(QWidget, \"MyLineEdit\")\n" ) );
139-
140-
}
141-
leEditFormInitCode->setText( code );
142-
// Show or hide as needed
143-
mPythonInitCodeGroupBox->setVisible( layer->editFormInitUseCode() );
144-
connect( leEditFormInitUseCode, SIGNAL( toggled( bool ) ), this, SLOT( on_leEditFormInitUseCodeToggled( bool ) ) );
145-
146118
loadRelations();
147119

148120
updateButtons();
@@ -213,10 +185,33 @@ QTreeWidgetItem *QgsFieldsProperties::loadAttributeEditorTreeItem( QgsAttributeE
213185

214186
void QgsFieldsProperties::setEditFormInit( const QString &editForm, const QString &editFormInit, const QString &editFormInitCode, const bool editFormInitUseCode )
215187
{
188+
189+
// Python init function and code
190+
QString code( editFormInitCode );
191+
if ( code.isEmpty( ) )
192+
{
193+
code.append( tr( "# -*- coding: utf-8 -*-\n\"\"\"\n"
194+
"QGIS forms can have a Python function that is called when the form is\n"
195+
"opened.\n"
196+
"\n"
197+
"Use this function to add extra logic to your forms.\n"
198+
"\n"
199+
"Enter the name of the function in the \"Python Init function\"\n"
200+
"field.\n"
201+
"An example follows:\n"
202+
"\"\"\"\n"
203+
"from PyQt4.QtGui import QWidget\n\n"
204+
"def my_form_open(dialog, layer, feature):\n"
205+
"\tgeom = feature.geometry()\n"
206+
"\tcontrol = dialog.findChild(QWidget, \"MyLineEdit\")\n" ) );
207+
208+
}
216209
leEditForm->setText( editForm );
210+
leEditFormInitCode->setText( code );
217211
leEditFormInit->setText( editFormInit );
218-
leEditFormInitCode->setText( editFormInitCode );
219212
leEditFormInitUseCode->setChecked( editFormInitUseCode );
213+
// Show or hide as needed
214+
mPythonInitCodeGroupBox->setVisible( editFormInitUseCode );
220215
}
221216

222217

@@ -458,7 +453,7 @@ void QgsFieldsProperties::on_mMoveUpItem_clicked()
458453
}
459454
}
460455

461-
void QgsFieldsProperties::on_leEditFormInitUseCodeToggled( bool checked )
456+
void QgsFieldsProperties::on_leEditFormInitUseCode_toggled( bool checked )
462457
{
463458
mPythonInitCodeGroupBox->setVisible( checked );
464459
}

src/app/qgsfieldsproperties.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPrope
179179
void onAttributeSelectionChanged();
180180
void on_pbnSelectEditForm_clicked();
181181
void on_mEditorLayoutComboBox_currentIndexChanged( int index );
182-
void on_leEditFormInitUseCodeToggled( bool checked );
182+
void on_leEditFormInitUseCode_toggled( bool checked );
183183
void attributeAdded( int idx );
184184
void attributeDeleted( int idx );
185185
void attributeTypeDialog();

src/gui/qgsattributedialog.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer* vl, QgsFeature* thepFeat
3333
QgsAttributeEditorContext context;
3434
context.setDistanceArea( myDa );
3535

36-
init( vl, thepFeature, context, parent );
36+
init( vl, thepFeature, context );
3737

3838
if ( !showDialogButtons )
3939
mAttributeForm->hideButtonBox();
@@ -44,7 +44,7 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer* vl, QgsFeature* thepFeat
4444
, mHighlight( 0 )
4545
, mOwnedFeature( featureOwner ? thepFeature : 0 )
4646
{
47-
init( vl, thepFeature, context, parent );
47+
init( vl, thepFeature, context );
4848

4949
if ( !showDialogButtons )
5050
mAttributeForm->hideButtonBox();
@@ -97,12 +97,12 @@ void QgsAttributeDialog::show( bool autoDelete )
9797
activateWindow();
9898
}
9999

100-
void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext &context, QWidget* parent )
100+
void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext &context )
101101
{
102102
setWindowTitle( tr( "%1 - Feature Attributes" ).arg( layer->name() ) );
103103
setLayout( new QGridLayout() );
104104
layout()->setMargin( 0 );
105-
mAttributeForm = new QgsAttributeForm( layer, *feature, context, parent );
105+
mAttributeForm = new QgsAttributeForm( layer, *feature, context, this );
106106
mAttributeForm->disconnectButtonBox();
107107
layout()->addWidget( mAttributeForm );
108108
QDialogButtonBox* buttonBox = mAttributeForm->findChild<QDialogButtonBox*>();

src/gui/qgsattributedialog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog
135135
void show( bool autoDelete = true );
136136

137137
private:
138-
void init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext& context, QWidget* parent );
138+
void init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext& context );
139139

140140
QString mSettingsPath;
141141
// Used to sync multiple widgets for the same field

0 commit comments

Comments
 (0)