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 05176ba2c..6666f3c30 100644 --- a/libshvvisu/include/shv/visu/timeline/graph.h +++ b/libshvvisu/include/shv/visu/timeline/graph.h @@ -23,6 +23,10 @@ #include #endif +#ifdef WITH_SHV_SVG +class QSvgGenerator; +#endif + namespace shv::visu::timeline { class SHVVISU_DECL_EXPORT Graph : public QObject @@ -199,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; @@ -235,7 +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(); - protected: void sanityXRangeZoom(); diff --git a/libshvvisu/src/timeline/graph.cpp b/libshvvisu/src/timeline/graph.cpp index 2d07a1a87..8b1770c7c 100644 --- a/libshvvisu/src/timeline/graph.cpp +++ b/libshvvisu/src/timeline/graph.cpp @@ -16,6 +16,10 @@ #include #include +#ifdef WITH_SHV_SVG +#include +#endif + #include namespace shv::visu::timeline { @@ -1295,7 +1299,16 @@ 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; + makeLayout(rect); + QPainter painter(svg_generator); + 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);