OGS
StratBar.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "StratBar.h"
5
6#include <QPainter>
7
9 std::map<std::string, DataHolderLib::Color>* stratColors,
10 QGraphicsItem* parent)
11 : QGraphicsItem(parent), _station(station)
12{
13 if (stratColors)
14 {
15 _stratColors = *stratColors;
16 }
17}
18
20{
21 return QRectF(0, 0, BARWIDTH + 10, totalLogHeight());
22}
23
24void StratBar::paint(QPainter* painter,
25 const QStyleOptionGraphicsItem* option,
26 QWidget* widget)
27{
28 Q_UNUSED(option)
29 Q_UNUSED(widget)
30
31 double top = 0;
32 double height = 0;
33
34 QPen pen(Qt::black, 1, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin);
35 pen.setCosmetic(true);
36 painter->setPen(pen);
37 // painter->drawRect(_bar);
38
39 // pen.setWidth(1);
40 std::vector<GeoLib::Point*> profile = _station->getProfile();
41 std::vector<std::string> soilNames = _station->getSoilNames();
42 std::size_t nLayers = profile.size();
43
44 painter->drawLine(0, 0, BARWIDTH + 5, 0);
45
46 for (std::size_t i = 1; i < nLayers; i++)
47 {
48 top += height;
49 height = logHeight(((*(profile[i - 1]))[2] - (*(profile[i]))[2]));
50 QRectF layer(0, top, BARWIDTH, height);
51 DataHolderLib::Color const& c(
53 QBrush brush(QColor(static_cast<int>(c[0]),
54 static_cast<int>(c[1]),
55 static_cast<int>(c[2]),
56 127),
57 Qt::SolidPattern);
58 painter->setBrush(brush);
59
60 painter->drawRect(layer);
61 painter->drawLine(0,
62 static_cast<int>(layer.bottom()),
63 BARWIDTH + 5,
64 static_cast<int>(layer.bottom()));
65 // painter->drawText(BARWIDTH+10, layer.bottom(),
66 // QString::number((*(profile[i]))[2]));
67 }
68}
69
71{
72 double height = 0;
73 std::vector<GeoLib::Point*> profile = _station->getProfile();
74
75 for (std::size_t i = 1; i < profile.size(); i++)
76 {
77 height += (log((*(profile[i - 1]))[2] - (*(profile[i]))[2] + 1) * 100);
78 }
79
80 return height;
81}
A borehole as a geometric object.
double logHeight(double h) const
Calculates the height for a soil layer by "log(d+1)*100".
Definition StratBar.h:46
double totalLogHeight() const
Calculates the total height of the bar by calculating and adding the log-height for all layers in the...
Definition StratBar.cpp:70
static const int BARWIDTH
The default width of the bar.
Definition StratBar.h:52
QRectF boundingRect() const override
Returns the bounding rectangle of the bar.
Definition StratBar.cpp:19
std::map< std::string, DataHolderLib::Color > _stratColors
Definition StratBar.h:55
GeoLib::StationBorehole * _station
Definition StratBar.h:54
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Paints the bar.
Definition StratBar.cpp:24
StratBar(GeoLib::StationBorehole *station, std::map< std::string, DataHolderLib::Color > *stratColors=nullptr, QGraphicsItem *parent=nullptr)
Constructor.
Definition StratBar.cpp:8
Color getColor(const std::string &id, std::map< std::string, Color > &colors)
Definition Color.cpp:25
std::array< unsigned char, 4 > Color
Definition Color.h:12