Skip to content

Commit

Permalink
Add QtSvg to libshvvisu dependences
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanda Vacek authored and fvacek committed Oct 30, 2024
1 parent 79df35d commit de2110c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
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: 6 additions & 4 deletions libshvvisu/include/shv/visu/timeline/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include <QTimeZone>
#endif

#ifdef WITH_SHV_SVG
class QSvgGenerator;
#endif

namespace shv::visu::timeline {

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
9 changes: 6 additions & 3 deletions libshvvisu/src/timeline/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <shv/core/exception.h>
#include <shv/coreqt/log.h>
#include <shv/chainpack/rpcvalue.h>
#include <QtSvg/QSvgGenerator>

#include <QPainter>
#include <QFontMetrics>
Expand All @@ -17,6 +16,10 @@
#include <QPainterPath>
#include <QSettings>

#ifdef WITH_SHV_SVG
#include <QSvgGenerator>
#endif

#include <cmath>

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

0 comments on commit de2110c

Please sign in to comment.