Fixed passing data through qml

This commit is contained in:
Andrey Tkachenko 2014-07-29 17:47:14 +04:00
parent b6b4bf3eb6
commit 23f5479b35
6 changed files with 19 additions and 17 deletions

View File

@ -152,7 +152,8 @@ ApplicationWindow {
Item {
anchors.fill: parent
SvPointCloudViewer {
pointCloud: app.getPointCloud()
id: pointCloudViewer1
pointCloud: app.pointCloud()
anchors.fill: parent
}
}

View File

@ -14,8 +14,7 @@ int main(int argc, char *argv[])
QGuiApplication a(argc, argv);
qmlRegisterType<SvPointCloudViewer>("SvPCV", 1, 0, "SvPointCloudViewer");
qmlRegisterType<SvApplicationContext>("SvPCV", 1, 0, "SvApplicationContext");
qRegisterMetaType<SvPointCloud*>();
qmlRegisterUncreatableType<SvPointCloud>("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();

View File

@ -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;

View File

@ -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);

View File

@ -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)

View File

@ -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);
}
}
}