Skip to content
Permalink
Browse files

add support for a python feature form initialization function

git-svn-id: http://svn.osgeo.org/qgis/trunk@12215 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Nov 21, 2009
1 parent c59f11c commit 865fce9cf314a9b26fe3430f5efe8fe78a96b0bf
@@ -425,6 +425,16 @@ public:
*/
void setEditForm( QString ui );

/** get edit form init function
@note added in 1.4
*/
QString editFormInit();

/** set edit form init function
@note added in 1.4
*/
void setEditFormInit( QString function );

/**access value map*/
QMap<QString, QVariant> &valueMap(int idx);

@@ -25,6 +25,8 @@
#include "qgssymbol.h"
#include "qgsattributeeditor.h"

#include "qgisapp.h"

#include <QTableWidgetItem>
#include <QSettings>
#include <QLabel>
@@ -187,11 +189,34 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
}

connect( buttonBox, SIGNAL( rejected() ), mDialog, SLOT( reject() ) );
connect( buttonBox, SIGNAL( rejected() ), this, SLOT( rejected() ) );
}

QMetaObject::connectSlotsByName( mDialog );

connect( mDialog, SIGNAL( destroyed() ), this, SLOT( dialogDestroyed() ) );

if ( !vl->editFormInit().isEmpty() )
{
#if 0
// would be nice if only PyQt's QVariant.toPyObject() wouldn't take ownership
vl->setProperty( "featureForm.dialog", QVariant::fromValue( qobject_cast<QObject*>( mDialog ) ) );
vl->setProperty( "featureForm.id", QVariant( mpFeature->id() ) );
#endif

QString module = vl->editFormInit();
int pos = module.lastIndexOf( "." );
if ( pos >= 0 )
{
QgisApp::instance()->runPythonString( QString( "import %1" ).arg( module.left( pos ) ) );
}

QgisApp::instance()->runPythonString( QString( "_qgis_featureform_%1 = wrapinstance( %2, QtGui.QDialog )" ).arg( mLayer->getLayerID() ).arg(( unsigned long ) mDialog ) );

QString expr = QString( "%1(_qgis_featureform_%2,'%2',%3)" ).arg( vl->editFormInit() ).arg( vl->getLayerID() ).arg( mpFeature->id() );
QgsDebugMsg( QString( "running featureForm init: %1" ).arg( expr ) );
QgisApp::instance()->runPythonString( expr );
}

restoreGeometry();
}

@@ -223,17 +248,41 @@ void QgsAttributeDialog::accept()

int QgsAttributeDialog::exec()
{
return mDialog->exec();
if ( mDialog )
{
return mDialog->exec();
}
else
{
QgsDebugMsg( "No dialog" );
return QDialog::Rejected;
}
}

void QgsAttributeDialog::saveGeometry()
{
QSettings settings;
settings.setValue( mSettingsPath + "geometry", mDialog->saveGeometry() );
if ( mDialog )
{
QSettings settings;
settings.setValue( mSettingsPath + "geometry", mDialog->saveGeometry() );
}
}

void QgsAttributeDialog::restoreGeometry()
{
QSettings settings;
mDialog->restoreGeometry( settings.value( mSettingsPath + "geometry" ).toByteArray() );
if ( mDialog )
{
QSettings settings;
mDialog->restoreGeometry( settings.value( mSettingsPath + "geometry" ).toByteArray() );
}
}

void QgsAttributeDialog::dialogDestroyed()
{
#if 0
mLayer->setProperty( "featureForm.dialog", QVariant() );
mLayer->setProperty( "featureForm.id", QVariant() );
#endif
QgisApp::instance()->runPythonString( QString( "del _qgis_featureform_%1" ).arg( mLayer->getLayerID() ) );
mDialog = NULL;
}
@@ -55,6 +55,8 @@ class QgsAttributeDialog : public QObject

int exec();

void dialogDestroyed();

private:

QDialog *mDialog;
@@ -372,6 +372,10 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectFileName() ) );
}
break;

case QgsVectorLayer::Immutable:
return NULL;

}

if ( editType == QgsVectorLayer::Immutable )
@@ -132,6 +132,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
leSpatialRefSys->setCursorPosition( 0 );

leEditForm->setText( layer->editForm() );
leEditFormInit->setText( layer->editFormInit() );

connect( sliderTransparency, SIGNAL( valueChanged( int ) ), this, SLOT( sliderTransparency_valueChanged( int ) ) );

@@ -568,6 +569,7 @@ void QgsVectorLayerProperties::apply()
layer->setDisplayField( displayFieldComboBox->currentText() );

layer->setEditForm( leEditForm->text() );
layer->setEditFormInit( leEditFormInit->text() );

actionDialog->apply();

@@ -102,14 +102,14 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
mEditable( false ),
mModified( false ),
mMaxUpdatedIndex( -1 ),
mActiveCommand( NULL ),
mRenderer( 0 ),
mRendererV2( NULL ),
mUsingRendererV2( false ),
mLabel( 0 ),
mLabelOn( false ),
mActiveCommand( NULL ),
mVertexMarkerOnlyForSelection( false ),
mFetching( false ),
mRendererV2( NULL ),
mUsingRendererV2( false )
mFetching( false )
{
mActions = new QgsAttributeAction;

@@ -2687,6 +2687,12 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
mEditForm = QgsProject::instance()->readPath( e.text() );
}

QDomNode editFormInitNode = node.namedItem( "editforminit" );
if ( !editFormInitNode.isNull() )
{
mEditFormInit = editFormInitNode.toElement().text();
}

mAttributeAliasMap.clear();
QDomNode aliasesNode = node.namedItem( "aliases" );
if ( !aliasesNode.isNull() )
@@ -2828,6 +2834,11 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
efField.appendChild( efText );
node.appendChild( efField );

QDomElement efiField = doc.createElement( "editforminit" );
QDomText efiText = doc.createTextNode( mEditFormInit );
efiField.appendChild( efiText );
node.appendChild( efiField );

//attribute aliases
if ( mAttributeAliasMap.size() > 0 )
{
@@ -4026,6 +4037,16 @@ void QgsVectorLayer::setEditForm( QString ui )
mEditForm = ui;
}

QString QgsVectorLayer::editFormInit()
{
return mEditFormInit;
}

void QgsVectorLayer::setEditFormInit( QString function )
{
mEditFormInit = function;
}

QMap< QString, QVariant > &QgsVectorLayer::valueMap( int idx )
{
const QgsFieldMap &fields = pendingFields();
@@ -477,6 +477,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** set edit form (added in 1.4) */
void setEditForm( QString ui );

/** get python function for edit form initialization (added in 1.4) */
QString editFormInit();

/** set python function for edit form initialization (added in 1.4) */
void setEditFormInit( QString function );

/**access value map*/
QMap<QString, QVariant> &valueMap( int idx );

@@ -754,7 +760,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
QMap< QString, QMap<QString, QVariant> > mValueMaps;
QMap< QString, RangeData > mRanges;
QMap< QString, QPair<QString, QString> > mCheckedStates;
QString mEditForm;

QString mEditForm, mEditFormInit;

bool mFetching;
QgsRectangle mFetchRect;
@@ -74,7 +74,7 @@
<item row="0" column="2" colspan="3">
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<widget class="QWidget" name="page_3">
<layout class="QGridLayout" name="gridLayout_4">
@@ -172,7 +172,7 @@
<enum>QFrame::Sunken</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="page"/>
<widget class="QWidget" name="page_2"/>
@@ -355,8 +355,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>407</width>
<height>394</height>
<width>554</width>
<height>397</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">
@@ -409,7 +409,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="1" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="leEditForm"/>
@@ -423,7 +423,24 @@
</item>
</layout>
</item>
<item row="1" column="2">
<item row="1" column="3">
<widget class="QPushButton" name="pbnIndex">
<property name="text">
<string>Create Spatial Index</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="4">
<widget class="QLineEdit" name="leSpatialRefSys">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLineEdit" name="leEditFormInit"/>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="pbnChangeSpatialRefSys">
<property name="toolTip">
<string>Specify the coordinate reference system of the layer's geometry.</string>
@@ -436,17 +453,10 @@
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="pbnIndex">
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Create Spatial Index</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="4">
<widget class="QLineEdit" name="leSpatialRefSys">
<property name="readOnly">
<bool>true</bool>
<string>Init function</string>
</property>
</widget>
</item>
@@ -650,7 +660,6 @@
<tabstop>displayFieldComboBox</tabstop>
<tabstop>leSpatialRefSys</tabstop>
<tabstop>pbnIndex</tabstop>
<tabstop>pbnChangeSpatialRefSys</tabstop>
<tabstop>spinMinimumScale</tabstop>
<tabstop>spinMaximumScale</tabstop>
<tabstop>txtSubsetSQL</tabstop>

0 comments on commit 865fce9

Please sign in to comment.