@@ -456,8 +456,20 @@ QTreeWidgetItem *QgsAttributesFormProperties::loadAttributeEditorTreeItem( QgsAt
456
456
{
457
457
loadAttributeEditorTreeItem ( wdg, newWidget, tree );
458
458
}
459
+ break ;
460
+ }
461
+
462
+ case QgsAttributeEditorElement::AeTypeQmlElement:
463
+ {
464
+ const QgsAttributeEditorQmlElement *qmlElementEditor = static_cast <const QgsAttributeEditorQmlElement *>( widgetDef );
465
+ DnDTreeItemData itemData = DnDTreeItemData ( DnDTreeItemData::QmlWidget, widgetDef->name (), widgetDef->name () );
466
+ itemData.setShowLabel ( widgetDef->showLabel () );
467
+ QmlElementEditorConfiguration qmlEdConfig;
468
+ qmlEdConfig.qmlCode = qmlElementEditor->qmlCode ();
469
+ itemData.setQmlElementEditorConfiguration ( qmlEdConfig );
470
+ newWidget = tree->addItem ( parent, itemData );
471
+ break ;
459
472
}
460
- break ;
461
473
default :
462
474
// should not happen
463
475
break ;
@@ -580,8 +592,43 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid
580
592
581
593
case DnDTreeItemData::QmlWidget:
582
594
{
583
- QgsAttributeEditorQmlElement *element = new QgsAttributeEditorQmlElement ( parent );
584
- element->setQmlCode ( " ABC " );
595
+ QgsAttributeEditorQmlElement *element = new QgsAttributeEditorQmlElement ( item->text ( 0 ), parent );
596
+ element->setQmlCode ( itemData.qmlElementEditorConfiguration ().qmlCode );
597
+
598
+ /*
599
+ element->setQmlCode( QStringLiteral(
600
+ "import QtQuick 2.0\n"
601
+ "\n"
602
+ "Rectangle {\n"
603
+ " width: 100\n"
604
+ " height: 100\n"
605
+ " color: \"red\"\n"
606
+ "}\n" ) );
607
+
608
+ element->setQmlCode( QStringLiteral(
609
+ "import QtQuick 2.0\n"
610
+ "import QtCharts 2.0\n"
611
+ "\n"
612
+ "ChartView {\n"
613
+ " width: 600\n"
614
+ " height: 400\n"
615
+ "\n"
616
+ " PieSeries {\n"
617
+ " id: pieSeries\n"
618
+ " PieSlice { label: \"outlet 1\"; value: attributes.outlet_1 }\n"
619
+ " PieSlice { label: \"outlet 2\"; value: attributes.outlet_2 }\n"
620
+ " PieSlice { label: \"outlet 3\"; value: attributes.outlet_3 }\n"
621
+ " PieSlice { label: \"outlet 4\"; value: attributes.outlet_4 }\n"
622
+ " }\n"
623
+ "}\n" ) );
624
+ import QtQuick 2.0
625
+
626
+ Rectangle {
627
+ width: 100
628
+ height: 100
629
+ color: "red"
630
+ }
631
+ */
585
632
586
633
widgetDef = element;
587
634
break ;
@@ -1087,12 +1134,11 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
1087
1134
dlg.setLayout ( layout );
1088
1135
layout->addWidget ( baseWidget );
1089
1136
1090
- QCheckBox *showLinkButton = new QCheckBox ( tr ( " Show link button" ) );
1091
- showLinkButton->setChecked ( itemData.relationEditorConfiguration ().showLinkButton );
1092
- QCheckBox *showUnlinkButton = new QCheckBox ( tr ( " Show unlink button" ) );
1093
- showUnlinkButton->setChecked ( itemData.relationEditorConfiguration ().showUnlinkButton );
1094
- layout->addRow ( showLinkButton );
1095
- layout->addRow ( showUnlinkButton );
1137
+ QPlainTextEdit *qmlCode = new QPlainTextEdit ( itemData.qmlElementEditorConfiguration ().qmlCode );
1138
+ QLineEdit *title = new QLineEdit ( itemData.name () );
1139
+
1140
+ layout->addRow ( tr ( " Title" ), title );
1141
+ layout->addRow ( tr ( " QML Code" ), qmlCode );
1096
1142
1097
1143
QDialogButtonBox *buttonBox = new QDialogButtonBox ( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
1098
1144
@@ -1103,13 +1149,14 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
1103
1149
1104
1150
if ( dlg.exec () )
1105
1151
{
1106
- QgsAttributesFormProperties::RelationEditorConfiguration relEdCfg;
1107
- relEdCfg.showLinkButton = showLinkButton->isChecked ();
1108
- relEdCfg.showUnlinkButton = showUnlinkButton->isChecked ();
1152
+ QgsAttributesFormProperties::QmlElementEditorConfiguration qmlEdCfg;
1153
+ qmlEdCfg.qmlCode = qmlCode->toPlainText ();
1154
+ itemData.setName ( title->text () );
1155
+ itemData.setQmlElementEditorConfiguration ( qmlEdCfg );
1109
1156
itemData.setShowLabel ( showLabelCheckbox->isChecked () );
1110
- itemData.setRelationEditorConfiguration ( relEdCfg );
1111
1157
1112
1158
item->setData ( 0 , QgsAttributesFormProperties::DnDTreeRole, itemData );
1159
+ item->setText ( 0 , title->text () );
1113
1160
}
1114
1161
}
1115
1162
break ;
@@ -1216,3 +1263,13 @@ void QgsAttributesFormProperties::DnDTreeItemData::setRelationEditorConfiguratio
1216
1263
mRelationEditorConfiguration = relationEditorConfiguration;
1217
1264
}
1218
1265
1266
+ QgsAttributesFormProperties::QmlElementEditorConfiguration QgsAttributesFormProperties::DnDTreeItemData::qmlElementEditorConfiguration () const
1267
+ {
1268
+ return mQmlElementEditorConfiguration ;
1269
+ }
1270
+
1271
+ void QgsAttributesFormProperties::DnDTreeItemData::setQmlElementEditorConfiguration ( QgsAttributesFormProperties::QmlElementEditorConfiguration qmlElementEditorConfiguration )
1272
+ {
1273
+ mQmlElementEditorConfiguration = qmlElementEditorConfiguration;
1274
+ }
1275
+
0 commit comments