mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
parent
ee770c4f81
commit
644dd13c3a
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user