Skip to content

Commit bc187ba

Browse files
committed
identify shows a non-modal feature form
1 parent 4588d9b commit bc187ba

File tree

8 files changed

+23
-44
lines changed

8 files changed

+23
-44
lines changed

python/gui/qgisinterface.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ class QgisInterface : QObject
515515
* @return true when dialog was accepted
516516
* @note added in 1.6
517517
*/
518-
virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f, bool updateFeatureOnly = false ) = 0;
518+
virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f, bool updateFeatureOnly = false, bool showModal = true ) = 0;
519519

520520
virtual QgsAttributeDialog* getFeatureForm( QgsVectorLayer *l, QgsFeature &f ) = 0;
521521

src/app/qgisappinterface.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ QAction *QgisAppInterface::actionQgisHomePage() { return qgis->actionQgisHomePag
572572
QAction *QgisAppInterface::actionCheckQgisVersion() { return qgis->actionCheckQgisVersion(); }
573573
QAction *QgisAppInterface::actionAbout() { return qgis->actionAbout(); }
574574

575-
bool QgisAppInterface::openFeatureForm( QgsVectorLayer *vlayer, QgsFeature &f, bool updateFeatureOnly )
575+
bool QgisAppInterface::openFeatureForm( QgsVectorLayer *vlayer, QgsFeature &f, bool updateFeatureOnly, bool showModal )
576576
{
577577
Q_UNUSED( updateFeatureOnly );
578578
if ( !vlayer )
@@ -581,11 +581,12 @@ bool QgisAppInterface::openFeatureForm( QgsVectorLayer *vlayer, QgsFeature &f, b
581581
QgsFeatureAction action( tr( "Attributes changed" ), f, vlayer, -1, -1, QgisApp::instance() );
582582
if ( vlayer->isEditable() )
583583
{
584-
return action.editFeature();
584+
return action.editFeature( showModal );
585585
}
586586
else
587587
{
588-
return action.viewFeatureForm();
588+
action.viewFeatureForm();
589+
return true;
589590
}
590591
}
591592

src/app/qgisappinterface.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,14 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
434434

435435
/**
436436
* Open feature form
437-
* returns true when dialog was accepted
437+
* returns true when dialog was accepted (if shown modal, true otherwise)
438438
* @param l vector layer
439439
* @param f feature to show/modify
440440
* @param updateFeatureOnly only update the feature update (don't change any attributes of the layer)
441+
* @param showModal if true, will wait for the dialog to be executed (only shown otherwise)
441442
* @note added in 1.6
442443
*/
443-
virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f, bool updateFeatureOnly = false );
444+
virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f, bool updateFeatureOnly = false , bool showModal = true );
444445

445446
/**
446447
* Returns a feature form for a given feature

src/app/qgsfeatureaction.cpp

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -102,49 +102,27 @@ bool QgsFeatureAction::viewFeatureForm( QgsHighlight *h )
102102
return true;
103103
}
104104

105-
bool QgsFeatureAction::editFeature()
105+
bool QgsFeatureAction::editFeature( bool showModal )
106106
{
107-
bool res = false;
108-
109107
if ( !mLayer )
110-
return res;
108+
return false;
111109

112110
QgsAttributeDialog *dialog = newDialog( false );
113111

114-
if ( !mLayer->isEditable() )
112+
if ( !mFeature.isValid() )
113+
dialog->setIsAddDialog( true );
114+
115+
if ( showModal )
115116
{
116-
res = dialog->exec();
117+
dialog->setAttribute( Qt::WA_DeleteOnClose );
118+
return dialog->exec();
117119
}
118120
else
119121
{
120-
QgsAttributes src = mFeature.attributes();
121-
if ( !mFeature.isValid() )
122-
dialog->setIsAddDialog( true );
123-
124-
if ( dialog->exec() )
125-
{
126-
mLayer->beginEditCommand( text() );
127-
128-
const QgsAttributes &dst = mFeature.attributes();
129-
for ( int i = 0; i < dst.count(); ++i )
130-
{
131-
if ( dst[i] != src[i] )
132-
{
133-
mLayer->changeAttributeValue( mFeature.id(), i, dst[i], src[i] );
134-
}
135-
}
136-
137-
mLayer->endEditCommand();
138-
res = true;
139-
}
140-
else
141-
{
142-
res = false;
143-
}
122+
dialog->show();
144123
}
145124

146-
delete dialog;
147-
return res;
125+
return true;
148126
}
149127

150128
bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes )

src/app/qgsfeatureaction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class APP_EXPORT QgsFeatureAction : public QAction
3939
public slots:
4040
void execute();
4141
bool viewFeatureForm( QgsHighlight *h = 0 );
42-
bool editFeature();
42+
bool editFeature( bool showModal = true );
4343

4444
/**
4545
* Add a new feature to the layer.

src/app/qgsidentifyresultsdialog.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,10 +1585,7 @@ void QgsIdentifyResultsDialog::featureForm()
15851585
QgsFeatureAction action( tr( "Attributes changed" ), f, vlayer, idx, -1, this );
15861586
if ( vlayer->isEditable() )
15871587
{
1588-
if ( action.editFeature() )
1589-
{
1590-
mCanvas->refresh();
1591-
}
1588+
action.editFeature( false );
15921589
}
15931590
else
15941591
{

src/gui/qgisinterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ class GUI_EXPORT QgisInterface : public QObject
570570
* @return true when dialog was accepted
571571
* @note added in 1.6
572572
*/
573-
virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f, bool updateFeatureOnly = false ) = 0;
573+
virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f, bool updateFeatureOnly = false, bool showModal = true ) = 0;
574574

575575
/**
576576
* Returns a feature form for a given feature

src/gui/qgsattributeform.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ bool QgsAttributeForm::save()
230230

231231
emit featureSaved( updatedFeature );
232232

233+
mLayer->triggerRepaint();
234+
233235
mIsSaving = false;
234236

235237
return success;

0 commit comments

Comments
 (0)