diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-01-01 22:03:26 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-01-02 11:04:03 -0800 |
commit | 99f98ea6d482c7bb5526fad8246e12bb8714b252 (patch) | |
tree | 03b4eeeef2b071eedd1a9e97f63a2738bf884529 /stats/informationbox.h | |
parent | 907e6ff05d35278303bc72ba5d93614da6ca0ab7 (diff) | |
download | subsurface-99f98ea6d482c7bb5526fad8246e12bb8714b252.tar.gz |
statistics: implement a simple information box
When the user hovers over features in the chart, they should
be presented with more information. For example in bar charts
on the dives the bar represents and the exact value that the
bar represents, etc.
The InformationBox is a simple QGraphicsWidget, which can be
placed on top of QCharts and can show a number of arbitrary
text lines.
When placing the box on the chart, the code attempts to stay
inside the plot area of the chart.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/informationbox.h')
-rw-r--r-- | stats/informationbox.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/stats/informationbox.h b/stats/informationbox.h new file mode 100644 index 000000000..7e9253dc7 --- /dev/null +++ b/stats/informationbox.h @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 +// A small box displaying statistics information, notably +// for a scatter-plot item or a bar in a bar chart. +#ifndef INFORMATION_BOX_H +#define INFORMATION_BOX_H + +#include <vector> +#include <memory> +#include <QGraphicsRectItem> +#include <QFont> + +namespace QtCharts { + class QChart; +} +struct dive; + +// Information window showing data of highlighted dive +struct InformationBox : QGraphicsRectItem { + InformationBox(QtCharts::QChart *chart); + void setText(const std::vector<QString> &text, QPointF pos); + void setPos(QPointF pos); + int recommendedMaxLines() const; +private: + QtCharts::QChart *chart; + QFont font; // For future specialization. + double width, height; + void addLine(const QString &s); + std::vector<std::unique_ptr<QGraphicsSimpleTextItem>> textItems; +}; + +#endif |