Skip to content

Commit bb6702f

Browse files
committed
basics with configurable code and attributes
1 parent 016b0cb commit bb6702f

File tree

1 file changed

+61
-38
lines changed

1 file changed

+61
-38
lines changed

src/app/qgsattributesformproperties.cpp

+61-38
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgsattributerelationedit.h"
1919
#include "qgsattributesforminitcode.h"
2020
#include "qgisapp.h"
21+
#include "qgsfieldcombobox.h"
2122

2223
QgsAttributesFormProperties::QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent )
2324
: QWidget( parent )
@@ -594,42 +595,6 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid
594595
{
595596
QgsAttributeEditorQmlElement *element = new QgsAttributeEditorQmlElement( item->text( 0 ), parent );
596597
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-
633598
widgetDef = element;
634599
break;
635600
}
@@ -1130,15 +1095,73 @@ void DnDTree::onItemDoubleClicked( QTreeWidgetItem *item, int column )
11301095
{
11311096
QDialog dlg;
11321097
dlg.setWindowTitle( tr( "Configure QML Widget" ) );
1098+
dlg.setBaseSize( 600, 400 );
11331099
QFormLayout *layout = new QFormLayout() ;
11341100
dlg.setLayout( layout );
11351101
layout->addWidget( baseWidget );
11361102

1137-
QPlainTextEdit *qmlCode = new QPlainTextEdit( itemData.qmlElementEditorConfiguration().qmlCode );
1103+
//widget title
11381104
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+
11391157

11401158
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 );
11421165

11431166
QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
11441167

0 commit comments

Comments
 (0)