29 : QGraphicsScene(parent)
75 auto* arrow =
new QArrow(length, angle, 8, 5, pen);
83 auto* caption =
new QGraphicsItemGroup(
nullptr);
84 QGraphicsLineItem* l = addLine(0, 0, 100, 0, pen);
85 QGraphicsTextItem* t = addText(name);
87 t->setPos(110, -(t->boundingRect()).height() / 2);
88 caption->addToGroup(l);
89 caption->addToGroup(t);
90 caption->setFlag(QGraphicsItem::ItemIgnoresTransformations,
true);
129 const QString& text,
const QFont& font)
141 const int MinTicks = 4;
142 double grossStep = (max - min) / MinTicks;
143 double step = pow(10.0, std::floor(log10(grossStep)));
144 if (5 * step < grossStep)
148 else if (2 * step < grossStep)
152 numberOfTicks = int(ceil(max / step) - std::floor(min / step));
153 if (numberOfTicks < MinTicks)
155 numberOfTicks = MinTicks;
157 min = std::floor(min / step) * step;
158 max = ceil(max / step) * step;
193 removeItem(graphCaption);
224 QPen pen(Qt::black, 1, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin);
229 for (
int i = 0; i <= numXTicks; ++i)
240 for (
int i = 0; i <= numXTicks; ++i)
245 QDateTime currentDate =
_startDate.addSecs(x);
252 for (
int j = 0; j <= numYTicks; ++j)
270 QPen pen(list->
getColor(), 2, Qt::SolidLine, Qt::SquareCap,
272 pen.setCosmetic(
true);
273 _graphs.push_back(addPath(path, pen));
284 (
_graphs[last]->boundingRect()).height());
286 QTransform(QMatrix(1, 0, 0, -1, 0, verticalShift)));
296 :
static_cast<int>(
_bounds.bottom());
305 :
static_cast<int>(
_bounds.left());
312 QPen pen(Qt::black, 1, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin);
313 pen.setCosmetic(
true);
386 for (
int i = 0; i <
_graphs.size(); i++)
388 rect =
_graphs[i]->boundingRect();
389 auto offset =
static_cast<int>(fabs(rect.bottom() -
_bounds.bottom()) -
390 fabs(rect.top() -
_bounds.top()));
393 rect = itemsBoundingRect();
static constexpr float kDefaultX
static constexpr float kDefaultY
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.
A 2D cartesian grid as a QGraphicsItem.
A QGraphicsTextItem that will ignore all geometric transformations.