From 8f383df0c295e1049bcf2211869e0b069fb3890e Mon Sep 17 00:00:00 2001 From: Nikita Kostovsky Date: Mon, 2 Dec 2024 19:42:40 +0100 Subject: draw lines --- CMakeLists.txt | 2 ++ Main.qml | 2 ++ QmlCustomPlot.cpp | 6 ++++-- main.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++------ 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 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 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 #include #include - +#include #include "QmlCustomPlot.h" -template -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 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 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"); + + 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); -- cgit v1.2.3-70-g09d2