|
18 | 18 | #include "qgsattributerelationedit.h"
|
19 | 19 | #include "qgsattributesforminitcode.h"
|
20 | 20 | #include "qgisapp.h"
|
| 21 | +#include "qgsfieldcombobox.h" |
21 | 22 |
|
22 | 23 | QgsAttributesFormProperties::QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent )
|
23 | 24 | : QWidget( parent )
|
@@ -594,42 +595,6 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid
|
594 | 595 | {
|
595 | 596 | QgsAttributeEditorQmlElement *element = new QgsAttributeEditorQmlElement( item->text( 0 ), parent );
|
596 | 597 | 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 |
| - */ |
632 |
| - |
633 | 598 | widgetDef = element;
|
634 | 599 | break;
|
635 | 600 | }
|
@@ -1130,15 +1095,73 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
|
1130 | 1095 | {
|
1131 | 1096 | QDialog dlg;
|
1132 | 1097 | dlg.setWindowTitle( tr( "Configure QML Widget" ) );
|
| 1098 | + dlg.setBaseSize( 600, 400 ); |
1133 | 1099 | QFormLayout *layout = new QFormLayout() ;
|
1134 | 1100 | dlg.setLayout( layout );
|
1135 | 1101 | layout->addWidget( baseWidget );
|
1136 | 1102 |
|
1137 |
| - QPlainTextEdit *qmlCode = new QPlainTextEdit( itemData.qmlElementEditorConfiguration().qmlCode ); |
| 1103 | + //widget title |
1138 | 1104 | QLineEdit *title = new QLineEdit( itemData.name() );
|
| 1105 | + //qml code |
| 1106 | + QPlainTextEdit *qmlCode = new QPlainTextEdit( itemData.qmlElementEditorConfiguration().qmlCode ); |
| 1107 | + //template to select |
| 1108 | + QComboBox *qmlObjectTemplate = new QComboBox(); |
| 1109 | + qmlObjectTemplate->addItem( "Rectangle" ); |
| 1110 | + qmlObjectTemplate->addItem( "Pie Chart" ); |
| 1111 | + connect( qmlObjectTemplate, QOverload<int>::of( &QComboBox::currentIndexChanged ), qmlCode, [ = ]( int index ) |
| 1112 | + { |
| 1113 | + switch ( index ) |
| 1114 | + { |
| 1115 | + case 0: |
| 1116 | + { |
| 1117 | + qmlCode->insertPlainText( QStringLiteral( "import QtQuick 2.0\n" |
| 1118 | + "\n" |
| 1119 | + "Rectangle {\n" |
| 1120 | + " width: 100\n" |
| 1121 | + " height: 100\n" |
| 1122 | + " color: \"red\"\n" |
| 1123 | + "}\n" ) ); |
| 1124 | + break; |
| 1125 | + } |
| 1126 | + case 1: |
| 1127 | + { |
| 1128 | + qmlCode->insertPlainText( QStringLiteral( "import QtQuick 2.0\n" |
| 1129 | + "import QtCharts 2.0\n" |
| 1130 | + "\n" |
| 1131 | + "ChartView {\n" |
| 1132 | + " width: 600\n" |
| 1133 | + " height: 400\n" |
| 1134 | + "\n" |
| 1135 | + " PieSeries {\n" |
| 1136 | + " id: pieSeries\n" |
| 1137 | + " PieSlice { label: \"First slice\"; value: 25 }\n" |
| 1138 | + " PieSlice { label: \"Second slice\"; value: 45 }\n" |
| 1139 | + " PieSlice { label: \"Third slice\"; value: 30 }\n" |
| 1140 | + " }\n" |
| 1141 | + "}\n" ) ); |
| 1142 | + break; |
| 1143 | + } |
| 1144 | + default: |
| 1145 | + break; |
| 1146 | + } |
| 1147 | + } ); |
| 1148 | + |
| 1149 | + //attributes to select |
| 1150 | + QgsFieldComboBox *attributeFieldCombo = new QgsFieldComboBox(); |
| 1151 | + attributeFieldCombo->setLayer( mLayer ); |
| 1152 | + connect( attributeFieldCombo, &QgsFieldComboBox::fieldChanged, qmlCode, [ = ]( QString attributeName ) |
| 1153 | + { |
| 1154 | + qmlCode->insertPlainText( QStringLiteral( "feature.attribute(\"%1\")" ).arg( attributeName ) ); |
| 1155 | + } ); |
| 1156 | + |
1139 | 1157 |
|
1140 | 1158 | layout->addRow( tr( "Title" ), title );
|
1141 |
| - layout->addRow( tr( "QML Code" ), qmlCode ); |
| 1159 | + QGroupBox *qmlCodeBox = new QGroupBox( tr( "QML Code" ) ); |
| 1160 | + qmlCodeBox->setLayout( new QGridLayout ); |
| 1161 | + qmlCodeBox->layout()->addWidget( qmlObjectTemplate ); |
| 1162 | + qmlCodeBox->layout()->addWidget( attributeFieldCombo ); |
| 1163 | + qmlCodeBox->layout()->addWidget( qmlCode ); |
| 1164 | + layout->addRow( qmlCodeBox ); |
1142 | 1165 |
|
1143 | 1166 | QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
|
1144 | 1167 |
|
|
0 commit comments