Skip to content

Commit

Permalink
fix form actions
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14765 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 25, 2010
1 parent a16d598 commit 07d01b9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
22 changes: 14 additions & 8 deletions src/app/qgsattributedialog.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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 );
}
Expand All @@ -260,6 +261,11 @@ QgsAttributeDialog::~QgsAttributeDialog()
delete mRubberBand;
}

if ( mFeatureOwner )
{
delete mFeature;
}

saveGeometry();

if ( mDialog )
Expand All @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgsattributedialog.h
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions src/app/qgsfeatureaction.cpp
Expand Up @@ -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 );

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

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

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

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

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

QgsAttributeDialog *dialog = newDialog();
QgsAttributeDialog *dialog = newDialog( false );
if ( dialog->exec() )
{
if ( reuseLastValues )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsfeatureaction.h
Expand Up @@ -43,7 +43,7 @@ class QgsFeatureAction : public QAction
bool addFeature();

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

QgsVectorLayer *mLayer;
QgsFeature &mFeature;
Expand Down

0 comments on commit 07d01b9

Please sign in to comment.