Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw graph into svg #518

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions libshvvisu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions libshvvisu/include/shv/visu/timeline/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <QTimeZone>
#endif

#ifdef WITH_SHV_SVG
class QSvgGenerator;
#endif

namespace shv::visu::timeline {

class SHVVISU_DECL_EXPORT Graph : public QObject
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
15 changes: 14 additions & 1 deletion libshvvisu/src/timeline/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <QPainterPath>
#include <QSettings>

#ifdef WITH_SHV_SVG
#include <QSvgGenerator>
#endif

#include <cmath>

namespace shv::visu::timeline {
Expand Down Expand Up @@ -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);
Expand Down