#include "pifile.h" #include "pijson.h" #include "piqt_connection_edit.h" #include "pivaluetree_conversions.h" #include "pivaluetree_edit.h" #include #include #include #include #include #include #include #include int main(int argc, char * argv[]) { QApplication a(argc, argv); PIValueTree root, group, array; root.addChild({"bool", false}); root.addChild({ "integer", 256, {{PIValueTree::Attribute::minimum, -100}, {PIValueTree::Attribute::maximum, 200}, {PIValueTree::Attribute::singleStep, 5}} }); root.addChild({"Label here", PIVariant(), {{PIValueTree::Attribute::isLabel, true}}}); root.addChild({"string", "str"}); group.addChild({"substr", "str2"}); group.addChild({"real", 12.3}); group.setName("group"); array.setAttribute(PIValueTree::Attribute::arrayType, "string"); array.setAttribute(PIValueTree::Attribute::arrayResize, true); array.setAttribute(PIValueTree::Attribute::arrayMinCount, 0); array.setAttribute(PIValueTree::Attribute::arrayMaxCount, 10); array.setName("array"); array.addChild({"0", "1E+2"}); array.addChild({"1", -5}); array.addChild({"3", 0.1}); root.addChild(group); root.addChild(array); PIString json = PIValueTreeConversions::toJSON(root).toJSON(PIJSON::Tree); // piCout << PIValueTreeConversions::fromJSON(PIJSON::fromJSON(json)); PIFile f("C:/work/config.conf", PIIODevice::ReadOnly); auto vt = PIValueTreeConversions::fromText(&f); PIVariantTypes::Enum en; en << "first" << "second"; en << PIVariantTypes::Enumerator(10, "TEN"); en.selectValue(1); vt.addChild({"Enum", en}); // piCout << PIValueTreeConversions::toText(vt); QScrollArea area; area.setWidgetResizable(true); PIValueTreeEdit e; e.setGroupingEnabled(false); e.setFullEditMode(true); e.setGeometry(500, 400, 100, 50); // e.setValue(PIValueTreeConversions::fromJSON(PIJSON::fromJSON(PIValueTreeConversions::toJSON(vt).toJSON()))); e.setValue(vt); area.setWidget(&e); area.show(); // piCout << PIValueTreeConversions::toText(e.value()); //.toJSON(PIJSON::Tree); QTimer timer; QObject::connect(&timer, &QTimer::timeout, [&]() { e.rollback(); }); // timer.start(5); // QTimer::singleShot(1000, [&e](){e.setValue(50);}); // QTimer::singleShot(2000, [&e, vt]() { // e.setValue(PIValueTreeConversions::fromText(PIValueTreeConversions::toText(vt) + "\n[]\nAHAHA = 123\n")); //}); // QTimer::singleShot(3000, [&e]() { e.setFullEditMode(false); }); return a.exec(); /* PIINTROSPECTION_START(piconnedit) QApplication a(argc, argv); enableHighDPI(); ConnectionEdit w; if (a.arguments().size() > 1) { QPIConfig cfg(a.arguments()[1]); QByteArray model = cfg.getValue("connectionmodel").toByteArray(); if (!model.isEmpty()) w.setModel(model); } else w.recreateConnection(); if (w.exec() == QDialog::Accepted) { QString c = QFileDialog::getSaveFileName(&w, "Save config to file", a.applicationDirPath(), "*.conf"); if (!c.isEmpty()) { QFile f(c); if (f.open(QIODevice::WriteOnly)) { QTextStream ts(&f); ts << w.configuration(); ts << "connectionmodel = " << QByteArray2QString(w.model()) << "\n"; f.close(); } } } return 0;*/ }