boat
C++23 geospatial library
Loading...
Searching...
No Matches
qt.hpp
Go to the documentation of this file.
1// Andrew Naplavkov
2
3#ifndef BOAT_GUI_QT_HPP
4#define BOAT_GUI_QT_HPP
5
6#include <QImage>
7#include <QPainter>
8#include <QPainterPath>
9#include <boat/gui/detail/geometry.hpp>
10#include <boat/gui/detail/raster.hpp>
11
12namespace boat::gui {
13namespace detail {
14
15constexpr auto qt = overloaded{
16 [](geometry::point auto&& v) { return QPointF(v.x(), v.y()); },
17 [](this auto&& self, geometry::curve auto&& v) -> QList<QPointF> {
18 return v | std::views::transform(self) | std::ranges::to<QList>();
19 },
20 [](this auto&& self, geometry::polygon auto&& v) -> QPainterPath {
21 auto ret = QPainterPath{};
22 ret.addPolygon(self(v.outer()));
23 for (auto& item : v.inners())
24 ret.addPolygon(self(item));
25 return ret;
26 }};
27
28} // namespace detail
29
30inline auto draw_geometry(QPainter& out)
31{
32 return geometry::visitor(
33 [&](geometry::point auto&& v) { out.drawPoint(detail::qt(v)); },
34 [&](geometry::linestring auto&& v) { out.drawPolyline(detail::qt(v)); },
35 [&](geometry::polygon auto&& v) { out.drawPath(detail::qt(v)); });
36}
37
40 execution_policy auto policy,
41 rgba8_view auto in,
42 geometry::matrix const& in_affine,
43 geometry::srs_spec auto&& in_crs,
44 QPainter& out,
45 geometry::matrix const& out_affine,
46 geometry::srs_spec auto&& out_crs)
47{
48 auto img = QImage{};
49 int x, y, w, h;
50 out.window().getRect(&x, &y, &w, &h);
51 auto rect = draw_image(
52 policy,
53 in,
54 in_affine,
55 in_crs,
56 out_affine,
57 out_crs,
58 {{x, y}, {x + w, y + h}},
59 [&](int w, int h) {
60 img = QImage{w, h, QImage::Format_RGBA8888};
61 return [bits = img.bits()](auto i, auto px) {
62 for (int j{}; j < 4; ++j)
63 bits[4 * i + j] = px[j];
64 };
65 });
66 if (rect)
67 out.drawImage(detail::qt(rect->min_corner()), img);
68}
69
70} // namespace boat::gui
71
72#endif // BOAT_GUI_QT_HPP
Definition vocabulary.hpp:37
Definition vocabulary.hpp:46
Definition vocabulary.hpp:49
Definition transform.hpp:29
Definition variant.hpp:17
auto visitor(auto... fn)
Definition algorithm.hpp:64
boost::qvm::mat< double, 3, 3 > matrix
Definition vocabulary.hpp:104
Definition cache.hpp:9
auto draw_geometry(QPainter &out)
Definition qt.hpp:30
void draw_image(execution_policy auto policy, rgba8_view auto in, geometry::matrix const &in_affine, geometry::srs_spec auto &&in_crs, QPainter &out, geometry::matrix const &out_affine, geometry::srs_spec auto &&out_crs)
Affine matrices map pixels to spatial coordinates.
Definition qt.hpp:39