Skip to content
Permalink
Browse files
Fix add features dialog
Fix #10362
  • Loading branch information
m-kuhn committed May 27, 2014
1 parent ee770c4 commit 644dd13c3a00d55e89bf14a917e5dfd23dcd22bb
Showing with 39 additions and 52 deletions.
  1. +25 −23 src/app/qgsfeatureaction.cpp
  2. +3 −1 src/app/qgsfeatureaction.h
  3. +3 −22 src/app/qgsmaptooladdfeature.cpp
  4. +2 −2 src/gui/qgsattributedialog.cpp
  5. +2 −0 src/gui/qgsattributedialog.h
  6. +4 −4 src/gui/qgsattributeform.cpp
@@ -36,6 +36,7 @@ QgsFeatureAction::QgsFeatureAction( const QString &name, QgsFeature &f, QgsVecto
, mFeature( f )
, mAction( action )
, mIdx( defaultAttr )
, mFeatureSaved( false )
{
}

@@ -176,10 +177,6 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes )
}
}

bool res = false;



// show the dialog to enter attribute values
bool isDisabledAttributeValuesDlg = settings.value( "/qgis/digitizing/disable_enter_attribute_values_dialog", false ).toBool();
// override application-wide setting with any layer setting
@@ -197,46 +194,51 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes )
if ( isDisabledAttributeValuesDlg )
{
mLayer->beginEditCommand( text() );
res = mLayer->addFeature( mFeature );
mFeatureSaved = mLayer->addFeature( mFeature );

if ( res )
if ( mFeatureSaved )
mLayer->endEditCommand();
else
mLayer->destroyEditCommand();
}
else
{
QgsAttributes origValues;
if ( reuseLastValues )
origValues = mFeature.attributes();

QgsAttributeDialog *dialog = newDialog( false );
dialog->setIsAddDialog( true );
dialog->setEditCommandMessage( text() );

connect( dialog->attributeForm(), SIGNAL( featureSaved( QgsFeature ) ), this, SLOT( onFeatureSaved( QgsFeature ) ) );

dialog->exec();
if ( reuseLastValues )
{
connect( dialog->dialog(), SIGNAL( featureSaved( const QgsFeature& feature ) ), this, SLOT( updateLastUsedValues( const QgsFeature& feature ) ) );
}
}

return res;
// Will be set in the onFeatureSaved SLOT
return mFeatureSaved;
}

void QgsFeatureAction::updateLastUsedValues( const QgsFeature& feature )
void QgsFeatureAction::onFeatureSaved( const QgsFeature& feature )
{
QgsAttributeForm* form = qobject_cast<QgsAttributeForm*>( sender() );
Q_ASSERT( form );

QgsFields fields = mLayer->pendingFields();
for ( int idx = 0; idx < fields.count(); ++idx )
mFeatureSaved = true;

QSettings settings;
bool reuseLastValues = settings.value( "/qgis/digitizing/reuseLastValues", false ).toBool();
QgsDebugMsg( QString( "reuseLastValues: %1" ).arg( reuseLastValues ) );

if ( reuseLastValues )
{
const QgsAttributes &newValues = feature.attributes();
QgsAttributeMap origValues = sLastUsedValues[ mLayer ];
if ( origValues[idx] != newValues[idx] )
QgsFields fields = mLayer->pendingFields();
for ( int idx = 0; idx < fields.count(); ++idx )
{
QgsDebugMsg( QString( "saving %1 for %2" ).arg( sLastUsedValues[ mLayer ][idx].toString() ).arg( idx ) );
sLastUsedValues[ mLayer ][idx] = newValues[idx];
const QgsAttributes &newValues = feature.attributes();
QgsAttributeMap origValues = sLastUsedValues[ mLayer ];
if ( origValues[idx] != newValues[idx] )
{
QgsDebugMsg( QString( "saving %1 for %2" ).arg( sLastUsedValues[ mLayer ][idx].toString() ).arg( idx ) );
sLastUsedValues[ mLayer ][idx] = newValues[idx];
}
}
}
}
@@ -53,7 +53,7 @@ class APP_EXPORT QgsFeatureAction : public QAction
bool addFeature( const QgsAttributeMap& defaultAttributes = QgsAttributeMap() );

private slots:
void updateLastUsedValues( const QgsFeature& feature );
void onFeatureSaved( const QgsFeature& feature );

private:
QgsAttributeDialog *newDialog( bool cloneFeature );
@@ -63,6 +63,8 @@ class APP_EXPORT QgsFeatureAction : public QAction
int mAction;
int mIdx;

bool mFeatureSaved;

static QMap<QgsVectorLayer *, QgsAttributeMap> sLastUsedValues;
};

@@ -133,7 +133,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
//grass provider has its own mechanism of feature addition
if ( provider->capabilities() & QgsVectorDataProvider::AddFeatures )
{
QgsFeature* f = new QgsFeature( vlayer->pendingFields(), 0 );
QgsFeature f( vlayer->pendingFields(), 0 );

QgsGeometry *g = 0;
if ( layerWKBType == QGis::WKBPoint || layerWKBType == QGis::WKBPoint25D )
@@ -145,19 +145,9 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
g = QgsGeometry::fromMultiPoint( QgsMultiPoint() << savePoint );
}

f->setGeometry( g );
f.setGeometry( g );

vlayer->beginEditCommand( tr( "Feature added" ) );

if ( addFeature( vlayer, f ) )
{
vlayer->endEditCommand();
}
else
{
delete f;
vlayer->destroyEditCommand();
}
addFeature( vlayer, &f );

mCanvas->refresh();
}
@@ -307,8 +297,6 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
}
}

vlayer->beginEditCommand( tr( "Feature added" ) );

if ( addFeature( vlayer, f ) )
{
//add points to other features to keep topology up-to-date
@@ -336,13 +324,6 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
{
vlayer->addTopologicalPoints( f->geometry() );
}

vlayer->endEditCommand();
}
else
{
delete f;
vlayer->destroyEditCommand();
}

stopCapturing();
@@ -149,6 +149,6 @@ void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, QgsAt
mAttributeForm = new QgsAttributeForm( layer, *feature, context, parent );
mDialog->layout()->addWidget( mAttributeForm );
QDialogButtonBox* buttonBox = mAttributeForm->findChild<QDialogButtonBox*>();
connect( buttonBox, SIGNAL( rejected() ), mDialog, SLOT( close() ) );
connect( buttonBox, SIGNAL( accepted() ), mDialog, SLOT( close() ) );
connect( buttonBox, SIGNAL( rejected() ), mDialog, SLOT( reject() ) );
connect( buttonBox, SIGNAL( accepted() ), mDialog, SLOT( accept() ) );
}
@@ -84,6 +84,8 @@ class GUI_EXPORT QgsAttributeDialog : public QObject

QDialog* dialog() { return mDialog; }

QgsAttributeForm* attributeForm() { return mAttributeForm; }

const QgsFeature* feature() { return &mAttributeForm->feature(); }

/**
@@ -132,6 +132,7 @@ bool QgsAttributeForm::save()
if ( !success )
return false;

QgsFeature updatedFeature = QgsFeature( mFeature );

if ( mFeature.isValid() || mIsAddDialog )
{
@@ -161,7 +162,6 @@ bool QgsAttributeForm::save()
}
}

QgsFeature updatedFeature = QgsFeature( mFeature );
updatedFeature.setAttributes( dst );

Q_FOREACH( QgsAttributeFormInterface* iface, mInterfaces )
@@ -174,8 +174,6 @@ bool QgsAttributeForm::save()

if ( doUpdate )
{
mLayer->beginEditCommand( mEditCommandMessage );

if ( mIsAddDialog )
{
mFeature.setValid( true );
@@ -188,6 +186,8 @@ bool QgsAttributeForm::save()
}
else
{
mLayer->beginEditCommand( mEditCommandMessage );

for ( int i = 0; i < dst.count(); ++i )
{
if ( dst[i] == src[i] || !src[i].isValid() )
@@ -209,7 +209,7 @@ bool QgsAttributeForm::save()
}
}

emit featureSaved( mFeature );
emit featureSaved( updatedFeature );

mIsSaving = false;

0 comments on commit 644dd13

Please sign in to comment.