From 23f5479b35484d8019ac95f0924d0e1e77cd936a Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Tue, 29 Jul 2014 17:47:14 +0400 Subject: [PATCH] Fixed passing data through qml --- Main.qml | 3 ++- main.cpp | 9 ++++----- svapplicationcontext.h | 2 +- svkernel.cpp | 2 ++ svpoint.cpp | 5 +++-- svpointcloudviewer.cpp | 15 +++++++-------- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Main.qml b/Main.qml index 406bf54..85f33d6 100644 --- a/Main.qml +++ b/Main.qml @@ -152,7 +152,8 @@ ApplicationWindow { Item { anchors.fill: parent SvPointCloudViewer { - pointCloud: app.getPointCloud() + id: pointCloudViewer1 + pointCloud: app.pointCloud() anchors.fill: parent } } diff --git a/main.cpp b/main.cpp index 4fd389a..7e7fa0a 100644 --- a/main.cpp +++ b/main.cpp @@ -14,8 +14,7 @@ int main(int argc, char *argv[]) QGuiApplication a(argc, argv); qmlRegisterType("SvPCV", 1, 0, "SvPointCloudViewer"); - qmlRegisterType("SvPCV", 1, 0, "SvApplicationContext"); - qRegisterMetaType(); + qmlRegisterUncreatableType("SvPCV", 1, 0, "SvApplicationContext", "c++ only"); QQmlApplicationEngine engine; SvImageProvider imageProvider; @@ -27,9 +26,9 @@ int main(int argc, char *argv[]) SvImage right(imgRight); SvPointCloud pointCloud(imgLeft.width(), imgLeft.height()); - SvApplicationContext m; + SvApplicationContext applicationContext; - m.setPointCloud(&pointCloud); + applicationContext.setPointCloud(&pointCloud); SvProcessor proc(4); @@ -40,7 +39,7 @@ int main(int argc, char *argv[]) engine.addImageProvider("images", &imageProvider); engine.rootContext()->setContextProperty("processor", &proc); - engine.rootContext()->setContextProperty("app", &m); + engine.rootContext()->setContextProperty("app", &applicationContext); engine.load(QUrl(QStringLiteral("qrc:///Main.qml"))); proc.start(); diff --git a/svapplicationcontext.h b/svapplicationcontext.h index a40d5fa..a2f0c6c 100644 --- a/svapplicationcontext.h +++ b/svapplicationcontext.h @@ -13,7 +13,7 @@ public: explicit SvApplicationContext(QObject *parent = 0); void setPointCloud(SvPointCloud *pointCloud) { m_pointCloud = pointCloud; } - Q_INVOKABLE SvPointCloud* getPointCloud() { return m_pointCloud; } + Q_INVOKABLE SvPointCloud* pointCloud() { return m_pointCloud; } private: SvPointCloud *m_pointCloud; diff --git a/svkernel.cpp b/svkernel.cpp index 1f8c635..c781ab8 100644 --- a/svkernel.cpp +++ b/svkernel.cpp @@ -92,6 +92,8 @@ void SvKernel::exec(SvPointCloud *pc, SvImage *image, int line) if (x > 0 && line > 0){ p.setX(x - 1); p.setY(line - 1); + int color = value > 255 ? 255 : value; + p.setColor(qRgb(value, value, value)); pc->addPoint(p); diff --git a/svpoint.cpp b/svpoint.cpp index 63e4f21..860805d 100644 --- a/svpoint.cpp +++ b/svpoint.cpp @@ -7,8 +7,9 @@ SvPoint::SvPoint() SvPoint::SvPoint(SvPoint &point) { - m_px = point.x(); - m_py = point.y(); + m_px = point.x(); + m_py = point.y(); + m_color = point.color(); } void SvPoint::addCurve(SvCurve *curve) diff --git a/svpointcloudviewer.cpp b/svpointcloudviewer.cpp index d263815..2c3d4a0 100644 --- a/svpointcloudviewer.cpp +++ b/svpointcloudviewer.cpp @@ -20,22 +20,21 @@ void SvPointCloudViewer::paint(QPainter *painter) glViewport(0, 0, width(), height()); - glClearColor(0, 1, 1, 1); - glClear(GL_COLOR_BUFFER_BIT/* | GL_DEPTH_BUFFER_BIT*/); + glClearColor(0, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); + //glEnable (GL_BLEND); + //glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glLoadIdentity(); - glTranslatef(0.0f, height(), -400.0f); - glScalef(0.1f, 0.1f, 0.1f); - glColor3f(1.0f, 0.0f, 0.0f); - glPointSize(3.0f); + glTranslatef(100.0f, height()-10, -40.0f); glBegin(GL_POINTS); for (int y = 0; y < m_pointCloud->getHeight(); y++) { for (int x = 0; x < m_pointCloud->getWidth(); x++) { SvPoint *p = m_pointCloud->point(x, y); if (p) { - glColor3ub(qRed(p->color()),qGreen(p->color()), qBlue(p->color())); - glVertex3i(x, y, 0); + glColor3ub(qRed(p->color()), qGreen(p->color()), qBlue(p->color())); + glVertex3i(x, -y, 0); } } }