diff --git a/include/rqt_demo_plugin/lineItem.hpp b/include/rqt_demo_plugin/lineItem.hpp index 670d4f6..aaa9ae3 100644 --- a/include/rqt_demo_plugin/lineItem.hpp +++ b/include/rqt_demo_plugin/lineItem.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -11,7 +12,11 @@ class LineItem : public QQuickItem { Q_OBJECT - Q_PROPERTY(QString stupid READ stupid WRITE setStupid) + Q_PROPERTY(float scale READ scale WRITE setScale NOTIFY scaleChanged) + Q_PROPERTY(QString stupid READ stupid WRITE setStupid NOTIFY stupidChanged) + Q_PROPERTY(QObject* handler READ handler WRITE setHandler NOTIFY handlerChanged) + + QML_ELEMENT public: LineItem(QQuickItem *parent = nullptr); @@ -20,13 +25,21 @@ public: QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; QString stupid() const {return stupid_;} + QObject* handler() const {return handler_;} + + void setStupid(const QString &str) {stupid_ = str;} + void setScale(const float scale) {scale_ = scale;} + void setHandler(QObject* const obj) {handler_ = obj;} + +signals: + void stupidChanged(const QString &str); + void handlerChanged(QObject* const obj); - void setStupid(const QString &str) { - stupid_ = str; - qDebug() << str; - } private: + float scale_; QString stupid_; + QObject* handler_; + int prev_size=0; }; \ No newline at end of file diff --git a/include/rqt_demo_plugin/rqt_demo_plugin.hpp b/include/rqt_demo_plugin/rqt_demo_plugin.hpp index d3180cf..edc4b3d 100644 --- a/include/rqt_demo_plugin/rqt_demo_plugin.hpp +++ b/include/rqt_demo_plugin/rqt_demo_plugin.hpp @@ -6,11 +6,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -21,21 +23,48 @@ namespace mg { class DemoPluginMg : public rqt_gui_cpp::Plugin { Q_OBJECT + Q_PROPERTY(QObject* demoPlugin READ demoPlugin NOTIFY demoPluginChanged) public: DemoPluginMg(); virtual void shutdownPlugin() { cleanupResources(); } + virtual void initPlugin(qt_gui_cpp::PluginContext &); + + QObject * demoPlugin() const { + return (QObject *)(this); + } + + const QSGGeometry::Point2D hello[8] = { + {0.2,0.2}, {0.8,0.2}, + {0.2,0.2}, {0.2,0.8}, + {0.2,0.4}, {0.4,0.8}, + {0.2,0.4}, {0.1,0.1}, + }; + + const int hello_c = 8; + +signals: + + void demoPluginChanged(QObject * const); + }; inline void DemoPluginMg::initPlugin(qt_gui_cpp::PluginContext &pc) { initResources(); - QQuickView *qv = new QQuickView(QUrl("qrc:/qml/helloworld.qml")); + const QUrl qrl("qrc:/qml/helloworld.qml"); + QQuickView *qv = new QQuickView(); + qv->rootContext()->setContextProperty("DemoPlug", this); + qv->setSource(qrl); qv->setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView); + QSurfaceFormat format = qv->format(); + format.setSamples(4); + qv->setFormat(format); QWidget *qw_ = QWidget::createWindowContainer(qv); pc.addWidget(qw_); } + }; // namespace mg diff --git a/log/latest_build b/log/latest_build index b60e059..a8de713 120000 --- a/log/latest_build +++ b/log/latest_build @@ -1 +1 @@ -build_2025-03-09_02-21-28 \ No newline at end of file +build_2025-03-10_12-03-53 \ No newline at end of file diff --git a/resources/qml/helloworld.qml b/resources/qml/helloworld.qml index 17ae47b..075739e 100644 --- a/resources/qml/helloworld.qml +++ b/resources/qml/helloworld.qml @@ -1,12 +1,15 @@ import QtQuick 2.3 import LineItem 1.0 +import DemoPlugin 1.0 Rectangle { + id: rr color: "gray" + property var scale: 0.4 Flickable { width: parent.width; height: parent.height - contentWidth: 2500*4; contentHeight: 1500*4 + contentWidth: 3000*rr.scale; contentHeight: 2000*rr.scale flickDeceleration: 10000 leftMargin: Math.max((width - contentWidth)/2,0) topMargin: Math.max((height - contentHeight)/2,0) @@ -17,36 +20,21 @@ Rectangle { id: contentRect anchors.top: parent.top anchors.left: parent.left - width: parent.width/4 - height: parent.height/4 + width: parent.width/rr.scale + height: parent.height/rr.scale - transform: Scale {yScale: 4; xScale: 4} + transform: Scale {yScale: rr.scale; xScale: rr.scale} transformOrigin: Item.TopLeft Row { x:0 y:0 - spacing: 4 - Rectangle { - height: 100 - width: 100 - color: "green" - Text { - text: "Hello, World!" - } - } - Rectangle { - height: 100 - width: 100 - color: "red" - Text { - text: "Hello, World!" - } - } LineItem { - height: 100 - width: 100 + height: 2000 + width: 3000 + scale: rr.scale + handler: DemoPlug.demoPlugin } } } diff --git a/src/lineItem.cpp b/src/lineItem.cpp index b43ec81..8613722 100644 --- a/src/lineItem.cpp +++ b/src/lineItem.cpp @@ -1,4 +1,7 @@ #include "rqt_demo_plugin/lineItem.hpp" +#include "rqt_demo_plugin/rqt_demo_plugin.hpp" +#include +#include #include #include #include @@ -7,7 +10,9 @@ LineItem::LineItem(QQuickItem *parent) : QQuickItem(parent) - , stupid_("") + , scale_(1) + , stupid_("") + , handler_(nullptr) { setFlag(ItemHasContents, true); } @@ -19,12 +24,21 @@ QSGNode *LineItem::updatePaintNode(QSGNode *old, UpdatePaintNodeData *) { QSGGeometryNode *node = nullptr; QSGGeometry *geometry = nullptr; + mg::DemoPluginMg *plugin = static_cast(handler_); + if(!plugin) { + qmlEngine(this)->throwError("Handler plugin was not provided"); + return old; + } + + const int hello_c = plugin->hello_c; if(!old) { node = new QSGGeometryNode; - geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 4); - geometry->setLineWidth(5); + geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), hello_c); + geometry->setLineWidth(3*scale_); geometry->setDrawingMode(QSGGeometry::DrawLines); + geometry->setVertexDataPattern(QSGGeometry::DynamicPattern); + geometry->setIndexDataPattern(QSGGeometry::DynamicPattern); node->setGeometry(geometry); node->setFlag(QSGNode::OwnsGeometry); auto *material = new QSGFlatColorMaterial; @@ -32,13 +46,26 @@ QSGNode *LineItem::updatePaintNode(QSGNode *old, UpdatePaintNodeData *) node->setMaterial(material); node->setFlag(QSGNode::OwnsMaterial); - QSGGeometry::Point2D *verticies = geometry->vertexDataAsPoint2D(); - QSizeF s = size(); - verticies[0].set(0.1 * s.width(), 0.1 * s.height()); - verticies[1].set(0.75 * s.width(), 0.75 * s.height()); - verticies[2].set(0.1 * s.width(), 0.9 * s.height()); - verticies[3].set(0.9 * s.width(), 0.1 * s.height()); - node->markDirty(QSGNode::DirtyGeometry); + } else { + node = static_cast(old); + geometry = node->geometry(); + if(hello_c != prev_size) { + geometry->allocate(prev_size); + } } + + + if(hello_c != prev_size) { + const QSizeF s = size(); + QSGGeometry::Point2D *verticies = geometry->vertexDataAsPoint2D(); + for(int i = 0; ihello[i].x * s.width(); + verticies[i].y = plugin->hello[i].y * s.height(); + } + geometry->markVertexDataDirty(); + node->markDirty(QSGNode::DirtyGeometry); + prev_size = hello_c; + } + return node; } \ No newline at end of file diff --git a/src/rqt_demo_plugin.cpp b/src/rqt_demo_plugin.cpp index f7d998e..b0dcdbd 100644 --- a/src/rqt_demo_plugin.cpp +++ b/src/rqt_demo_plugin.cpp @@ -3,6 +3,7 @@ #include "pluginlib/class_list_macros.hpp" #include +#include #include PLUGINLIB_EXPORT_CLASS(mg::DemoPluginMg, rqt_gui_cpp::Plugin) @@ -14,6 +15,7 @@ mg::DemoPluginMg::DemoPluginMg() : Plugin() { static bool typesRegistered = 0; if(!typesRegistered) { qmlRegisterType("LineItem", 1, 0, "LineItem"); + qmlRegisterAnonymousType("DemoPlugin", 1); typesRegistered = 1; } } \ No newline at end of file