From f55958ac7c65d8bd82bcc367d21fbf07f62940ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0pirk?= Date: Tue, 29 Oct 2024 09:56:06 +0100 Subject: [PATCH 1/2] draw graph into SVG --- libshvvisu/include/shv/visu/timeline/graph.h | 4 ++++ libshvvisu/src/timeline/graph.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/libshvvisu/include/shv/visu/timeline/graph.h b/libshvvisu/include/shv/visu/timeline/graph.h index 05176ba2c..0bdbfb82b 100644 --- a/libshvvisu/include/shv/visu/timeline/graph.h +++ b/libshvvisu/include/shv/visu/timeline/graph.h @@ -23,6 +23,8 @@ #include #endif +class QSvgGenerator; + namespace shv::visu::timeline { class SHVVISU_DECL_EXPORT Graph : public QObject @@ -236,6 +238,8 @@ class SHVVISU_DECL_EXPORT Graph : public QObject void loadVisualSettings(const QString &settings_id, const QString &name); QString loadedVisualSettingsId(); + void draw(QSvgGenerator *svg_generator, const QRect &rect); + protected: void sanityXRangeZoom(); diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index 2d07a1a87..933facb73 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -1296,6 +1297,15 @@ int Graph::maximizedChannelIndex() const return -1; } +void Graph::draw(QSvgGenerator *svg_generator, const QRect &rect) +{ + auto orig_layout = m_layout.rect; + makeLayout(rect); + QPainter painter(svg_generator); + draw(&painter, rect, rect); + makeLayout(orig_layout); +} + void Graph::draw(QPainter *painter, const QRect &dirty_rect, const QRect &view_rect) { drawBackground(painter, dirty_rect); From 2b83eeadb642336c8974b36b93cc18986ecab488 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Tue, 29 Oct 2024 16:42:45 +0100 Subject: [PATCH 2/2] Add QtSvg to libshvvisu dependences --- CMakeLists.txt | 15 ++++++++++++--- libshvvisu/CMakeLists.txt | 5 +++++ libshvvisu/include/shv/visu/timeline/graph.h | 10 ++++++---- libshvvisu/src/timeline/graph.cpp | 9 ++++++--- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6fca7af8..b9dc29b07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,16 +159,18 @@ if(LIBSHV_WITH_COREQT) if(LIBSHV_USE_QT6) message(STATUS "Enabling Qt6 support") if(EMSCRIPTEN) - find_package(Qt6 COMPONENTS Core LinguistTools Network OPTIONAL_COMPONENTS WebSockets Widgets) + find_package(Qt6 COMPONENTS Core LinguistTools Network OPTIONAL_COMPONENTS Svg WebSockets Widgets) else() - find_package(Qt6 COMPONENTS Core LinguistTools Network Sql SerialPort OPTIONAL_COMPONENTS WebSockets Widgets) + find_package(Qt6 COMPONENTS Core LinguistTools Network Sql SerialPort OPTIONAL_COMPONENTS Svg WebSockets Widgets) endif() set(QtWebSockets_FOUND ${Qt6WebSockets_FOUND}) + set(QtSvg_FOUND ${Qt6Svg_FOUND}) set(Qt_FOUND ${Qt6_FOUND}) set(QtWidgets_FOUND ${Qt6Widgets_FOUND}) else() - find_package(Qt5 COMPONENTS Core LinguistTools Network Sql SerialPort OPTIONAL_COMPONENTS WebSockets Widgets) + find_package(Qt5 COMPONENTS Core LinguistTools Network Sql SerialPort OPTIONAL_COMPONENTS Svg WebSockets Widgets) set(QtWebSockets_FOUND ${Qt5WebSockets_FOUND}) + set(QtSvg_FOUND ${Qt6Svg_FOUND}) set(Qt_FOUND ${Qt5_FOUND}) set(QtWidgets_FOUND ${Qt5Widgets_FOUND}) @@ -206,6 +208,13 @@ else() message(STATUS "SHV websocket support disabled") endif() +set(LIBSHV_WITH_SVG ${QtSvg_FOUND}) +if(LIBSHV_WITH_SVG) + message(STATUS "SVG support enabled") +else() + message(STATUS "SVG support disabled") +endif() + if(LIBSHV_WITH_CORE) if(Qt_FOUND) set(CMAKE_AUTOMOC ON) diff --git a/libshvvisu/CMakeLists.txt b/libshvvisu/CMakeLists.txt index dc540b8b7..4374b84fe 100644 --- a/libshvvisu/CMakeLists.txt +++ b/libshvvisu/CMakeLists.txt @@ -76,6 +76,11 @@ target_include_directories(libshvvisu PUBLIC ) target_compile_definitions(libshvvisu PRIVATE SHVVISU_BUILD_DLL) +if(LIBSHV_WITH_SVG) + target_compile_definitions(libshvvisu PUBLIC WITH_SHV_SVG) + target_link_libraries(libshvvisu PUBLIC Qt::Svg) +endif() + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/shv" TYPE INCLUDE) install(TARGETS libshvvisu EXPORT libshvConfig) diff --git a/libshvvisu/include/shv/visu/timeline/graph.h b/libshvvisu/include/shv/visu/timeline/graph.h index 0bdbfb82b..6666f3c30 100644 --- a/libshvvisu/include/shv/visu/timeline/graph.h +++ b/libshvvisu/include/shv/visu/timeline/graph.h @@ -23,7 +23,9 @@ #include #endif +#ifdef WITH_SHV_SVG class QSvgGenerator; +#endif namespace shv::visu::timeline { @@ -201,8 +203,11 @@ class SHVVISU_DECL_EXPORT Graph : public QObject GraphChannel::Style defaultChannelStyle() const; void makeLayout(const QRect &pref_rect); - void draw(QPainter *painter, const QRect &dirty_rect, const QRect &view_rect); + void draw(QPainter *painter, const QRect &dirty_rect, const QRect &view_rect); +#ifdef WITH_SHV_SVG + void draw(QSvgGenerator *svg_generator, const QRect &rect); +#endif int u2px(double u) const; double u2pxf(double u) const; double px2u(int px) const; @@ -237,9 +242,6 @@ class SHVVISU_DECL_EXPORT Graph : public QObject QStringList savedVisualSettingsNames(const QString &settings_id) const; void loadVisualSettings(const QString &settings_id, const QString &name); QString loadedVisualSettingsId(); - - void draw(QSvgGenerator *svg_generator, const QRect &rect); - protected: void sanityXRangeZoom(); diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index 933facb73..8b1770c7c 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -17,6 +16,10 @@ #include #include +#ifdef WITH_SHV_SVG +#include +#endif + #include namespace shv::visu::timeline { @@ -1296,7 +1299,7 @@ int Graph::maximizedChannelIndex() const return -1; } - +#ifdef WITH_SHV_SVG void Graph::draw(QSvgGenerator *svg_generator, const QRect &rect) { auto orig_layout = m_layout.rect; @@ -1305,7 +1308,7 @@ void Graph::draw(QSvgGenerator *svg_generator, const QRect &rect) draw(&painter, rect, rect); makeLayout(orig_layout); } - +#endif void Graph::draw(QPainter *painter, const QRect &dirty_rect, const QRect &view_rect) { drawBackground(painter, dirty_rect);