OGS
StratBar Class Reference

Detailed Description

A 2D bar visualisation of a borehole stratigraphy.

A 2D bar visualisation of a borehole stratigraphy as a QGraphicsItem.

Definition at line 29 of file StratBar.h.

#include <StratBar.h>

Inheritance diagram for StratBar:
[legend]
Collaboration diagram for StratBar:
[legend]

Public Member Functions

 StratBar (GeoLib::StationBorehole *station, std::map< std::string, DataHolderLib::Color > *stratColors=nullptr, QGraphicsItem *parent=nullptr)
 Constructor.
 
 ~StratBar () override=default
 
QRectF boundingRect () const override
 Returns the bounding rectangle of the bar.
 
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
 Paints the bar.
 

Private Member Functions

double logHeight (double h) const
 Calculates the height for a soil layer by "log(d+1)*100".
 
double totalLogHeight () const
 Calculates the total height of the bar by calculating and adding the log-height for all layers in the borehole.
 

Private Attributes

GeoLib::StationBorehole_station
 
std::map< std::string, DataHolderLib::Color_stratColors
 

Static Private Attributes

static const int BARWIDTH = 50
 The default width of the bar.
 

Constructor & Destructor Documentation

◆ StratBar()

StratBar::StratBar ( GeoLib::StationBorehole * station,
std::map< std::string, DataHolderLib::Color > * stratColors = nullptr,
QGraphicsItem * parent = nullptr )
explicit

Constructor.

Parameters
stationThe borehole whose stratigraphy will be visualised.
stratColorsA color map.
parentThe parent QGraphicsItem.

Definition at line 19 of file StratBar.cpp.

22 : QGraphicsItem(parent), _station(station)
23{
24 if (stratColors)
25 {
26 _stratColors = *stratColors;
27 }
28}
std::map< std::string, DataHolderLib::Color > _stratColors
Definition StratBar.h:66
GeoLib::StationBorehole * _station
Definition StratBar.h:65

References _stratColors.

◆ ~StratBar()

StratBar::~StratBar ( )
overridedefault

Member Function Documentation

◆ boundingRect()

QRectF StratBar::boundingRect ( ) const
override

Returns the bounding rectangle of the bar.

Definition at line 30 of file StratBar.cpp.

31{
32 return QRectF(0, 0, BARWIDTH + 10, totalLogHeight());
33}
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:81
static const int BARWIDTH
The default width of the bar.
Definition StratBar.h:63

References BARWIDTH, and totalLogHeight().

Referenced by StratScene::StratScene().

◆ logHeight()

double StratBar::logHeight ( double h) const
inlineprivate

Calculates the height for a soil layer by "log(d+1)*100".

Parameters
hThe original thickness of the soil layer.

Definition at line 57 of file StratBar.h.

57{ return log(h + 1) * 100; }

Referenced by paint().

◆ paint()

void StratBar::paint ( QPainter * painter,
const QStyleOptionGraphicsItem * option,
QWidget * widget )
override

Paints the bar.

Definition at line 35 of file StratBar.cpp.

38{
39 Q_UNUSED(option)
40 Q_UNUSED(widget)
41
42 double top = 0;
43 double height = 0;
44
45 QPen pen(Qt::black, 1, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin);
46 pen.setCosmetic(true);
47 painter->setPen(pen);
48 // painter->drawRect(_bar);
49
50 // pen.setWidth(1);
51 std::vector<GeoLib::Point*> profile = _station->getProfile();
52 std::vector<std::string> soilNames = _station->getSoilNames();
53 std::size_t nLayers = profile.size();
54
55 painter->drawLine(0, 0, BARWIDTH + 5, 0);
56
57 for (std::size_t i = 1; i < nLayers; i++)
58 {
59 top += height;
60 height = logHeight(((*(profile[i - 1]))[2] - (*(profile[i]))[2]));
61 QRectF layer(0, top, BARWIDTH, height);
64 QBrush brush(QColor(static_cast<int>(c[0]),
65 static_cast<int>(c[1]),
66 static_cast<int>(c[2]),
67 127),
68 Qt::SolidPattern);
69 painter->setBrush(brush);
70
71 painter->drawRect(layer);
72 painter->drawLine(0,
73 static_cast<int>(layer.bottom()),
74 BARWIDTH + 5,
75 static_cast<int>(layer.bottom()));
76 // painter->drawText(BARWIDTH+10, layer.bottom(),
77 // QString::number((*(profile[i]))[2]));
78 }
79}
const std::vector< std::string > & getSoilNames() const
const std::vector< Point * > & getProfile() const
double logHeight(double h) const
Calculates the height for a soil layer by "log(d+1)*100".
Definition StratBar.h:57
Color getColor(const std::string &id, std::map< std::string, Color > &colors)
Definition Color.cpp:36
std::array< unsigned char, 4 > Color
Definition Color.h:24

References _station, _stratColors, BARWIDTH, DataHolderLib::getColor(), GeoLib::StationBorehole::getProfile(), GeoLib::StationBorehole::getSoilNames(), and logHeight().

◆ totalLogHeight()

double StratBar::totalLogHeight ( ) const
private

Calculates the total height of the bar by calculating and adding the log-height for all layers in the borehole.

Definition at line 81 of file StratBar.cpp.

82{
83 double height = 0;
84 std::vector<GeoLib::Point*> profile = _station->getProfile();
85
86 for (std::size_t i = 1; i < profile.size(); i++)
87 {
88 height += (log((*(profile[i - 1]))[2] - (*(profile[i]))[2] + 1) * 100);
89 }
90
91 return height;
92}

References _station, and GeoLib::StationBorehole::getProfile().

Referenced by boundingRect().

Member Data Documentation

◆ _station

GeoLib::StationBorehole* StratBar::_station
private

Definition at line 65 of file StratBar.h.

Referenced by paint(), and totalLogHeight().

◆ _stratColors

std::map<std::string, DataHolderLib::Color> StratBar::_stratColors
private

Definition at line 66 of file StratBar.h.

Referenced by StratBar(), and paint().

◆ BARWIDTH

const int StratBar::BARWIDTH = 50
staticprivate

The default width of the bar.

Definition at line 63 of file StratBar.h.

Referenced by boundingRect(), and paint().


The documentation for this class was generated from the following files: