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 );
646 storeAttributeWidgetEdit();
648 clearAttributeTypeFrame();
650 if ( emitter->selectedItems().count() != 1 )
652 receiver->clearSelection();
656 const DnDTreeItemData itemData = emitter->selectedItems().at( 0 )->data( 0,
DnDTreeRole ).value<DnDTreeItemData>();
657 switch ( itemData.type() )
664 loadAttributeWidgetEdit();
668 loadInfoWidget( tr(
"This configuration is available in the Drag and Drop Designer" ) );
676 loadAttributeWidgetEdit();
677 loadAttributeTypeDialog();
682 receiver->clearSelection();
683 loadAttributeContainerEdit();
690 loadInfoWidget( action.html() );
700 loadInfoWidget( tr(
"This configuration is available with double-click in the Drag and Drop Designer" ) );
704 loadInfoWidget( tr(
"This configuration is available with double-click" ) );
706 receiver->clearSelection();
711 receiver->clearSelection();
718void QgsAttributesFormProperties::clearAttributeTypeFrame()
746void QgsAttributesFormProperties::onInvertSelectionButtonClicked(
bool checked )
751 for (
int i = 0; i < rootItem->childCount(); ++i )
753 rootItem->child( i )->setSelected( !selectedItemList.contains( rootItem->child( i ) ) );
757void QgsAttributesFormProperties::addContainer()
759 QList<QgsAddAttributeFormContainerDialog::ContainerPair> existingContainerList;
763 const DnDTreeItemData itemData = ( *it )->data( 0,
DnDTreeRole ).value<DnDTreeItemData>();
769 QTreeWidgetItem *currentItem =
mFormLayoutTree->selectedItems().value( 0 );
772 if ( !dialog.exec() )
775 const QString name = dialog.name();
776 QTreeWidgetItem *parentContainerItem = dialog.parentContainerItem();
780void QgsAttributesFormProperties::removeTabOrGroupButton()
786 const QList<QTreeWidgetItem *> items =
mFormLayoutTree->selectedItems();
790 delete items.at( 0 );
800 switch ( itemData.
type() )
849 for (
int t = 0; t < item->childCount(); t++ )
856 widgetDef = container;
907void QgsAttributesFormProperties::mEditorLayoutComboBox_currentIndexChanged(
int )
913 mFormLayoutWidget->setVisible(
false );
914 mUiFileFrame->setVisible(
false );
915 mAddTabOrGroupButton->setVisible(
false );
916 mRemoveTabOrGroupButton->setVisible(
false );
917 mInvertSelectionButton->setVisible(
false );
921 mFormLayoutWidget->setVisible(
true );
922 mUiFileFrame->setVisible(
false );
923 mAddTabOrGroupButton->setVisible(
true );
924 mRemoveTabOrGroupButton->setVisible(
true );
925 mInvertSelectionButton->setVisible(
true );
930 mFormLayoutWidget->setVisible(
false );
931 mUiFileFrame->setVisible(
true );
932 mAddTabOrGroupButton->setVisible(
false );
933 mRemoveTabOrGroupButton->setVisible(
false );
934 mInvertSelectionButton->setVisible(
false );
939void QgsAttributesFormProperties::mTbInitCode_clicked()
948 if ( !attributesFormInitCode.exec() )
951 mInitCodeSource = attributesFormInitCode.
codeSource();
952 mInitCode = attributesFormInitCode.
initCode();
957void QgsAttributesFormProperties::pbnSelectEditForm_clicked()
960 const QString lastUsedDir = myQSettings.
value( QStringLiteral(
"style/lastUIDir" ), QDir::homePath() ).toString();
961 const QString uifilename = QFileDialog::getOpenFileName(
this, tr(
"Select edit form" ), lastUsedDir, tr(
"UI file" ) +
" (*.ui)" );
963 if ( uifilename.isNull() )
966 const QFileInfo fi( uifilename );
967 myQSettings.
setValue( QStringLiteral(
"style/lastUIDir" ), fi.path() );
968 mEditFormLineEdit->setText( uifilename );
973 storeAttributeWidgetEdit();
974 storeAttributeContainerEdit();
975 storeAttributeTypeDialog();
981 storeAttributeWidgetEdit();
982 storeAttributeContainerEdit();
983 storeAttributeTypeDialog();
989 for (
int i = 0; i < fieldContainer->childCount(); i++ )
991 QTreeWidgetItem *fieldItem = fieldContainer->child( i );
994 const QString fieldName { fieldItem->data( 0,
FieldNameRole ).toString() };
1046 for (
int t = 0; t <
mFormLayoutTree->invisibleRootItem()->childCount(); t++ )
1048 QTreeWidgetItem *tabItem =
mFormLayoutTree->invisibleRootItem()->child( t );
1050 if ( editorElement )
1051 editFormConfig.
addTab( editorElement );
1054 editFormConfig.
setUiForm( mEditFormLineEdit->text() );
1068 for (
int i = 0; i < relationContainer->childCount(); i++ )
1070 QTreeWidgetItem *relationItem = relationContainer->child( i );
1073 for (
int t = 0; t <
mFormLayoutTree->invisibleRootItem()->childCount(); t++ )
1075 QTreeWidgetItem *tabItem =
mFormLayoutTree->invisibleRootItem()->child( t );
1078 if ( tabItemData.
type() == itemData.
type() && tabItemData.
name() == itemData.
name() )
1115QgsAttributesFormProperties::FieldConfig::operator QVariant()
1117 return QVariant::fromValue<QgsAttributesFormProperties::FieldConfig>( *
this );
1124QgsAttributesFormProperties::RelationEditorConfiguration::operator QVariant()
1126 return QVariant::fromValue<QgsAttributesFormProperties::RelationEditorConfiguration>( *
this );
1135 QTreeWidgetItem *newItem =
new QTreeWidgetItem( QStringList() << title );
1136 newItem->setBackground( 0, QBrush( Qt::lightGray ) );
1137 newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled );
1142 parent->addChild( newItem );
1143 newItem->setExpanded(
true );
1148 : QTreeWidget( parent )
1151 connect(
this, &QTreeWidget::itemDoubleClicked,
this, &QgsAttributesDnDTree::onItemDoubleClicked );
1156 QTreeWidgetItem *newItem =
new QTreeWidgetItem( QStringList() << data.
name() );
1158 switch ( data.
type() )
1167 newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
1173 newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled );
1174 newItem->setBackground( 0, QBrush( Qt::lightGray ) );
1181 newItem->setIcon( 0, icon );
1188 newItem->setText( 0, tr(
"Invalid relation" ) );
1189 newItem->setForeground( 0, QColor( 255, 0, 0 ) );
1194 parent->addChild( newItem );
1196 parent->insertChild( index, newItem );
1208 const QMimeData *data =
event->mimeData();
1210 if ( data->hasFormat( QStringLiteral(
"application/x-qgsattributetabledesignerelement" ) ) )
1214 QByteArray itemData = data->data( QStringLiteral(
"application/x-qgsattributetabledesignerelement" ) );
1215 QDataStream stream( &itemData, QIODevice::ReadOnly );
1216 stream >> itemElement;
1219 if ( event->source() ==
this )
1221 event->setDropAction( Qt::MoveAction );
1229 QTreeWidget::dragMoveEvent( event );
1235 bool bDropSuccessful =
false;
1237 if ( action == Qt::IgnoreAction )
1239 bDropSuccessful =
true;
1241 else if ( data->hasFormat( QStringLiteral(
"application/x-qgsattributetabledesignerelement" ) ) )
1243 QByteArray itemData = data->data( QStringLiteral(
"application/x-qgsattributetabledesignerelement" ) );
1244 QDataStream stream( &itemData, QIODevice::ReadOnly );
1247 while ( !stream.atEnd() )
1249 stream >> itemElement;
1251 QTreeWidgetItem *newItem;
1255 newItem =
addItem( parent, itemElement, index++ );
1256 bDropSuccessful =
true;
1260 newItem =
addItem( invisibleRootItem(), itemElement, index++ );
1261 bDropSuccessful =
true;
1266 onItemDoubleClicked( newItem, 0 );
1271 onItemDoubleClicked( newItem, 0 );
1276 onItemDoubleClicked( newItem, 0 );
1281 onItemDoubleClicked( newItem, 0 );
1285 newItem->setSelected(
true );
1289 return bDropSuccessful;
1294 if ( !event->mimeData()->hasFormat( QStringLiteral(
"application/x-qgsattributetabledesignerelement" ) ) )
1297 if ( event->source() ==
this )
1299 event->setDropAction( Qt::MoveAction );
1302 QTreeWidget::dropEvent( event );
1307 return QStringList() << QStringLiteral(
"application/x-qgsattributetabledesignerelement" );
1310#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
1316 if ( items.count() <= 0 )
1319 const QStringList types = mimeTypes();
1321 if ( types.isEmpty() )
1324 QMimeData *data =
new QMimeData();
1325 const QString format = types.at( 0 );
1327 QDataStream stream( &encoded, QIODevice::WriteOnly );
1329 const auto constItems = items;
1330 for (
const QTreeWidgetItem *item : constItems )
1340 data->setData( format, encoded );
1345void QgsAttributesDnDTree::onItemDoubleClicked( QTreeWidgetItem *item,
int column )
1351 QGroupBox *baseData =
new QGroupBox( tr(
"Base configuration" ) );
1353 QFormLayout *baseLayout =
new QFormLayout();
1354 baseData->setLayout( baseLayout );
1355 QCheckBox *showLabelCheckbox =
new QCheckBox( QStringLiteral(
"Show label" ) );
1356 showLabelCheckbox->setChecked( itemData.
showLabel() );
1357 baseLayout->addRow( showLabelCheckbox );
1358 QWidget *baseWidget =
new QWidget();
1359 baseWidget->setLayout( baseLayout );
1361 switch ( itemData.
type() )
1376 dlg.setObjectName(
"QML Form Configuration Widget" );
1378 dlg.setWindowTitle( tr(
"Configure QML Widget" ) );
1380 QVBoxLayout *mainLayout =
new QVBoxLayout( &dlg );
1381 QSplitter *qmlSplitter =
new QSplitter();
1382 QWidget *qmlConfigWiget =
new QWidget();
1383 QVBoxLayout *layout =
new QVBoxLayout( qmlConfigWiget );
1384 layout->setContentsMargins( 0, 0, 0, 0 );
1385 mainLayout->addWidget( qmlSplitter );
1386 qmlSplitter->addWidget( qmlConfigWiget );
1387 layout->addWidget( baseWidget );
1389 QLineEdit *title =
new QLineEdit( itemData.
name() );
1408 QComboBox *qmlObjectTemplate =
new QComboBox();
1409 qmlObjectTemplate->addItem( tr(
"Free Text…" ) );
1410 qmlObjectTemplate->addItem( tr(
"Rectangle" ) );
1411 qmlObjectTemplate->addItem( tr(
"Pie Chart" ) );
1412 qmlObjectTemplate->addItem( tr(
"Bar Chart" ) );
1413 connect( qmlObjectTemplate, qOverload<int>( &QComboBox::activated ), qmlCode, [=](
int index ) {
1419 qmlCode->
setText( QString() );
1424 qmlCode->
setText( QStringLiteral(
"import QtQuick 2.0\n"
1429 " color: \"steelblue\"\n"
1430 " Text{ text: \"A rectangle\" }\n"
1436 qmlCode->
setText( QStringLiteral(
"import QtQuick 2.0\n"
1437 "import QtCharts 2.0\n"
1445 " PieSlice { label: \"First slice\"; value: 25 }\n"
1446 " PieSlice { label: \"Second slice\"; value: 45 }\n"
1447 " PieSlice { label: \"Third slice\"; value: 30 }\n"
1454 qmlCode->
setText( QStringLiteral(
"import QtQuick 2.0\n"
1455 "import QtCharts 2.0\n"
1458 " title: \"Bar series\"\n"
1461 " legend.alignment: Qt.AlignBottom\n"
1462 " antialiasing: true\n"
1471 " axisY: valueAxisY\n"
1472 " axisX: BarCategoryAxis { categories: [\"2007\", \"2008\", \"2009\", \"2010\", \"2011\", \"2012\" ] }\n"
1473 " BarSet { label: \"Bob\"; values: [2, 2, 3, 4, 5, 6] }\n"
1474 " BarSet { label: \"Susan\"; values: [5, 1, 2, 4, 1, 7] }\n"
1475 " BarSet { label: \"James\"; values: [3, 5, 8, 13, 5, 8] }\n"
1487 expressionWidget->registerExpressionContextGenerator(
this );
1488 expressionWidget->setLayer( mLayer );
1489 QToolButton *addFieldButton =
new QToolButton();
1492 QToolButton *editExpressionButton =
new QToolButton();
1494 editExpressionButton->setToolTip( tr(
"Insert/Edit Expression" ) );
1496 connect( addFieldButton, &QAbstractButton::clicked,
this, [=] {
1497 QString expression = expressionWidget->expression().trimmed().replace(
'"', QLatin1String(
"\\\"" ) );
1498 if ( !expression.isEmpty() )
1499 qmlCode->
insertText( QStringLiteral(
"expression.evaluate(\"%1\")" ).arg( expression ) );
1502 connect( editExpressionButton, &QAbstractButton::clicked,
this, [=] {
1504 expression.replace( QLatin1String(
"\\\"" ), QLatin1String(
"\"" ) );
1508 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
1509 if ( exprDlg.exec() == QDialog::Accepted && !exprDlg.expressionText().trimmed().isEmpty() )
1511 QString expression = exprDlg.expressionText().trimmed().replace(
'"', QLatin1String(
"\\\"" ) );
1512 if ( !expression.isEmpty() )
1513 qmlCode->
insertText( QStringLiteral(
"expression.evaluate(\"%1\")" ).arg( expression ) );
1517 layout->addWidget(
new QLabel( tr(
"Title" ) ) );
1518 layout->addWidget( title );
1519 QGroupBox *qmlCodeBox =
new QGroupBox( tr(
"QML Code" ) );
1520 qmlCodeBox->setLayout(
new QVBoxLayout );
1521 qmlCodeBox->layout()->addWidget( qmlObjectTemplate );
1522 QWidget *expressionWidgetBox =
new QWidget();
1523 qmlCodeBox->layout()->addWidget( expressionWidgetBox );
1524 expressionWidgetBox->setLayout(
new QHBoxLayout );
1525 expressionWidgetBox->layout()->setContentsMargins( 0, 0, 0, 0 );
1526 expressionWidgetBox->layout()->addWidget( expressionWidget );
1527 expressionWidgetBox->layout()->addWidget( addFieldButton );
1528 expressionWidgetBox->layout()->addWidget( editExpressionButton );
1529 expressionWidgetBox->layout()->addWidget( editExpressionButton );
1530 layout->addWidget( qmlCodeBox );
1531 layout->addWidget( qmlCode );
1533 qmlPreviewBox->setMinimumWidth( 200 );
1534 qmlPreviewBox->setWidget( qmlWrapper->
widget() );
1537 qmlSplitter->addWidget( qmlPreviewBox );
1538 qmlSplitter->setChildrenCollapsible(
false );
1539 qmlSplitter->setHandleWidth( 6 );
1540 qmlSplitter->setSizes( QList<int>() << 1 << 1 );
1542 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help );
1544 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1545 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1546 connect( buttonBox, &QDialogButtonBox::helpRequested, &dlg, [=] {
1547 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#other-widgets" ) );
1550 mainLayout->addWidget( buttonBox );
1555 qmlEdCfg.
qmlCode = qmlCode->text();
1556 itemData.
setName( title->text() );
1558 itemData.
setShowLabel( showLabelCheckbox->isChecked() );
1561 item->setText( 0, title->text() );
1571 dlg.setObjectName(
"HTML Form Configuration Widget" );
1573 dlg.setWindowTitle( tr(
"Configure HTML Widget" ) );
1575 QVBoxLayout *mainLayout =
new QVBoxLayout( &dlg );
1576 QSplitter *htmlSplitter =
new QSplitter();
1577 QWidget *htmlConfigWiget =
new QWidget();
1578 QVBoxLayout *layout =
new QVBoxLayout( htmlConfigWiget );
1579 layout->setContentsMargins( 0, 0, 0, 0 );
1580 mainLayout->addWidget( htmlSplitter );
1581 htmlSplitter->addWidget( htmlConfigWiget );
1582 htmlSplitter->setChildrenCollapsible(
false );
1583 htmlSplitter->setHandleWidth( 6 );
1584 htmlSplitter->setSizes( QList<int>() << 1 << 1 );
1585 layout->addWidget( baseWidget );
1587 QLineEdit *title =
new QLineEdit( itemData.
name() );
1591 htmlCode->setSizePolicy( QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Expanding );
1599 connect( htmlCode, &QgsCodeEditorHTML::textChanged,
this, [=] {
1607 expressionWidget->registerExpressionContextGenerator(
this );
1608 expressionWidget->setLayer( mLayer );
1609 QToolButton *addFieldButton =
new QToolButton();
1612 QToolButton *editExpressionButton =
new QToolButton();
1614 editExpressionButton->setToolTip( tr(
"Insert/Edit Expression" ) );
1616 connect( addFieldButton, &QAbstractButton::clicked,
this, [=] {
1617 QString expression = expressionWidget->expression().trimmed().replace(
'"', QLatin1String(
"\\\"" ) );
1618 if ( !expression.isEmpty() )
1619 htmlCode->
insertText( QStringLiteral(
"<script>document.write(expression.evaluate(\"%1\"));</script>" ).arg( expression ) );
1622 connect( editExpressionButton, &QAbstractButton::clicked,
this, [=] {
1624 expression.replace( QLatin1String(
"\\\"" ), QLatin1String(
"\"" ) );
1628 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
1629 if ( exprDlg.exec() == QDialog::Accepted && !exprDlg.expressionText().trimmed().isEmpty() )
1631 QString expression = exprDlg.expressionText().trimmed().replace(
'"', QLatin1String(
"\\\"" ) );
1632 if ( !expression.isEmpty() )
1633 htmlCode->
insertText( QStringLiteral(
"<script>document.write(expression.evaluate(\"%1\"));</script>" ).arg( expression ) );
1637 layout->addWidget(
new QLabel( tr(
"Title" ) ) );
1638 layout->addWidget( title );
1639 QGroupBox *expressionWidgetBox =
new QGroupBox( tr(
"HTML Code" ) );
1640 layout->addWidget( expressionWidgetBox );
1641 expressionWidgetBox->setLayout(
new QHBoxLayout );
1642 expressionWidgetBox->layout()->addWidget( expressionWidget );
1643 expressionWidgetBox->layout()->addWidget( addFieldButton );
1644 expressionWidgetBox->layout()->addWidget( editExpressionButton );
1645 layout->addWidget( htmlCode );
1647 htmlPreviewBox->setLayout(
new QGridLayout );
1648 htmlPreviewBox->setMinimumWidth( 200 );
1649 htmlPreviewBox->layout()->addWidget( htmlWrapper->
widget() );
1651 emit htmlCode->textChanged();
1652 htmlSplitter->addWidget( htmlPreviewBox );
1653 htmlSplitter->setChildrenCollapsible(
false );
1654 htmlSplitter->setHandleWidth( 6 );
1655 htmlSplitter->setSizes( QList<int>() << 1 << 1 );
1657 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help );
1659 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1660 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1661 connect( buttonBox, &QDialogButtonBox::helpRequested, &dlg, [=] {
1662 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#other-widgets" ) );
1665 mainLayout->addWidget( buttonBox );
1670 htmlEdCfg.
htmlCode = htmlCode->text();
1671 itemData.
setName( title->text() );
1673 itemData.
setShowLabel( showLabelCheckbox->isChecked() );
1676 item->setText( 0, title->text() );
1686 dlg.setObjectName(
"Text Form Configuration Widget" );
1688 dlg.setWindowTitle( tr(
"Configure Text Widget" ) );
1690 QVBoxLayout *mainLayout =
new QVBoxLayout( &dlg );
1691 QSplitter *textSplitter =
new QSplitter();
1692 QWidget *textConfigWiget =
new QWidget();
1693 QVBoxLayout *layout =
new QVBoxLayout( textConfigWiget );
1694 layout->setContentsMargins( 0, 0, 0, 0 );
1695 mainLayout->addWidget( textSplitter );
1696 textSplitter->addWidget( textConfigWiget );
1697 layout->addWidget( baseWidget );
1699 QLineEdit *title =
new QLineEdit( itemData.
name() );
1702 text->setSizePolicy( QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Expanding );
1710 connect( text, &QgsCodeEditorExpression::textChanged,
this, [=] {
1711 textWrapper->
setText( text->text() );
1718 expressionWidget->registerExpressionContextGenerator(
this );
1719 expressionWidget->setLayer( mLayer );
1720 QToolButton *addFieldButton =
new QToolButton();
1723 QToolButton *editExpressionButton =
new QToolButton();
1725 editExpressionButton->setToolTip( tr(
"Insert/Edit Expression" ) );
1727 connect( addFieldButton, &QAbstractButton::clicked,
this, [=] {
1728 QString expression = expressionWidget->expression().trimmed();
1729 if ( !expression.isEmpty() )
1730 text->
insertText( QStringLiteral(
"[%%1%]" ).arg( expression ) );
1732 connect( editExpressionButton, &QAbstractButton::clicked,
this, [=] {
1738 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
1739 if ( exprDlg.exec() == QDialog::Accepted && !exprDlg.expressionText().trimmed().isEmpty() )
1741 QString expression = exprDlg.expressionText().trimmed();
1742 if ( !expression.isEmpty() )
1743 text->
insertText( QStringLiteral(
"[%%1%]" ).arg( expression ) );
1747 layout->addWidget(
new QLabel( tr(
"Title" ) ) );
1748 layout->addWidget( title );
1749 QGroupBox *expressionWidgetBox =
new QGroupBox( tr(
"Text" ) );
1750 layout->addWidget( expressionWidgetBox );
1751 expressionWidgetBox->setLayout(
new QHBoxLayout );
1752 expressionWidgetBox->layout()->addWidget( expressionWidget );
1753 expressionWidgetBox->layout()->addWidget( addFieldButton );
1754 expressionWidgetBox->layout()->addWidget( editExpressionButton );
1755 layout->addWidget( text );
1757 textPreviewBox->setLayout(
new QGridLayout );
1758 textPreviewBox->setMinimumWidth( 200 );
1759 textPreviewBox->layout()->addWidget( textWrapper->
widget() );
1761 emit text->textChanged();
1762 textSplitter->addWidget( textPreviewBox );
1763 textSplitter->setChildrenCollapsible(
false );
1764 textSplitter->setHandleWidth( 6 );
1765 textSplitter->setSizes( QList<int>() << 1 << 1 );
1767 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help );
1769 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1770 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1771 connect( buttonBox, &QDialogButtonBox::helpRequested, &dlg, [=] {
1772 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#other-widgets" ) );
1775 mainLayout->addWidget( buttonBox );
1780 textEdCfg.
text = text->text();
1781 itemData.
setName( title->text() );
1783 itemData.
setShowLabel( showLabelCheckbox->isChecked() );
1786 item->setText( 0, title->text() );
1796 dlg.setObjectName(
"Spacer Form Configuration Widget" );
1798 dlg.setWindowTitle( tr(
"Configure Spacer Widget" ) );
1800 QVBoxLayout *mainLayout =
new QVBoxLayout();
1801 mainLayout->addWidget(
new QLabel( tr(
"Title" ) ) );
1802 QLineEdit *title =
new QLineEdit( itemData.
name() );
1803 mainLayout->addWidget( title );
1805 QHBoxLayout *cbLayout =
new QHBoxLayout();
1806 mainLayout->addLayout( cbLayout );
1807 dlg.setLayout( mainLayout );
1808 QCheckBox *cb =
new QCheckBox { &dlg };
1810 cbLayout->addWidget(
new QLabel( tr(
"Draw horizontal line" ), &dlg ) );
1811 cbLayout->addWidget( cb );
1813 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help );
1815 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1816 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1817 connect( buttonBox, &QDialogButtonBox::helpRequested, &dlg, [=] {
1818 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#other-widgets" ) );
1821 mainLayout->addWidget( buttonBox );
1826 spacerEdCfg.
drawLine = cb->isChecked();
1829 itemData.
setName( title->text() );
1831 item->setText( 0, title->text() );
1864 QTreeWidgetItemIterator it(
this );
1870 if ( selectedItems().count() == 1 && ( *it )->isSelected() == true )
1877 ( *it )->setSelected(
true );
1900 QString displayName;
1903 stream >> type >> name >> displayName;
1914 return mContainerType;
1919 mContainerType = type;
1929 mLabelStyle = labelStyle;
1939 mShowLabel = showLabel;
1944 return mVisibilityExpression;
1949 mVisibilityExpression = visibilityExpression;
1954 return mCollapsedExpression;
1959 mCollapsedExpression = collapsedExpression;
1964 return mRelationEditorConfiguration;
1969 mRelationEditorConfiguration = relationEditorConfiguration;
1974 return mQmlElementEditorConfiguration;
1979 mQmlElementEditorConfiguration = qmlElementEditorConfiguration;
1985 return mHtmlElementEditorConfiguration;
1990 mHtmlElementEditorConfiguration = htmlElementEditorConfiguration;
1995 return mSpacerElementEditorConfiguration;
2000 mSpacerElementEditorConfiguration = spacerElementEditorConfiguration;
2005 return mBackgroundColor;
2010 mBackgroundColor = backgroundColor;
2015 return mTextElementEditorConfiguration;
2020 mTextElementEditorConfiguration = textElementEditorConfiguration;
2023void QgsAttributesFormProperties::updatedFields()
2026 QMap<QString, FieldConfig> fieldConfigs;
2028 for (
int i = 0; i < fieldContainer->childCount(); i++ )
2030 QTreeWidgetItem *fieldItem = fieldContainer->child( i );
2031 const QString fieldName = fieldItem->data( 0,
FieldNameRole ).toString();
2033 fieldConfigs[fieldName] = cfg;
2039 for (
int i = 0; i < fieldContainer->childCount(); i++ )
2041 QTreeWidgetItem *fieldItem = fieldContainer->child( i );
2042 const QString fieldName = fieldItem->data( 0,
FieldNameRole ).toString();
2043 if ( fieldConfigs.contains( fieldName ) )
2050void QgsAttributesFormProperties::onContextMenuRequested( QPoint point )
2058 const DnDTreeItemData itemData = item->data( 0,
DnDTreeRole ).value<DnDTreeItemData>();
2061 const QClipboard *clipboard = QApplication::clipboard();
2062 const bool pasteEnabled = clipboard->mimeData()->hasFormat( QStringLiteral(
"application/x-qgsattributetabledesignerelementclipboard" ) );
2063 mActionPasteWidgetConfiguration->setEnabled( pasteEnabled );
2064 mAvailableWidgetsTreeContextMenu->popup( globalPos );
2068void QgsAttributesFormProperties::copyWidgetConfiguration()
2074 const DnDTreeItemData itemData = item->data( 0,
DnDTreeRole ).value<DnDTreeItemData>();
2078 const QString fieldName = item->data( 0,
FieldNameRole ).toString();
2088 QDomElement documentElement = doc.createElement( QStringLiteral(
"FormWidgetClipboard" ) );
2089 documentElement.setAttribute( QStringLiteral(
"name" ), field.
name() );
2094 QDomElement editWidgetElement = doc.createElement( QStringLiteral(
"editWidget" ) );
2095 documentElement.appendChild( editWidgetElement );
2096 editWidgetElement.setAttribute( QStringLiteral(
"type" ), widgetSetup.
type() );
2097 QDomElement editWidgetConfigElement = doc.createElement( QStringLiteral(
"config" ) );
2100 editWidgetElement.appendChild( editWidgetConfigElement );
2103 QDomElement splitPolicyElement = doc.createElement( QStringLiteral(
"splitPolicy" ) );
2105 documentElement.appendChild( splitPolicyElement );
2108 QDomElement duplicatePolicyElement = doc.createElement( QStringLiteral(
"duplicatePolicy" ) );
2110 documentElement.appendChild( duplicatePolicyElement );
2113 QDomElement defaultElem = doc.createElement( QStringLiteral(
"default" ) );
2116 documentElement.appendChild( defaultElem );
2119 QDomElement constraintElem = doc.createElement( QStringLiteral(
"constraint" ) );
2124 documentElement.appendChild( constraintElem );
2127 QDomElement constraintExpressionElem = doc.createElement( QStringLiteral(
"constraintExpression" ) );
2130 documentElement.appendChild( constraintExpressionElem );
2133 QDomElement widgetGeneralSettingsElem = doc.createElement( QStringLiteral(
"widgetGeneralSettings" ) );
2137 documentElement.appendChild( widgetGeneralSettingsElem );
2146 const QTreeWidgetItem *itemLayout =
mFormLayoutTree->selectedItems().at( 0 );
2147 const DnDTreeItemData itemDataLayout = itemLayout->data( 0,
DnDTreeRole ).value<DnDTreeItemData>();
2149 QDomElement displayElement = doc.createElement( QStringLiteral(
"widgetDisplay" ) );
2150 displayElement.setAttribute( QStringLiteral(
"showLabel" ), itemDataLayout.showLabel() );
2151 displayElement.setAttribute( QStringLiteral(
"horizontalStretch" ), itemDataLayout.horizontalStretch() );
2152 displayElement.setAttribute( QStringLiteral(
"verticalStretch" ), itemDataLayout.verticalStretch() );
2153 displayElement.appendChild( itemDataLayout.labelStyle().writeXml( doc ) );
2154 documentElement.appendChild( displayElement );
2157 doc.appendChild( documentElement );
2159 QMimeData *mimeData =
new QMimeData;
2160 mimeData->setData( QStringLiteral(
"application/x-qgsattributetabledesignerelementclipboard" ), doc.toByteArray() );
2161 QClipboard *clipboard = QApplication::clipboard();
2162 clipboard->setMimeData( mimeData );
2165void QgsAttributesFormProperties::pasteWidgetConfiguration()
2172 const QString fieldName = item->data( 0,
FieldNameRole ).toString();
2175 if ( fieldIndex < 0 )
2179 FieldConfig config = item->data( 0,
FieldConfigRole ).value<FieldConfig>();
2182 QClipboard *clipboard = QApplication::clipboard();
2183 if ( doc.setContent( clipboard->mimeData()->data( QStringLiteral(
"application/x-qgsattributetabledesignerelementclipboard" ) ) ) )
2185 QDomElement docElem = doc.documentElement();
2186 if ( docElem.tagName() != QLatin1String(
"FormWidgetClipboard" ) )
2195 const QDomElement fieldWidgetElement = docElem.firstChildElement( QStringLiteral(
"editWidget" ) );
2196 if ( !fieldWidgetElement.isNull() )
2198 const QString widgetType = fieldWidgetElement.attribute( QStringLiteral(
"type" ) );
2204 const QDomElement configElement = fieldWidgetElement.firstChildElement( QStringLiteral(
"config" ) );
2205 if ( !configElement.isNull() )
2207 const QDomElement optionsElem = configElement.childNodes().at( 0 ).toElement();
2210 if ( widgetType == QLatin1String(
"ValueRelation" ) )
2212 optionsMap[QStringLiteral(
"Value" )] = context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1:fields:%2:valuerelationvalue" ).arg(
mLayer->
id(), fieldName ), optionsMap[QStringLiteral(
"Value" )].toString() );
2215 config.mEditorWidgetType = widgetType;
2216 config.mEditorWidgetConfig = optionsMap;
2221 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 );
2226 const QDomElement splitPolicyElement = docElem.firstChildElement( QStringLiteral(
"splitPolicy" ) );
2227 if ( !splitPolicyElement.isNull() )
2230 config.mSplitPolicy = policy;
2234 const QDomElement duplicatePolicyElement = docElem.firstChildElement( QStringLiteral(
"duplicatePolicy" ) );
2235 if ( !duplicatePolicyElement.isNull() )
2238 config.mDuplicatePolicy = policy;
2242 const QDomElement defaultElement = docElem.firstChildElement( QStringLiteral(
"default" ) );
2243 if ( !defaultElement.isNull() )
2245 mAttributeTypeDialog->setDefaultValueExpression( defaultElement.attribute( QStringLiteral(
"expression" ) ) );
2246 mAttributeTypeDialog->setApplyDefaultValueOnUpdate( defaultElement.attribute( QStringLiteral(
"applyOnUpdate" ) ).toInt() );
2252 const QDomElement constraintElement = docElem.firstChildElement( QStringLiteral(
"constraint" ) );
2253 if ( !constraintElement.isNull() )
2255 const int intConstraints = constraintElement.attribute( QStringLiteral(
"constraints" ), QStringLiteral(
"0" ) ).toInt();
2281 const int uniqueStrength = constraintElement.attribute( QStringLiteral(
"unique_strength" ), QStringLiteral(
"1" ) ).toInt();
2282 const int notNullStrength = constraintElement.attribute( QStringLiteral(
"notnull_strength" ), QStringLiteral(
"1" ) ).toInt();
2283 const int expStrength = constraintElement.attribute( QStringLiteral(
"exp_strength" ), QStringLiteral(
"1" ) ).toInt();
2294 const QDomElement constraintExpressionElement = docElem.firstChildElement( QStringLiteral(
"constraintExpression" ) );
2295 if ( !constraintExpressionElement.isNull() )
2297 QString expression = constraintExpressionElement.attribute( QStringLiteral(
"exp" ), QString() );
2298 QString description = constraintExpressionElement.attribute( QStringLiteral(
"desc" ), QString() );
2302 config.mFieldConstraints = fieldConstraints;
2304 const QDomElement widgetGeneralSettingsElement = docElem.firstChildElement( QStringLiteral(
"widgetGeneralSettings" ) );
2305 if ( !widgetGeneralSettingsElement.isNull() )
2307 const int editable = widgetGeneralSettingsElement.attribute( QStringLiteral(
"editable" ), QStringLiteral(
"0" ) ).toInt();
2308 const int reuse = widgetGeneralSettingsElement.attribute( QStringLiteral(
"reuse_last_values" ), QStringLiteral(
"0" ) ).toInt();
2309 const int labelOnTop = widgetGeneralSettingsElement.attribute( QStringLiteral(
"label_on_top" ), QStringLiteral(
"0" ) ).toInt();
2311 config.mEditable = editable;
2312 config.mReuseLastValues = reuse;
2313 config.mLabelOnTop = labelOnTop;
2316 loadAttributeTypeDialogFromConfiguration( config );
2321 const QDomElement displayElement = docElem.firstChildElement( QStringLiteral(
"widgetDisplay" ) );
2322 if ( !displayElement.isNull() )
2324 const int showLabel = displayElement.attribute( QStringLiteral(
"showLabel" ), QStringLiteral(
"0" ) ).toInt();
2325 const int horizontalStretch = displayElement.attribute( QStringLiteral(
"horizontalStretch" ), QStringLiteral(
"0" ) ).toInt();
2326 const int verticalStretch = displayElement.attribute( QStringLiteral(
"verticalStretch" ), QStringLiteral(
"0" ) ).toInt();
2328 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.