Enum Mode in QgsAttributeEditorContext

instead of QgsAttributeForm - because it's used on places not including QgsAttributeForm
now it's able to use @form_mode in expressions of containers and QML widgets
This commit is contained in:
signedav 2018-09-11 12:14:20 +02:00
parent 05b1e83932
commit b3e4755e2e
31 changed files with 154 additions and 183 deletions

View File

@ -0,0 +1,2 @@
# The following has been generated automatically from src/gui/qgsattributeeditorcontext.h
QgsAttributeEditorContext.Mode.baseClass = QgsAttributeEditorContext

View File

@ -240,7 +240,7 @@ Is emitted when a filter expression is set using the view.
.. versionadded:: 2.16
%End
void formModeChanged( QgsAttributeForm::Mode mode );
void formModeChanged( QgsAttributeEditorContext::Mode mode );
%Docstring
Emitted when the form changes mode.

View File

@ -171,7 +171,7 @@ might be lost.
void contextChanged();
%Docstring
Signal when QgsAttributeEditorContext mContext changed after the widget wrapper has already been intialized
Signal when QgsAttributeEditorContext mContext changed
.. versionadded:: 3.4
%End

View File

@ -49,9 +49,6 @@ writes the ``qmlCode`` into a temporary file
%End
public slots:
void setQmlContext();
virtual void setFeature( const QgsFeature &feature );

View File

@ -73,7 +73,7 @@ Change the feature on which actions are performed
as long as the menu is displayed and the action is running.
%End
void setMode( QgsAttributeForm::Mode mode );
void setMode( QgsAttributeEditorContext::Mode mode );
%Docstring
Change the mode of the actions

View File

@ -50,11 +50,11 @@ Is this dialog editable?
:return: returns true, if this dialog was created in an editable manner.
%End
void setMode( QgsAttributeForm::Mode mode );
void setMode( QgsAttributeEditorContext::Mode mode );
%Docstring
Toggles the form mode.
:param mode: form mode. For example, if set to QgsAttributeForm.AddFeatureMode, the dialog will be editable even with an invalid feature and
:param mode: form mode. For example, if set to QgsAttributeEditorContext.AddFeatureMode, the dialog will be editable even with an invalid feature and
will add a new feature when the form is accepted.
%End

View File

@ -22,6 +22,9 @@ showing an embedded form due to relations)
%TypeHeaderCode
#include "qgsattributeeditorcontext.h"
%End
public:
static const QMetaObject staticMetaObject;
public:
enum Mode
@ -208,17 +211,24 @@ Set current ``feature`` for the currently edited form or table row
.. versionadded:: 3.2
%End
QString attributeFormMode() const;
Mode attributeFormMode() const;
%Docstring
Returns current attributeFormMode
.. versionadded:: 3.4
%End
void setAttributeFormMode( const QString &attributeFormMode );
void setAttributeFormMode( const Mode &attributeFormMode );
%Docstring
Set ``attributeFormMode`` for the edited form
.. versionadded:: 3.4
%End
QString attributeFormModeString( const Mode &attributeFormMode );
%Docstring
Returns given ``attributeFormMode`` as string
.. versionadded:: 3.4
%End

View File

@ -19,16 +19,6 @@ class QgsAttributeForm : QWidget
%End
public:
enum Mode
{
SingleEditMode,
AddFeatureMode,
MultiEditMode,
SearchMode,
AggregateSearchMode,
IdentifyMode
};
enum FilterType
{
ReplaceFilter,
@ -71,7 +61,7 @@ Returns if the form is currently in editable mode.
:return: Editable mode of this form
%End
Mode mode() const;
QgsAttributeEditorContext::Mode mode() const;
%Docstring
Returns the current mode of the form.
@ -80,7 +70,7 @@ Returns the current mode of the form.
.. versionadded:: 2.16
%End
void setMode( Mode mode );
void setMode( QgsAttributeEditorContext::Mode mode );
%Docstring
Sets the current mode of the form.
@ -89,13 +79,6 @@ Sets the current mode of the form.
.. seealso:: :py:func:`mode`
.. versionadded:: 2.16
%End
QString modeString( Mode mode ) const;
%Docstring
Returns the context as string of ``mode``
.. versionadded:: 3.4
%End
void setEditCommandMessage( const QString &message );
@ -184,7 +167,7 @@ Is emitted when a filter expression is set using the form.
.. versionadded:: 2.16
%End
void modeChanged( QgsAttributeForm::Mode mode );
void modeChanged( QgsAttributeEditorContext::Mode mode );
%Docstring
Emitted when the form changes mode.

View File

@ -8196,7 +8196,7 @@ void QgisApp::modifyAttributesOfSelectedFeatures()
context.setAllowCustomUi( false );
QgsAttributeDialog *dialog = new QgsAttributeDialog( vl, &f, false, this, true, context );
dialog->setMode( QgsAttributeForm::MultiEditMode );
dialog->setMode( QgsAttributeEditorContext::MultiEditMode );
dialog->exec();
}

View File

@ -745,7 +745,7 @@ QgsAttributeDialog *QgisAppInterface::getFeatureForm( QgsVectorLayer *l, QgsFeat
QgsAttributeDialog *dialog = new QgsAttributeDialog( l, &feature, false, qgis, true, context );
if ( !feature.isValid() )
{
dialog->setMode( QgsAttributeForm::AddFeatureMode );
dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );
}
return dialog;
}

View File

@ -475,9 +475,9 @@ void QgsAttributeTableDialog::updateFieldFromExpressionSelected()
runFieldCalculation( mLayer, mFieldCombo->currentField(), mUpdateExpressionText->asExpression(), filteredIds );
}
void QgsAttributeTableDialog::viewModeChanged( QgsAttributeForm::Mode mode )
void QgsAttributeTableDialog::viewModeChanged( QgsAttributeEditorContext::Mode mode )
{
if ( mode != QgsAttributeForm::SearchMode )
if ( mode != QgsAttributeEditorContext::SearchMode )
mActionSearchForm->setChecked( false );
}

View File

@ -218,7 +218,7 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
void runFieldCalculation( QgsVectorLayer *layer, const QString &fieldName, const QString &expression, const QgsFeatureIds &filteredIds = QgsFeatureIds() );
void updateFieldFromExpression();
void updateFieldFromExpressionSelected();
void viewModeChanged( QgsAttributeForm::Mode mode );
void viewModeChanged( QgsAttributeEditorContext::Mode mode );
void formFilterSet( const QString &filter, QgsAttributeForm::FilterType type );
void showContextMenu( QgsActionMenu *menu, QgsFeatureId fid );
void toggleDockMode( bool docked );

View File

@ -135,7 +135,7 @@ bool QgsFeatureAction::editFeature( bool showModal )
std::unique_ptr<QgsAttributeDialog> dialog( newDialog( false ) );
if ( !mFeature->isValid() )
dialog->setMode( QgsAttributeForm::AddFeatureMode );
dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );
int rv = dialog->exec();
mFeature->setAttributes( dialog->feature()->attributes() );
@ -155,7 +155,7 @@ bool QgsFeatureAction::editFeature( bool showModal )
dialog = newDialog( false );
if ( !mFeature->isValid() )
dialog->setMode( QgsAttributeForm::AddFeatureMode );
dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );
// delete the dialog when it is closed
dialog->setAttribute( Qt::WA_DeleteOnClose );
@ -235,7 +235,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, boo
QgsAttributeDialog *dialog = newDialog( false );
// delete the dialog when it is closed
dialog->setAttribute( Qt::WA_DeleteOnClose );
dialog->setMode( QgsAttributeForm::AddFeatureMode );
dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );
dialog->setEditCommandMessage( text() );
connect( dialog->attributeForm(), &QgsAttributeForm::featureSaved, this, &QgsFeatureAction::onFeatureSaved );

View File

@ -161,7 +161,7 @@ void QgsMapToolFillRing::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
else
{
QgsAttributeDialog *dialog = new QgsAttributeDialog( vlayer, &ft, false, nullptr, true );
dialog->setMode( QgsAttributeForm::AddFeatureMode );
dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );
res = dialog->exec(); // will also add the feature
}

View File

@ -30,7 +30,7 @@ QgsSelectByFormDialog::QgsSelectByFormDialog( QgsVectorLayer *layer, const QgsAt
dlgContext.setAllowCustomUi( false );
mForm = new QgsAttributeForm( layer, QgsFeature(), dlgContext, this );
mForm->setMode( QgsAttributeForm::SearchMode );
mForm->setMode( QgsAttributeEditorContext::SearchMode );
QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->setMargin( 0 );

View File

@ -547,6 +547,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsdatasourcemanagerdialog.h
qgsabstractdatasourcewidget.h
qgswidgetstatehelper_p.h
qgsattributeeditorcontext.h
ogr/qgsnewogrconnection.h
ogr/qgsvectorlayersaveasdialog.h
@ -757,7 +758,6 @@ ENDIF(MSVC)
# for installing headers
SET(QGIS_GUI_HDRS
qgsattributeeditorcontext.h
qgsattributeforminterface.h
qgsattributeformlegacyinterface.h
qgsdetaileditemdata.h

View File

@ -446,7 +446,7 @@ void QgsDualView::setMultiEditEnabled( bool enabled )
if ( enabled )
setView( AttributeEditor );
mAttributeForm->setMode( enabled ? QgsAttributeForm::MultiEditMode : QgsAttributeForm::SingleEditMode );
mAttributeForm->setMode( enabled ? QgsAttributeEditorContext::MultiEditMode : QgsAttributeEditorContext::SingleEditMode );
}
void QgsDualView::toggleSearchMode( bool enabled )
@ -454,11 +454,11 @@ void QgsDualView::toggleSearchMode( bool enabled )
if ( enabled )
{
setView( AttributeEditor );
mAttributeForm->setMode( QgsAttributeForm::SearchMode );
mAttributeForm->setMode( QgsAttributeEditorContext::SearchMode );
}
else
{
mAttributeForm->setMode( QgsAttributeForm::SingleEditMode );
mAttributeForm->setMode( QgsAttributeEditorContext::SingleEditMode );
}
}

View File

@ -267,7 +267,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
* Emitted when the form changes mode.
* \param mode new mode
*/
void formModeChanged( QgsAttributeForm::Mode mode );
void formModeChanged( QgsAttributeEditorContext::Mode mode );
/**
* Emitted when selecting context menu on the feature list to create the context menu individually

View File

@ -205,7 +205,7 @@ class GUI_EXPORT QgsWidgetWrapper : public QObject
signals:
/**
* Signal when QgsAttributeEditorContext mContext changed after the widget wrapper has already been intialized
* Signal when QgsAttributeEditorContext mContext changed
*
* \since QGIS 3.4
*/

View File

@ -85,8 +85,9 @@ void QgsQmlWidgetWrapper::setQmlContext( )
if ( !mWidget )
return;
QgsAttributeEditorContext attributecontext = context();
QgsExpressionContext expressionContext = layer()->createExpressionContext();
expressionContext << QgsExpressionContextUtils::formScope( mFeature, context().attributeFormMode() );
expressionContext << QgsExpressionContextUtils::formScope( mFeature, attributecontext.attributeFormModeString( attributecontext.attributeFormMode() ) );
expressionContext.setFeature( mFeature );
QmlExpression *qmlExpression = new QmlExpression();

View File

@ -54,11 +54,12 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
void setQmlCode( const QString &qmlCode );
public slots:
void setQmlContext();
void setFeature( const QgsFeature &feature ) override;
private slots:
//! sets the qml context with the current values
void setQmlContext();
private:
QTemporaryFile mQmlFile;
QQuickWidget *mWidget = nullptr;

View File

@ -90,7 +90,7 @@ bool QgsRelationAggregateSearchWidgetWrapper::eventFilter( QObject *watched, QEv
{
QgsAttributeEditorContext subContext = QgsAttributeEditorContext( context(), mWrapper->relation(), QgsAttributeEditorContext::Multiple, QgsAttributeEditorContext::Embed );
mAttributeForm = new QgsAttributeForm( mWrapper->relation().referencingLayer(), QgsFeature(), subContext, mContainerWidget );
mAttributeForm->setMode( QgsAttributeForm::AggregateSearchMode );
mAttributeForm->setMode( QgsAttributeEditorContext::AggregateSearchMode );
QGridLayout *glayout = new QGridLayout();
mContainerWidget->setLayout( glayout );
glayout->setMargin( 0 );

View File

@ -67,7 +67,7 @@ void QgsActionMenu::setFeature( const QgsFeature &feature )
mFeature = feature;
}
void QgsActionMenu::setMode( const QgsAttributeForm::Mode mode )
void QgsActionMenu::setMode( const QgsAttributeEditorContext::Mode mode )
{
mMode = mode;
reloadActions();
@ -120,7 +120,7 @@ void QgsActionMenu::reloadActions()
if ( !mLayer->isEditable() && action.isEnabledOnlyWhenEditable() )
continue;
if ( action.isEnabledOnlyWhenEditable() && ( mMode == QgsAttributeForm::AddFeatureMode || mMode == QgsAttributeForm::IdentifyMode ) )
if ( action.isEnabledOnlyWhenEditable() && ( mMode == QgsAttributeEditorContext::AddFeatureMode || mMode == QgsAttributeEditorContext::IdentifyMode ) )
continue;
QgsAction act( action );
@ -155,7 +155,7 @@ void QgsActionMenu::reloadActions()
{
QgsMapLayerAction *qaction = mapLayerActions.at( i );
if ( qaction->isEnabledOnlyWhenEditable() && ( mMode == QgsAttributeForm::AddFeatureMode || mMode == QgsAttributeForm::IdentifyMode ) )
if ( qaction->isEnabledOnlyWhenEditable() && ( mMode == QgsAttributeEditorContext::AddFeatureMode || mMode == QgsAttributeEditorContext::IdentifyMode ) )
continue;
QAction *qAction = new QAction( qaction->icon(), qaction->text(), this );

View File

@ -97,7 +97,7 @@ class GUI_EXPORT QgsActionMenu : public QMenu
*
* \param mode The mode of the attribute form
*/
void setMode( QgsAttributeForm::Mode mode );
void setMode( QgsAttributeEditorContext::Mode mode );
/**
* Sets an expression context scope used to resolve underlying actions.
@ -131,7 +131,7 @@ class GUI_EXPORT QgsActionMenu : public QMenu
QgsFeatureId mFeatureId;
QString mActionScope;
QgsExpressionContextScope mExpressionContextScope;
QgsAttributeForm::Mode mMode;
QgsAttributeEditorContext::Mode mMode;
};

View File

@ -79,7 +79,7 @@ void QgsAttributeDialog::show()
void QgsAttributeDialog::reject()
{
// Delete any actions on other layers that may have been triggered from this dialog
if ( mAttributeForm->mode() == QgsAttributeForm::AddFeatureMode )
if ( mAttributeForm->mode() == QgsAttributeEditorContext::AddFeatureMode )
mTrackedVectorLayerTools.rollback();
QDialog::reject();
@ -116,7 +116,7 @@ void QgsAttributeDialog::init( QgsVectorLayer *layer, QgsFeature *feature, const
focusNextChild();
}
void QgsAttributeDialog::setMode( QgsAttributeForm::Mode mode )
void QgsAttributeDialog::setMode( QgsAttributeEditorContext::Mode mode )
{
mAttributeForm->setMode( mode );
mMenu->setMode( mode );

View File

@ -75,10 +75,10 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog
/**
* Toggles the form mode.
* \param mode form mode. For example, if set to QgsAttributeForm::AddFeatureMode, the dialog will be editable even with an invalid feature and
* \param mode form mode. For example, if set to QgsAttributeEditorContext::AddFeatureMode, the dialog will be editable even with an invalid feature and
* will add a new feature when the form is accepted.
*/
void setMode( QgsAttributeForm::Mode mode );
void setMode( QgsAttributeEditorContext::Mode mode );
/**
* Sets the edit command message (Undo) that will be used when the dialog is accepted

View File

@ -18,6 +18,7 @@
#include <QMap>
#include <QWidget>
#include <QMetaEnum>
#include "qgsdistancearea.h"
#include "qgsvectorlayer.h"
@ -36,9 +37,11 @@ class QgsMapCanvas;
class GUI_EXPORT QgsAttributeEditorContext
{
Q_GADGET
public:
//! Form modes
//! modes
enum Mode
{
SingleEditMode, //!< Single edit mode, for editing a single feature
@ -49,6 +52,7 @@ class GUI_EXPORT QgsAttributeEditorContext
AggregateSearchMode, //!< Form is in aggregate search mode, show each widget in this mode \since QGIS 3.0
IdentifyMode //!< Identify the feature \since QGIS 3.0
};
Q_ENUM( Mode )
/**
* Determines in which direction a relation was resolved.
@ -220,13 +224,23 @@ class GUI_EXPORT QgsAttributeEditorContext
* Returns current attributeFormMode
* \since QGIS 3.4
*/
QString attributeFormMode() const { return mAttributeFormMode; }
Mode attributeFormMode() const { return mAttributeFormMode; }
/**
* Set \a attributeFormMode for the edited form
* \since QGIS 3.4
*/
void setAttributeFormMode( const QString &attributeFormMode ) { mAttributeFormMode = attributeFormMode; }
void setAttributeFormMode( const Mode &attributeFormMode ) { mAttributeFormMode = attributeFormMode; }
/**
* Returns given \a attributeFormMode as string
* \since QGIS 3.4
*/
QString attributeFormModeString( const Mode &attributeFormMode )
{
const QMetaEnum metaEnum( QMetaEnum::fromType<Mode>() );
return metaEnum.valueToKey( static_cast<int>( attributeFormMode ) );
}
private:
const QgsAttributeEditorContext *mParentContext = nullptr;
@ -240,7 +254,7 @@ class GUI_EXPORT QgsAttributeEditorContext
QgsFeature mFormFeature;
FormMode mFormMode = Embed;
bool mAllowCustomUi = true;
QString mAttributeFormMode = QStringLiteral( "SingleEditMode" );
Mode mAttributeFormMode = SingleEditMode;
};
#endif // QGSATTRIBUTEEDITORCONTEXT_H

View File

@ -67,7 +67,7 @@ QgsAttributeForm::QgsAttributeForm( QgsVectorLayer *vl, const QgsFeature &featur
, mIsSettingMultiEditFeatures( false )
, mUnsavedMultiEditChanges( false )
, mEditCommandMessage( tr( "Attributes changed" ) )
, mMode( SingleEditMode )
, mMode( QgsAttributeEditorContext::SingleEditMode )
{
init();
initPython();
@ -93,7 +93,7 @@ void QgsAttributeForm::hideButtonBox()
mButtonBox->hide();
// Make sure that changes are taken into account if somebody tries to figure out if there have been some
if ( mMode == SingleEditMode )
if ( mMode == QgsAttributeEditorContext::SingleEditMode )
connect( mLayer, &QgsVectorLayer::beforeModifiedCheck, this, &QgsAttributeForm::save );
}
@ -120,12 +120,12 @@ bool QgsAttributeForm::editable()
return mFeature.isValid() && mLayer->isEditable();
}
void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )
void QgsAttributeForm::setMode( QgsAttributeEditorContext::Mode mode )
{
if ( mode == mMode )
return;
if ( mMode == MultiEditMode )
if ( mMode == QgsAttributeEditorContext::MultiEditMode )
{
//switching out of multi edit mode triggers a save
if ( mUnsavedMultiEditChanges )
@ -144,7 +144,7 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )
mMode = mode;
if ( mButtonBox->isVisible() && mMode == SingleEditMode )
if ( mButtonBox->isVisible() && mMode == QgsAttributeEditorContext::SingleEditMode )
{
connect( mLayer, &QgsVectorLayer::beforeModifiedCheck, this, &QgsAttributeForm::save );
}
@ -158,27 +158,27 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )
{
switch ( mode )
{
case QgsAttributeForm::SingleEditMode:
case QgsAttributeEditorContext::SingleEditMode:
w->setMode( QgsAttributeFormWidget::DefaultMode );
break;
case QgsAttributeForm::AddFeatureMode:
case QgsAttributeEditorContext::AddFeatureMode:
w->setMode( QgsAttributeFormWidget::DefaultMode );
break;
case QgsAttributeForm::MultiEditMode:
case QgsAttributeEditorContext::MultiEditMode:
w->setMode( QgsAttributeFormWidget::MultiEditMode );
break;
case QgsAttributeForm::SearchMode:
case QgsAttributeEditorContext::SearchMode:
w->setMode( QgsAttributeFormWidget::SearchMode );
break;
case QgsAttributeForm::AggregateSearchMode:
case QgsAttributeEditorContext::AggregateSearchMode:
w->setMode( QgsAttributeFormWidget::AggregateSearchMode );
break;
case QgsAttributeForm::IdentifyMode:
case QgsAttributeEditorContext::IdentifyMode:
w->setMode( QgsAttributeFormWidget::DefaultMode );
break;
}
@ -187,11 +187,11 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )
for ( QgsWidgetWrapper *w : qgis::as_const( mWidgets ) )
{
QgsAttributeEditorContext newContext = w->context();
newContext.setAttributeFormMode( modeString( mMode ) );
newContext.setAttributeFormMode( mMode );
w->setContext( newContext );
}
bool relationWidgetsVisible = ( mMode != QgsAttributeForm::MultiEditMode && mMode != QgsAttributeForm::AggregateSearchMode );
bool relationWidgetsVisible = ( mMode != QgsAttributeEditorContext::MultiEditMode && mMode != QgsAttributeEditorContext::AggregateSearchMode );
for ( QgsAttributeFormRelationEditorWidget *w : findChildren< QgsAttributeFormRelationEditorWidget * >() )
{
w->setVisible( relationWidgetsVisible );
@ -199,33 +199,33 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )
switch ( mode )
{
case QgsAttributeForm::SingleEditMode:
case QgsAttributeEditorContext::SingleEditMode:
setFeature( mFeature );
mSearchButtonBox->setVisible( false );
break;
case QgsAttributeForm::AddFeatureMode:
case QgsAttributeEditorContext::AddFeatureMode:
synchronizeEnabledState();
mSearchButtonBox->setVisible( false );
break;
case QgsAttributeForm::MultiEditMode:
case QgsAttributeEditorContext::MultiEditMode:
resetMultiEdit( false );
synchronizeEnabledState();
mSearchButtonBox->setVisible( false );
break;
case QgsAttributeForm::SearchMode:
case QgsAttributeEditorContext::SearchMode:
mSearchButtonBox->setVisible( true );
hideButtonBox();
break;
case QgsAttributeForm::AggregateSearchMode:
case QgsAttributeEditorContext::AggregateSearchMode:
mSearchButtonBox->setVisible( false );
hideButtonBox();
break;
case QgsAttributeForm::IdentifyMode:
case QgsAttributeEditorContext::IdentifyMode:
setFeature( mFeature );
mSearchButtonBox->setVisible( false );
break;
@ -234,25 +234,6 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )
emit modeChanged( mMode );
}
QString QgsAttributeForm::modeString( Mode mode ) const
{
switch ( mode )
{
case SingleEditMode:
return QStringLiteral( "SingleEditMode" );
case AddFeatureMode:
return QStringLiteral( "AddFeatureMode" );
case MultiEditMode:
return QStringLiteral( "MultiEditMode" );
case SearchMode:
return QStringLiteral( "SearchMode" );
case AggregateSearchMode:
return QStringLiteral( "AggregateSearchMode" );
case IdentifyMode:
return QStringLiteral( "IdentifyMode" );
}
}
void QgsAttributeForm::changeAttribute( const QString &field, const QVariant &value, const QString &hintText )
{
Q_FOREACH ( QgsWidgetWrapper *ww, mWidgets )
@ -273,9 +254,9 @@ void QgsAttributeForm::setFeature( const QgsFeature &feature )
switch ( mMode )
{
case SingleEditMode:
case IdentifyMode:
case AddFeatureMode:
case QgsAttributeEditorContext::SingleEditMode:
case QgsAttributeEditorContext::IdentifyMode:
case QgsAttributeEditorContext::AddFeatureMode:
{
resetValues();
@ -287,9 +268,9 @@ void QgsAttributeForm::setFeature( const QgsFeature &feature )
}
break;
}
case MultiEditMode:
case SearchMode:
case AggregateSearchMode:
case QgsAttributeEditorContext::MultiEditMode:
case QgsAttributeEditorContext::SearchMode:
case QgsAttributeEditorContext::AggregateSearchMode:
{
//ignore setFeature
break;
@ -305,13 +286,13 @@ bool QgsAttributeForm::saveEdits()
QgsFeature updatedFeature = QgsFeature( mFeature );
if ( mFeature.isValid() || mMode == AddFeatureMode )
if ( mFeature.isValid() || mMode == QgsAttributeEditorContext::AddFeatureMode )
{
bool doUpdate = false;
// An add dialog should perform an action by default
// and not only if attributes have "changed"
if ( mMode == AddFeatureMode )
if ( mMode == QgsAttributeEditorContext::AddFeatureMode )
doUpdate = true;
QgsAttributes src = mFeature.attributes();
@ -351,7 +332,7 @@ bool QgsAttributeForm::saveEdits()
if ( doUpdate )
{
if ( mMode == AddFeatureMode )
if ( mMode == QgsAttributeEditorContext::AddFeatureMode )
{
mFeature.setValid( true );
mLayer->beginEditCommand( mEditCommandMessage );
@ -360,7 +341,7 @@ bool QgsAttributeForm::saveEdits()
{
mFeature.setAttributes( updatedFeature.attributes() );
mLayer->endEditCommand();
setMode( SingleEditMode );
setMode( QgsAttributeEditorContext::SingleEditMode );
changedLayer = true;
}
else
@ -444,7 +425,7 @@ void QgsAttributeForm::filterTriggered()
QString filter = createFilterExpression();
emit filterExpressionSet( filter, ReplaceFilter );
if ( mContext.formMode() == QgsAttributeEditorContext::Embed )
setMode( SingleEditMode );
setMode( QgsAttributeEditorContext::SingleEditMode );
}
void QgsAttributeForm::searchZoomTo()
@ -472,7 +453,7 @@ void QgsAttributeForm::filterAndTriggered()
return;
if ( mContext.formMode() == QgsAttributeEditorContext::Embed )
setMode( SingleEditMode );
setMode( QgsAttributeEditorContext::SingleEditMode );
emit filterExpressionSet( filter, FilterAnd );
}
@ -483,7 +464,7 @@ void QgsAttributeForm::filterOrTriggered()
return;
if ( mContext.formMode() == QgsAttributeEditorContext::Embed )
setMode( SingleEditMode );
setMode( QgsAttributeEditorContext::SingleEditMode );
emit filterExpressionSet( filter, FilterOr );
}
@ -516,7 +497,7 @@ void QgsAttributeForm::runSearchSelect( QgsVectorLayer::SelectBehavior behavior
mLayer->selectByExpression( filter, behavior );
pushSelectedFeaturesMessage();
if ( mContext.formMode() == QgsAttributeEditorContext::Embed )
setMode( SingleEditMode );
setMode( QgsAttributeEditorContext::SingleEditMode );
}
void QgsAttributeForm::searchSetSelection()
@ -625,16 +606,16 @@ bool QgsAttributeForm::save()
// default values
switch ( mMode )
{
case SingleEditMode:
case IdentifyMode:
case MultiEditMode:
case QgsAttributeEditorContext::SingleEditMode:
case QgsAttributeEditorContext::IdentifyMode:
case QgsAttributeEditorContext::MultiEditMode:
if ( !mDirty )
return true;
break;
case AddFeatureMode:
case SearchMode:
case AggregateSearchMode:
case QgsAttributeEditorContext::AddFeatureMode:
case QgsAttributeEditorContext::SearchMode:
case QgsAttributeEditorContext::AggregateSearchMode:
break;
}
@ -650,15 +631,15 @@ bool QgsAttributeForm::save()
switch ( mMode )
{
case SingleEditMode:
case IdentifyMode:
case AddFeatureMode:
case SearchMode:
case AggregateSearchMode:
case QgsAttributeEditorContext::SingleEditMode:
case QgsAttributeEditorContext::IdentifyMode:
case QgsAttributeEditorContext::AddFeatureMode:
case QgsAttributeEditorContext::SearchMode:
case QgsAttributeEditorContext::AggregateSearchMode:
success = saveEdits();
break;
case MultiEditMode:
case QgsAttributeEditorContext::MultiEditMode:
success = saveMultiEdits();
break;
}
@ -735,9 +716,9 @@ void QgsAttributeForm::onAttributeChanged( const QVariant &value )
switch ( mMode )
{
case SingleEditMode:
case IdentifyMode:
case AddFeatureMode:
case QgsAttributeEditorContext::SingleEditMode:
case QgsAttributeEditorContext::IdentifyMode:
case QgsAttributeEditorContext::AddFeatureMode:
{
Q_NOWARN_DEPRECATED_PUSH
emit attributeChanged( eww->field().name(), value );
@ -750,7 +731,7 @@ void QgsAttributeForm::onAttributeChanged( const QVariant &value )
break;
}
case MultiEditMode:
case QgsAttributeEditorContext::MultiEditMode:
{
if ( !mIsSettingMultiEditFeatures )
{
@ -768,8 +749,8 @@ void QgsAttributeForm::onAttributeChanged( const QVariant &value )
}
break;
}
case SearchMode:
case AggregateSearchMode:
case QgsAttributeEditorContext::SearchMode:
case QgsAttributeEditorContext::AggregateSearchMode:
//nothing to do
break;
}
@ -824,7 +805,7 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
mExpressionContext.setFeature( ft );
mExpressionContext << QgsExpressionContextUtils::formScope( ft, modeString( mMode ) );
mExpressionContext << QgsExpressionContextUtils::formScope( ft, mContext.attributeFormModeString( mMode ) );
// Recheck visibility for all containers which are controlled by this value
const QVector<ContainerInformation *> infos = mContainerInformationDependency.value( eww->field().name() );
@ -838,7 +819,7 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
void QgsAttributeForm::updateContainersVisibility()
{
mExpressionContext << QgsExpressionContextUtils::formScope( QgsFeature( mFeature ), modeString( mMode ) );
mExpressionContext << QgsExpressionContextUtils::formScope( QgsFeature( mFeature ), mContext.attributeFormModeString( mMode ) );
const QVector<ContainerInformation *> infos = mContainerVisibilityInformation;
@ -1077,8 +1058,8 @@ void QgsAttributeForm::refreshFeature()
void QgsAttributeForm::synchronizeEnabledState()
{
bool isEditable = ( mFeature.isValid()
|| mMode == AddFeatureMode
|| mMode == MultiEditMode ) && mLayer->isEditable();
|| mMode == QgsAttributeEditorContext::AddFeatureMode
|| mMode == QgsAttributeEditorContext::MultiEditMode ) && mLayer->isEditable();
for ( QgsWidgetWrapper *ww : qgis::as_const( mWidgets ) )
{
@ -1099,7 +1080,7 @@ void QgsAttributeForm::synchronizeEnabledState()
}
}
if ( mMode != SearchMode )
if ( mMode != QgsAttributeEditorContext::SearchMode )
{
QStringList invalidFields, descriptions;
bool validConstraint = currentFormValidConstraints( invalidFields, descriptions );
@ -1498,7 +1479,7 @@ void QgsAttributeForm::init()
layout->addWidget( mSearchButtonBox );
}
mSearchButtonBox->setVisible( mMode == SearchMode );
mSearchButtonBox->setVisible( mMode == QgsAttributeEditorContext::SearchMode );
afterWidgetInit();
@ -1519,7 +1500,7 @@ void QgsAttributeForm::init()
iface->initForm();
}
if ( mContext.formMode() == QgsAttributeEditorContext::Embed || mMode == SearchMode )
if ( mContext.formMode() == QgsAttributeEditorContext::Embed || mMode == QgsAttributeEditorContext::SearchMode )
{
hideButtonBox();
}
@ -1821,7 +1802,7 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
QgsQmlWidgetWrapper *qmlWrapper = new QgsQmlWidgetWrapper( mLayer, nullptr, this );
qmlWrapper->setQmlCode( elementDef->qmlCode() );
qmlWrapper->setConfig( mLayer->editFormConfig().widgetConfig( elementDef->name() ) );
context.setAttributeFormMode( modeString( mMode ) );
context.setAttributeFormMode( mMode );
qmlWrapper->setContext( context );
mWidgets.append( qmlWrapper );
@ -1983,14 +1964,14 @@ void QgsAttributeForm::layerSelectionChanged()
{
switch ( mMode )
{
case SingleEditMode:
case IdentifyMode:
case AddFeatureMode:
case SearchMode:
case AggregateSearchMode:
case QgsAttributeEditorContext::SingleEditMode:
case QgsAttributeEditorContext::IdentifyMode:
case QgsAttributeEditorContext::AddFeatureMode:
case QgsAttributeEditorContext::SearchMode:
case QgsAttributeEditorContext::AggregateSearchMode:
break;
case MultiEditMode:
case QgsAttributeEditorContext::MultiEditMode:
resetMultiEdit( true );
break;
}
@ -2053,7 +2034,7 @@ void QgsAttributeForm::setMessageBar( QgsMessageBar *messageBar )
QString QgsAttributeForm::aggregateFilter() const
{
if ( mMode != AggregateSearchMode )
if ( mMode != QgsAttributeEditorContext::AggregateSearchMode )
{
Q_ASSERT( false );
}
@ -2165,7 +2146,7 @@ bool QgsAttributeForm::fieldIsEditable( int fieldIndex ) const
int srcFieldIndex;
const QgsVectorLayerJoinInfo *info = mLayer->joinBuffer()->joinForFieldIndex( fieldIndex, mLayer->fields(), srcFieldIndex );
if ( info && !info->hasUpsertOnEdit() && mMode == QgsAttributeForm::AddFeatureMode )
if ( info && !info->hasUpsertOnEdit() && mMode == QgsAttributeEditorContext::AddFeatureMode )
editable = false;
else if ( info && info->isEditable() && info->joinLayer()->isEditable() )
editable = fieldIsEditable( *( info->joinLayer() ), srcFieldIndex, mFeature.id() );
@ -2206,7 +2187,7 @@ void QgsAttributeForm::updateIcon( QgsEditorWidgetWrapper *eww )
const QString tooltip = tr( "Join settings do not allow editing" );
reloadIcon( file, tooltip, mIconMap[eww->widget()] );
}
else if ( mMode == QgsAttributeForm::AddFeatureMode && !info->hasUpsertOnEdit() )
else if ( mMode == QgsAttributeEditorContext::AddFeatureMode && !info->hasUpsertOnEdit() )
{
const QString file = QStringLiteral( "mIconJoinHasNotUpsertOnEdit.svg" );
const QString tooltip = tr( "Join settings do not allow upsert on edit" );

View File

@ -46,18 +46,6 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
public:
//! Form modes
enum Mode
{
SingleEditMode, //!< Single edit mode, for editing a single feature
AddFeatureMode, /*!< Add feature mode, for setting attributes for a new feature. In this mode the dialog will be editable even with an invalid feature and
will add a new feature when the form is accepted. */
MultiEditMode, //!< Multi edit mode, for editing fields of multiple features at once
SearchMode, //!< Form values are used for searching/filtering the layer
AggregateSearchMode, //!< Form is in aggregate search mode, show each widget in this mode \since QGIS 3.0
IdentifyMode //!< Identify the feature \since QGIS 3.0
};
//! Filter types
enum FilterType
{
@ -120,7 +108,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
* \see setMode()
* \since QGIS 2.16
*/
Mode mode() const { return mMode; }
QgsAttributeEditorContext::Mode mode() const { return mMode; }
/**
* Sets the current mode of the form.
@ -128,13 +116,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
* \see mode()
* \since QGIS 2.16
*/
void setMode( Mode mode );
/**
* Returns the context as string of \a mode
* \since QGIS 3.4
*/
QString modeString( Mode mode ) const;
void setMode( QgsAttributeEditorContext::Mode mode );
/**
* Sets the edit command message (Undo) that will be used when the dialog is accepted
@ -226,7 +208,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
* Emitted when the form changes mode.
* \param mode new mode
*/
void modeChanged( QgsAttributeForm::Mode mode );
void modeChanged( QgsAttributeEditorContext::Mode mode );
/**
* Emitted when the user selects the close option from the form's button bar.
@ -440,7 +422,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
QString mEditCommandMessage;
Mode mMode;
QgsAttributeEditorContext::Mode mMode;
QMap<QWidget *, QSvgWidget *> mIconMap;

View File

@ -260,7 +260,7 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer *layer, const QList<QgsMapT
if ( !createMenu && mShowFeatureActions )
{
QgsActionMenu *featureActionMenu = new QgsActionMenu( layer, results[0].mFeature, QStringLiteral( "Feature" ), this );
featureActionMenu->setMode( QgsAttributeForm::IdentifyMode );
featureActionMenu->setMode( QgsAttributeEditorContext::IdentifyMode );
createMenu = !featureActionMenu->actions().isEmpty();
delete featureActionMenu;
}
@ -346,7 +346,7 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer *layer, const QList<QgsMapT
if ( mShowFeatureActions )
{
featureActionMenu = new QgsActionMenu( layer, result.mFeature, QStringLiteral( "Feature" ), layerMenu );
featureActionMenu->setMode( QgsAttributeForm::IdentifyMode );
featureActionMenu->setMode( QgsAttributeEditorContext::IdentifyMode );
featureActionMenu->setExpressionContextScope( mExpressionContextScope );
}

View File

@ -373,7 +373,7 @@ void TestQgsAttributeForm::testDynamicForm()
// build a form with feature A
QgsAttributeForm form( layerA );
form.setMode( QgsAttributeForm::AddFeatureMode );
form.setMode( QgsAttributeEditorContext::AddFeatureMode );
form.setFeature( ftA );
// test that there's no joined feature by default
@ -487,7 +487,7 @@ void TestQgsAttributeForm::testConstraintsOnJoinedFields()
// build a form for this feature
QgsAttributeForm form( layerA );
form.setMode( QgsAttributeForm::AddFeatureMode );
form.setMode( QgsAttributeEditorContext::AddFeatureMode );
form.setFeature( ftA );
// change layerA join id field
@ -568,7 +568,7 @@ void TestQgsAttributeForm::testEditableJoin()
ftA = layerA->getFeature( 1 );
QgsAttributeForm form( layerA );
form.setMode( QgsAttributeForm::SingleEditMode );
form.setMode( QgsAttributeEditorContext::SingleEditMode );
form.setFeature( ftA );
// change layerA join id field to join with layerB and layerC
@ -692,7 +692,7 @@ void TestQgsAttributeForm::testUpsertOnEdit()
// build a form with feature A
QgsAttributeForm form( layerA );
form.setMode( QgsAttributeForm::AddFeatureMode );
form.setMode( QgsAttributeEditorContext::AddFeatureMode );
form.setFeature( ft0A );
// count features
@ -725,7 +725,7 @@ void TestQgsAttributeForm::testUpsertOnEdit()
// add a new feature with not null joined fields. Joined feature should be
// added
QgsAttributeForm form1( layerA );
form1.setMode( QgsAttributeForm::AddFeatureMode );
form1.setMode( QgsAttributeEditorContext::AddFeatureMode );
form1.setFeature( ft0A );
form1.changeAttribute( QStringLiteral( "id_a" ), QVariant( 34 ) );
@ -760,7 +760,7 @@ void TestQgsAttributeForm::testUpsertOnEdit()
// create a target feature but update a joined feature. A new feature should
// be added in layerA and values in layerB should be updated
QgsAttributeForm form2( layerA );
form2.setMode( QgsAttributeForm::AddFeatureMode );
form2.setMode( QgsAttributeEditorContext::AddFeatureMode );
form2.setFeature( ft0A );
form2.changeAttribute( QStringLiteral( "id_a" ), QVariant( 33 ) );
form2.changeAttribute( QStringLiteral( "layerB_col0" ), QVariant( 3333 ) );
@ -794,7 +794,7 @@ void TestQgsAttributeForm::testUpsertOnEdit()
// update feature which does not exist in joined layer but with null joined
// fields. A new feature should NOT be added in joined layer
QgsAttributeForm form3( layerA );
form3.setMode( QgsAttributeForm::SingleEditMode );
form3.setMode( QgsAttributeEditorContext::SingleEditMode );
form3.setFeature( ft0A );
form3.changeAttribute( QStringLiteral( "id_a" ), QVariant( 31 ) );
form3.changeAttribute( QStringLiteral( "layerB_col0" ), QVariant() );
@ -819,7 +819,7 @@ void TestQgsAttributeForm::testUpsertOnEdit()
// update feature which does not exist in joined layer with NOT null joined
// fields. A new feature should be added in joined layer
QgsAttributeForm form4( layerA );
form4.setMode( QgsAttributeForm::SingleEditMode );
form4.setMode( QgsAttributeEditorContext::SingleEditMode );
form4.setFeature( ft0A );
form4.changeAttribute( QStringLiteral( "id_a" ), QVariant( 31 ) );
form4.changeAttribute( QStringLiteral( "layerB_col0" ), QVariant( 1111 ) );