Skip to content
Permalink
Browse files

Fixed attribute sync to layer for init code

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 17df615c187a0eccb847f661a223eaa59aa0150f
Showing with 26 additions and 31 deletions.
  1. +25 −30 src/app/qgsfieldsproperties.cpp
  2. +1 −1 src/app/qgsfieldsproperties.h
@@ -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();
@@ -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 );
}


@@ -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 );
}
@@ -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();

0 comments on commit 17df615

Please sign in to comment.
You can’t perform that action at this time.