Added plugin object to qml context
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
#include <QtQuick/QQuickItem>
|
||||
#include <qchar.h>
|
||||
#include <qglobal.h>
|
||||
#include <qobject.h>
|
||||
#include <qobjectdefs.h>
|
||||
#include <qpoint.h>
|
||||
#include <qquickitem.h>
|
||||
@ -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;
|
||||
};
|
||||
@ -6,11 +6,13 @@
|
||||
#include <QtQuick>
|
||||
#include <QtWidgets>
|
||||
#include <qfileinfo.h>
|
||||
#include <qobject.h>
|
||||
#include <qobjectdefs.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <qquickview.h>
|
||||
#include <qquickwindow.h>
|
||||
#include <qresource.h>
|
||||
#include <qsggeometry.h>
|
||||
#include <qurl.h>
|
||||
#include <qwidget.h>
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user