Skip to content
Permalink
Browse files

fix form actions

git-svn-id: http://svn.osgeo.org/qgis/trunk@14765 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Nov 25, 2010
1 parent a16d598 commit 07d01b947a473dec48896e6a122a22e7c5a6bb19
Showing with 26 additions and 18 deletions.
  1. +14 −8 src/app/qgsattributedialog.cpp
  2. +3 −2 src/app/qgsattributedialog.h
  3. +8 −7 src/app/qgsfeatureaction.cpp
  4. +1 −1 src/app/qgsfeatureaction.h
@@ -44,22 +44,23 @@

int QgsAttributeDialog::smFormCounter = 0;

QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature )
QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner )
: mDialog( 0 )
, mSettingsPath( "/Windows/AttributeDialog/" )
, mLayer( vl )
, mpFeature( thepFeature )
, mFeature( thepFeature )
, mFeatureOwner( featureOwner )
, mRubberBand( 0 )
, mFormNr( -1 )
{
if ( mpFeature == NULL || vl->dataProvider() == NULL )
if ( !mFeature || !vl->dataProvider() )
return;

const QgsFieldMap &theFieldMap = vl->pendingFields();
if ( theFieldMap.isEmpty() )
return;

QgsAttributeMap myAttributes = mpFeature->attributeMap();
QgsAttributeMap myAttributes = mFeature->attributeMap();

QDialogButtonBox *buttonBox = NULL;

@@ -243,7 +244,7 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
mFormNr = smFormCounter++;
QgisApp::instance()->runPythonString( QString( "_qgis_featureform_%1 = wrapinstance( %2, QtGui.QDialog )" ).arg( mFormNr ).arg(( unsigned long ) mDialog ) );

QString expr = QString( "%1(_qgis_featureform_%2,'%3',%4)" ).arg( vl->editFormInit() ).arg( mFormNr ).arg( vl->getLayerID() ).arg( mpFeature->id() );
QString expr = QString( "%1(_qgis_featureform_%2,'%3',%4)" ).arg( vl->editFormInit() ).arg( mFormNr ).arg( vl->getLayerID() ).arg( mFeature->id() );
QgsDebugMsg( QString( "running featureForm init: %1" ).arg( expr ) );
QgisApp::instance()->runPythonString( expr );
}
@@ -260,6 +261,11 @@ QgsAttributeDialog::~QgsAttributeDialog()
delete mRubberBand;
}

if ( mFeatureOwner )
{
delete mFeature;
}

saveGeometry();

if ( mDialog )
@@ -270,19 +276,19 @@ QgsAttributeDialog::~QgsAttributeDialog()

void QgsAttributeDialog::accept()
{
if ( !mLayer->isEditable() )
if ( !mLayer->isEditable() || !mFeature )
return;

//write the new values back to the feature
QgsAttributeMap myAttributes = mpFeature->attributeMap();
QgsAttributeMap myAttributes = mFeature->attributeMap();
int myIndex = 0;
for ( QgsAttributeMap::const_iterator it = myAttributes.begin(); it != myAttributes.end(); ++it )
{
QVariant value;

int idx = mpIndizes.value( myIndex );
if ( QgsAttributeEditor::retrieveValue( mpWidgets.value( myIndex ), mLayer, idx, value ) )
mpFeature->changeAttribute( idx, value );
mFeature->changeAttribute( idx, value );

++myIndex;
}
@@ -32,7 +32,7 @@ class QgsAttributeDialog : public QObject
Q_OBJECT

public:
QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature * thepFeature );
QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner );
~QgsAttributeDialog();

/** Saves the size and position for the next time
@@ -66,7 +66,8 @@ class QgsAttributeDialog : public QObject
QList<QWidget *> mpWidgets;
QList<int> mpIndizes;
QgsVectorLayer *mLayer;
QgsFeature *mpFeature;
QgsFeature *mFeature;
bool mFeatureOwner;
QgsRubberBand *mRubberBand;
int mFormNr;
static int smFormCounter;
@@ -39,11 +39,12 @@ void QgsFeatureAction::execute()
mLayer->actions()->doAction( mAction, mFeature.attributeMap(), mIdx );
}

QgsAttributeDialog *QgsFeatureAction::newDialog()
QgsAttributeDialog *QgsFeatureAction::newDialog( bool cloneFeature )
{
QgsAttributeDialog *dialog = new QgsAttributeDialog( mLayer, &mFeature );
QgsFeature *f = cloneFeature ? new QgsFeature( mFeature ) : &mFeature;
QgsAttributeDialog *dialog = new QgsAttributeDialog( mLayer, f, cloneFeature );

if ( mLayer->actions()->size() == 0 )
if ( mLayer->actions()->size() > 0 )
{
dialog->dialog()->setContextMenuPolicy( Qt::ActionsContextMenu );

@@ -58,7 +59,7 @@ QgsAttributeDialog *QgsFeatureAction::newDialog()
if ( !action.runable() )
continue;

QgsFeatureAction *a = new QgsFeatureAction( action.name(), mFeature, mLayer, i, dialog->dialog() );
QgsFeatureAction *a = new QgsFeatureAction( action.name(), *f, mLayer, i, dialog->dialog() );
dialog->dialog()->addAction( a );
connect( a, SIGNAL( triggered() ), a, SLOT( execute() ) );

@@ -76,7 +77,7 @@ bool QgsFeatureAction::viewFeatureForm( QgsRubberBand *rb )
if ( !mLayer )
return false;

QgsAttributeDialog *dialog = newDialog();
QgsAttributeDialog *dialog = newDialog( true );
dialog->setHighlight( rb );
dialog->show();

@@ -90,7 +91,7 @@ bool QgsFeatureAction::editFeature()
if ( !mLayer )
return res;

QgsAttributeDialog *dialog = newDialog();
QgsAttributeDialog *dialog = newDialog( false );

if ( !mLayer->isEditable() )
{
@@ -168,7 +169,7 @@ bool QgsFeatureAction::addFeature()
if ( reuseLastValues )
origValues = mFeature.attributeMap();

QgsAttributeDialog *dialog = newDialog();
QgsAttributeDialog *dialog = newDialog( false );
if ( dialog->exec() )
{
if ( reuseLastValues )
@@ -43,7 +43,7 @@ class QgsFeatureAction : public QAction
bool addFeature();

private:
QgsAttributeDialog *newDialog();
QgsAttributeDialog *newDialog( bool cloneFeature );

QgsVectorLayer *mLayer;
QgsFeature &mFeature;

0 comments on commit 07d01b9

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