From 56856d081ba260dceab4f8064d2a29baec556286 Mon Sep 17 00:00:00 2001 From: Jos van den Oever Date: Thu, 31 Aug 2017 22:28:37 +0200 Subject: [PATCH] Show table in qml view chart tab --- demo/chart.qml | 3 +- demo/demo.qml | 75 ++++++++++++++++++++++++++++++--------- demo/src/Bindings.h | 15 +++++--- src/cpp.cpp | 9 ++--- tests/test_objects_rust.h | 6 ++-- 5 files changed, 76 insertions(+), 32 deletions(-) diff --git a/demo/chart.qml b/demo/chart.qml index e791df2..a944f39 100644 --- a/demo/chart.qml +++ b/demo/chart.qml @@ -13,7 +13,6 @@ Item { titleText: "Date" format: "MMM yyyy" tickCount: 10 - //alignment: Qt.AlignBottom } ValueAxis { @@ -29,7 +28,7 @@ Item { } VXYModelMapper { - model: timeSeries + model: demo.timeSeries xColumn: 0 yColumn: 1 series: cpu diff --git a/demo/demo.qml b/demo/demo.qml index 3b8b278..9b49a61 100644 --- a/demo/demo.qml +++ b/demo/demo.qml @@ -56,11 +56,11 @@ ApplicationWindow { id: fibonacciInput placeholderText: "Your number" validator: IntValidator {bottom: 0; top: 100;} - Component.onCompleted: { text = fibonacci.input } - onTextChanged: { fibonacci.input = parseInt(text, 10) } + Component.onCompleted: { text = demo.fibonacci.input } + onTextChanged: { demo.fibonacci.input = parseInt(text, 10) } } Text { - text: "The Fibonacci number: " + fibonacci.result + text: "The Fibonacci number: " + demo.fibonacci.result } } } @@ -68,7 +68,7 @@ ApplicationWindow { title: "list" TableView { id: listView - model: fibonacciList + model: demo.fibonacciList TableViewColumn { role: "display" title: "Row" @@ -171,31 +171,72 @@ ApplicationWindow { Tab { id: chartTab title: "chart" -// Row { -// anchors.fill: parent - Text { - text: "YAYAYA" -anchors.left: parent.left -anchors.right: i.left + RowLayout { + anchors.fill: parent + Component { + id: editableDelegate + Item { + Text { + text: styleData.value + visible: !styleData.selected + } + Loader { + id: loaderEditor + anchors.fill: parent + Connections { + target: loaderEditor.item + onEditingFinished: { + console.log('hi ', styleData.row, styleData.role, loaderEditor.item.text); + console.log(demo.timeSeries.data(styleData.row)); + } + } + sourceComponent: styleData.selected ? editor : null + } + Component { + id: editor + TextInput { + id: textInput + text: styleData.value + MouseArea { + anchors.fill: parent + hoverEnabled: true + onClicked: textInput.forceActiveFocus() + } + } + } + } + } + TableView { + model: demo.timeSeries + Layout.fillHeight: true + + TableViewColumn { + role: "input" + title: "input" + } + TableViewColumn { + role: "result" + title: "result" + } + itemDelegate: { + return editableDelegate; + } } Item { -id: i -anchors.right: parent.right + Layout.fillWidth: true + Layout.fillHeight: true Text { anchors.centerIn: parent text: "QtChart is not available."; visible: chartLoader.status !== Loader.Ready } Loader { -width: 100 - + anchors.fill: parent id: chartLoader - // anchors.fill: parent source: "chart.qml" } } - -// } + } } } } diff --git a/demo/src/Bindings.h b/demo/src/Bindings.h index 1d33a51..cea7be3 100644 --- a/demo/src/Bindings.h +++ b/demo/src/Bindings.h @@ -25,11 +25,11 @@ private: TimeSeries* const m_timeSeries; Private * m_d; bool m_ownsPrivate; - Q_PROPERTY(Fibonacci* fibonacci READ fibonacci FINAL) - Q_PROPERTY(FibonacciList* fibonacciList READ fibonacciList FINAL) - Q_PROPERTY(FileSystemTree* fileSystemTree READ fileSystemTree FINAL) - Q_PROPERTY(Processes* processes READ processes FINAL) - Q_PROPERTY(TimeSeries* timeSeries READ timeSeries FINAL) + Q_PROPERTY(Fibonacci* fibonacci READ fibonacci NOTIFY fibonacciChanged FINAL) + Q_PROPERTY(FibonacciList* fibonacciList READ fibonacciList NOTIFY fibonacciListChanged FINAL) + Q_PROPERTY(FileSystemTree* fileSystemTree READ fileSystemTree NOTIFY fileSystemTreeChanged FINAL) + Q_PROPERTY(Processes* processes READ processes NOTIFY processesChanged FINAL) + Q_PROPERTY(TimeSeries* timeSeries READ timeSeries NOTIFY timeSeriesChanged FINAL) explicit Demo(bool owned, QObject *parent); public: explicit Demo(QObject *parent = nullptr); @@ -45,6 +45,11 @@ public: const TimeSeries* timeSeries() const; TimeSeries* timeSeries(); signals: + void fibonacciChanged(); + void fibonacciListChanged(); + void fileSystemTreeChanged(); + void processesChanged(); + void timeSeriesChanged(); }; class Fibonacci : public QObject diff --git a/src/cpp.cpp b/src/cpp.cpp index fad872a..1c7438b 100644 --- a/src/cpp.cpp +++ b/src/cpp.cpp @@ -365,11 +365,10 @@ private: )"; for (auto p: o.properties) { bool obj = p.type.type == BindingType::Object; - h << QString(" Q_PROPERTY(%1 %2 READ %2 %3%4FINAL)") + h << QString(" Q_PROPERTY(%1 %2 READ %2 %3NOTIFY %2Changed FINAL)") .arg(p.type.name + (obj ?"*" :""), p.name, - p.write ? writeProperty(p.name) :"", - obj ?"" :("NOTIFY " +p.name + "Changed ")) + p.write ? writeProperty(p.name) :"") << endl; } h << QString(R"( explicit %1(bool owned, QObject *parent); @@ -393,9 +392,7 @@ public: } h << "signals:" << endl; for (auto p: o.properties) { - if (p.type.type != BindingType::Object) { - h << " void " << p.name << "Changed();" << endl; - } + h << " void " << p.name << "Changed();" << endl; } h << "};" << endl; } diff --git a/tests/test_objects_rust.h b/tests/test_objects_rust.h index 747f0ac..7a02f12 100644 --- a/tests/test_objects_rust.h +++ b/tests/test_objects_rust.h @@ -19,7 +19,7 @@ private: Person* const m_person; Private * m_d; bool m_ownsPrivate; - Q_PROPERTY(Person* person READ person FINAL) + Q_PROPERTY(Person* person READ person NOTIFY personChanged FINAL) explicit Group(bool owned, QObject *parent); public: explicit Group(QObject *parent = nullptr); @@ -27,6 +27,7 @@ public: const Person* person() const; Person* person(); signals: + void personChanged(); }; class InnerObject : public QObject @@ -60,7 +61,7 @@ private: InnerObject* const m_object; Private * m_d; bool m_ownsPrivate; - Q_PROPERTY(InnerObject* object READ object FINAL) + Q_PROPERTY(InnerObject* object READ object NOTIFY objectChanged FINAL) explicit Person(bool owned, QObject *parent); public: explicit Person(QObject *parent = nullptr); @@ -68,5 +69,6 @@ public: const InnerObject* object() const; InnerObject* object(); signals: + void objectChanged(); }; #endif // TEST_OBJECTS_RUST_H