Skip to content

Commit 07d01b9

Browse files
author
jef
committed
fix form actions
git-svn-id: http://svn.osgeo.org/qgis/trunk@14765 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a16d598 commit 07d01b9

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

src/app/qgsattributedialog.cpp

+14-8
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,23 @@
4444

4545
int QgsAttributeDialog::smFormCounter = 0;
4646

47-
QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature )
47+
QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner )
4848
: mDialog( 0 )
4949
, mSettingsPath( "/Windows/AttributeDialog/" )
5050
, mLayer( vl )
51-
, mpFeature( thepFeature )
51+
, mFeature( thepFeature )
52+
, mFeatureOwner( featureOwner )
5253
, mRubberBand( 0 )
5354
, mFormNr( -1 )
5455
{
55-
if ( mpFeature == NULL || vl->dataProvider() == NULL )
56+
if ( !mFeature || !vl->dataProvider() )
5657
return;
5758

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

62-
QgsAttributeMap myAttributes = mpFeature->attributeMap();
63+
QgsAttributeMap myAttributes = mFeature->attributeMap();
6364

6465
QDialogButtonBox *buttonBox = NULL;
6566

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

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

264+
if ( mFeatureOwner )
265+
{
266+
delete mFeature;
267+
}
268+
263269
saveGeometry();
264270

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

271277
void QgsAttributeDialog::accept()
272278
{
273-
if ( !mLayer->isEditable() )
279+
if ( !mLayer->isEditable() || !mFeature )
274280
return;
275281

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

283289
int idx = mpIndizes.value( myIndex );
284290
if ( QgsAttributeEditor::retrieveValue( mpWidgets.value( myIndex ), mLayer, idx, value ) )
285-
mpFeature->changeAttribute( idx, value );
291+
mFeature->changeAttribute( idx, value );
286292

287293
++myIndex;
288294
}

src/app/qgsattributedialog.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class QgsAttributeDialog : public QObject
3232
Q_OBJECT
3333

3434
public:
35-
QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature * thepFeature );
35+
QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner );
3636
~QgsAttributeDialog();
3737

3838
/** Saves the size and position for the next time
@@ -66,7 +66,8 @@ class QgsAttributeDialog : public QObject
6666
QList<QWidget *> mpWidgets;
6767
QList<int> mpIndizes;
6868
QgsVectorLayer *mLayer;
69-
QgsFeature *mpFeature;
69+
QgsFeature *mFeature;
70+
bool mFeatureOwner;
7071
QgsRubberBand *mRubberBand;
7172
int mFormNr;
7273
static int smFormCounter;

src/app/qgsfeatureaction.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ void QgsFeatureAction::execute()
3939
mLayer->actions()->doAction( mAction, mFeature.attributeMap(), mIdx );
4040
}
4141

42-
QgsAttributeDialog *QgsFeatureAction::newDialog()
42+
QgsAttributeDialog *QgsFeatureAction::newDialog( bool cloneFeature )
4343
{
44-
QgsAttributeDialog *dialog = new QgsAttributeDialog( mLayer, &mFeature );
44+
QgsFeature *f = cloneFeature ? new QgsFeature( mFeature ) : &mFeature;
45+
QgsAttributeDialog *dialog = new QgsAttributeDialog( mLayer, f, cloneFeature );
4546

46-
if ( mLayer->actions()->size() == 0 )
47+
if ( mLayer->actions()->size() > 0 )
4748
{
4849
dialog->dialog()->setContextMenuPolicy( Qt::ActionsContextMenu );
4950

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

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

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

79-
QgsAttributeDialog *dialog = newDialog();
80+
QgsAttributeDialog *dialog = newDialog( true );
8081
dialog->setHighlight( rb );
8182
dialog->show();
8283

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

93-
QgsAttributeDialog *dialog = newDialog();
94+
QgsAttributeDialog *dialog = newDialog( false );
9495

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

171-
QgsAttributeDialog *dialog = newDialog();
172+
QgsAttributeDialog *dialog = newDialog( false );
172173
if ( dialog->exec() )
173174
{
174175
if ( reuseLastValues )

src/app/qgsfeatureaction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class QgsFeatureAction : public QAction
4343
bool addFeature();
4444

4545
private:
46-
QgsAttributeDialog *newDialog();
46+
QgsAttributeDialog *newDialog( bool cloneFeature );
4747

4848
QgsVectorLayer *mLayer;
4949
QgsFeature &mFeature;

0 commit comments

Comments
 (0)