19#include "moc_qgsattributesformproperties.cpp"
20#include "qgsattributetypedialog.h"
21#include "qgsattributeformcontaineredit.h"
22#include "qgsattributewidgetedit.h"
41#ifdef ENABLE_MODELTEST
62 QGridLayout *availableWidgetsWidgetLayout =
new QGridLayout;
65 availableWidgetsWidgetLayout->setContentsMargins( 0, 0, 0, 0 );
66 mAvailableWidgetsWidget->setLayout( availableWidgetsWidgetLayout );
72 mAvailableWidgetsProxyModel->setRecursiveFilteringEnabled(
true );
75#ifdef ENABLE_MODELTEST
76 new ModelTest( mAvailableWidgetsProxyModel,
this );
80 QGridLayout *formLayoutWidgetLayout =
new QGridLayout;
83 formLayoutWidgetLayout->setContentsMargins( 0, 0, 0, 0 );
84 mFormLayoutWidget->setLayout( formLayoutWidgetLayout );
89 mFormLayoutProxyModel->setRecursiveFilteringEnabled(
true );
92#ifdef ENABLE_MODELTEST
93 new ModelTest( mFormLayoutProxyModel,
this );
96 connect(
mAvailableWidgetsView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
97 connect(
mFormLayoutView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAttributesFormProperties::onFormLayoutSelectionChanged );
99 connect(
mAvailableWidgetsView, &QWidget::customContextMenuRequested,
this, &QgsAttributesFormProperties::onContextMenuRequested );
101 connect( mAddContainerButton, &QAbstractButton::clicked,
this, &QgsAttributesFormProperties::addContainer );
102 connect( mRemoveLayoutItemButton, &QAbstractButton::clicked,
this, &QgsAttributesFormProperties::removeTabOrGroupButton );
103 connect( mInvertSelectionButton, &QAbstractButton::clicked,
this, &QgsAttributesFormProperties::onInvertSelectionButtonClicked );
104 connect( mShowAliasesButton, &QAbstractButton::toggled,
this, &QgsAttributesFormProperties::toggleShowAliases );
105 connect( mEditorLayoutComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsAttributesFormProperties::mEditorLayoutComboBox_currentIndexChanged );
106 connect( pbnSelectEditForm, &QToolButton::clicked,
this, &QgsAttributesFormProperties::pbnSelectEditForm_clicked );
107 connect( mTbInitCode, &QPushButton::clicked,
this, &QgsAttributesFormProperties::mTbInitCode_clicked );
109 connect( mSearchLineEdit, &QgsFilterLineEdit::textChanged,
this, &QgsAttributesFormProperties::updateFilteredItems );
112 if ( !mBlockUpdates )
117 mAvailableWidgetsContextMenu =
new QMenu(
this );
118 mActionCopyWidgetConfiguration =
new QAction( tr(
"Copy widget configuration" ),
this );
119 mActionPasteWidgetConfiguration =
new QAction( tr(
"Paste widget configuration" ),
this );
121 connect( mActionCopyWidgetConfiguration, &QAction::triggered,
this, &QgsAttributesFormProperties::copyWidgetConfiguration );
122 connect( mActionPasteWidgetConfiguration, &QAction::triggered,
this, &QgsAttributesFormProperties::pasteWidgetConfiguration );
124 mAvailableWidgetsContextMenu->addAction( mActionCopyWidgetConfiguration );
125 mAvailableWidgetsContextMenu->addAction( mActionPasteWidgetConfiguration );
128 mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
129 gridLayout->addWidget( mMessageBar, 0, 0 );
133 splitter->setSizes( { widget->minimumSizeHint().width(), 600 } );
163 mFormLayoutView->setSelectionBehavior( QAbstractItemView::SelectRows );
164 mFormLayoutView->setSelectionMode( QAbstractItemView::SelectionMode::ExtendedSelection );
166 mFormLayoutView->setDragDropMode( QAbstractItemView::DragDropMode::DragDrop );
206 mEditorLayoutComboBox->setCurrentIndex( mEditorLayoutComboBox->findData( QVariant::fromValue(
mLayer->
editFormConfig().
layout() ) ) );
208 mEditorLayoutComboBox_currentIndexChanged( mEditorLayoutComboBox->currentIndex() );
211 mEditFormLineEdit->setText( cfg.
uiForm() );
223 if ( mInitCode.isEmpty() )
225 mInitCode.append( tr(
"# -*- coding: utf-8 -*-\n\"\"\"\n"
226 "QGIS forms can have a Python function that is called when the form is\n"
229 "Use this function to add extra logic to your forms.\n"
231 "Enter the name of the function in the \"Python Init function\"\n"
233 "An example follows:\n"
235 "from qgis.PyQt.QtWidgets import QWidget\n\n"
236 "def my_form_open(dialog, layer, feature):\n"
237 " geom = feature.geometry()\n"
238 " control = dialog.findChild(QWidget, \"MyLineEdit\")\n" ) );
242void QgsAttributesFormProperties::loadAttributeTypeDialog()
253 if ( fieldIndex < 0 )
258 loadAttributeTypeDialogFromConfiguration( cfg );
264 mAttributeTypeFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
306void QgsAttributesFormProperties::storeAttributeTypeDialog()
367 QModelIndex index = mAvailableWidgetsModel->
fieldModelIndex( fieldName );
368 if ( index.isValid() )
378void QgsAttributesFormProperties::storeAttributeWidgetEdit()
387 storeAttributeWidgetEdit( index );
390void QgsAttributesFormProperties::storeAttributeWidgetEdit(
const QModelIndex &index )
395 if ( !index.isValid() )
404 itemData.setRelationEditorConfiguration( config );
410void QgsAttributesFormProperties::loadAttributeWidgetEdit()
422 mAttributeTypeFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
426void QgsAttributesFormProperties::loadInfoWidget(
const QString &infoText )
429 mAttributeTypeFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
433void QgsAttributesFormProperties::storeAttributeContainerEdit()
442 storeAttributeContainerEdit( currentIndex );
445void QgsAttributesFormProperties::storeAttributeContainerEdit(
const QModelIndex &index )
450 if ( !index.isValid() )
454 QString containerName;
461void QgsAttributesFormProperties::loadAttributeContainerEdit()
474 mAttributeTypeFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
478void QgsAttributesFormProperties::onAttributeSelectionChanged(
const QItemSelection &,
const QItemSelection & )
480 disconnect(
mFormLayoutView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAttributesFormProperties::onFormLayoutSelectionChanged );
483 if (
mFormLayoutView->selectionModel()->selectedRows( 0 ).count() == 1 )
491 connect(
mFormLayoutView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAttributesFormProperties::onFormLayoutSelectionChanged );
494void QgsAttributesFormProperties::onFormLayoutSelectionChanged(
const QItemSelection &,
const QItemSelection &deselected )
497 disconnect(
mAvailableWidgetsView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
499 if ( deselected.indexes().count() == 1 )
501 index = mFormLayoutProxyModel->mapToSource( deselected.indexes().at( 0 ) );
503 else if ( deselected.indexes().count() == 0 &&
mFormLayoutView->selectionModel()->selectedIndexes().count() == 2 )
510 connect(
mAvailableWidgetsView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
519 storeAttributeWidgetEdit( deselectedFormLayoutIndex );
520 storeAttributeContainerEdit( deselectedFormLayoutIndex );
524 storeAttributeTypeDialog();
527 clearAttributeTypeFrame();
529 if ( emitter->selectionModel()->selectedRows( 0 ).count() != 1 )
531 receiver->clearSelection();
544 loadAttributeWidgetEdit();
548 loadInfoWidget( tr(
"This configuration is available in the Drag and Drop Designer" ) );
557 loadAttributeWidgetEdit();
559 loadAttributeTypeDialog();
564 receiver->clearSelection();
565 loadAttributeContainerEdit();
572 loadInfoWidget( action.html() );
582 loadInfoWidget( tr(
"This configuration is available with double-click in the Drag and Drop Designer" ) );
586 loadInfoWidget( tr(
"This configuration is available with double-click in the Form Layout panel" ) );
588 receiver->clearSelection();
593 receiver->clearSelection();
600void QgsAttributesFormProperties::clearAttributeTypeFrame()
628void QgsAttributesFormProperties::onInvertSelectionButtonClicked(
bool checked )
631 for (
int i = 0; i < mFormLayoutProxyModel->rowCount(); ++i )
633 QModelIndex index = mFormLayoutProxyModel->index( i, 0 );
634 mFormLayoutView->selectionModel()->select( index, QItemSelectionModel::Toggle );
638void QgsAttributesFormProperties::toggleShowAliases(
bool checked )
645void QgsAttributesFormProperties::addContainer()
647 QList<QgsAddAttributeFormContainerDialog::ContainerPair> existingContainerList = mFormLayoutModel->
listOfContainers();
649 QModelIndex currentItem;
655 if ( !dialog.exec() )
658 const QString name = dialog.name();
659 QModelIndex parentContainerItem = dialog.parentContainerItem();
661 mFormLayoutModel->
addContainer( parentContainerItem, name, dialog.columnCount(), dialog.containerType() );
662 if ( parentContainerItem.isValid() )
666void QgsAttributesFormProperties::removeTabOrGroupButton()
672 const QModelIndexList items =
mFormLayoutView->selectionModel()->selectedRows();
676 const QModelIndex item = mFormLayoutProxyModel->mapToSource( items.at( 0 ) );
677 mFormLayoutModel->
removeRow( item.row(), item.parent() );
681void QgsAttributesFormProperties::mEditorLayoutComboBox_currentIndexChanged(
int )
685 if ( selection.count() > 0 )
699 mFormLayoutWidget->setVisible(
false );
700 mTreeViewHorizontalSpacer->changeSize( 0, 20, QSizePolicy::Fixed, QSizePolicy::Fixed );
701 mUiFileFrame->setVisible(
false );
702 mAddContainerButton->setVisible(
false );
703 mRemoveLayoutItemButton->setVisible(
false );
704 mInvertSelectionButton->setVisible(
false );
708 mFormLayoutWidget->setVisible(
true );
709 mTreeViewHorizontalSpacer->changeSize( 6, 20, QSizePolicy::Fixed, QSizePolicy::Fixed );
710 mUiFileFrame->setVisible(
false );
711 mAddContainerButton->setVisible(
true );
712 mRemoveLayoutItemButton->setVisible(
true );
713 mInvertSelectionButton->setVisible(
true );
718 mFormLayoutWidget->setVisible(
false );
719 mTreeViewHorizontalSpacer->changeSize( 0, 20, QSizePolicy::Fixed, QSizePolicy::Fixed );
720 mUiFileFrame->setVisible(
true );
721 mAddContainerButton->setVisible(
false );
722 mRemoveLayoutItemButton->setVisible(
false );
723 mInvertSelectionButton->setVisible(
false );
728 if ( selection.count() > 0 )
734void QgsAttributesFormProperties::mTbInitCode_clicked()
743 if ( !attributesFormInitCode.exec() )
746 mInitCodeSource = attributesFormInitCode.
codeSource();
747 mInitCode = attributesFormInitCode.
initCode();
752void QgsAttributesFormProperties::pbnSelectEditForm_clicked()
755 const QString lastUsedDir = myQSettings.
value( QStringLiteral(
"style/lastUIDir" ), QDir::homePath() ).toString();
756 const QString uifilename = QFileDialog::getOpenFileName(
this, tr(
"Select edit form" ), lastUsedDir, tr(
"UI file" ) +
" (*.ui)" );
758 if ( uifilename.isNull() )
761 const QFileInfo fi( uifilename );
762 myQSettings.
setValue( QStringLiteral(
"style/lastUIDir" ), fi.path() );
763 mEditFormLineEdit->setText( uifilename );
768 storeAttributeWidgetEdit();
769 storeAttributeContainerEdit();
770 storeAttributeTypeDialog();
780 const QModelIndex fieldContainer = mAvailableWidgetsModel->
fieldContainer();
783 for (
int i = 0; i < mAvailableWidgetsModel->
rowCount( fieldContainer ); i++ )
785 index = mAvailableWidgetsModel->
index( i, 0, fieldContainer );
842 for (
int t = 0; t < mFormLayoutModel->
rowCount(); t++ )
844 QModelIndex index = mFormLayoutModel->
index( t, 0 );
847 editFormConfig.
addTab( editorElement );
850 editFormConfig.
setUiForm( mEditFormLineEdit->text() );
862 const QModelIndex relationContainer = mAvailableWidgetsModel->
relationContainer();
864 for (
int i = 0; i < mAvailableWidgetsModel->
rowCount( relationContainer ); i++ )
866 const QModelIndex relationIndex = mAvailableWidgetsModel->
index( i, 0, relationContainer );
873 if ( layoutIndex.isValid() )
892 : QTreeView( parent )
899 if ( selectionModel()->selectedRows( 0 ).count() == 0 )
900 return QModelIndex();
902 return mModel->mapToSource( selectionModel()->selectedRows( 0 ).at( 0 ) );
922 QModelIndex index =
mModel->mapFromSource( model->firstRecursiveMatchingModelIndex( itemType, itemId ) );
924 if ( index.isValid() )
927 selectionModel()->setCurrentIndex( index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
931 selectionModel()->clearSelection();
948 mModel = qobject_cast<QgsAttributesFormProxyModel *>( model );
952 QTreeView::setModel(
mModel );
964 connect(
this, &QTreeView::doubleClicked,
this, &QgsAttributesFormLayoutView::onItemDoubleClicked );
969 mModel = qobject_cast<QgsAttributesFormProxyModel *>( model );
973 QTreeView::setModel(
mModel );
981void QgsAttributesFormLayoutView::handleExternalDroppedItem( QModelIndex &index )
983 selectionModel()->setCurrentIndex(
mModel->mapFromSource( index ), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
992 onItemDoubleClicked(
mModel->mapFromSource( index ) );
996void QgsAttributesFormLayoutView::handleInternalDroppedItem( QModelIndex &index )
998 selectionModel()->clearCurrentIndex();
1002 expandRecursively(
mModel->mapFromSource( index ) );
1008 const QMimeData *data =
event->mimeData();
1010 if ( data->hasFormat( QStringLiteral(
"application/x-qgsattributesformavailablewidgetsrelement" ) )
1011 || data->hasFormat( QStringLiteral(
"application/x-qgsattributesformlayoutelement" ) ) )
1014 if ( event->source() ==
this )
1016 event->setDropAction( Qt::MoveAction );
1024 QTreeView::dragEnterEvent( event );
1033 const QMimeData *data =
event->mimeData();
1035 if ( data->hasFormat( QStringLiteral(
"application/x-qgsattributesformavailablewidgetsrelement" ) )
1036 || data->hasFormat( QStringLiteral(
"application/x-qgsattributesformlayoutelement" ) ) )
1039 if ( event->source() ==
this )
1041 event->setDropAction( Qt::MoveAction );
1049 QTreeView::dragMoveEvent( event );
1054 if ( !( event->mimeData()->hasFormat( QStringLiteral(
"application/x-qgsattributesformavailablewidgetsrelement" ) )
1055 || event->mimeData()->hasFormat( QStringLiteral(
"application/x-qgsattributesformlayoutelement" ) ) ) )
1058 if ( event->source() ==
this )
1060 event->setDropAction( Qt::MoveAction );
1063 QTreeView::dropEvent( event );
1066void QgsAttributesFormLayoutView::onItemDoubleClicked(
const QModelIndex &index )
1068 QModelIndex sourceIndex =
mModel->mapToSource( index );
1073 QGroupBox *baseData =
new QGroupBox( tr(
"Base configuration" ) );
1075 QFormLayout *baseLayout =
new QFormLayout();
1076 baseData->setLayout( baseLayout );
1077 QCheckBox *showLabelCheckbox =
new QCheckBox( QStringLiteral(
"Show label" ) );
1078 showLabelCheckbox->setChecked( itemData.
showLabel() );
1079 baseLayout->addRow( showLabelCheckbox );
1080 QWidget *baseWidget =
new QWidget();
1081 baseWidget->setLayout( baseLayout );
1095 dlg.setObjectName(
"QML Form Configuration Widget" );
1097 dlg.setWindowTitle( tr(
"Configure QML Widget" ) );
1099 QVBoxLayout *mainLayout =
new QVBoxLayout( &dlg );
1100 QSplitter *qmlSplitter =
new QSplitter();
1101 QWidget *qmlConfigWiget =
new QWidget();
1102 QVBoxLayout *layout =
new QVBoxLayout( qmlConfigWiget );
1103 layout->setContentsMargins( 0, 0, 0, 0 );
1104 mainLayout->addWidget( qmlSplitter );
1105 qmlSplitter->addWidget( qmlConfigWiget );
1106 layout->addWidget( baseWidget );
1108 QLineEdit *title =
new QLineEdit( itemName );
1127 QComboBox *qmlObjectTemplate =
new QComboBox();
1128 qmlObjectTemplate->addItem( tr(
"Free Text…" ) );
1129 qmlObjectTemplate->addItem( tr(
"Rectangle" ) );
1130 qmlObjectTemplate->addItem( tr(
"Pie Chart" ) );
1131 qmlObjectTemplate->addItem( tr(
"Bar Chart" ) );
1132 connect( qmlObjectTemplate, qOverload<int>( &QComboBox::activated ), qmlCode, [qmlCode](
int index ) {
1138 qmlCode->
setText( QString() );
1143 qmlCode->
setText( QStringLiteral(
"import QtQuick 2.0\n"
1148 " color: \"steelblue\"\n"
1149 " Text{ text: \"A rectangle\" }\n"
1155 qmlCode->
setText( QStringLiteral(
"import QtQuick 2.0\n"
1156 "import QtCharts 2.0\n"
1164 " PieSlice { label: \"First slice\"; value: 25 }\n"
1165 " PieSlice { label: \"Second slice\"; value: 45 }\n"
1166 " PieSlice { label: \"Third slice\"; value: 30 }\n"
1173 qmlCode->
setText( QStringLiteral(
"import QtQuick 2.0\n"
1174 "import QtCharts 2.0\n"
1177 " title: \"Bar series\"\n"
1180 " legend.alignment: Qt.AlignBottom\n"
1181 " antialiasing: true\n"
1190 " axisY: valueAxisY\n"
1191 " axisX: BarCategoryAxis { categories: [\"2007\", \"2008\", \"2009\", \"2010\", \"2011\", \"2012\" ] }\n"
1192 " BarSet { label: \"Bob\"; values: [2, 2, 3, 4, 5, 6] }\n"
1193 " BarSet { label: \"Susan\"; values: [5, 1, 2, 4, 1, 7] }\n"
1194 " BarSet { label: \"James\"; values: [3, 5, 8, 13, 5, 8] }\n"
1206 expressionWidget->registerExpressionContextGenerator(
this );
1207 expressionWidget->setLayer(
mLayer );
1208 QToolButton *addFieldButton =
new QToolButton();
1211 QToolButton *editExpressionButton =
new QToolButton();
1213 editExpressionButton->setToolTip( tr(
"Insert/Edit Expression" ) );
1215 connect( addFieldButton, &QAbstractButton::clicked,
this, [expressionWidget, qmlCode] {
1216 QString expression = expressionWidget->expression().trimmed().replace(
'"', QLatin1String(
"\\\"" ) );
1217 if ( !expression.isEmpty() )
1218 qmlCode->
insertText( QStringLiteral(
"expression.evaluate(\"%1\")" ).arg( expression ) );
1221 connect( editExpressionButton, &QAbstractButton::clicked,
this, [
this, qmlCode] {
1223 expression.replace( QLatin1String(
"\\\"" ), QLatin1String(
"\"" ) );
1227 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
1228 if ( exprDlg.exec() == QDialog::Accepted && !exprDlg.expressionText().trimmed().isEmpty() )
1230 QString expression = exprDlg.expressionText().trimmed().replace(
'"', QLatin1String(
"\\\"" ) );
1231 if ( !expression.isEmpty() )
1232 qmlCode->
insertText( QStringLiteral(
"expression.evaluate(\"%1\")" ).arg( expression ) );
1236 layout->addWidget(
new QLabel( tr(
"Title" ) ) );
1237 layout->addWidget( title );
1238 QGroupBox *qmlCodeBox =
new QGroupBox( tr(
"QML Code" ) );
1239 qmlCodeBox->setLayout(
new QVBoxLayout );
1240 qmlCodeBox->layout()->addWidget( qmlObjectTemplate );
1241 QWidget *expressionWidgetBox =
new QWidget();
1242 qmlCodeBox->layout()->addWidget( expressionWidgetBox );
1243 expressionWidgetBox->setLayout(
new QHBoxLayout );
1244 expressionWidgetBox->layout()->setContentsMargins( 0, 0, 0, 0 );
1245 expressionWidgetBox->layout()->addWidget( expressionWidget );
1246 expressionWidgetBox->layout()->addWidget( addFieldButton );
1247 expressionWidgetBox->layout()->addWidget( editExpressionButton );
1248 expressionWidgetBox->layout()->addWidget( editExpressionButton );
1249 layout->addWidget( qmlCodeBox );
1250 layout->addWidget( qmlCode );
1252 qmlPreviewBox->setMinimumWidth( 200 );
1253 qmlPreviewBox->setWidget( qmlWrapper->
widget() );
1256 qmlSplitter->addWidget( qmlPreviewBox );
1257 qmlSplitter->setChildrenCollapsible(
false );
1258 qmlSplitter->setHandleWidth( 6 );
1259 qmlSplitter->setSizes( QList<int>() << 1 << 1 );
1261 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help );
1263 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1264 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1265 connect( buttonBox, &QDialogButtonBox::helpRequested, &dlg, [] {
1266 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#other-widgets" ) );
1269 mainLayout->addWidget( buttonBox );
1274 qmlEdCfg.
qmlCode = qmlCode->text();
1276 itemData.
setShowLabel( showLabelCheckbox->isChecked() );
1287 dlg.setObjectName(
"HTML Form Configuration Widget" );
1289 dlg.setWindowTitle( tr(
"Configure HTML Widget" ) );
1291 QVBoxLayout *mainLayout =
new QVBoxLayout( &dlg );
1292 QSplitter *htmlSplitter =
new QSplitter();
1293 QWidget *htmlConfigWiget =
new QWidget();
1294 QVBoxLayout *layout =
new QVBoxLayout( htmlConfigWiget );
1295 layout->setContentsMargins( 0, 0, 0, 0 );
1296 mainLayout->addWidget( htmlSplitter );
1297 htmlSplitter->addWidget( htmlConfigWiget );
1298 htmlSplitter->setChildrenCollapsible(
false );
1299 htmlSplitter->setHandleWidth( 6 );
1300 htmlSplitter->setSizes( QList<int>() << 1 << 1 );
1301 layout->addWidget( baseWidget );
1303 QLineEdit *title =
new QLineEdit( itemName );
1307 htmlCode->setSizePolicy( QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Expanding );
1315 connect( htmlCode, &QgsCodeEditorHTML::textChanged,
this, [htmlWrapper, htmlCode, previewFeature] {
1323 expressionWidget->registerExpressionContextGenerator(
this );
1324 expressionWidget->setLayer(
mLayer );
1325 QToolButton *addFieldButton =
new QToolButton();
1328 QToolButton *editExpressionButton =
new QToolButton();
1330 editExpressionButton->setToolTip( tr(
"Insert/Edit Expression" ) );
1332 connect( addFieldButton, &QAbstractButton::clicked,
this, [expressionWidget, htmlCode] {
1333 QString expression = expressionWidget->expression().trimmed().replace(
'"', QLatin1String(
"\\\"" ) );
1334 if ( !expression.isEmpty() )
1335 htmlCode->
insertText( QStringLiteral(
"<script>document.write(expression.evaluate(\"%1\"));</script>" ).arg( expression ) );
1338 connect( editExpressionButton, &QAbstractButton::clicked,
this, [
this, htmlCode] {
1340 expression.replace( QLatin1String(
"\\\"" ), QLatin1String(
"\"" ) );
1344 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
1345 if ( exprDlg.exec() == QDialog::Accepted && !exprDlg.expressionText().trimmed().isEmpty() )
1347 QString expression = exprDlg.expressionText().trimmed().replace(
'"', QLatin1String(
"\\\"" ) );
1348 if ( !expression.isEmpty() )
1349 htmlCode->
insertText( QStringLiteral(
"<script>document.write(expression.evaluate(\"%1\"));</script>" ).arg( expression ) );
1353 layout->addWidget(
new QLabel( tr(
"Title" ) ) );
1354 layout->addWidget( title );
1355 QGroupBox *expressionWidgetBox =
new QGroupBox( tr(
"HTML Code" ) );
1356 layout->addWidget( expressionWidgetBox );
1357 expressionWidgetBox->setLayout(
new QHBoxLayout );
1358 expressionWidgetBox->layout()->addWidget( expressionWidget );
1359 expressionWidgetBox->layout()->addWidget( addFieldButton );
1360 expressionWidgetBox->layout()->addWidget( editExpressionButton );
1361 layout->addWidget( htmlCode );
1363 htmlPreviewBox->setLayout(
new QGridLayout );
1364 htmlPreviewBox->setMinimumWidth( 200 );
1365 htmlPreviewBox->layout()->addWidget( htmlWrapper->
widget() );
1367 emit htmlCode->textChanged();
1368 htmlSplitter->addWidget( htmlPreviewBox );
1369 htmlSplitter->setChildrenCollapsible(
false );
1370 htmlSplitter->setHandleWidth( 6 );
1371 htmlSplitter->setSizes( QList<int>() << 1 << 1 );
1373 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help );
1375 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1376 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1377 connect( buttonBox, &QDialogButtonBox::helpRequested, &dlg, [] {
1378 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#other-widgets" ) );
1381 mainLayout->addWidget( buttonBox );
1386 htmlEdCfg.
htmlCode = htmlCode->text();
1388 itemData.
setShowLabel( showLabelCheckbox->isChecked() );
1399 dlg.setObjectName(
"Text Form Configuration Widget" );
1401 dlg.setWindowTitle( tr(
"Configure Text Widget" ) );
1403 QVBoxLayout *mainLayout =
new QVBoxLayout( &dlg );
1404 QSplitter *textSplitter =
new QSplitter();
1405 QWidget *textConfigWiget =
new QWidget();
1406 QVBoxLayout *layout =
new QVBoxLayout( textConfigWiget );
1407 layout->setContentsMargins( 0, 0, 0, 0 );
1408 mainLayout->addWidget( textSplitter );
1409 textSplitter->addWidget( textConfigWiget );
1410 layout->addWidget( baseWidget );
1412 QLineEdit *title =
new QLineEdit( itemName );
1415 text->setSizePolicy( QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Expanding );
1423 connect( text, &QgsCodeEditorExpression::textChanged,
this, [textWrapper, previewFeature, text] {
1424 textWrapper->
setText( text->text() );
1431 expressionWidget->registerExpressionContextGenerator(
this );
1432 expressionWidget->setLayer(
mLayer );
1433 QToolButton *addFieldButton =
new QToolButton();
1436 QToolButton *editExpressionButton =
new QToolButton();
1438 editExpressionButton->setToolTip( tr(
"Insert/Edit Expression" ) );
1440 connect( addFieldButton, &QAbstractButton::clicked,
this, [expressionWidget, text] {
1441 QString expression = expressionWidget->expression().trimmed();
1442 if ( !expression.isEmpty() )
1443 text->
insertText( QStringLiteral(
"[%%1%]" ).arg( expression ) );
1445 connect( editExpressionButton, &QAbstractButton::clicked,
this, [
this, text] {
1451 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
1452 if ( exprDlg.exec() == QDialog::Accepted && !exprDlg.expressionText().trimmed().isEmpty() )
1454 QString expression = exprDlg.expressionText().trimmed();
1455 if ( !expression.isEmpty() )
1456 text->
insertText( QStringLiteral(
"[%%1%]" ).arg( expression ) );
1460 layout->addWidget(
new QLabel( tr(
"Title" ) ) );
1461 layout->addWidget( title );
1462 QGroupBox *expressionWidgetBox =
new QGroupBox( tr(
"Text" ) );
1463 layout->addWidget( expressionWidgetBox );
1464 expressionWidgetBox->setLayout(
new QHBoxLayout );
1465 expressionWidgetBox->layout()->addWidget( expressionWidget );
1466 expressionWidgetBox->layout()->addWidget( addFieldButton );
1467 expressionWidgetBox->layout()->addWidget( editExpressionButton );
1468 layout->addWidget( text );
1470 textPreviewBox->setLayout(
new QGridLayout );
1471 textPreviewBox->setMinimumWidth( 200 );
1472 textPreviewBox->layout()->addWidget( textWrapper->
widget() );
1474 emit text->textChanged();
1475 textSplitter->addWidget( textPreviewBox );
1476 textSplitter->setChildrenCollapsible(
false );
1477 textSplitter->setHandleWidth( 6 );
1478 textSplitter->setSizes( QList<int>() << 1 << 1 );
1480 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help );
1482 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1483 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1484 connect( buttonBox, &QDialogButtonBox::helpRequested, &dlg, [] {
1485 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#other-widgets" ) );
1488 mainLayout->addWidget( buttonBox );
1493 textEdCfg.
text = text->text();
1495 itemData.
setShowLabel( showLabelCheckbox->isChecked() );
1506 dlg.setObjectName(
"Spacer Form Configuration Widget" );
1508 dlg.setWindowTitle( tr(
"Configure Spacer Widget" ) );
1510 QVBoxLayout *mainLayout =
new QVBoxLayout();
1511 mainLayout->addWidget(
new QLabel( tr(
"Title" ) ) );
1512 QLineEdit *title =
new QLineEdit( itemName );
1513 mainLayout->addWidget( title );
1515 QHBoxLayout *cbLayout =
new QHBoxLayout();
1516 mainLayout->addLayout( cbLayout );
1517 dlg.setLayout( mainLayout );
1518 QCheckBox *cb =
new QCheckBox { &dlg };
1520 cbLayout->addWidget(
new QLabel( tr(
"Draw horizontal line" ), &dlg ) );
1521 cbLayout->addWidget( cb );
1523 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help );
1525 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1526 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1527 connect( buttonBox, &QDialogButtonBox::helpRequested, &dlg, [] {
1528 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#other-widgets" ) );
1531 mainLayout->addWidget( buttonBox );
1536 spacerEdCfg.
drawLine = cb->isChecked();
1550void QgsAttributesFormProperties::updatedFields()
1553 QMap<QString, QgsAttributesFormData::FieldConfig> fieldConfigs;
1555 const QModelIndex fieldContainerBefore = mAvailableWidgetsModel->
fieldContainer();
1558 for (
int i = 0; i < mAvailableWidgetsModel->
rowCount( fieldContainerBefore ); i++ )
1560 index = mAvailableWidgetsModel->
index( i, 0, fieldContainerBefore );
1563 fieldConfigs[fieldName] = config;
1568 const QModelIndex fieldContainerAfter = mAvailableWidgetsModel->
fieldContainer();
1570 for (
int i = 0; i < mAvailableWidgetsModel->
rowCount( fieldContainerAfter ); i++ )
1572 index = mAvailableWidgetsModel->
index( i, 0, fieldContainerAfter );
1575 if ( fieldConfigs.contains( fieldName ) )
1583void QgsAttributesFormProperties::updateFilteredItems(
const QString &filterText )
1585 const int availableWidgetsPreviousSelectionCount =
mAvailableWidgetsView->selectionModel()->selectedRows().count();
1586 const int formLayoutPreviousSelectionCount =
mFormLayoutView->selectionModel()->selectedRows().count();
1596 if ( !( availableWidgetsPreviousSelectionCount == 0 && formLayoutPreviousSelectionCount == 0 ) )
1598 const int selectedAvailableWidgetItemCount =
mAvailableWidgetsView->selectionModel()->selectedRows().count();
1599 const int selectedFormLayoutItemCount =
mFormLayoutView->selectionModel()->selectedRows().count();
1601 if ( selectedAvailableWidgetItemCount == 0 && selectedFormLayoutItemCount == 0 )
1604 clearAttributeTypeFrame();
1609void QgsAttributesFormProperties::onContextMenuRequested( QPoint point )
1620 const QClipboard *clipboard = QApplication::clipboard();
1621 const QMimeData *mimeData = clipboard->mimeData();
1625 const bool pasteEnabled = mimeData->hasFormat( QStringLiteral(
"application/x-qgsattributetabledesignerelementclipboard" ) );
1626 mActionPasteWidgetConfiguration->setEnabled( pasteEnabled );
1627 mAvailableWidgetsContextMenu->popup( globalPos );
1631void QgsAttributesFormProperties::copyWidgetConfiguration()
1645 if ( fieldIndex < 0 )
1652 QDomElement documentElement = doc.createElement( QStringLiteral(
"FormWidgetClipboard" ) );
1653 documentElement.setAttribute( QStringLiteral(
"name" ), field.
name() );
1658 QDomElement editWidgetElement = doc.createElement( QStringLiteral(
"editWidget" ) );
1659 documentElement.appendChild( editWidgetElement );
1660 editWidgetElement.setAttribute( QStringLiteral(
"type" ), widgetSetup.
type() );
1661 QDomElement editWidgetConfigElement = doc.createElement( QStringLiteral(
"config" ) );
1664 editWidgetElement.appendChild( editWidgetConfigElement );
1667 QDomElement splitPolicyElement = doc.createElement( QStringLiteral(
"splitPolicy" ) );
1669 documentElement.appendChild( splitPolicyElement );
1672 QDomElement duplicatePolicyElement = doc.createElement( QStringLiteral(
"duplicatePolicy" ) );
1674 documentElement.appendChild( duplicatePolicyElement );
1677 QDomElement mergePolicyElement = doc.createElement( QStringLiteral(
"mergePolicy" ) );
1679 documentElement.appendChild( mergePolicyElement );
1682 QDomElement defaultElem = doc.createElement( QStringLiteral(
"default" ) );
1685 documentElement.appendChild( defaultElem );
1688 QDomElement constraintElem = doc.createElement( QStringLiteral(
"constraint" ) );
1693 documentElement.appendChild( constraintElem );
1696 QDomElement constraintExpressionElem = doc.createElement( QStringLiteral(
"constraintExpression" ) );
1699 documentElement.appendChild( constraintExpressionElem );
1704 QDomElement widgetGeneralSettingsElem = doc.createElement( QStringLiteral(
"widgetGeneralSettings" ) );
1705 widgetGeneralSettingsElem.setAttribute( QStringLiteral(
"editable" ),
mAttributeTypeDialog->fieldEditable() );
1706 widgetGeneralSettingsElem.setAttribute( QStringLiteral(
"reuse_last_values" ),
mAttributeTypeDialog->labelOnTop() );
1707 widgetGeneralSettingsElem.setAttribute( QStringLiteral(
"label_on_top" ),
mAttributeTypeDialog->reuseLastValues() );
1708 documentElement.appendChild( widgetGeneralSettingsElem );
1721 QDomElement displayElement = doc.createElement( QStringLiteral(
"widgetDisplay" ) );
1722 displayElement.setAttribute( QStringLiteral(
"showLabel" ), layoutData.showLabel() );
1723 displayElement.setAttribute( QStringLiteral(
"horizontalStretch" ), layoutData.horizontalStretch() );
1724 displayElement.setAttribute( QStringLiteral(
"verticalStretch" ), layoutData.verticalStretch() );
1725 displayElement.appendChild( layoutData.labelStyle().writeXml( doc ) );
1726 documentElement.appendChild( displayElement );
1729 doc.appendChild( documentElement );
1731 QMimeData *mimeData =
new QMimeData;
1732 mimeData->setData( QStringLiteral(
"application/x-qgsattributetabledesignerelementclipboard" ), doc.toByteArray() );
1733 QClipboard *clipboard = QApplication::clipboard();
1734 clipboard->setMimeData( mimeData );
1737void QgsAttributesFormProperties::pasteWidgetConfiguration()
1747 if ( fieldIndex < 0 )
1754 QClipboard *clipboard = QApplication::clipboard();
1755 const QMimeData *mimeData = clipboard->mimeData();
1759 if ( doc.setContent( mimeData->data( QStringLiteral(
"application/x-qgsattributetabledesignerelementclipboard" ) ) ) )
1761 QDomElement docElem = doc.documentElement();
1762 if ( docElem.tagName() != QLatin1String(
"FormWidgetClipboard" ) )
1771 const QDomElement fieldWidgetElement = docElem.firstChildElement( QStringLiteral(
"editWidget" ) );
1772 if ( !fieldWidgetElement.isNull() )
1774 const QString widgetType = fieldWidgetElement.attribute( QStringLiteral(
"type" ) );
1780 const QDomElement configElement = fieldWidgetElement.firstChildElement( QStringLiteral(
"config" ) );
1781 if ( !configElement.isNull() )
1783 const QDomElement optionsElem = configElement.childNodes().at( 0 ).toElement();
1787 if ( widgetType == QStringLiteral(
"ValueRelation" ) )
1789 optionsMap[QStringLiteral(
"Value" )] = context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1:fields:%2:valuerelationvalue" ).arg(
mLayer->
id(), fieldName ), optionsMap[QStringLiteral(
"Value" )].toString() );
1791 if ( widgetType == QStringLiteral(
"ValueMap" ) )
1793 if ( optionsMap[QStringLiteral(
"map" )].canConvert<QList<QVariant>>() )
1795 QList<QVariant> translatedValueList;
1796 const QList<QVariant> valueList = optionsMap[QStringLiteral(
"map" )].toList();
1797 for (
int i = 0, row = 0; i < valueList.count(); i++, row++ )
1799 QMap<QString, QVariant> translatedValueMap;
1800 QString translatedKey = context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1:fields:%2:valuemapdescriptions" ).arg(
mLayer->
id(), fieldName ), valueList[i].toMap().constBegin().key() );
1801 translatedValueMap.insert( translatedKey, valueList[i].toMap().constBegin().value() );
1802 translatedValueList.append( translatedValueMap );
1804 optionsMap.insert( QStringLiteral(
"map" ), translatedValueList );
1813 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 );
1818 const QDomElement splitPolicyElement = docElem.firstChildElement( QStringLiteral(
"splitPolicy" ) );
1819 if ( !splitPolicyElement.isNull() )
1826 const QDomElement duplicatePolicyElement = docElem.firstChildElement( QStringLiteral(
"duplicatePolicy" ) );
1827 if ( !duplicatePolicyElement.isNull() )
1834 const QDomElement mergePolicyElement = docElem.firstChildElement( QStringLiteral(
"mergePolicy" ) );
1835 if ( !mergePolicyElement.isNull() )
1842 const QDomElement defaultElement = docElem.firstChildElement( QStringLiteral(
"default" ) );
1843 if ( !defaultElement.isNull() )
1845 mAttributeTypeDialog->setDefaultValueExpression( defaultElement.attribute( QStringLiteral(
"expression" ) ) );
1846 mAttributeTypeDialog->setApplyDefaultValueOnUpdate( defaultElement.attribute( QStringLiteral(
"applyOnUpdate" ) ).toInt() );
1852 const QDomElement constraintElement = docElem.firstChildElement( QStringLiteral(
"constraint" ) );
1853 if ( !constraintElement.isNull() )
1855 const int intConstraints = constraintElement.attribute( QStringLiteral(
"constraints" ), QStringLiteral(
"0" ) ).toInt();
1881 const int uniqueStrength = constraintElement.attribute( QStringLiteral(
"unique_strength" ), QStringLiteral(
"1" ) ).toInt();
1882 const int notNullStrength = constraintElement.attribute( QStringLiteral(
"notnull_strength" ), QStringLiteral(
"1" ) ).toInt();
1883 const int expStrength = constraintElement.attribute( QStringLiteral(
"exp_strength" ), QStringLiteral(
"1" ) ).toInt();
1894 const QDomElement constraintExpressionElement = docElem.firstChildElement( QStringLiteral(
"constraintExpression" ) );
1895 if ( !constraintExpressionElement.isNull() )
1897 QString expression = constraintExpressionElement.attribute( QStringLiteral(
"exp" ), QString() );
1898 QString description = constraintExpressionElement.attribute( QStringLiteral(
"desc" ), QString() );
1904 const QDomElement widgetGeneralSettingsElement = docElem.firstChildElement( QStringLiteral(
"widgetGeneralSettings" ) );
1905 if ( !widgetGeneralSettingsElement.isNull() )
1907 const int editable = widgetGeneralSettingsElement.attribute( QStringLiteral(
"editable" ), QStringLiteral(
"0" ) ).toInt();
1908 const int reuse = widgetGeneralSettingsElement.attribute( QStringLiteral(
"reuse_last_values" ), QStringLiteral(
"0" ) ).toInt();
1909 const int labelOnTop = widgetGeneralSettingsElement.attribute( QStringLiteral(
"label_on_top" ), QStringLiteral(
"0" ) ).toInt();
1916 loadAttributeTypeDialogFromConfiguration( config );
1921 const QDomElement displayElement = docElem.firstChildElement( QStringLiteral(
"widgetDisplay" ) );
1922 if ( !displayElement.isNull() )
1924 const int showLabel = displayElement.attribute( QStringLiteral(
"showLabel" ), QStringLiteral(
"0" ) ).toInt();
1925 const int horizontalStretch = displayElement.attribute( QStringLiteral(
"horizontalStretch" ), QStringLiteral(
"0" ) ).toInt();
1926 const int verticalStretch = displayElement.attribute( QStringLiteral(
"verticalStretch" ), QStringLiteral(
"0" ) ).toInt();
1928 style.
readXml( displayElement );
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.
QgsAction action(QUuid id) const
Gets an action by its id.
Utility class that encapsulates an action based on vector attributes.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
An abstract base class for any elements of a drag and drop form.
A HTML editor based on QScintilla2.
A text editor based on QScintilla2.
void setText(const QString &text) override
void setEditingTimeoutInterval(int timeout)
Sets the timeout (in milliseconds) threshold for the editingTimeout() signal to be emitted after an e...
void insertText(const QString &text)
Insert text at cursor position, or replace any selected text if user has made a selection.
void editingTimeout()
Emitted when either:
Provides a container for managing client side default values for fields.
A generic dialog for building expression strings.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * formScope(const QgsFeature &formFeature=QgsFeature(), const QString &formMode=QString())
Creates a new scope which contains functions and variables from the current attribute form/table form...
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
static QString findAndSelectActiveExpression(QgsCodeEditor *editor, const QString &pattern=QString())
Find the expression under the cursor in the given editor and select it.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Stores information about constraints which may be present on a field.
ConstraintStrength
Strength of constraints.
@ 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
Encapsulate a field in an attribute table or data source.
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.
QgsField field(int fieldIdx) const
Returns the field at particular index (must be in range 0..N-1).
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
A bar for displaying non-blocking messages to the user.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::MessageLevel::Info, int duration=-1)
A convenience method for pushing a message with the specified text to the bar.
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,...
static QgsProject * instance()
Returns the QgsProject singleton instance.
int count() const
Returns the number of properties contained within the collection.
A container for the context for various read/write operations on objects.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
A boolean settings entry.
static const QgsSettingsEntryBool * settingsDigitizingDisableEnterAttributeValuesDialog
Settings entry digitizing disable enter attribute values dialog.
Stores settings for use within QGIS.
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.
Wraps a label widget to display text.
void setText(const QString &text)
Sets the text code to htmlCode.
void reinitWidget()
Clears the content and makes new initialization.
void setFeature(const QgsFeature &feature) override
Represents a vector layer which manages a vector based dataset.
QgsDefaultValue defaultValueDefinition(int index) const
Returns the definition of the expression used when calculating the default value for a field.
void setFieldConstraint(int index, QgsFieldConstraints::Constraint constraint, QgsFieldConstraints::ConstraintStrength strength=QgsFieldConstraints::ConstraintStrengthHard)
Sets a constraint for a specified field index.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
void removeFieldConstraint(int index, QgsFieldConstraints::Constraint constraint)
Removes a constraint for a specified field index.
void setFieldMergePolicy(int index, Qgis::FieldDomainMergePolicy policy)
Sets a merge policy for the field with the specified index.
void setDefaultValueDefinition(int index, const QgsDefaultValue &definition)
Sets the definition of the expression to use when calculating the default value for a field.
void setEditFormConfig(const QgsEditFormConfig &editFormConfig)
Sets the editFormConfig (configuration) of the form used to represent this vector layer.
void setEditorWidgetSetup(int index, const QgsEditorWidgetSetup &setup)
Sets the editor widget setup for the field at the specified index.
void setConstraintExpression(int index, const QString &expression, const QString &description=QString())
Sets the constraint expression for the specified field index.
void setFieldDuplicatePolicy(int index, Qgis::FieldDuplicatePolicy policy)
Sets a duplicate policy for the field with the specified index.
QgsActionManager * actions()
Returns all layer actions defined on this layer.
void setFieldAlias(int index, const QString &aliasString)
Sets an alias (a display name) for attributes to display in dialogs.
void updatedFields()
Emitted whenever the fields available from this layer have been changed.
QgsEditFormConfig editFormConfig
void setFieldSplitPolicy(int index, Qgis::FieldDomainSplitPolicy policy)
Sets a split policy for the field with the specified index.
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.
The TabStyle struct defines color and font overrides for form fields, tabs and groups labels.
void readXml(const QDomNode &node)
Reads configuration from node.