OGS
StratScene.cpp
Go to the documentation of this file.
1
15#include "StratScene.h"
16
17#include <math.h>
18
19#include <QGraphicsTextItem>
20#include <limits>
21
23#include "BaseLib/DateTools.h"
24#include "StratBar.h"
25
27 std::map<std::string, DataHolderLib::Color>* stratColors,
28 QObject* parent)
29 : QGraphicsScene(parent)
30{
31 QRectF textBounds;
32 int stratBarOffset = 250;
33
34 QFont font("Arial", 15, QFont::DemiBold, false);
35
36 QNonScalableGraphicsTextItem* boreholeTag =
37 addNonScalableText("Borehole", font);
39 "\"" + QString::fromStdString(station->getName()) + "\"", font);
40 textBounds = boreholeTag->boundingRect();
41 boreholeTag->setPos((textBounds.width() / 2.0), 80);
42 textBounds = boreholeName->boundingRect();
43 boreholeName->setPos((textBounds.width() / 2.0), 200);
44
46 "Depth: " + QString::number(station->getDepth()) + " m");
47 textBounds = totalDepth->boundingRect();
48 totalDepth->setPos((textBounds.width() / 2.0), 350);
49 /*
50 QNonScalableGraphicsTextItem* dateText = addNonScalableText("Date: " +
51 QString::fromStdString(date2string(station->getDate()))); textBounds =
52 dateText->boundingRect(); dateText->setPos(this->MARGIN +
53 (textBounds.width()/2.0), 350);
54 */
56 dot->setPos(0, 0);
57
58 StratBar* stratBar = addStratBar(station, stratColors);
59 stratBar->setPos(stratBarOffset, MARGIN);
60 QRectF stratBarBounds = stratBar->boundingRect();
61
62 addDepthLabels(station->getProfile(),
63 stratBarOffset + stratBarBounds.width());
64
65 if (!station->getSoilNames().empty())
66 {
67 addSoilNameLabels(station->getSoilNames(), station->getProfile(),
68 stratBarOffset + (stratBarBounds.width() / 2));
69 }
70}
71
72StratScene::~StratScene() = default;
73
74void StratScene::addDepthLabels(std::vector<GeoLib::Point*> profile,
75 double offset)
76{
77 QRectF textBounds;
78 double vertPos = MARGIN;
79 std::vector<QNonScalableGraphicsTextItem*> depthText;
80 depthText.push_back(
81 addNonScalableText(QString::number((*(profile[0]))[2])));
82 textBounds = depthText[0]->boundingRect();
83 depthText[0]->setPos(offset + textBounds.width() / 2, vertPos);
84
85 for (std::size_t i = 1; i < profile.size(); i++)
86 {
87 depthText.push_back(
88 addNonScalableText(QString::number((*(profile[i]))[2])));
89 vertPos += log((*(profile[i - 1]))[2] - (*(profile[i]))[2] + 1) * 100;
90 textBounds = depthText[i]->boundingRect();
91 depthText[i]->setPos(offset + textBounds.width() / 2, vertPos);
92 }
93}
94
96 const QString& text, const QFont& font)
97{
98 auto* item = new QNonScalableGraphicsTextItem(text);
99 item->setFont(font);
100 addItem(item);
101 return item;
102}
103
104void StratScene::addSoilNameLabels(std::vector<std::string> soilNames,
105 std::vector<GeoLib::Point*>
106 profile,
107 double offset)
108{
109 // QRectF textBounds;
110 double vertPos = MARGIN;
111 double halfHeight = 0;
112 std::vector<QNonScalableGraphicsTextItem*> soilText;
113 soilText.push_back(
114 addNonScalableText(QString::fromStdString(soilNames[0])));
115 // textBounds = soilText[0]->boundingRect();
116 soilText[0]->setPos(offset /* - textBounds.width() */, vertPos);
117
118 for (std::size_t i = 1; i < soilNames.size(); i++)
119 {
120 soilText.push_back(
121 addNonScalableText(QString::fromStdString(soilNames[i])));
122 halfHeight =
123 log((*(profile[i - 1]))[2] - (*(profile[i]))[2] + 1) * 100 / 2;
124 // textBounds = soilText[i]->boundingRect();
125 soilText[i]->setPos(offset /* - textBounds.width() */,
126 vertPos + halfHeight);
127 vertPos += (2 * halfHeight);
128 }
129}
130
133 std::map<std::string, DataHolderLib::Color>* stratColors)
134{
135 auto* b = new StratBar(station, stratColors);
136 addItem(b);
137 return b;
138}
Definition of date helper functions.
Definition of the QNonScalableGraphicsTextItem class.
Definition of the StratBar class.
Definition of the StratScene class.
A borehole as a geometric object.
const std::vector< std::string > & getSoilNames() const
const std::vector< Point * > & getProfile() const
std::string const & getName() const
Returns the name of the station.
Definition Station.h:60
A QGraphicsTextItem that will ignore all geometric transformations.
QRectF boundingRect() const override
Returns the bounding rectangle of the text item.
A 2D bar visualisation of a borehole stratigraphy.
Definition StratBar.h:30
QRectF boundingRect() const override
Returns the bounding rectangle of the bar.
Definition StratBar.cpp:30
QNonScalableGraphicsTextItem * addNonScalableText(const QString &text, const QFont &font=QFont())
Add a non-scalable text item to the scene.
void addSoilNameLabels(std::vector< std::string > soilNames, std::vector< GeoLib::Point * > profile, double offset)
Adds text labels indicating the name of each soil layer.
StratScene(GeoLib::StationBorehole *station, std::map< std::string, DataHolderLib::Color > *stratColors=nullptr, QObject *parent=nullptr)
Constructor.
~StratScene() override
void addDepthLabels(std::vector< GeoLib::Point * > profile, double offset)
Adds text labels indicating the depth at the beginning and end of each soil layer.
static const int MARGIN
The margin between the boundary of the scene and the bounding box of all items within the scene.
Definition StratScene.h:39
StratBar * addStratBar(GeoLib::StationBorehole *station, std::map< std::string, DataHolderLib::Color > *stratColors=nullptr)
Add a stratigraphy-bar to the scene.