fix form actions

git-svn-id: http://svn.osgeo.org/qgis/trunk@14765 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
jef 2010-11-25 21:45:30 +00:00
parent a16d598d47
commit 07d01b947a
4 changed files with 26 additions and 18 deletions

View File

@ -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,11 +276,11 @@ 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 )
{
@ -282,7 +288,7 @@ void QgsAttributeDialog::accept()
int idx = mpIndizes.value( myIndex );
if ( QgsAttributeEditor::retrieveValue( mpWidgets.value( myIndex ), mLayer, idx, value ) )
mpFeature->changeAttribute( idx, value );
mFeature->changeAttribute( idx, value );
++myIndex;
}

View File

@ -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;

View File

@ -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 )

View File

@ -43,7 +43,7 @@ class QgsFeatureAction : public QAction
bool addFeature();
private:
QgsAttributeDialog *newDialog();
QgsAttributeDialog *newDialog( bool cloneFeature );
QgsVectorLayer *mLayer;
QgsFeature &mFeature;