21#include "moc_qgsattributesformproperties.cpp"
22#include "qgsattributetypedialog.h"
23#include "qgsattributeformcontaineredit.h"
24#include "qgsattributewidgetedit.h"
63 QGridLayout *availableWidgetsWidgetLayout =
new QGridLayout;
66 availableWidgetsWidgetLayout->setContentsMargins( 0, 0, 0, 0 );
67 mAvailableWidgetsWidget->setLayout( availableWidgetsWidgetLayout );
74 QGridLayout *formLayoutWidgetLayout =
new QGridLayout;
76 mFormLayoutWidget->setLayout( formLayoutWidgetLayout );
78 formLayoutWidgetLayout->setContentsMargins( 0, 0, 0, 0 );
79 mFormLayoutTree->setHeaderLabels( QStringList() << tr(
"Form Layout" ) );
82 connect(
mAvailableWidgetsTree, &QTreeWidget::itemSelectionChanged,
this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
83 connect(
mAvailableWidgetsTree, &QWidget::customContextMenuRequested,
this, &QgsAttributesFormProperties::onContextMenuRequested );
84 connect(
mFormLayoutTree, &QTreeWidget::itemSelectionChanged,
this, &QgsAttributesFormProperties::onFormLayoutSelectionChanged );
85 connect( mAddTabOrGroupButton, &QAbstractButton::clicked,
this, &QgsAttributesFormProperties::addContainer );
86 connect( mRemoveTabOrGroupButton, &QAbstractButton::clicked,
this, &QgsAttributesFormProperties::removeTabOrGroupButton );
87 connect( mInvertSelectionButton, &QAbstractButton::clicked,
this, &QgsAttributesFormProperties::onInvertSelectionButtonClicked );
88 connect( mEditorLayoutComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsAttributesFormProperties::mEditorLayoutComboBox_currentIndexChanged );
89 connect( pbnSelectEditForm, &QToolButton::clicked,
this, &QgsAttributesFormProperties::pbnSelectEditForm_clicked );
90 connect( mTbInitCode, &QPushButton::clicked,
this, &QgsAttributesFormProperties::mTbInitCode_clicked );
98 mAvailableWidgetsTreeContextMenu =
new QMenu(
this );
99 mActionCopyWidgetConfiguration =
new QAction( tr(
"Copy widget configuration" ),
this );
100 mActionPasteWidgetConfiguration =
new QAction( tr(
"Paste widget configuration" ),
this );
102 connect( mActionCopyWidgetConfiguration, &QAction::triggered,
this, &QgsAttributesFormProperties::copyWidgetConfiguration );
103 connect( mActionPasteWidgetConfiguration, &QAction::triggered,
this, &QgsAttributesFormProperties::pasteWidgetConfiguration );
105 mAvailableWidgetsTreeContextMenu->addAction( mActionCopyWidgetConfiguration );
106 mAvailableWidgetsTreeContextMenu->addAction( mActionPasteWidgetConfiguration );
109 mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
110 gridLayout->addWidget( mMessageBar, 0, 0 );
137 for (
int i = 0; i < fields.
size(); ++i )
151 if ( !field.
alias().isEmpty() )
152 tooltip = tr(
"%1 (%2)" ).arg( field.
name(), field.
alias() );
154 tooltip = field.
name();
155 item->setToolTip( 0, tooltip );
157 catitem->setExpanded(
true );
169 if ( polymorphicRelation.
isValid() )
171 name = QStringLiteral(
"%1 (%2)" ).arg( relation.name(), polymorphicRelation.
name() );
175 name = relation.
name();
182 catitem->setExpanded(
true );
190 for (
const auto &action : std::as_const( actions ) )
192 if ( action.isValid() && action.runable() && ( action.actionScopes().contains( QStringLiteral(
"Feature" ) ) || action.actionScopes().contains( QStringLiteral(
"Layer" ) ) ) )
194 const QString actionTitle { action.shortTitle().isEmpty() ? action.name() : action.shortTitle() };
221 catitem->setExpanded(
true );
229 mFormLayoutTree->setSelectionBehavior( QAbstractItemView::SelectRows );
230 mFormLayoutTree->setSelectionMode( QAbstractItemView::SelectionMode::ExtendedSelection );
267 mEditorLayoutComboBox->setCurrentIndex( mEditorLayoutComboBox->findData( QVariant::fromValue(
mLayer->
editFormConfig().
layout() ) ) );
269 mEditorLayoutComboBox_currentIndexChanged( mEditorLayoutComboBox->currentIndex() );
272 mEditFormLineEdit->setText( cfg.
uiForm() );
284 if ( mInitCode.isEmpty() )
286 mInitCode.append( tr(
"# -*- coding: utf-8 -*-\n\"\"\"\n"
287 "QGIS forms can have a Python function that is called when the form is\n"
290 "Use this function to add extra logic to your forms.\n"
292 "Enter the name of the function in the \"Python Init function\"\n"
294 "An example follows:\n"
296 "from qgis.PyQt.QtWidgets import QWidget\n\n"
297 "def my_form_open(dialog, layer, feature):\n"
298 " geom = feature.geometry()\n"
299 " control = dialog.findChild(QWidget, \"MyLineEdit\")\n" ) );
303void QgsAttributesFormProperties::loadAttributeTypeDialog()
310 const FieldConfig cfg = item->data( 0,
FieldConfigRole ).value<FieldConfig>();
311 const QString fieldName = item->data( 0,
FieldNameRole ).toString();
319 loadAttributeTypeDialogFromConfiguration( cfg );
325 mAttributeTypeFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
330void QgsAttributesFormProperties::loadAttributeTypeDialogFromConfiguration(
const FieldConfig config )
366void QgsAttributesFormProperties::storeAttributeTypeDialog()
415 cfg.mFieldConstraints = constraints;
428 QTreeWidgetItem *item = *itemIt;
429 if ( item->data( 0,
FieldNameRole ).toString() == fieldName )
430 item->setData( 0,
FieldConfigRole, QVariant::fromValue<FieldConfig>( cfg ) );
434void QgsAttributesFormProperties::storeAttributeWidgetEdit()
442void QgsAttributesFormProperties::loadAttributeWidgetEdit()
447 QTreeWidgetItem *currentItem =
mFormLayoutTree->selectedItems().at( 0 );
449 mAttributeTypeFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
453void QgsAttributesFormProperties::loadInfoWidget(
const QString &infoText )
456 mAttributeTypeFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
460void QgsAttributesFormProperties::storeAttributeContainerEdit()
468void QgsAttributesFormProperties::loadAttributeContainerEdit()
473 QTreeWidgetItem *currentItem =
mFormLayoutTree->selectedItems().at( 0 );
477 mAttributeTypeFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
483 auto setCommonProperties = [widgetDef]( DnDTreeItemData &itemData ) {
484 itemData.setShowLabel( widgetDef->
showLabel() );
485 itemData.setLabelStyle( widgetDef->
labelStyle() );
490 QTreeWidgetItem *newWidget =
nullptr;
491 switch ( widgetDef->
type() )
496 setCommonProperties( itemData );
497 newWidget = tree->
addItem( parent, itemData );
505 if ( action.isValid() )
507 DnDTreeItemData itemData = DnDTreeItemData(
DnDTreeItemData::Action, action.id().toString(), action.shortTitle().isEmpty() ? action.name() : action.shortTitle() );
508 setCommonProperties( itemData );
509 newWidget = tree->
addItem( parent, itemData );
522 setCommonProperties( itemData );
524 RelationEditorConfiguration relEdConfig;
528 relEdConfig.nmRelationId = relationEditor->
nmRelationId();
530 relEdConfig.label = relationEditor->
label();
531 itemData.setRelationEditorConfiguration( relEdConfig );
532 newWidget = tree->
addItem( parent, itemData );
545 itemData.setContainerType( container->
type() );
549 itemData.setCollapsed( container->
collapsed() );
551 setCommonProperties( itemData );
553 newWidget = tree->
addItem( parent, itemData );
555 const QList<QgsAttributeEditorElement *> children = container->
children();
558 loadAttributeEditorTreeItem( wdg, newWidget, tree );
567 QmlElementEditorConfiguration qmlEdConfig;
568 qmlEdConfig.qmlCode = qmlElementEditor->
qmlCode();
569 itemData.setQmlElementEditorConfiguration( qmlEdConfig );
570 setCommonProperties( itemData );
571 newWidget = tree->
addItem( parent, itemData );
579 HtmlElementEditorConfiguration htmlEdConfig;
580 htmlEdConfig.htmlCode = htmlElementEditor->
htmlCode();
581 itemData.setHtmlElementEditorConfiguration( htmlEdConfig );
582 setCommonProperties( itemData );
583 newWidget = tree->
addItem( parent, itemData );
591 TextElementEditorConfiguration textEdConfig;
592 textEdConfig.text = textElementEditor->
text();
593 itemData.setTextElementEditorConfiguration( textEdConfig );
594 setCommonProperties( itemData );
595 newWidget = tree->
addItem( parent, itemData );
603 SpacerElementEditorConfiguration spacerEdConfig;
604 spacerEdConfig.drawLine = spacerElementEditor->
drawLine();
605 itemData.setSpacerElementEditorConfiguration( spacerEdConfig );
606 setCommonProperties( itemData );
607 itemData.setShowLabel(
false );
608 newWidget = tree->
addItem( parent, itemData );
614 QgsDebugError( QStringLiteral(
"Not loading invalid attribute editor type..." ) );
620 newWidget->setExpanded(
true );
626void QgsAttributesFormProperties::onAttributeSelectionChanged()
628 disconnect(
mFormLayoutTree, &QTreeWidget::itemSelectionChanged,
this, &QgsAttributesFormProperties::onFormLayoutSelectionChanged );
630 connect(
mFormLayoutTree, &QTreeWidget::itemSelectionChanged,
this, &QgsAttributesFormProperties::onFormLayoutSelectionChanged );
633void QgsAttributesFormProperties::onFormLayoutSelectionChanged()
636 disconnect(
mAvailableWidgetsTree, &QTreeWidget::itemSelectionChanged,
this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
638 connect(
mAvailableWidgetsTree, &QTreeWidget::itemSelectionChanged,
this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
647 storeAttributeWidgetEdit();
651 storeAttributeTypeDialog();
654 clearAttributeTypeFrame();
656 if ( emitter->selectedItems().count() != 1 )
658 receiver->clearSelection();
662 const DnDTreeItemData itemData = emitter->selectedItems().at( 0 )->data( 0,
DnDTreeRole ).value<DnDTreeItemData>();
663 switch ( itemData.type() )
670 loadAttributeWidgetEdit();
674 loadInfoWidget( tr(
"This configuration is available in the Drag and Drop Designer" ) );
683 loadAttributeWidgetEdit();
685 loadAttributeTypeDialog();
690 receiver->clearSelection();
691 loadAttributeContainerEdit();
698 loadInfoWidget( action.html() );
708 loadInfoWidget( tr(
"This configuration is available with double-click in the Drag and Drop Designer" ) );
712 loadInfoWidget( tr(
"This configuration is available with double-click" ) );
714 receiver->clearSelection();
719 receiver->clearSelection();
726void QgsAttributesFormProperties::clearAttributeTypeFrame()
754void QgsAttributesFormProperties::onInvertSelectionButtonClicked(
bool checked )
759 for (
int i = 0; i < rootItem->childCount(); ++i )
761 rootItem->child( i )->setSelected( !selectedItemList.contains( rootItem->child( i ) ) );
765void QgsAttributesFormProperties::addContainer()
767 QList<QgsAddAttributeFormContainerDialog::ContainerPair> existingContainerList;
771 const DnDTreeItemData itemData = ( *it )->data( 0,
DnDTreeRole ).value<DnDTreeItemData>();
777 QTreeWidgetItem *currentItem =
mFormLayoutTree->selectedItems().value( 0 );
780 if ( !dialog.exec() )
783 const QString name = dialog.name();
784 QTreeWidgetItem *parentContainerItem = dialog.parentContainerItem();
788void QgsAttributesFormProperties::removeTabOrGroupButton()
794 const QList<QTreeWidgetItem *> items =
mFormLayoutTree->selectedItems();
798 delete items.at( 0 );
808 switch ( itemData.
type() )
857 for (
int t = 0; t < item->childCount(); t++ )
864 widgetDef = container;
915void QgsAttributesFormProperties::mEditorLayoutComboBox_currentIndexChanged(
int )
921 mFormLayoutWidget->setVisible(
false );
922 mUiFileFrame->setVisible(
false );
923 mAddTabOrGroupButton->setVisible(
false );
924 mRemoveTabOrGroupButton->setVisible(
false );
925 mInvertSelectionButton->setVisible(
false );
929 mFormLayoutWidget->setVisible(
true );
930 mUiFileFrame->setVisible(
false );
931 mAddTabOrGroupButton->setVisible(
true );
932 mRemoveTabOrGroupButton->setVisible(
true );
933 mInvertSelectionButton->setVisible(
true );
938 mFormLayoutWidget->setVisible(
false );
939 mUiFileFrame->setVisible(
true );
940 mAddTabOrGroupButton->setVisible(
false );
941 mRemoveTabOrGroupButton->setVisible(
false );
942 mInvertSelectionButton->setVisible(
false );
947void QgsAttributesFormProperties::mTbInitCode_clicked()
956 if ( !attributesFormInitCode.exec() )
959 mInitCodeSource = attributesFormInitCode.
codeSource();
960 mInitCode = attributesFormInitCode.
initCode();
965void QgsAttributesFormProperties::pbnSelectEditForm_clicked()
968 const QString lastUsedDir = myQSettings.
value( QStringLiteral(
"style/lastUIDir" ), QDir::homePath() ).toString();
969 const QString uifilename = QFileDialog::getOpenFileName(
this, tr(
"Select edit form" ), lastUsedDir, tr(
"UI file" ) +
" (*.ui)" );
971 if ( uifilename.isNull() )
974 const QFileInfo fi( uifilename );
975 myQSettings.
setValue( QStringLiteral(
"style/lastUIDir" ), fi.path() );
976 mEditFormLineEdit->setText( uifilename );
981 storeAttributeWidgetEdit();
982 storeAttributeContainerEdit();
983 storeAttributeTypeDialog();
989 storeAttributeWidgetEdit();
990 storeAttributeContainerEdit();
991 storeAttributeTypeDialog();
997 for (
int i = 0; i < fieldContainer->childCount(); i++ )
999 QTreeWidgetItem *fieldItem = fieldContainer->child( i );
1002 const QString fieldName { fieldItem->data( 0,
FieldNameRole ).toString() };
1054 for (
int t = 0; t <
mFormLayoutTree->invisibleRootItem()->childCount(); t++ )
1056 QTreeWidgetItem *tabItem =
mFormLayoutTree->invisibleRootItem()->child( t );
1058 if ( editorElement )
1059 editFormConfig.
addTab( editorElement );
1062 editFormConfig.
setUiForm( mEditFormLineEdit->text() );
1076 for (
int i = 0; i < relationContainer->childCount(); i++ )
1078 QTreeWidgetItem *relationItem = relationContainer->child( i );
1081 for (
int t = 0; t <
mFormLayoutTree->invisibleRootItem()->childCount(); t++ )
1083 QTreeWidgetItem *tabItem =
mFormLayoutTree->invisibleRootItem()->child( t );
1086 if ( tabItemData.
type() == itemData.
type() && tabItemData.
name() == itemData.
name() )
1123QgsAttributesFormProperties::FieldConfig::operator QVariant()
1125 return QVariant::fromValue<QgsAttributesFormProperties::FieldConfig>( *
this );
1123QgsAttributesFormProperties::FieldConfig::operator QVariant() {
…}
1132QgsAttributesFormProperties::RelationEditorConfiguration::operator QVariant()
1134 return QVariant::fromValue<QgsAttributesFormProperties::RelationEditorConfiguration>( *
this );
1132QgsAttributesFormProperties::RelationEditorConfiguration::operator QVariant() {
…}
1143 QTreeWidgetItem *newItem =
new QTreeWidgetItem( QStringList() << title );
1144 newItem->setBackground( 0, QBrush( Qt::lightGray ) );
1145 newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled );
1150 parent->addChild( newItem );
1151 newItem->setExpanded(
true );
1156 : QTreeWidget( parent )
1159 connect(
this, &QTreeWidget::itemDoubleClicked,
this, &QgsAttributesDnDTree::onItemDoubleClicked );
1164 QTreeWidgetItem *newItem =
new QTreeWidgetItem( QStringList() << data.
name() );
1166 switch ( data.
type() )
1175 newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
1181 newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled );
1182 newItem->setBackground( 0, QBrush( Qt::lightGray ) );
1189 newItem->setIcon( 0, icon );
1196 newItem->setText( 0, tr(
"Invalid relation" ) );
1197 newItem->setForeground( 0, QColor( 255, 0, 0 ) );
1202 parent->addChild( newItem );
1204 parent->insertChild( index, newItem );
1216 const QMimeData *data =
event->mimeData();
1218 if ( data->hasFormat( QStringLiteral(
"application/x-qgsattributetabledesignerelement" ) ) )
1222 QByteArray itemData = data->data( QStringLiteral(
"application/x-qgsattributetabledesignerelement" ) );
1223 QDataStream stream( &itemData, QIODevice::ReadOnly );
1224 stream >> itemElement;
1227 if ( event->source() ==
this )
1229 event->setDropAction( Qt::MoveAction );
1237 QTreeWidget::dragMoveEvent( event );
1243 bool bDropSuccessful =
false;
1245 if ( action == Qt::IgnoreAction )
1247 bDropSuccessful =
true;
1249 else if ( data->hasFormat( QStringLiteral(
"application/x-qgsattributetabledesignerelement" ) ) )
1251 QByteArray itemData = data->data( QStringLiteral(
"application/x-qgsattributetabledesignerelement" ) );
1252 QDataStream stream( &itemData, QIODevice::ReadOnly );
1255 while ( !stream.atEnd() )
1257 stream >> itemElement;
1259 QTreeWidgetItem *newItem;
1263 newItem =
addItem( parent, itemElement, index++ );
1264 bDropSuccessful =
true;
1268 newItem =
addItem( invisibleRootItem(), itemElement, index++ );
1269 bDropSuccessful =
true;
1274 onItemDoubleClicked( newItem, 0 );
1279 onItemDoubleClicked( newItem, 0 );
1284 onItemDoubleClicked( newItem, 0 );
1289 onItemDoubleClicked( newItem, 0 );
1293 newItem->setSelected(
true );
1297 return bDropSuccessful;
1302 if ( !event->mimeData()->hasFormat( QStringLiteral(
"application/x-qgsattributetabledesignerelement" ) ) )
1305 if ( event->source() ==
this )
1307 event->setDropAction( Qt::MoveAction );
1310 QTreeWidget::dropEvent( event );
1315 return QStringList() << QStringLiteral(
"application/x-qgsattributetabledesignerelement" );
1318#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
1324 if ( items.count() <= 0 )
1327 const QStringList types = mimeTypes();
1329 if ( types.isEmpty() )
1332 QMimeData *data =
new QMimeData();
1333 const QString format = types.at( 0 );
1335 QDataStream stream( &encoded, QIODevice::WriteOnly );
1337 const auto constItems = items;
1338 for (
const QTreeWidgetItem *item : constItems )
1348 data->setData( format, encoded );
1353void QgsAttributesDnDTree::onItemDoubleClicked( QTreeWidgetItem *item,
int column )
1359 QGroupBox *baseData =
new QGroupBox( tr(
"Base configuration" ) );
1361 QFormLayout *baseLayout =
new QFormLayout();
1362 baseData->setLayout( baseLayout );
1363 QCheckBox *showLabelCheckbox =
new QCheckBox( QStringLiteral(
"Show label" ) );
1364 showLabelCheckbox->setChecked( itemData.
showLabel() );
1365 baseLayout->addRow( showLabelCheckbox );
1366 QWidget *baseWidget =
new QWidget();
1367 baseWidget->setLayout( baseLayout );
1369 switch ( itemData.
type() )
1384 dlg.setObjectName(
"QML Form Configuration Widget" );
1386 dlg.setWindowTitle( tr(
"Configure QML Widget" ) );
1388 QVBoxLayout *mainLayout =
new QVBoxLayout( &dlg );
1389 QSplitter *qmlSplitter =
new QSplitter();
1390 QWidget *qmlConfigWiget =
new QWidget();
1391 QVBoxLayout *layout =
new QVBoxLayout( qmlConfigWiget );
1392 layout->setContentsMargins( 0, 0, 0, 0 );
1393 mainLayout->addWidget( qmlSplitter );
1394 qmlSplitter->addWidget( qmlConfigWiget );
1395 layout->addWidget( baseWidget );
1397 QLineEdit *title =
new QLineEdit( itemData.
name() );
1416 QComboBox *qmlObjectTemplate =
new QComboBox();
1417 qmlObjectTemplate->addItem( tr(
"Free Text…" ) );
1418 qmlObjectTemplate->addItem( tr(
"Rectangle" ) );
1419 qmlObjectTemplate->addItem( tr(
"Pie Chart" ) );
1420 qmlObjectTemplate->addItem( tr(
"Bar Chart" ) );
1421 connect( qmlObjectTemplate, qOverload<int>( &QComboBox::activated ), qmlCode, [=](
int index ) {
1427 qmlCode->
setText( QString() );
1432 qmlCode->
setText( QStringLiteral(
"import QtQuick 2.0\n"
1437 " color: \"steelblue\"\n"
1438 " Text{ text: \"A rectangle\" }\n"
1444 qmlCode->
setText( QStringLiteral(
"import QtQuick 2.0\n"
1445 "import QtCharts 2.0\n"
1453 " PieSlice { label: \"First slice\"; value: 25 }\n"
1454 " PieSlice { label: \"Second slice\"; value: 45 }\n"
1455 " PieSlice { label: \"Third slice\"; value: 30 }\n"
1462 qmlCode->
setText( QStringLiteral(
"import QtQuick 2.0\n"
1463 "import QtCharts 2.0\n"
1466 " title: \"Bar series\"\n"
1469 " legend.alignment: Qt.AlignBottom\n"
1470 " antialiasing: true\n"
1479 " axisY: valueAxisY\n"
1480 " axisX: BarCategoryAxis { categories: [\"2007\", \"2008\", \"2009\", \"2010\", \"2011\", \"2012\" ] }\n"
1481 " BarSet { label: \"Bob\"; values: [2, 2, 3, 4, 5, 6] }\n"
1482 " BarSet { label: \"Susan\"; values: [5, 1, 2, 4, 1, 7] }\n"
1483 " BarSet { label: \"James\"; values: [3, 5, 8, 13, 5, 8] }\n"
1495 expressionWidget->registerExpressionContextGenerator(
this );
1496 expressionWidget->setLayer( mLayer );
1497 QToolButton *addFieldButton =
new QToolButton();
1500 QToolButton *editExpressionButton =
new QToolButton();
1502 editExpressionButton->setToolTip( tr(
"Insert/Edit Expression" ) );
1504 connect( addFieldButton, &QAbstractButton::clicked,
this, [=] {
1505 QString expression = expressionWidget->expression().trimmed().replace(
'"', QLatin1String(
"\\\"" ) );
1506 if ( !expression.isEmpty() )
1507 qmlCode->
insertText( QStringLiteral(
"expression.evaluate(\"%1\")" ).arg( expression ) );
1510 connect( editExpressionButton, &QAbstractButton::clicked,
this, [=] {
1512 expression.replace( QLatin1String(
"\\\"" ), QLatin1String(
"\"" ) );
1516 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
1517 if ( exprDlg.exec() == QDialog::Accepted && !exprDlg.expressionText().trimmed().isEmpty() )
1519 QString expression = exprDlg.expressionText().trimmed().replace(
'"', QLatin1String(
"\\\"" ) );
1520 if ( !expression.isEmpty() )
1521 qmlCode->
insertText( QStringLiteral(
"expression.evaluate(\"%1\")" ).arg( expression ) );
1525 layout->addWidget(
new QLabel( tr(
"Title" ) ) );
1526 layout->addWidget( title );
1527 QGroupBox *qmlCodeBox =
new QGroupBox( tr(
"QML Code" ) );
1528 qmlCodeBox->setLayout(
new QVBoxLayout );
1529 qmlCodeBox->layout()->addWidget( qmlObjectTemplate );
1530 QWidget *expressionWidgetBox =
new QWidget();
1531 qmlCodeBox->layout()->addWidget( expressionWidgetBox );
1532 expressionWidgetBox->setLayout(
new QHBoxLayout );
1533 expressionWidgetBox->layout()->setContentsMargins( 0, 0, 0, 0 );
1534 expressionWidgetBox->layout()->addWidget( expressionWidget );
1535 expressionWidgetBox->layout()->addWidget( addFieldButton );
1536 expressionWidgetBox->layout()->addWidget( editExpressionButton );
1537 expressionWidgetBox->layout()->addWidget( editExpressionButton );
1538 layout->addWidget( qmlCodeBox );
1539 layout->addWidget( qmlCode );
1541 qmlPreviewBox->setMinimumWidth( 200 );
1542 qmlPreviewBox->setWidget( qmlWrapper->
widget() );
1545 qmlSplitter->addWidget( qmlPreviewBox );
1546 qmlSplitter->setChildrenCollapsible(
false );
1547 qmlSplitter->setHandleWidth( 6 );
1548 qmlSplitter->setSizes( QList<int>() << 1 << 1 );
1550 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help );
1552 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1553 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1554 connect( buttonBox, &QDialogButtonBox::helpRequested, &dlg, [=] {
1555 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#other-widgets" ) );
1558 mainLayout->addWidget( buttonBox );
1563 qmlEdCfg.
qmlCode = qmlCode->text();
1564 itemData.
setName( title->text() );
1566 itemData.
setShowLabel( showLabelCheckbox->isChecked() );
1569 item->setText( 0, title->text() );
1579 dlg.setObjectName(
"HTML Form Configuration Widget" );
1581 dlg.setWindowTitle( tr(
"Configure HTML Widget" ) );
1583 QVBoxLayout *mainLayout =
new QVBoxLayout( &dlg );
1584 QSplitter *htmlSplitter =
new QSplitter();
1585 QWidget *htmlConfigWiget =
new QWidget();
1586 QVBoxLayout *layout =
new QVBoxLayout( htmlConfigWiget );
1587 layout->setContentsMargins( 0, 0, 0, 0 );
1588 mainLayout->addWidget( htmlSplitter );
1589 htmlSplitter->addWidget( htmlConfigWiget );
1590 htmlSplitter->setChildrenCollapsible(
false );
1591 htmlSplitter->setHandleWidth( 6 );
1592 htmlSplitter->setSizes( QList<int>() << 1 << 1 );
1593 layout->addWidget( baseWidget );
1595 QLineEdit *title =
new QLineEdit( itemData.
name() );
1599 htmlCode->setSizePolicy( QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Expanding );
1607 connect( htmlCode, &QgsCodeEditorHTML::textChanged,
this, [=] {
1615 expressionWidget->registerExpressionContextGenerator(
this );
1616 expressionWidget->setLayer( mLayer );
1617 QToolButton *addFieldButton =
new QToolButton();
1620 QToolButton *editExpressionButton =
new QToolButton();
1622 editExpressionButton->setToolTip( tr(
"Insert/Edit Expression" ) );
1624 connect( addFieldButton, &QAbstractButton::clicked,
this, [=] {
1625 QString expression = expressionWidget->expression().trimmed().replace(
'"', QLatin1String(
"\\\"" ) );
1626 if ( !expression.isEmpty() )
1627 htmlCode->
insertText( QStringLiteral(
"<script>document.write(expression.evaluate(\"%1\"));</script>" ).arg( expression ) );
1630 connect( editExpressionButton, &QAbstractButton::clicked,
this, [=] {
1632 expression.replace( QLatin1String(
"\\\"" ), QLatin1String(
"\"" ) );
1636 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
1637 if ( exprDlg.exec() == QDialog::Accepted && !exprDlg.expressionText().trimmed().isEmpty() )
1639 QString expression = exprDlg.expressionText().trimmed().replace(
'"', QLatin1String(
"\\\"" ) );
1640 if ( !expression.isEmpty() )
1641 htmlCode->
insertText( QStringLiteral(
"<script>document.write(expression.evaluate(\"%1\"));</script>" ).arg( expression ) );
1645 layout->addWidget(
new QLabel( tr(
"Title" ) ) );
1646 layout->addWidget( title );
1647 QGroupBox *expressionWidgetBox =
new QGroupBox( tr(
"HTML Code" ) );
1648 layout->addWidget( expressionWidgetBox );
1649 expressionWidgetBox->setLayout(
new QHBoxLayout );
1650 expressionWidgetBox->layout()->addWidget( expressionWidget );
1651 expressionWidgetBox->layout()->addWidget( addFieldButton );
1652 expressionWidgetBox->layout()->addWidget( editExpressionButton );
1653 layout->addWidget( htmlCode );
1655 htmlPreviewBox->setLayout(
new QGridLayout );
1656 htmlPreviewBox->setMinimumWidth( 200 );
1657 htmlPreviewBox->layout()->addWidget( htmlWrapper->
widget() );
1659 emit htmlCode->textChanged();
1660 htmlSplitter->addWidget( htmlPreviewBox );
1661 htmlSplitter->setChildrenCollapsible(
false );
1662 htmlSplitter->setHandleWidth( 6 );
1663 htmlSplitter->setSizes( QList<int>() << 1 << 1 );
1665 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help );
1667 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1668 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1669 connect( buttonBox, &QDialogButtonBox::helpRequested, &dlg, [=] {
1670 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#other-widgets" ) );
1673 mainLayout->addWidget( buttonBox );
1678 htmlEdCfg.
htmlCode = htmlCode->text();
1679 itemData.
setName( title->text() );
1681 itemData.
setShowLabel( showLabelCheckbox->isChecked() );
1684 item->setText( 0, title->text() );
1694 dlg.setObjectName(
"Text Form Configuration Widget" );
1696 dlg.setWindowTitle( tr(
"Configure Text Widget" ) );
1698 QVBoxLayout *mainLayout =
new QVBoxLayout( &dlg );
1699 QSplitter *textSplitter =
new QSplitter();
1700 QWidget *textConfigWiget =
new QWidget();
1701 QVBoxLayout *layout =
new QVBoxLayout( textConfigWiget );
1702 layout->setContentsMargins( 0, 0, 0, 0 );
1703 mainLayout->addWidget( textSplitter );
1704 textSplitter->addWidget( textConfigWiget );
1705 layout->addWidget( baseWidget );
1707 QLineEdit *title =
new QLineEdit( itemData.
name() );
1710 text->setSizePolicy( QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Expanding );
1718 connect( text, &QgsCodeEditorExpression::textChanged,
this, [=] {
1719 textWrapper->
setText( text->text() );
1726 expressionWidget->registerExpressionContextGenerator(
this );
1727 expressionWidget->setLayer( mLayer );
1728 QToolButton *addFieldButton =
new QToolButton();
1731 QToolButton *editExpressionButton =
new QToolButton();
1733 editExpressionButton->setToolTip( tr(
"Insert/Edit Expression" ) );
1735 connect( addFieldButton, &QAbstractButton::clicked,
this, [=] {
1736 QString expression = expressionWidget->expression().trimmed();
1737 if ( !expression.isEmpty() )
1738 text->
insertText( QStringLiteral(
"[%%1%]" ).arg( expression ) );
1740 connect( editExpressionButton, &QAbstractButton::clicked,
this, [=] {
1746 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
1747 if ( exprDlg.exec() == QDialog::Accepted && !exprDlg.expressionText().trimmed().isEmpty() )
1749 QString expression = exprDlg.expressionText().trimmed();
1750 if ( !expression.isEmpty() )
1751 text->
insertText( QStringLiteral(
"[%%1%]" ).arg( expression ) );
1755 layout->addWidget(
new QLabel( tr(
"Title" ) ) );
1756 layout->addWidget( title );
1757 QGroupBox *expressionWidgetBox =
new QGroupBox( tr(
"Text" ) );
1758 layout->addWidget( expressionWidgetBox );
1759 expressionWidgetBox->setLayout(
new QHBoxLayout );
1760 expressionWidgetBox->layout()->addWidget( expressionWidget );
1761 expressionWidgetBox->layout()->addWidget( addFieldButton );
1762 expressionWidgetBox->layout()->addWidget( editExpressionButton );
1763 layout->addWidget( text );
1765 textPreviewBox->setLayout(
new QGridLayout );
1766 textPreviewBox->setMinimumWidth( 200 );
1767 textPreviewBox->layout()->addWidget( textWrapper->
widget() );
1769 emit text->textChanged();
1770 textSplitter->addWidget( textPreviewBox );
1771 textSplitter->setChildrenCollapsible(
false );
1772 textSplitter->setHandleWidth( 6 );
1773 textSplitter->setSizes( QList<int>() << 1 << 1 );
1775 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help );
1777 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1778 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1779 connect( buttonBox, &QDialogButtonBox::helpRequested, &dlg, [=] {
1780 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#other-widgets" ) );
1783 mainLayout->addWidget( buttonBox );
1788 textEdCfg.
text = text->text();
1789 itemData.
setName( title->text() );
1791 itemData.
setShowLabel( showLabelCheckbox->isChecked() );
1794 item->setText( 0, title->text() );
1804 dlg.setObjectName(
"Spacer Form Configuration Widget" );
1806 dlg.setWindowTitle( tr(
"Configure Spacer Widget" ) );
1808 QVBoxLayout *mainLayout =
new QVBoxLayout();
1809 mainLayout->addWidget(
new QLabel( tr(
"Title" ) ) );
1810 QLineEdit *title =
new QLineEdit( itemData.
name() );
1811 mainLayout->addWidget( title );
1813 QHBoxLayout *cbLayout =
new QHBoxLayout();
1814 mainLayout->addLayout( cbLayout );
1815 dlg.setLayout( mainLayout );
1816 QCheckBox *cb =
new QCheckBox { &dlg };
1818 cbLayout->addWidget(
new QLabel( tr(
"Draw horizontal line" ), &dlg ) );
1819 cbLayout->addWidget( cb );
1821 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help );
1823 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1824 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1825 connect( buttonBox, &QDialogButtonBox::helpRequested, &dlg, [=] {
1826 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#other-widgets" ) );
1829 mainLayout->addWidget( buttonBox );
1834 spacerEdCfg.
drawLine = cb->isChecked();
1837 itemData.
setName( title->text() );
1839 item->setText( 0, title->text() );
1872 QTreeWidgetItemIterator it(
this );
1878 if ( selectedItems().count() == 1 && ( *it )->isSelected() == true )
1885 ( *it )->setSelected(
true );
1908 QString displayName;
1911 stream >> type >> name >> displayName;
1922 return mContainerType;
1927 mContainerType = type;
1937 mLabelStyle = labelStyle;
1947 mShowLabel = showLabel;
1952 return mVisibilityExpression;
1957 mVisibilityExpression = visibilityExpression;
1962 return mCollapsedExpression;
1967 mCollapsedExpression = collapsedExpression;
1972 return mRelationEditorConfiguration;
1977 mRelationEditorConfiguration = relationEditorConfiguration;
1982 return mQmlElementEditorConfiguration;
1987 mQmlElementEditorConfiguration = qmlElementEditorConfiguration;
1993 return mHtmlElementEditorConfiguration;
1998 mHtmlElementEditorConfiguration = htmlElementEditorConfiguration;
2003 return mSpacerElementEditorConfiguration;
2008 mSpacerElementEditorConfiguration = spacerElementEditorConfiguration;
2013 return mBackgroundColor;
2018 mBackgroundColor = backgroundColor;
2023 return mTextElementEditorConfiguration;
2028 mTextElementEditorConfiguration = textElementEditorConfiguration;
2031void QgsAttributesFormProperties::updatedFields()
2034 QMap<QString, FieldConfig> fieldConfigs;
2036 for (
int i = 0; i < fieldContainer->childCount(); i++ )
2038 QTreeWidgetItem *fieldItem = fieldContainer->child( i );
2039 const QString fieldName = fieldItem->data( 0,
FieldNameRole ).toString();
2041 fieldConfigs[fieldName] = cfg;
2047 for (
int i = 0; i < fieldContainer->childCount(); i++ )
2049 QTreeWidgetItem *fieldItem = fieldContainer->child( i );
2050 const QString fieldName = fieldItem->data( 0,
FieldNameRole ).toString();
2051 if ( fieldConfigs.contains( fieldName ) )
2058void QgsAttributesFormProperties::onContextMenuRequested( QPoint point )
2066 const DnDTreeItemData itemData = item->data( 0,
DnDTreeRole ).value<DnDTreeItemData>();
2069 const QClipboard *clipboard = QApplication::clipboard();
2070 const bool pasteEnabled = clipboard->mimeData()->hasFormat( QStringLiteral(
"application/x-qgsattributetabledesignerelementclipboard" ) );
2071 mActionPasteWidgetConfiguration->setEnabled( pasteEnabled );
2072 mAvailableWidgetsTreeContextMenu->popup( globalPos );
2076void QgsAttributesFormProperties::copyWidgetConfiguration()
2082 const DnDTreeItemData itemData = item->data( 0,
DnDTreeRole ).value<DnDTreeItemData>();
2086 const QString fieldName = item->data( 0,
FieldNameRole ).toString();
2096 QDomElement documentElement = doc.createElement( QStringLiteral(
"FormWidgetClipboard" ) );
2097 documentElement.setAttribute( QStringLiteral(
"name" ), field.
name() );
2102 QDomElement editWidgetElement = doc.createElement( QStringLiteral(
"editWidget" ) );
2103 documentElement.appendChild( editWidgetElement );
2104 editWidgetElement.setAttribute( QStringLiteral(
"type" ), widgetSetup.
type() );
2105 QDomElement editWidgetConfigElement = doc.createElement( QStringLiteral(
"config" ) );
2108 editWidgetElement.appendChild( editWidgetConfigElement );
2111 QDomElement splitPolicyElement = doc.createElement( QStringLiteral(
"splitPolicy" ) );
2113 documentElement.appendChild( splitPolicyElement );
2116 QDomElement duplicatePolicyElement = doc.createElement( QStringLiteral(
"duplicatePolicy" ) );
2118 documentElement.appendChild( duplicatePolicyElement );
2121 QDomElement defaultElem = doc.createElement( QStringLiteral(
"default" ) );
2124 documentElement.appendChild( defaultElem );
2127 QDomElement constraintElem = doc.createElement( QStringLiteral(
"constraint" ) );
2132 documentElement.appendChild( constraintElem );
2135 QDomElement constraintExpressionElem = doc.createElement( QStringLiteral(
"constraintExpression" ) );
2138 documentElement.appendChild( constraintExpressionElem );
2141 QDomElement widgetGeneralSettingsElem = doc.createElement( QStringLiteral(
"widgetGeneralSettings" ) );
2145 documentElement.appendChild( widgetGeneralSettingsElem );
2154 const QTreeWidgetItem *itemLayout =
mFormLayoutTree->selectedItems().at( 0 );
2155 const DnDTreeItemData itemDataLayout = itemLayout->data( 0,
DnDTreeRole ).value<DnDTreeItemData>();
2157 QDomElement displayElement = doc.createElement( QStringLiteral(
"widgetDisplay" ) );
2158 displayElement.setAttribute( QStringLiteral(
"showLabel" ), itemDataLayout.showLabel() );
2159 displayElement.setAttribute( QStringLiteral(
"horizontalStretch" ), itemDataLayout.horizontalStretch() );
2160 displayElement.setAttribute( QStringLiteral(
"verticalStretch" ), itemDataLayout.verticalStretch() );
2161 displayElement.appendChild( itemDataLayout.labelStyle().writeXml( doc ) );
2162 documentElement.appendChild( displayElement );
2165 doc.appendChild( documentElement );
2167 QMimeData *mimeData =
new QMimeData;
2168 mimeData->setData( QStringLiteral(
"application/x-qgsattributetabledesignerelementclipboard" ), doc.toByteArray() );
2169 QClipboard *clipboard = QApplication::clipboard();
2170 clipboard->setMimeData( mimeData );
2173void QgsAttributesFormProperties::pasteWidgetConfiguration()
2180 const QString fieldName = item->data( 0,
FieldNameRole ).toString();
2183 if ( fieldIndex < 0 )
2187 FieldConfig config = item->data( 0,
FieldConfigRole ).value<FieldConfig>();
2190 QClipboard *clipboard = QApplication::clipboard();
2191 if ( doc.setContent( clipboard->mimeData()->data( QStringLiteral(
"application/x-qgsattributetabledesignerelementclipboard" ) ) ) )
2193 QDomElement docElem = doc.documentElement();
2194 if ( docElem.tagName() != QLatin1String(
"FormWidgetClipboard" ) )
2203 const QDomElement fieldWidgetElement = docElem.firstChildElement( QStringLiteral(
"editWidget" ) );
2204 if ( !fieldWidgetElement.isNull() )
2206 const QString widgetType = fieldWidgetElement.attribute( QStringLiteral(
"type" ) );
2212 const QDomElement configElement = fieldWidgetElement.firstChildElement( QStringLiteral(
"config" ) );
2213 if ( !configElement.isNull() )
2215 const QDomElement optionsElem = configElement.childNodes().at( 0 ).toElement();
2218 if ( widgetType == QLatin1String(
"ValueRelation" ) )
2220 optionsMap[QStringLiteral(
"Value" )] = context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1:fields:%2:valuerelationvalue" ).arg(
mLayer->
id(), fieldName ), optionsMap[QStringLiteral(
"Value" )].toString() );
2223 config.mEditorWidgetType = widgetType;
2224 config.mEditorWidgetConfig = optionsMap;
2229 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 );
2234 const QDomElement splitPolicyElement = docElem.firstChildElement( QStringLiteral(
"splitPolicy" ) );
2235 if ( !splitPolicyElement.isNull() )
2238 config.mSplitPolicy = policy;
2242 const QDomElement duplicatePolicyElement = docElem.firstChildElement( QStringLiteral(
"duplicatePolicy" ) );
2243 if ( !duplicatePolicyElement.isNull() )
2246 config.mDuplicatePolicy = policy;
2250 const QDomElement defaultElement = docElem.firstChildElement( QStringLiteral(
"default" ) );
2251 if ( !defaultElement.isNull() )
2253 mAttributeTypeDialog->setDefaultValueExpression( defaultElement.attribute( QStringLiteral(
"expression" ) ) );
2254 mAttributeTypeDialog->setApplyDefaultValueOnUpdate( defaultElement.attribute( QStringLiteral(
"applyOnUpdate" ) ).toInt() );
2260 const QDomElement constraintElement = docElem.firstChildElement( QStringLiteral(
"constraint" ) );
2261 if ( !constraintElement.isNull() )
2263 const int intConstraints = constraintElement.attribute( QStringLiteral(
"constraints" ), QStringLiteral(
"0" ) ).toInt();
2289 const int uniqueStrength = constraintElement.attribute( QStringLiteral(
"unique_strength" ), QStringLiteral(
"1" ) ).toInt();
2290 const int notNullStrength = constraintElement.attribute( QStringLiteral(
"notnull_strength" ), QStringLiteral(
"1" ) ).toInt();
2291 const int expStrength = constraintElement.attribute( QStringLiteral(
"exp_strength" ), QStringLiteral(
"1" ) ).toInt();
2302 const QDomElement constraintExpressionElement = docElem.firstChildElement( QStringLiteral(
"constraintExpression" ) );
2303 if ( !constraintExpressionElement.isNull() )
2305 QString expression = constraintExpressionElement.attribute( QStringLiteral(
"exp" ), QString() );
2306 QString description = constraintExpressionElement.attribute( QStringLiteral(
"desc" ), QString() );
2310 config.mFieldConstraints = fieldConstraints;
2312 const QDomElement widgetGeneralSettingsElement = docElem.firstChildElement( QStringLiteral(
"widgetGeneralSettings" ) );
2313 if ( !widgetGeneralSettingsElement.isNull() )
2315 const int editable = widgetGeneralSettingsElement.attribute( QStringLiteral(
"editable" ), QStringLiteral(
"0" ) ).toInt();
2316 const int reuse = widgetGeneralSettingsElement.attribute( QStringLiteral(
"reuse_last_values" ), QStringLiteral(
"0" ) ).toInt();
2317 const int labelOnTop = widgetGeneralSettingsElement.attribute( QStringLiteral(
"label_on_top" ), QStringLiteral(
"0" ) ).toInt();
2319 config.mEditable = editable;
2320 config.mReuseLastValues = reuse;
2321 config.mLabelOnTop = labelOnTop;
2324 loadAttributeTypeDialogFromConfiguration( config );
2329 const QDomElement displayElement = docElem.firstChildElement( QStringLiteral(
"widgetDisplay" ) );
2330 if ( !displayElement.isNull() )
2332 const int showLabel = displayElement.attribute( QStringLiteral(
"showLabel" ), QStringLiteral(
"0" ) ).toInt();
2333 const int horizontalStretch = displayElement.attribute( QStringLiteral(
"horizontalStretch" ), QStringLiteral(
"0" ) ).toInt();
2334 const int verticalStretch = displayElement.attribute( QStringLiteral(
"verticalStretch" ), QStringLiteral(
"0" ) ).toInt();
2336 style.
readXml( displayElement );
AttributeEditorContainerType
Attribute editor container types.
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.
@ Warning
Warning message.
FieldDomainSplitPolicy
Split policy for field domains.
@ Duplicate
Duplicate original value.
FieldDuplicatePolicy
Duplicate policy for fields.
@ Duplicate
Duplicate original value.
@ Action
A layer action element.
@ QmlElement
A QML element.
@ HtmlElement
A HTML element.
@ TextElement
A text element.
@ SpacerElement
A spacer element.
QList< QgsAction > actions(const QString &actionScope=QString()) const
Returns a list of actions that are available in the given action scope.
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.
This element will load a layer action onto the form.
const QgsAction & action(const QgsVectorLayer *layer) const
Returns the (possibly lazy loaded) action for the given layer.
This is a container for attribute editors, used to group them visually in the attribute form if it is...
virtual void addChildElement(QgsAttributeEditorElement *element)
Add a child element to this container.
QgsOptionalExpression visibilityExpression() const
The visibility expression is used in the attribute form to show or hide this container based on an ex...
void setColumnCount(int columnCount)
Set the number of columns in this group.
void setVisibilityExpression(const QgsOptionalExpression &visibilityExpression)
The visibility expression is used in the attribute form to show or hide this container based on an ex...
QgsOptionalExpression collapsedExpression() const
The collapsed expression is used in the attribute form to set the collapsed status of the group box c...
bool collapsed() const
For group box containers returns true if this group box is collapsed.
Qgis::AttributeEditorContainerType type() const
Returns the container type.
void setType(Qgis::AttributeEditorContainerType type)
Sets the container type.
void setCollapsedExpression(const QgsOptionalExpression &collapsedExpression)
The collapsed expression is used in the attribute form to set the collapsed status of the group box o...
QList< QgsAttributeEditorElement * > children() const
Gets a list of the children elements of this container.
QColor backgroundColor() const
Returns the background color of the container.
void setCollapsed(bool collapsed)
For group box containers sets if this group box is collapsed.
int columnCount() const
Gets the number of columns in this group.
void setBackgroundColor(const QColor &backgroundColor)
Sets the background color to backgroundColor.
This is an abstract base class for any elements of a drag and drop form.
void setHorizontalStretch(int stretch)
Sets the horizontal stretch factor for the element.
LabelStyle labelStyle() const
Returns the label style.
void setLabelStyle(const LabelStyle &labelStyle)
Sets the labelStyle.
Qgis::AttributeEditorType type() const
The type of this element.
int verticalStretch() const
Returns the vertical stretch factor for the element.
bool showLabel() const
Controls if this element should be labeled with a title (field, relation or groupname).
QString name() const
Returns the name of this element.
void setVerticalStretch(int stretch)
Sets the vertical stretch factor for the element.
void setShowLabel(bool showLabel)
Controls if this element should be labeled with a title (field, relation or groupname).
int horizontalStretch() const
Returns the horizontal stretch factor for the element.
This element will load a field's widget onto the form.
An attribute editor widget that will represent arbitrary HTML code.
QString htmlCode() const
The Html code that will be represented within this widget.
void setHtmlCode(const QString &htmlCode)
Sets the HTML code that will be represented within this widget to htmlCode.
An attribute editor widget that will represent arbitrary QML code.
QString qmlCode() const
The QML code that will be represented within this widget.
void setQmlCode(const QString &qmlCode)
Sets the QML code that will be represented within this widget to qmlCode.
This element will load a relation editor onto the form.
void setNmRelationId(const QVariant &nmRelationId=QVariant())
Sets nmRelationId for the relation id of the second relation involved in an N:M relation.
void setRelationWidgetTypeId(const QString &relationWidgetTypeId)
Sets the relation widget type.
const QgsRelation & relation() const
Gets the id of the relation which shall be embedded.
QVariantMap relationEditorConfiguration() const
Returns the relation editor widget configuration.
void setForceSuppressFormPopup(bool forceSuppressFormPopup)
Sets force suppress form popup status to forceSuppressFormPopup.
QVariant nmRelationId() const
Determines the relation id of the second relation involved in an N:M relation.
bool forceSuppressFormPopup() const
Determines the force suppress form popup status.
QString relationWidgetTypeId() const
Returns the current relation widget type id.
void setRelationEditorConfiguration(const QVariantMap &config)
Sets the relation editor configuration.
void setLabel(const QString &label=QString())
Sets label for this element If it's empty it takes the relation id as label.
QString label() const
Determines the label of this element.
An attribute editor widget that will represent a spacer.
void setDrawLine(bool drawLine)
Sets a flag to define if the spacer element will contain an horizontal line.
bool drawLine() const
Returns true if the spacer element will contain an horizontal line.
An attribute editor widget that will represent arbitrary text code.
void setText(const QString &text)
Sets the text that will be represented within this widget to text.
QString text() const
The Text that will be represented within this widget.
This class overrides mime type handling to be able to work with the drag and drop attribute editor.
void setType(QgsAttributesDnDTree::Type value)
void dropEvent(QDropEvent *event) override
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QTreeWidgetItem * addContainer(QTreeWidgetItem *parent, const QString &title, int columnCount, Qgis::AttributeEditorContainerType type)
Adds a new container to parent.
QStringList mimeTypes() const override
QgsAttributesDnDTree(QgsVectorLayer *layer, QWidget *parent=nullptr)
QMimeData * mimeData(const QList< QTreeWidgetItem * > &items) const override
bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) override
void dragMoveEvent(QDragMoveEvent *event) override
Is called when mouse is moved over attributes tree before a drop event.
void selectFirstMatchingItem(const QgsAttributesFormProperties::DnDTreeItemData &data)
QTreeWidgetItem * addItem(QTreeWidgetItem *parent, const QgsAttributesFormProperties::DnDTreeItemData &data, int index=-1, const QIcon &icon=QIcon())
Adds a new item to a parent.
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:
The QgsDefaultValue class 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
QgsFieldConstraints constraints
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
Container of fields for a vector layer.
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).
int size() const
Returns number of items.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QIcon iconForField(int fieldIdx, bool considerOrigin=false) const
Returns an icon corresponding to a field index, based on the field's type and source.
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.
An expression with an additional enabled flag.
A polymorphic relation consists of the same properties like a normal relation except for the referenc...
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.
QgsRelationManager * relationManager
static QgsProject * instance()
Returns the QgsProject singleton instance.
int count() const
Returns the number of properties contained within the collection.
The class is used as a container of context for various read/write operations on other objects.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
QList< QgsRelation > referencedRelations(const QgsVectorLayer *layer=nullptr) const
Gets all relations where this layer is the referenced part (i.e.
Q_INVOKABLE QgsRelation relation(const QString &id) const
Gets access to a relation by its id.
Represents a relationship between two vector layers.
QgsVectorLayer * referencedLayer
static const QgsSettingsEntryBool * settingsDigitizingDisableEnterAttributeValuesDialog
Settings entry digitizing disable enter attribute values dialog.
This class is a composition of two QSettings instances:
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 data sets.
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 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.
#define QgsDebugError(str)
The TabStyle struct defines color and font overrides for form fields, tabs and groups labels.
void readXml(const QDomNode &node)
Reads configuration from node.