Skip to content

Commit

Permalink
Fixed attribute sync to layer for init code
Browse files Browse the repository at this point in the history
Also removed UI connect in favour of QMetaObject::connectSlotsByName
to be consistent with other methods in the same class
  • Loading branch information
elpaso committed Nov 12, 2015
1 parent c483411 commit 17df615
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
55 changes: 25 additions & 30 deletions src/app/qgsfieldsproperties.cpp
Expand Up @@ -115,34 +115,6 @@ QgsFieldsProperties::QgsFieldsProperties( QgsVectorLayer *layer, QWidget* parent
mRelationsList->setHorizontalHeaderItem( RelFieldCol, new QTableWidgetItem( tr( "Field" ) ) );
mRelationsList->verticalHeader()->hide();

// Python init function and code
leEditForm->setText( layer->editForm() );
leEditFormInit->setText( layer->editFormInit() );
leEditFormInitUseCode->setChecked( layer->editFormInitUseCode() );
QString code( layer->editFormInitCode() );
if ( code.isEmpty( ) )
{
code.append( tr( "# -*- coding: utf-8 -*-\n\"\"\"\n"
"QGIS forms can have a Python function that is called when the form is\n"
"opened.\n"
"\n"
"Use this function to add extra logic to your forms.\n"
"\n"
"Enter the name of the function in the \"Python Init function\"\n"
"field.\n"
"An example follows:\n"
"\"\"\"\n"
"from PyQt4.QtGui import QWidget\n\n"
"def my_form_open(dialog, layer, feature):\n"
"\tgeom = feature.geometry()\n"
"\tcontrol = dialog.findChild(QWidget, \"MyLineEdit\")\n" ) );

}
leEditFormInitCode->setText( code );
// Show or hide as needed
mPythonInitCodeGroupBox->setVisible( layer->editFormInitUseCode() );
connect( leEditFormInitUseCode, SIGNAL( toggled( bool ) ), this, SLOT( on_leEditFormInitUseCodeToggled( bool ) ) );

loadRelations();

updateButtons();
Expand Down Expand Up @@ -213,10 +185,33 @@ QTreeWidgetItem *QgsFieldsProperties::loadAttributeEditorTreeItem( QgsAttributeE

void QgsFieldsProperties::setEditFormInit( const QString &editForm, const QString &editFormInit, const QString &editFormInitCode, const bool editFormInitUseCode )
{

// Python init function and code
QString code( editFormInitCode );
if ( code.isEmpty( ) )
{
code.append( tr( "# -*- coding: utf-8 -*-\n\"\"\"\n"
"QGIS forms can have a Python function that is called when the form is\n"
"opened.\n"
"\n"
"Use this function to add extra logic to your forms.\n"
"\n"
"Enter the name of the function in the \"Python Init function\"\n"
"field.\n"
"An example follows:\n"
"\"\"\"\n"
"from PyQt4.QtGui import QWidget\n\n"
"def my_form_open(dialog, layer, feature):\n"
"\tgeom = feature.geometry()\n"
"\tcontrol = dialog.findChild(QWidget, \"MyLineEdit\")\n" ) );

}
leEditForm->setText( editForm );
leEditFormInitCode->setText( code );
leEditFormInit->setText( editFormInit );
leEditFormInitCode->setText( editFormInitCode );
leEditFormInitUseCode->setChecked( editFormInitUseCode );
// Show or hide as needed
mPythonInitCodeGroupBox->setVisible( editFormInitUseCode );
}


Expand Down Expand Up @@ -458,7 +453,7 @@ void QgsFieldsProperties::on_mMoveUpItem_clicked()
}
}

void QgsFieldsProperties::on_leEditFormInitUseCodeToggled( bool checked )
void QgsFieldsProperties::on_leEditFormInitUseCode_toggled( bool checked )
{
mPythonInitCodeGroupBox->setVisible( checked );
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsfieldsproperties.h
Expand Up @@ -179,7 +179,7 @@ class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPrope
void onAttributeSelectionChanged();
void on_pbnSelectEditForm_clicked();
void on_mEditorLayoutComboBox_currentIndexChanged( int index );
void on_leEditFormInitUseCodeToggled( bool checked );
void on_leEditFormInitUseCode_toggled( bool checked );
void attributeAdded( int idx );
void attributeDeleted( int idx );
void attributeTypeDialog();
Expand Down

0 comments on commit 17df615

Please sign in to comment.