21#include "qgsattributeformcontaineredit.h"
25#include "qgsattributetypedialog.h"
26#include "qgsattributewidgetedit.h"
35#include "moc_qgsattributesformproperties.cpp"
37#ifdef ENABLE_MODELTEST
58 QGridLayout *availableWidgetsWidgetLayout =
new QGridLayout;
61 availableWidgetsWidgetLayout->setContentsMargins( 0, 0, 0, 0 );
62 mAvailableWidgetsWidget->setLayout( availableWidgetsWidgetLayout );
71 mAvailableWidgetsProxyModel->setAttributesFormSourceModel( mAvailableWidgetsModel );
72 mAvailableWidgetsProxyModel->setRecursiveFilteringEnabled(
true );
78#ifdef ENABLE_MODELTEST
79 new ModelTest( mAvailableWidgetsProxyModel,
this );
83 QGridLayout *formLayoutWidgetLayout =
new QGridLayout;
86 formLayoutWidgetLayout->setContentsMargins( 0, 0, 0, 0 );
87 mFormLayoutWidget->setLayout( formLayoutWidgetLayout );
95 mFormLayoutProxyModel->setAttributesFormSourceModel( mFormLayoutModel );
96 mFormLayoutProxyModel->setRecursiveFilteringEnabled(
true );
102#ifdef ENABLE_MODELTEST
103 new ModelTest( mFormLayoutProxyModel,
this );
106 connect(
mAvailableWidgetsView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
107 connect(
mFormLayoutView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAttributesFormProperties::onFormLayoutSelectionChanged );
109 connect(
mAvailableWidgetsView, &QWidget::customContextMenuRequested,
this, &QgsAttributesFormProperties::onContextMenuRequested );
111 connect( mAddContainerButton, &QAbstractButton::clicked,
this, &QgsAttributesFormProperties::addContainer );
112 connect( mRemoveLayoutItemButton, &QAbstractButton::clicked,
this, &QgsAttributesFormProperties::removeTabOrGroupButton );
113 connect( mInvertSelectionButton, &QAbstractButton::clicked,
this, &QgsAttributesFormProperties::onInvertSelectionButtonClicked );
114 connect( mShowAliasesButton, &QAbstractButton::toggled,
this, &QgsAttributesFormProperties::toggleShowAliases );
115 connect( mEditorLayoutComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsAttributesFormProperties::mEditorLayoutComboBox_currentIndexChanged );
116 connect( pbnSelectEditForm, &QToolButton::clicked,
this, &QgsAttributesFormProperties::pbnSelectEditForm_clicked );
117 connect( mTbInitCode, &QPushButton::clicked,
this, &QgsAttributesFormProperties::mTbInitCode_clicked );
119 connect( mSearchLineEdit, &QgsFilterLineEdit::textChanged,
this, &QgsAttributesFormProperties::updateFilteredItems );
122 if ( !mBlockUpdates )
127 mAvailableWidgetsContextMenu =
new QMenu(
this );
128 mActionCopyWidgetConfiguration =
new QAction( tr(
"Copy widget configuration" ),
this );
129 mActionPasteWidgetConfiguration =
new QAction( tr(
"Paste widget configuration" ),
this );
131 connect( mActionCopyWidgetConfiguration, &QAction::triggered,
this, &QgsAttributesFormProperties::copyWidgetConfiguration );
132 connect( mActionPasteWidgetConfiguration, &QAction::triggered,
this, &QgsAttributesFormProperties::pasteWidgetConfiguration );
134 mAvailableWidgetsContextMenu->addAction( mActionCopyWidgetConfiguration );
135 mAvailableWidgetsContextMenu->addAction( mActionPasteWidgetConfiguration );
138 mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
139 gridLayout->addWidget( mMessageBar, 0, 0 );
143 splitter->setSizes( { widget->minimumSizeHint().width(), 600 } );
164 mAvailableWidgetsModel->populate();
173 mFormLayoutView->setSelectionBehavior( QAbstractItemView::SelectRows );
174 mFormLayoutView->setSelectionMode( QAbstractItemView::SelectionMode::ExtendedSelection );
176 mFormLayoutView->setDragDropMode( QAbstractItemView::DragDropMode::DragDrop );
180 mFormLayoutModel->populate();
199 mFormSuppressCmbBx->setCurrentIndex( mFormSuppressCmbBx->findData( QVariant::fromValue(
mLayer->editFormConfig().suppress() ) ) );
204 mAvailableWidgetsModel->populateLayerActions( actions );
216 mEditorLayoutComboBox->setCurrentIndex( mEditorLayoutComboBox->findData( QVariant::fromValue(
mLayer->editFormConfig().layout() ) ) );
218 mEditorLayoutComboBox_currentIndexChanged( mEditorLayoutComboBox->currentIndex() );
221 mEditFormLineEdit->setText( cfg.
uiForm() );
233 if ( mInitCode.isEmpty() )
235 mInitCode.append( tr(
"# -*- coding: utf-8 -*-\n\"\"\"\n"
236 "QGIS forms can have a Python function that is called when the form is\n"
239 "Use this function to add extra logic to your forms.\n"
241 "Enter the name of the function in the \"Python Init function\"\n"
243 "An example follows:\n"
245 "from qgis.PyQt.QtWidgets import QWidget\n\n"
246 "def my_form_open(dialog, layer, feature):\n"
247 " geom = feature.geometry()\n"
248 " control = dialog.findChild(QWidget, \"MyLineEdit\")\n" ) );
252void QgsAttributesFormProperties::loadAttributeTypeDialog()
263 if ( fieldIndex < 0 )
268 loadAttributeTypeDialogFromConfiguration( cfg );
271 mAttributeTypeFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
315void QgsAttributesFormProperties::storeAttributeTypeDialog()
323 QgsAttributesFormData::FieldConfig cfg;
332 QgsFieldConstraints constraints;
375 const QString fieldName =
mLayer->fields().at( fieldIndex ).name();
377 QModelIndex index = mAvailableWidgetsModel->fieldModelIndex( fieldName );
378 if ( index.isValid() )
385 mFormLayoutModel->updateFieldConfigForFieldItems( fieldName, cfg );
391void QgsAttributesFormProperties::storeAttributeWidgetEdit()
400 storeAttributeWidgetEdit( index );
403void QgsAttributesFormProperties::storeAttributeWidgetEdit(
const QModelIndex &index )
408 if ( !index.isValid() )
416 QgsAttributesFormData::RelationEditorConfiguration config =
mAttributeWidgetEdit->updatedRelationConfiguration();
417 itemData.setRelationEditorConfiguration( config );
423void QgsAttributesFormProperties::loadAttributeWidgetEdit()
428 const QModelIndex currentIndex =
mFormLayoutView->firstSelectedIndex();
429 const QgsAttributesFormData::AttributeFormItemData itemData = currentIndex.data(
QgsAttributesFormModel::ItemDataRole ).value< QgsAttributesFormData::AttributeFormItemData >();
435 mAttributeTypeFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
439void QgsAttributesFormProperties::loadInfoWidget(
const QString &infoText )
442 mAttributeTypeFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
446void QgsAttributesFormProperties::storeAttributeContainerEdit()
454 const QModelIndex currentIndex =
mFormLayoutView->firstSelectedIndex();
455 storeAttributeContainerEdit( currentIndex );
458void QgsAttributesFormProperties::storeAttributeContainerEdit(
const QModelIndex &index )
463 if ( !index.isValid() )
467 QString containerName;
474void QgsAttributesFormProperties::loadAttributeContainerEdit()
479 const QModelIndex currentIndex =
mFormLayoutView->firstSelectedIndex();
480 const QgsAttributesFormData::AttributeFormItemData itemData = currentIndex.data(
QgsAttributesFormModel::ItemDataRole ).value< QgsAttributesFormData::AttributeFormItemData >();
487 mAttributeTypeFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
491void QgsAttributesFormProperties::onAttributeSelectionChanged(
const QItemSelection &,
const QItemSelection & )
493 disconnect(
mFormLayoutView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAttributesFormProperties::onFormLayoutSelectionChanged );
496 if (
mFormLayoutView->selectionModel()->selectedRows( 0 ).count() == 1 )
504 connect(
mFormLayoutView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAttributesFormProperties::onFormLayoutSelectionChanged );
507void QgsAttributesFormProperties::onFormLayoutSelectionChanged(
const QItemSelection &,
const QItemSelection &deselected )
510 disconnect(
mAvailableWidgetsView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
512 if ( deselected.indexes().count() == 1 )
514 index = mFormLayoutProxyModel->mapToSource( deselected.indexes().at( 0 ) );
516 else if ( deselected.indexes().count() == 0 &&
mFormLayoutView->selectionModel()->selectedIndexes().count() == 2 )
523 connect(
mAvailableWidgetsView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
532 storeAttributeWidgetEdit( deselectedFormLayoutIndex );
533 storeAttributeContainerEdit( deselectedFormLayoutIndex );
537 storeAttributeTypeDialog();
540 clearAttributeTypeFrame();
542 if ( emitter->selectionModel()->selectedRows( 0 ).count() != 1 )
544 receiver->clearSelection();
557 loadAttributeWidgetEdit();
561 loadInfoWidget( tr(
"This configuration is available in the Drag and Drop Designer" ) );
570 loadAttributeWidgetEdit();
572 loadAttributeTypeDialog();
577 receiver->clearSelection();
578 loadAttributeContainerEdit();
585 loadInfoWidget( action.
html() );
595 loadInfoWidget( tr(
"This configuration is available with double-click in the Drag and Drop Designer" ) );
599 loadInfoWidget( tr(
"This configuration is available with double-click in the Form Layout panel" ) );
601 receiver->clearSelection();
606 receiver->clearSelection();
613void QgsAttributesFormProperties::clearAttributeTypeFrame()
641void QgsAttributesFormProperties::onInvertSelectionButtonClicked(
bool checked )
644 for (
int i = 0; i < mFormLayoutProxyModel->rowCount(); ++i )
646 QModelIndex index = mFormLayoutProxyModel->index( i, 0 );
647 mFormLayoutView->selectionModel()->select( index, QItemSelectionModel::Toggle );
651void QgsAttributesFormProperties::toggleShowAliases(
bool checked )
654 mAvailableWidgetsModel->setShowAliases( checked );
655 mFormLayoutModel->setShowAliases( checked );
658void QgsAttributesFormProperties::addContainer()
660 QList<QgsAddAttributeFormContainerDialog::ContainerPair> existingContainerList = mFormLayoutModel->listOfContainers();
662 QModelIndex currentItem;
666 QgsAddAttributeFormContainerDialog dialog(
mLayer, existingContainerList, currentItem,
this );
668 if ( !dialog.exec() )
671 const QString name = dialog.name();
672 QModelIndex parentContainerItem = dialog.parentContainerItem();
674 mFormLayoutModel->addContainer( parentContainerItem, name, dialog.columnCount(), dialog.containerType() );
675 if ( parentContainerItem.isValid() )
679void QgsAttributesFormProperties::removeTabOrGroupButton()
685 const QModelIndexList items =
mFormLayoutView->selectionModel()->selectedRows();
689 const QModelIndex item = mFormLayoutProxyModel->mapToSource( items.at( 0 ) );
690 mFormLayoutModel->removeRow( item.row(), item.parent() );
694void QgsAttributesFormProperties::mEditorLayoutComboBox_currentIndexChanged(
int )
698 if ( selection.count() > 0 )
712 mFormLayoutWidget->setVisible(
false );
713 mTreeViewHorizontalSpacer->changeSize( 0, 20, QSizePolicy::Fixed, QSizePolicy::Fixed );
714 mUiFileFrame->setVisible(
false );
715 mAddContainerButton->setVisible(
false );
716 mRemoveLayoutItemButton->setVisible(
false );
717 mInvertSelectionButton->setVisible(
false );
719 setAvailableWidgetsIndicatorProvidersEnabled(
true );
720 setFormLayoutIndicatorProvidersEnabled(
false );
724 mFormLayoutWidget->setVisible(
true );
725 mTreeViewHorizontalSpacer->changeSize( 6, 20, QSizePolicy::Fixed, QSizePolicy::Fixed );
726 mUiFileFrame->setVisible(
false );
727 mAddContainerButton->setVisible(
true );
728 mRemoveLayoutItemButton->setVisible(
true );
729 mInvertSelectionButton->setVisible(
true );
731 setAvailableWidgetsIndicatorProvidersEnabled(
false );
732 setFormLayoutIndicatorProvidersEnabled(
true );
737 mFormLayoutWidget->setVisible(
false );
738 mTreeViewHorizontalSpacer->changeSize( 0, 20, QSizePolicy::Fixed, QSizePolicy::Fixed );
739 mUiFileFrame->setVisible(
true );
740 mAddContainerButton->setVisible(
false );
741 mRemoveLayoutItemButton->setVisible(
false );
742 mInvertSelectionButton->setVisible(
false );
744 setAvailableWidgetsIndicatorProvidersEnabled(
true );
745 setFormLayoutIndicatorProvidersEnabled(
false );
750 if ( selection.count() > 0 )
756void QgsAttributesFormProperties::mTbInitCode_clicked()
758 QgsAttributesFormInitCode attributesFormInitCode;
765 if ( !attributesFormInitCode.exec() )
768 mInitCodeSource = attributesFormInitCode.
codeSource();
769 mInitCode = attributesFormInitCode.
initCode();
774void QgsAttributesFormProperties::pbnSelectEditForm_clicked()
776 QgsSettings myQSettings;
777 const QString lastUsedDir = myQSettings.
value( QStringLiteral(
"style/lastUIDir" ), QDir::homePath() ).toString();
778 const QString uifilename = QFileDialog::getOpenFileName(
this, tr(
"Select edit form" ), lastUsedDir, tr(
"UI file" ) +
" (*.ui)" );
780 if ( uifilename.isNull() )
783 const QFileInfo fi( uifilename );
784 myQSettings.
setValue( QStringLiteral(
"style/lastUIDir" ), fi.path() );
785 mEditFormLineEdit->setText( uifilename );
790 storeAttributeWidgetEdit();
791 storeAttributeContainerEdit();
792 storeAttributeTypeDialog();
802 const QModelIndex fieldContainer = mAvailableWidgetsModel->fieldContainer();
805 for (
int i = 0; i < mAvailableWidgetsModel->rowCount( fieldContainer ); i++ )
807 index = mAvailableWidgetsModel->index( i, 0, fieldContainer );
811 const int idx =
mLayer->fields().indexOf( fieldName );
866 for (
int t = 0; t < mFormLayoutModel->rowCount(); t++ )
868 QModelIndex index = mFormLayoutModel->index( t, 0 );
871 editFormConfig.
addTab( editorElement );
874 editFormConfig.
setUiForm( mEditFormLineEdit->text() );
886 const QModelIndex relationContainer = mAvailableWidgetsModel->relationContainer();
888 for (
int i = 0; i < mAvailableWidgetsModel->rowCount( relationContainer ); i++ )
890 const QModelIndex relationIndex = mAvailableWidgetsModel->index( i, 0, relationContainer );
896 const QModelIndex layoutIndex = mFormLayoutModel->firstRecursiveMatchingModelIndex( indexType, indexId );
897 if ( layoutIndex.isValid() )
910 mLayer->setEditFormConfig( editFormConfig );
915void QgsAttributesFormProperties::updatedFields()
918 QMap<QString, QgsAttributesFormData::FieldConfig> fieldConfigs;
920 const QModelIndex fieldContainerBefore = mAvailableWidgetsModel->
fieldContainer();
923 for (
int i = 0; i < mAvailableWidgetsModel->
rowCount( fieldContainerBefore ); i++ )
925 index = mAvailableWidgetsModel->
index( i, 0, fieldContainerBefore );
928 fieldConfigs[fieldName] = config;
933 const QModelIndex fieldContainerAfter = mAvailableWidgetsModel->fieldContainer();
935 for (
int i = 0; i < mAvailableWidgetsModel->rowCount( fieldContainerAfter ); i++ )
937 index = mAvailableWidgetsModel->index( i, 0, fieldContainerAfter );
940 if ( fieldConfigs.contains( fieldName ) )
948void QgsAttributesFormProperties::updateFilteredItems(
const QString &filterText )
950 const int availableWidgetsPreviousSelectionCount =
mAvailableWidgetsView->selectionModel()->selectedRows().count();
951 const int formLayoutPreviousSelectionCount =
mFormLayoutView->selectionModel()->selectedRows().count();
953 static_cast< QgsAttributesAvailableWidgetsView *
>(
mAvailableWidgetsView )->setFilterText( filterText );
956 static_cast< QgsAttributesFormLayoutView *
>(
mFormLayoutView )->setFilterText( filterText );
961 if ( !( availableWidgetsPreviousSelectionCount == 0 && formLayoutPreviousSelectionCount == 0 ) )
963 const int selectedAvailableWidgetItemCount =
mAvailableWidgetsView->selectionModel()->selectedRows().count();
964 const int selectedFormLayoutItemCount =
mFormLayoutView->selectionModel()->selectedRows().count();
966 if ( selectedAvailableWidgetItemCount == 0 && selectedFormLayoutItemCount == 0 )
969 clearAttributeTypeFrame();
974void QgsAttributesFormProperties::onContextMenuRequested( QPoint point )
985 const QClipboard *clipboard = QApplication::clipboard();
986 const QMimeData *mimeData = clipboard->mimeData();
990 const bool pasteEnabled = mimeData->hasFormat( QStringLiteral(
"application/x-qgsattributetabledesignerelementclipboard" ) );
991 mActionPasteWidgetConfiguration->setEnabled( pasteEnabled );
992 mAvailableWidgetsContextMenu->popup( globalPos );
996void QgsAttributesFormProperties::copyWidgetConfiguration()
1008 const int fieldIndex =
mLayer->fields().indexOf( fieldName );
1010 if ( fieldIndex < 0 )
1013 const QgsField field =
mLayer->fields().field( fieldIndex );
1017 QDomElement documentElement = doc.createElement( QStringLiteral(
"FormWidgetClipboard" ) );
1018 documentElement.setAttribute( QStringLiteral(
"name" ), field.
name() );
1023 QDomElement editWidgetElement = doc.createElement( QStringLiteral(
"editWidget" ) );
1024 documentElement.appendChild( editWidgetElement );
1025 editWidgetElement.setAttribute( QStringLiteral(
"type" ), widgetSetup.
type() );
1026 QDomElement editWidgetConfigElement = doc.createElement( QStringLiteral(
"config" ) );
1029 editWidgetElement.appendChild( editWidgetConfigElement );
1032 QDomElement splitPolicyElement = doc.createElement( QStringLiteral(
"splitPolicy" ) );
1034 documentElement.appendChild( splitPolicyElement );
1037 QDomElement duplicatePolicyElement = doc.createElement( QStringLiteral(
"duplicatePolicy" ) );
1039 documentElement.appendChild( duplicatePolicyElement );
1042 QDomElement mergePolicyElement = doc.createElement( QStringLiteral(
"mergePolicy" ) );
1044 documentElement.appendChild( mergePolicyElement );
1047 QDomElement defaultElem = doc.createElement( QStringLiteral(
"default" ) );
1050 documentElement.appendChild( defaultElem );
1053 QDomElement constraintElem = doc.createElement( QStringLiteral(
"constraint" ) );
1058 documentElement.appendChild( constraintElem );
1061 QDomElement constraintExpressionElem = doc.createElement( QStringLiteral(
"constraintExpression" ) );
1064 documentElement.appendChild( constraintExpressionElem );
1069 QDomElement widgetGeneralSettingsElem = doc.createElement( QStringLiteral(
"widgetGeneralSettings" ) );
1070 widgetGeneralSettingsElem.setAttribute( QStringLiteral(
"editable" ),
mAttributeTypeDialog->fieldEditable() );
1071 widgetGeneralSettingsElem.setAttribute( QStringLiteral(
"label_on_top" ),
mAttributeTypeDialog->labelOnTop() );
1073 documentElement.appendChild( widgetGeneralSettingsElem );
1083 const QModelIndex indexLayout =
mFormLayoutView->firstSelectedIndex();
1086 QDomElement displayElement = doc.createElement( QStringLiteral(
"widgetDisplay" ) );
1087 displayElement.setAttribute( QStringLiteral(
"showLabel" ), layoutData.showLabel() );
1088 displayElement.setAttribute( QStringLiteral(
"horizontalStretch" ), layoutData.horizontalStretch() );
1089 displayElement.setAttribute( QStringLiteral(
"verticalStretch" ), layoutData.verticalStretch() );
1090 displayElement.appendChild( layoutData.labelStyle().writeXml( doc ) );
1091 documentElement.appendChild( displayElement );
1094 doc.appendChild( documentElement );
1096 QMimeData *mimeData =
new QMimeData;
1097 mimeData->setData( QStringLiteral(
"application/x-qgsattributetabledesignerelementclipboard" ), doc.toByteArray() );
1098 QClipboard *clipboard = QApplication::clipboard();
1099 clipboard->setMimeData( mimeData );
1102void QgsAttributesFormProperties::pasteWidgetConfiguration()
1110 const int fieldIndex =
mLayer->fields().indexOf( fieldName );
1112 if ( fieldIndex < 0 )
1119 QClipboard *clipboard = QApplication::clipboard();
1120 const QMimeData *mimeData = clipboard->mimeData();
1124 if ( doc.setContent( mimeData->data( QStringLiteral(
"application/x-qgsattributetabledesignerelementclipboard" ) ) ) )
1126 QDomElement docElem = doc.documentElement();
1127 if ( docElem.tagName() != QLatin1String(
"FormWidgetClipboard" ) )
1136 const QDomElement fieldWidgetElement = docElem.firstChildElement( QStringLiteral(
"editWidget" ) );
1137 if ( !fieldWidgetElement.isNull() )
1139 const QString widgetType = fieldWidgetElement.attribute( QStringLiteral(
"type" ) );
1145 const QDomElement configElement = fieldWidgetElement.firstChildElement( QStringLiteral(
"config" ) );
1146 if ( !configElement.isNull() )
1148 const QDomElement optionsElem = configElement.childNodes().at( 0 ).toElement();
1150 QgsReadWriteContext context;
1152 if ( widgetType == QLatin1String(
"ValueRelation" ) )
1154 optionsMap[QStringLiteral(
"Value" )] = context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1:fields:%2:valuerelationvalue" ).arg(
mLayer->id(), fieldName ), optionsMap[QStringLiteral(
"Value" )].toString() );
1156 if ( widgetType == QLatin1String(
"ValueMap" ) )
1158 if ( optionsMap[QStringLiteral(
"map" )].canConvert<QList<QVariant>>() )
1160 QList<QVariant> translatedValueList;
1161 const QList<QVariant> valueList = optionsMap[QStringLiteral(
"map" )].toList();
1162 for (
int i = 0, row = 0; i < valueList.count(); i++, row++ )
1164 QMap<QString, QVariant> translatedValueMap;
1165 QString translatedKey = context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1:fields:%2:valuemapdescriptions" ).arg(
mLayer->id(), fieldName ), valueList[i].toMap().constBegin().key() );
1166 translatedValueMap.insert( translatedKey, valueList[i].toMap().constBegin().value() );
1167 translatedValueList.append( translatedValueMap );
1169 optionsMap.insert( QStringLiteral(
"map" ), translatedValueList );
1178 mMessageBar->pushMessage( QString(), tr(
"Unable to paste widget configuration. The target field (%1) does not support the %2 widget type." ).arg( fieldName, widgetType ),
Qgis::MessageLevel::Warning );
1183 const QDomElement splitPolicyElement = docElem.firstChildElement( QStringLiteral(
"splitPolicy" ) );
1184 if ( !splitPolicyElement.isNull() )
1191 const QDomElement duplicatePolicyElement = docElem.firstChildElement( QStringLiteral(
"duplicatePolicy" ) );
1192 if ( !duplicatePolicyElement.isNull() )
1199 const QDomElement mergePolicyElement = docElem.firstChildElement( QStringLiteral(
"mergePolicy" ) );
1200 if ( !mergePolicyElement.isNull() )
1207 const QDomElement defaultElement = docElem.firstChildElement( QStringLiteral(
"default" ) );
1208 if ( !defaultElement.isNull() )
1217 const QDomElement constraintElement = docElem.firstChildElement( QStringLiteral(
"constraint" ) );
1218 if ( !constraintElement.isNull() )
1220 const int intConstraints = constraintElement.attribute( QStringLiteral(
"constraints" ), QStringLiteral(
"0" ) ).toInt();
1246 const int uniqueStrength = constraintElement.attribute( QStringLiteral(
"unique_strength" ), QStringLiteral(
"1" ) ).toInt();
1247 const int notNullStrength = constraintElement.attribute( QStringLiteral(
"notnull_strength" ), QStringLiteral(
"1" ) ).toInt();
1248 const int expStrength = constraintElement.attribute( QStringLiteral(
"exp_strength" ), QStringLiteral(
"1" ) ).toInt();
1259 const QDomElement constraintExpressionElement = docElem.firstChildElement( QStringLiteral(
"constraintExpression" ) );
1260 if ( !constraintExpressionElement.isNull() )
1262 QString expression = constraintExpressionElement.attribute( QStringLiteral(
"exp" ), QString() );
1263 QString description = constraintExpressionElement.attribute( QStringLiteral(
"desc" ), QString() );
1269 const QDomElement widgetGeneralSettingsElement = docElem.firstChildElement( QStringLiteral(
"widgetGeneralSettings" ) );
1270 if ( !widgetGeneralSettingsElement.isNull() )
1272 const int editable = widgetGeneralSettingsElement.attribute( QStringLiteral(
"editable" ), QStringLiteral(
"0" ) ).toInt();
1274 if ( widgetGeneralSettingsElement.hasAttribute( QStringLiteral(
"reuse_last_values" ) ) )
1282 const int labelOnTop = widgetGeneralSettingsElement.attribute( QStringLiteral(
"label_on_top" ), QStringLiteral(
"0" ) ).toInt();
1289 loadAttributeTypeDialogFromConfiguration( config );
1294 const QDomElement displayElement = docElem.firstChildElement( QStringLiteral(
"widgetDisplay" ) );
1295 if ( !displayElement.isNull() )
1297 const int showLabel = displayElement.attribute( QStringLiteral(
"showLabel" ), QStringLiteral(
"0" ) ).toInt();
1298 const int horizontalStretch = displayElement.attribute( QStringLiteral(
"horizontalStretch" ), QStringLiteral(
"0" ) ).toInt();
1299 const int verticalStretch = displayElement.attribute( QStringLiteral(
"verticalStretch" ), QStringLiteral(
"0" ) ).toInt();
1300 QgsAttributeEditorElement::LabelStyle style;
1301 style.
readXml( displayElement );
1313void QgsAttributesFormProperties::setAvailableWidgetsIndicatorProvidersEnabled(
bool enabled )
1316 if ( enabled && !mDefaultValueIndicatorProviderAvailableWidgets->isEnabled() )
1319 mDefaultValueIndicatorProviderAvailableWidgets->setEnabled( enabled );
1321 else if ( !enabled && mDefaultValueIndicatorProviderAvailableWidgets->isEnabled() )
1324 mDefaultValueIndicatorProviderAvailableWidgets->setEnabled( enabled );
1327 if ( enabled && !mConstraintIndicatorProviderAvailableWidgets->isEnabled() )
1330 mConstraintIndicatorProviderAvailableWidgets->setEnabled( enabled );
1332 else if ( !enabled && mConstraintIndicatorProviderAvailableWidgets->isEnabled() )
1335 mConstraintIndicatorProviderAvailableWidgets->setEnabled( enabled );
1339void QgsAttributesFormProperties::setFormLayoutIndicatorProvidersEnabled(
bool enabled )
1342 if ( enabled && !mDefaultValueIndicatorProviderFormLayout->isEnabled() )
1345 mDefaultValueIndicatorProviderFormLayout->setEnabled( enabled );
1347 else if ( !enabled && mDefaultValueIndicatorProviderFormLayout->isEnabled() )
1350 mDefaultValueIndicatorProviderFormLayout->setEnabled( enabled );
1353 if ( enabled && !mConstraintIndicatorProviderFormLayout->isEnabled() )
1356 mConstraintIndicatorProviderFormLayout->setEnabled( enabled );
1358 else if ( !enabled && mConstraintIndicatorProviderFormLayout->isEnabled() )
1361 mConstraintIndicatorProviderFormLayout->setEnabled( enabled );
AttributeFormReuseLastValuePolicy
Attribute form policy for reusing last entered values.
@ AllowedDefaultOn
Reuse of last values allowed and enabled by default.
@ NotAllowed
Reuse of last values not allowed.
AttributeFormSuppression
Available form types for layout of the attribute form editor.
@ On
Always suppress feature form.
@ Default
Use the application-wide setting.
@ Off
Never suppress feature form.
AttributeFormLayout
Available form types for layout of the attribute form editor.
@ DragAndDrop
"Drag and drop" layout. Needs to be configured.
@ AutoGenerated
Autogenerate a simple tabular layout for the form.
@ UiFile
Load a .ui file for the layout. Needs to be configured.
FieldDomainMergePolicy
Merge policy for field domains.
@ DefaultValue
Use default field value.
@ Warning
Warning message.
FieldDomainSplitPolicy
Split policy for field domains.
@ Duplicate
Duplicate original value.
FieldDuplicatePolicy
Duplicate policy for fields.
@ Duplicate
Duplicate original value.
QString html() const
Returns an HTML table with the basic information about this action.
An abstract base class for any elements of a drag and drop form.
Provides a container for managing client side default values for fields.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Provides field constraint indicators for attribute form views.
Stores information about constraints which may be present on a field.
ConstraintStrength
Strength of constraints.
@ ConstraintStrengthSoft
User is warned if constraint is violated but feature can still be accepted.
@ ConstraintStrengthHard
Constraint must be honored before feature can be accepted.
void setConstraintStrength(Constraint constraint, ConstraintStrength strength)
Sets the strength of a constraint.
void setConstraintExpression(const QString &expression, const QString &description=QString())
Set the constraint expression for the field.
@ ConstraintOriginProvider
Constraint was set at data provider.
@ ConstraintOriginLayer
Constraint was set by layer.
ConstraintStrength constraintStrength(Constraint constraint) const
Returns the strength of a field constraint, or ConstraintStrengthNotSet if the constraint is not pres...
ConstraintOrigin constraintOrigin(Constraint constraint) const
Returns the origin of a field constraint, or ConstraintOriginNotSet if the constraint is not present ...
QString constraintExpression() const
Returns the constraint expression for the field, if set.
@ ConstraintNotNull
Field may not be null.
@ ConstraintUnique
Field must have a unique value.
@ ConstraintExpression
Field has an expression constraint set. See constraintExpression().
void removeConstraint(Constraint constraint)
Removes a constraint from the field.
QString constraintDescription() const
Returns the descriptive name for the constraint expression.
void setConstraint(Constraint constraint, ConstraintOrigin origin=ConstraintOriginLayer)
Sets a constraint on the field.
QFlags< Constraint > Constraints
Provides default value indicators for attribute form views.
Qgis::FieldDomainSplitPolicy splitPolicy() const
Returns the field's split policy, which indicates how field values should be handled during a split o...
Qgis::FieldDuplicatePolicy duplicatePolicy() const
Returns the field's duplicate policy, which indicates how field values should be handled during a dup...
QgsDefaultValue defaultValueDefinition
Qgis::FieldDomainMergePolicy mergePolicy() const
Returns the field's merge policy, which indicates how field values should be handled during a merge o...
QgsFieldConstraints constraints
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
Q_INVOKABLE int indexOf(const QString &fieldName) const
Gets the field index from the field name.
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories.
A bar for displaying non-blocking messages to the user.
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
Translates a string using the Qt QTranslator mechanism.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
int count() const
Returns the number of properties contained within the collection.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
A boolean settings entry.
static const QgsSettingsEntryBool * settingsDigitizingDisableEnterAttributeValuesDialog
Settings entry digitizing disable enter attribute values dialog.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Represents a vector layer which manages a vector based dataset.
void updatedFields()
Emitted whenever the fields available from this layer have been changed.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
void readXml(const QDomNode &node)
Reads configuration from node.