summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Kostovsky <luntik2012@gmail.com>2024-12-02 19:42:40 +0100
committerNikita Kostovsky <luntik2012@gmail.com>2024-12-02 19:42:40 +0100
commit8f383df0c295e1049bcf2211869e0b069fb3890e (patch)
treee55f09abca9aaed78bd413e1acd35f8aa611ba83
parent05a8166fa1ada3b386a4e0cce30c60f396587476 (diff)
draw lines
-rw-r--r--CMakeLists.txt2
-rw-r--r--Main.qml2
-rw-r--r--QmlCustomPlot.cpp6
-rw-r--r--main.cpp49
4 files changed, 51 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2923a7b..8d68a93 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -54,3 +54,5 @@ install(TARGETS appeurydice
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
+
+add_compile_options(-Ofast -fno-unroll-loops -Wall)
diff --git a/Main.qml b/Main.qml
index 65fa5a0..0875d49 100644
--- a/Main.qml
+++ b/Main.qml
@@ -542,6 +542,8 @@ ApplicationWindow {
QmlCustomPlot {
id: qmlPlot
+ objectName: "qmlCustomPlot"
+
Label {
anchors {
top: parent.top
diff --git a/QmlCustomPlot.cpp b/QmlCustomPlot.cpp
index ef30b3f..bba287e 100644
--- a/QmlCustomPlot.cpp
+++ b/QmlCustomPlot.cpp
@@ -127,7 +127,8 @@ void QmlCustomPlot::setLines(const QVector<QLineF> lines)
// const QColor color(Qt::green);
// QRgb green = QRandomGenerator::generate();
// QRgb blue = QRandomGenerator::generate();
- const QColor color { QRgb { QRandomGenerator::global()->generate() } };
+ QColor color { QRgb { QRandomGenerator::global()->generate() } };
+ color.setAlpha(100);
const QPen linePen(color, 4);
QCPItemLine * l;
@@ -145,7 +146,8 @@ void QmlCustomPlot::setLines(const QVector<QLineF> lines)
l = m_lineItems[i];
}
- const QPointF offset(0, 2);
+ // const QPointF offset(0, 2);
+ const QPointF offset(0, 0);
const auto & lineToSet = lines.at(i);
l->start->setCoords(lineToSet.p1() + offset);
diff --git a/main.cpp b/main.cpp
index 34719ef..eb44515 100644
--- a/main.cpp
+++ b/main.cpp
@@ -5,14 +5,10 @@
#include <QQmlContext>
#include <QtConcurrent/QtConcurrentRun>
#include <QTimer>
-
+#include <iostream>
#include "QmlCustomPlot.h"
-template <typename T>
-T& median3(const T& a, const T& b, const T& c) {
- using namespace std;
- return max(min(a,b), min(max(a,b),c));
-}
+// #include <execution>
int main(int argc, char *argv[])
{
@@ -132,6 +128,47 @@ int main(int argc, char *argv[])
graph->setData(x_profile, y_profile);
+ auto jsonLines = json["lines"].toArray();
+
+ QList<QLineF> lines(jsonLines.count());
+
+ // FIXME: validate
+ // WARNING
+ // AHTUNG
+ // DANGER
+ std::transform(
+ // std::execution::par_unseq
+ jsonLines.cbegin(),
+ jsonLines.cend(),
+ lines.begin(),
+ [](const auto& jsonLine) -> QLineF {
+ const auto jsonPoints = jsonLine.toArray();
+ const auto jsonPoint0 = jsonPoints.at(0).toArray();
+ const auto jsonPoint1 = jsonPoints.at(1).toArray();
+ return {
+ { jsonPoint0.at(0).toDouble(), jsonPoint0.at(1).toDouble() },
+ { jsonPoint1.at(0).toDouble(), jsonPoint1.at(1).toDouble() }
+ };
+ }
+ );
+
+ // lines.append({{6,780},{38,787}});
+
+ auto qmlCustomPlot = engine.rootObjects().first()->findChild<QmlCustomPlot*>("qmlCustomPlot");
+
+ if (!qmlCustomPlot)
+ {
+ qWarning() << "no qmlCustomPlot";
+ }
+ else
+ {
+ qDebug() << "set lines. count is" << lines.count();
+ qmlCustomPlot->setLines(lines);
+ }
+
+ // 6 780
+ // 38 787
+
engine.rootContext()->setContextProperty("max_diff", max_diff);
engine.rootContext()->setContextProperty("max_diff_idx", int(max_diff_idx));
engine.rootContext()->setContextProperty("min_diff", min_diff);