Skip to content

Commit

Permalink
avoid opening multiple attribute forms for a single feature in identify
Browse files Browse the repository at this point in the history
(fixes #13520)

On behalf of Faunalia, sponsored by ENEL

(cherry picked from commit 7b8fb79)
  • Loading branch information
jef-n committed Apr 20, 2017
1 parent 1bbc39e commit 20197c2
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/app/qgsfeatureaction.cpp
Expand Up @@ -65,6 +65,7 @@ QgsAttributeDialog *QgsFeatureAction::newDialog( bool cloneFeature )

QgsAttributeDialog *dialog = new QgsAttributeDialog( mLayer, f, cloneFeature, parentWidget(), true, context );
dialog->setWindowFlags( dialog->windowFlags() | Qt::Tool );
dialog->setObjectName( QString( "featureactiondlg:%1:%2" ).arg( mLayer->id(), f->id() ) );

QList<QgsAction> actions = mLayer->actions()->actions( QStringLiteral( "Feature" ) );
if ( !actions.isEmpty() )
Expand Down Expand Up @@ -96,10 +97,19 @@ QgsAttributeDialog *QgsFeatureAction::newDialog( bool cloneFeature )

bool QgsFeatureAction::viewFeatureForm( QgsHighlight *h )
{
if ( !mLayer )
if ( !mLayer || !mFeature )
return false;

QgsAttributeDialog *dialog = newDialog( true );
QString name( QString( "featureactiondlg:%1:%2" ).arg( mLayer->id(), mFeature->id() ) );

QgsAttributeDialog *dialog = QgisApp::instance()->findChild<QgsAttributeDialog *>( name );
if ( dialog )
{
dialog->raise();
return true;
}

dialog = newDialog( true );
dialog->setHighlight( h );
// delete the dialog when it is closed
dialog->setAttribute( Qt::WA_DeleteOnClose );
Expand All @@ -126,7 +136,16 @@ bool QgsFeatureAction::editFeature( bool showModal )
}
else
{
QgsAttributeDialog *dialog = newDialog( false );
QString name( QString( "featureactiondlg:%1:%2" ).arg( mLayer->id(), mFeature->id() ) );

QgsAttributeDialog *dialog = QgisApp::instance()->findChild<QgsAttributeDialog *>( name );
if ( dialog )
{
dialog->raise();
return true;
}

dialog = newDialog( false );

if ( !mFeature->isValid() )
dialog->setMode( QgsAttributeForm::AddFeatureMode );
Expand Down

3 comments on commit 20197c2

@bartoszschilling
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice to have this functionality. Thank you.
However, there is one nasty bug in this commit.

Dialog object name generation with

QString( "featureactiondlg:%1:%2" ).arg( mLayer->id(), f->id() )

calls overloaded function

QString QString::arg(const QString & a, int fieldWidth = 0, const QChar & fillChar = QLatin1Char( ' ' )) const

instead

QString QString::arg(const QString & a1, const QString & a2) const

It becomes huge performance issue when QgsCollapsibleGroupBox saves configuration using this object name. On Ubuntu with layers with big ids it causes configuration file to grow very fast to 10MB~100MB which make QGIS almost unusable.

@NathanW2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barteksch good find.

@jef-n
Copy link
Member Author

@jef-n jef-n commented on 20197c2 Jun 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 392b638 and 6dfcf40

Please sign in to comment.