40 : QGraphicsScene(parent)
86 auto* arrow =
new QArrow(length, angle, 8, 5, pen);
94 auto* caption =
new QGraphicsItemGroup(
nullptr);
95 QGraphicsLineItem* l = addLine(0, 0, 100, 0, pen);
96 QGraphicsTextItem* t = addText(name);
98 t->setPos(110, -(t->boundingRect()).height() / 2);
99 caption->addToGroup(l);
100 caption->addToGroup(t);
101 caption->setFlag(QGraphicsItem::ItemIgnoresTransformations,
true);
140 const QString& text,
const QFont& font)
152 const int MinTicks = 4;
153 double grossStep = (max - min) / MinTicks;
154 double step = pow(10.0, std::floor(log10(grossStep)));
155 if (5 * step < grossStep)
159 else if (2 * step < grossStep)
163 numberOfTicks = int(ceil(max / step) - std::floor(min / step));
164 if (numberOfTicks < MinTicks)
166 numberOfTicks = MinTicks;
168 min = std::floor(min / step) * step;
169 max = ceil(max / step) * step;
204 removeItem(graphCaption);
235 QPen pen(Qt::black, 1, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin);
240 for (
int i = 0; i <= numXTicks; ++i)
251 for (
int i = 0; i <= numXTicks; ++i)
256 QDateTime currentDate =
_startDate.addSecs(x);
263 for (
int j = 0; j <= numYTicks; ++j)
281 QPen pen(list->
getColor(), 2, Qt::SolidLine, Qt::SquareCap,
283 pen.setCosmetic(
true);
284 _graphs.push_back(addPath(path, pen));
295 (
_graphs[last]->boundingRect()).height());
297 QTransform(QMatrix(1, 0, 0, -1, 0, verticalShift)));
307 :
static_cast<int>(
_bounds.bottom());
316 :
static_cast<int>(
_bounds.left());
323 QPen pen(Qt::black, 1, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin);
324 pen.setCosmetic(
true);
397 for (
int i = 0; i <
_graphs.size(); i++)
399 rect =
_graphs[i]->boundingRect();
400 auto offset =
static_cast<int>(fabs(rect.bottom() -
_bounds.bottom()) -
401 fabs(rect.top() -
_bounds.top()));
404 rect = itemsBoundingRect();
static constexpr float kDefaultX
static constexpr float kDefaultY
Definition of the DiagramScene class.
A List of data points and all the necessary meta-information to draw a graph.
float minYValue() const
Returns the minimum y-value.
float maxXValue() const
Returns the maximum x-value.
QString getYUnit() const
Returns the unit associated with the y-axis.
const QDateTime getStartDate() const
Returns the start date of this list.
QString getXLabel() const
Returns the label associated with the x-axis.
float maxYValue() const
Returns the maximum y-value.
QString getXUnit() const
Returns the unit associated with the x-axis.
QString getName() const
Returns the name of the diagram.
float minXValue() const
Returns the minimum x-value.
QColor getColor() const
Returns the colour of the graph.
QString getYLabel() const
Returns the label associated with the y-axis.
bool getPath(QPainterPath &path, float scaleX, float scaleY)
DiagramScene(QObject *parent=nullptr)
void drawGraph(DiagramList *list)
Plots the graph.
QVector< QNonScalableGraphicsTextItem * > _xTicksText
void adjustAxis(qreal &min, qreal &max, int &numberOfTicks)
QNonScalableGraphicsTextItem * _xUnit
QVector< QGraphicsPathItem * > _graphs
QVector< QGraphicsItemGroup * > _graphCaptions
QVector< QNonScalableGraphicsTextItem * > _yTicksText
void addGraph(DiagramList *list)
Adds a graph to the scene, including all data points and meta-information.
QArrow * addArrow(qreal length, qreal angle, QPen &pen)
void addCaption(const QString &name, QPen &pen)
The margin between the boundary of the scene and the bounding box of all items within the scene.
QNonScalableGraphicsTextItem * _yUnit
QGraphicsGrid * addGrid(const QRectF &rect, int xTicks, int yTicks, const QPen &pen)
Adds a grid-object to the scene.
void setDiagramBoundaries(DiagramList *list)
QNonScalableGraphicsTextItem * _yLabel
QNonScalableGraphicsTextItem * _xLabel
QNonScalableGraphicsTextItem * addNonScalableText(const QString &text, const QFont &font=QFont())
Adds a non-scalable text object to the scene.
void setYAxis(QArrow *arrow)
Sets an arrow as y-axis.
QVector< DiagramList * > _lists
void clearGrid()
Destroys the grid object (coordinate system) when a new graph is added.
void setXAxis(QArrow *arrow)
Sets an arrow as x-axis.
An arrow as a QGraphicsObject.
void setLength(qreal l)
Changes the length of the arrow.
A 2D cartesian grid as a QGraphicsItem.
A QGraphicsTextItem that will ignore all geometric transformations.