Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
identify shows a non-modal feature form
  • Loading branch information
3nids committed Aug 19, 2014
1 parent 4588d9b commit bc187ba
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 44 deletions.
2 changes: 1 addition & 1 deletion python/gui/qgisinterface.sip
Expand Up @@ -515,7 +515,7 @@ class QgisInterface : QObject
* @return true when dialog was accepted
* @note added in 1.6
*/
virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f, bool updateFeatureOnly = false ) = 0;
virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f, bool updateFeatureOnly = false, bool showModal = true ) = 0;

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

Expand Down
7 changes: 4 additions & 3 deletions src/app/qgisappinterface.cpp
Expand Up @@ -572,7 +572,7 @@ QAction *QgisAppInterface::actionQgisHomePage() { return qgis->actionQgisHomePag
QAction *QgisAppInterface::actionCheckQgisVersion() { return qgis->actionCheckQgisVersion(); }
QAction *QgisAppInterface::actionAbout() { return qgis->actionAbout(); }

bool QgisAppInterface::openFeatureForm( QgsVectorLayer *vlayer, QgsFeature &f, bool updateFeatureOnly )
bool QgisAppInterface::openFeatureForm( QgsVectorLayer *vlayer, QgsFeature &f, bool updateFeatureOnly, bool showModal )
{
Q_UNUSED( updateFeatureOnly );
if ( !vlayer )
Expand All @@ -581,11 +581,12 @@ bool QgisAppInterface::openFeatureForm( QgsVectorLayer *vlayer, QgsFeature &f, b
QgsFeatureAction action( tr( "Attributes changed" ), f, vlayer, -1, -1, QgisApp::instance() );
if ( vlayer->isEditable() )
{
return action.editFeature();
return action.editFeature( showModal );
}
else
{
return action.viewFeatureForm();
action.viewFeatureForm();
return true;
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/app/qgisappinterface.h
Expand Up @@ -434,13 +434,14 @@ class APP_EXPORT QgisAppInterface : public QgisInterface

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

/**
* Returns a feature form for a given feature
Expand Down
42 changes: 10 additions & 32 deletions src/app/qgsfeatureaction.cpp
Expand Up @@ -102,49 +102,27 @@ bool QgsFeatureAction::viewFeatureForm( QgsHighlight *h )
return true;
}

bool QgsFeatureAction::editFeature()
bool QgsFeatureAction::editFeature( bool showModal )
{
bool res = false;

if ( !mLayer )
return res;
return false;

QgsAttributeDialog *dialog = newDialog( false );

if ( !mLayer->isEditable() )
if ( !mFeature.isValid() )
dialog->setIsAddDialog( true );

if ( showModal )
{
res = dialog->exec();
dialog->setAttribute( Qt::WA_DeleteOnClose );
return dialog->exec();
}
else
{
QgsAttributes src = mFeature.attributes();
if ( !mFeature.isValid() )
dialog->setIsAddDialog( true );

if ( dialog->exec() )
{
mLayer->beginEditCommand( text() );

const QgsAttributes &dst = mFeature.attributes();
for ( int i = 0; i < dst.count(); ++i )
{
if ( dst[i] != src[i] )
{
mLayer->changeAttributeValue( mFeature.id(), i, dst[i], src[i] );
}
}

mLayer->endEditCommand();
res = true;
}
else
{
res = false;
}
dialog->show();
}

delete dialog;
return res;
return true;
}

bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsfeatureaction.h
Expand Up @@ -39,7 +39,7 @@ class APP_EXPORT QgsFeatureAction : public QAction
public slots:
void execute();
bool viewFeatureForm( QgsHighlight *h = 0 );
bool editFeature();
bool editFeature( bool showModal = true );

/**
* Add a new feature to the layer.
Expand Down
5 changes: 1 addition & 4 deletions src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -1585,10 +1585,7 @@ void QgsIdentifyResultsDialog::featureForm()
QgsFeatureAction action( tr( "Attributes changed" ), f, vlayer, idx, -1, this );
if ( vlayer->isEditable() )
{
if ( action.editFeature() )
{
mCanvas->refresh();
}
action.editFeature( false );
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgisinterface.h
Expand Up @@ -570,7 +570,7 @@ class GUI_EXPORT QgisInterface : public QObject
* @return true when dialog was accepted
* @note added in 1.6
*/
virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f, bool updateFeatureOnly = false ) = 0;
virtual bool openFeatureForm( QgsVectorLayer *l, QgsFeature &f, bool updateFeatureOnly = false, bool showModal = true ) = 0;

/**
* Returns a feature form for a given feature
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -230,6 +230,8 @@ bool QgsAttributeForm::save()

emit featureSaved( updatedFeature );

mLayer->triggerRepaint();

mIsSaving = false;

return success;
Expand Down

0 comments on commit bc187ba

Please sign in to comment.