-
Notifications
You must be signed in to change notification settings - Fork 0
/
innfoschartview.cpp
84 lines (74 loc) · 2.12 KB
/
innfoschartview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "innfoschartview.h"
#include "callout.h"
#include <QtWidgets/QGraphicsScene>
#include <QtCharts/QChart>
#include <QDebug>
InnfosChartView::InnfosChartView(QChart *pChart, QWidget *parent):
QGraphicsView(new QGraphicsScene,parent),
m_pCurTooltip(nullptr),
m_pChart(pChart)
{
setDragMode(QGraphicsView::NoDrag);
// setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setMouseTracking(true);
scene()->addItem(m_pChart);
// QAbstractSeries * series = m_pChart->series().at(0);
// connect(series, SIGNAL(clicked(QPointF)), this, SLOT(keepCallout()));
// connect(series, SIGNAL(hovered(QPointF, bool)), this, SLOT(tooltip(QPointF,bool)));
}
void InnfosChartView::keepCallout()
{
m_callouts.append(m_pCurTooltip);
m_pCurTooltip = new Callout(m_pChart);
m_pCurTooltip->hide();
}
void InnfosChartView::tooltip(QPointF point, bool state)
{
if(!m_pCurTooltip)
m_pCurTooltip = new Callout(m_pChart);
if(state)
{
m_pCurTooltip->setText(QString("X:%1 \nY:%2 ").arg(point.x()).arg(point.y()));
m_pCurTooltip->setAnchor(point);
m_pCurTooltip->setZValue(11);
m_pCurTooltip->updateGeometry();
m_pCurTooltip->show();
}
else
{
m_pCurTooltip->hide();
}
}
void InnfosChartView::clearAllCallouts()
{
foreach (Callout * callout, m_callouts) {
if(scene())
{
scene()->removeItem(callout);
}
}
if(m_pCurTooltip)
{
scene()->removeItem(m_pCurTooltip);
m_pCurTooltip = nullptr;
}
}
void InnfosChartView::resizeEvent(QResizeEvent *event)
{
if(scene())
{
scene()->setSceneRect(QRect(QPoint(0, 0), event->size()));
m_pChart->resize(event->size());
foreach (Callout * callout, m_callouts) {
callout->updateGeometry();
}
}
QGraphicsView::resizeEvent(event);
}
void InnfosChartView::mouseMoveEvent(QMouseEvent *event)
{
// QList<QGraphicsItem *> items = scene()->items(event->pos());
// qDebug() << items <<endl;
QGraphicsView::mouseMoveEvent(event);
}