1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#ifndef GRID_H_
31#define GRID_H_
32
33#include "model.h"
34#include <QtWidgets/QGraphicsWidget>
35#include <QtCharts/QChartGlobal>
36
37QT_BEGIN_NAMESPACE
38class QGraphicsGridLayout;
39QT_END_NAMESPACE
40
41class Chart;
42
43QT_CHARTS_BEGIN_NAMESPACE
44class QChart;
45QT_CHARTS_END_NAMESPACE
46
47QT_CHARTS_USE_NAMESPACE
48
49class Grid : public QGraphicsWidget
50{
51 Q_OBJECT
52public:
53 enum State { NoState = 0, ZoomState, ScrollState};
54
55 Grid(int size, QGraphicsItem *parent = 0);
56 ~Grid();
57
58 QList<QChart *> charts();
59 void createCharts(const QString &category = QString());
60 void createCharts(const QString &category, const QString &subcategory, const QString &name);
61 void replaceChart(QChart *oldChart, Chart *newChart);
62 void setState(State state);
63 State state() const { return m_state; };
64 void setRubberPen(const QPen &pen);
65 void setSize(int size);
66 int size() const {return m_size;}
67
68Q_SIGNALS:
69 void chartSelected(QChart *chart);
70
71protected:
72 void mousePressEvent(QGraphicsSceneMouseEvent *event);
73 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
74 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
75
76private:
77 void clear();
78
79private:
80 int m_listCount;
81 int m_valueMax;
82 int m_valueCount;
83 int m_size;
84 DataTable m_dataTable;
85 QHash<QChart *, int> m_chartHash;
86 QHash<int, QChart *> m_chartHashRev;
87 State m_state;
88 State m_currentState;
89 QPointF m_origin;
90 QGraphicsRectItem *m_rubberBand;
91 QGraphicsGridLayout *m_gridLayout;
92};
93
94#endif /* GRID_H_ */
95

source code of qtcharts/tests/manual/chartviewer/grid.h