[QGIS Commit] r14765 - trunk/qgis/src/app

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Nov 25 16:45:30 EST 2010


Author: jef
Date: 2010-11-25 13:45:30 -0800 (Thu, 25 Nov 2010)
New Revision: 14765

Modified:
   trunk/qgis/src/app/qgsattributedialog.cpp
   trunk/qgis/src/app/qgsattributedialog.h
   trunk/qgis/src/app/qgsfeatureaction.cpp
   trunk/qgis/src/app/qgsfeatureaction.h
Log:
fix form actions

Modified: trunk/qgis/src/app/qgsattributedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributedialog.cpp	2010-11-25 21:45:20 UTC (rev 14764)
+++ trunk/qgis/src/app/qgsattributedialog.cpp	2010-11-25 21:45:30 UTC (rev 14765)
@@ -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 @@
     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 @@
     delete mRubberBand;
   }
 
+  if ( mFeatureOwner )
+  {
+    delete mFeature;
+  }
+
   saveGeometry();
 
   if ( mDialog )
@@ -270,11 +276,11 @@
 
 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 )
   {
@@ -282,7 +288,7 @@
 
     int idx = mpIndizes.value( myIndex );
     if ( QgsAttributeEditor::retrieveValue( mpWidgets.value( myIndex ), mLayer, idx, value ) )
-      mpFeature->changeAttribute( idx, value );
+      mFeature->changeAttribute( idx, value );
 
     ++myIndex;
   }

Modified: trunk/qgis/src/app/qgsattributedialog.h
===================================================================
--- trunk/qgis/src/app/qgsattributedialog.h	2010-11-25 21:45:20 UTC (rev 14764)
+++ trunk/qgis/src/app/qgsattributedialog.h	2010-11-25 21:45:30 UTC (rev 14765)
@@ -32,7 +32,7 @@
     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 @@
     QList<QWidget *> mpWidgets;
     QList<int> mpIndizes;
     QgsVectorLayer *mLayer;
-    QgsFeature *mpFeature;
+    QgsFeature *mFeature;
+    bool mFeatureOwner;
     QgsRubberBand *mRubberBand;
     int mFormNr;
     static int smFormCounter;

Modified: trunk/qgis/src/app/qgsfeatureaction.cpp
===================================================================
--- trunk/qgis/src/app/qgsfeatureaction.cpp	2010-11-25 21:45:20 UTC (rev 14764)
+++ trunk/qgis/src/app/qgsfeatureaction.cpp	2010-11-25 21:45:30 UTC (rev 14765)
@@ -39,11 +39,12 @@
   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 @@
       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 @@
   if ( !mLayer )
     return false;
 
-  QgsAttributeDialog *dialog = newDialog();
+  QgsAttributeDialog *dialog = newDialog( true );
   dialog->setHighlight( rb );
   dialog->show();
 
@@ -90,7 +91,7 @@
   if ( !mLayer )
     return res;
 
-  QgsAttributeDialog *dialog = newDialog();
+  QgsAttributeDialog *dialog = newDialog( false );
 
   if ( !mLayer->isEditable() )
   {
@@ -168,7 +169,7 @@
     if ( reuseLastValues )
       origValues = mFeature.attributeMap();
 
-    QgsAttributeDialog *dialog = newDialog();
+    QgsAttributeDialog *dialog = newDialog( false );
     if ( dialog->exec() )
     {
       if ( reuseLastValues )

Modified: trunk/qgis/src/app/qgsfeatureaction.h
===================================================================
--- trunk/qgis/src/app/qgsfeatureaction.h	2010-11-25 21:45:20 UTC (rev 14764)
+++ trunk/qgis/src/app/qgsfeatureaction.h	2010-11-25 21:45:30 UTC (rev 14765)
@@ -43,7 +43,7 @@
     bool addFeature();
 
   private:
-    QgsAttributeDialog *newDialog();
+    QgsAttributeDialog *newDialog( bool cloneFeature );
 
     QgsVectorLayer *mLayer;
     QgsFeature &mFeature;



More information about the QGIS-commit mailing list