@@ -2,7 +2,7 | |||||
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <cmath> |
|
3 | #include <cmath> | |
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 |
#include <qchart |
|
5 | #include <qchartview.h> | |
6 | #include <qpieseries.h> |
|
6 | #include <qpieseries.h> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
8 | QTCOMMERCIALCHART_USE_NAMESPACE | |
@@ -12,7 +12,7 int main(int argc, char *argv[]) | |||||
12 | QApplication a(argc, argv); |
|
12 | QApplication a(argc, argv); | |
13 |
|
13 | |||
14 | // Create widget and scatter series |
|
14 | // Create widget and scatter series | |
15 |
QChart |
|
15 | QChartView *chartWidget = new QChartView(); | |
16 | QPieSeries *series = qobject_cast<QPieSeries *>(chartWidget->createSeries(QChartSeries::SeriesTypePie)); |
|
16 | QPieSeries *series = qobject_cast<QPieSeries *>(chartWidget->createSeries(QChartSeries::SeriesTypePie)); | |
17 | Q_ASSERT(series); |
|
17 | Q_ASSERT(series); | |
18 |
|
18 |
@@ -2,7 +2,7 | |||||
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <cmath> |
|
3 | #include <cmath> | |
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 |
#include <qchart |
|
5 | #include <qchartview.h> | |
6 | #include <qscatterseries.h> |
|
6 | #include <qscatterseries.h> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
8 | QTCOMMERCIALCHART_USE_NAMESPACE | |
@@ -12,7 +12,7 int main(int argc, char *argv[]) | |||||
12 | QApplication a(argc, argv); |
|
12 | QApplication a(argc, argv); | |
13 |
|
13 | |||
14 | // Create widget and scatter series |
|
14 | // Create widget and scatter series | |
15 |
QChart |
|
15 | QChartView *chartWidget = new QChartView(); | |
16 | QScatterSeries *scatter = |
|
16 | QScatterSeries *scatter = | |
17 | qobject_cast<QScatterSeries *>(chartWidget->createSeries(QChartSeries::SeriesTypeScatter)); |
|
17 | qobject_cast<QScatterSeries *>(chartWidget->createSeries(QChartSeries::SeriesTypeScatter)); | |
18 | Q_ASSERT(scatter); |
|
18 | Q_ASSERT(scatter); |
@@ -11,7 +11,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
11 | QChartView::QChartView(QWidget *parent) : |
|
11 | QChartView::QChartView(QWidget *parent) : | |
12 | QGraphicsView(parent), |
|
12 | QGraphicsView(parent), | |
13 | m_scene(new QGraphicsScene()), |
|
13 | m_scene(new QGraphicsScene()), | |
14 | m_chart(new QChart()) |
|
14 | m_chart(new QChart()), | |
|
15 | m_rubberBand(0), | |||
|
16 | m_verticalRubberBand(false), | |||
|
17 | m_horizonalRubberBand(false) | |||
15 | { |
|
18 | { | |
16 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
19 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
17 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
20 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
@@ -82,4 +85,118 void QChartView::setChartBackgroundPen(const QPen& pen) | |||||
82 | { |
|
85 | { | |
83 | m_chart->setChartBackgroundPen(pen); |
|
86 | m_chart->setChartBackgroundPen(pen); | |
84 | } |
|
87 | } | |
|
88 | ||||
|
89 | ||||
|
90 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) | |||
|
91 | { | |||
|
92 | switch(policy){ | |||
|
93 | case VerticalRubberBand: | |||
|
94 | m_verticalRubberBand = true; | |||
|
95 | m_horizonalRubberBand = false; | |||
|
96 | break; | |||
|
97 | case HorizonalRubberBand: | |||
|
98 | m_verticalRubberBand = false; | |||
|
99 | m_horizonalRubberBand = true; | |||
|
100 | break; | |||
|
101 | case RectangleRubberBand: | |||
|
102 | m_verticalRubberBand = true; | |||
|
103 | m_horizonalRubberBand = true; | |||
|
104 | break; | |||
|
105 | case NoRubberBand: | |||
|
106 | default: | |||
|
107 | delete m_rubberBand; | |||
|
108 | m_rubberBand=0; | |||
|
109 | m_horizonalRubberBand = false; | |||
|
110 | m_verticalRubberBand = false; | |||
|
111 | return; | |||
|
112 | } | |||
|
113 | ||||
|
114 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |||
|
115 | m_rubberBand->setEnabled(true); | |||
|
116 | } | |||
|
117 | ||||
|
118 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const | |||
|
119 | { | |||
|
120 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; | |||
|
121 | if(m_horizonalRubberBand) return HorizonalRubberBand; | |||
|
122 | if(m_verticalRubberBand) return VerticalRubberBand; | |||
|
123 | return NoRubberBand; | |||
|
124 | } | |||
|
125 | ||||
|
126 | ||||
|
127 | void QChartView::mousePressEvent(QMouseEvent *event) | |||
|
128 | { | |||
|
129 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |||
|
130 | ||||
|
131 | int margin = m_chart->margin(); | |||
|
132 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |||
|
133 | ||||
|
134 | if (rect.contains(event->pos())) { | |||
|
135 | m_rubberBandOrigin = event->pos(); | |||
|
136 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); | |||
|
137 | m_rubberBand->show(); | |||
|
138 | event->accept(); | |||
|
139 | } | |||
|
140 | } | |||
|
141 | } | |||
|
142 | ||||
|
143 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |||
|
144 | { | |||
|
145 | if(m_rubberBand && m_rubberBand->isVisible()){ | |||
|
146 | int margin = m_chart->margin(); | |||
|
147 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |||
|
148 | int width = event->pos().x() - m_rubberBandOrigin.x(); | |||
|
149 | int height = event->pos().y() - m_rubberBandOrigin.y(); | |||
|
150 | if(!m_verticalRubberBand) { | |||
|
151 | m_rubberBandOrigin.setY(rect.top()); | |||
|
152 | height = rect.height(); | |||
|
153 | } | |||
|
154 | if(!m_horizonalRubberBand) { | |||
|
155 | m_rubberBandOrigin.setX(rect.left()); | |||
|
156 | width= rect.width(); | |||
|
157 | } | |||
|
158 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); | |||
|
159 | } else { | |||
|
160 | QGraphicsView::mouseMoveEvent(event); | |||
|
161 | } | |||
|
162 | } | |||
|
163 | ||||
|
164 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |||
|
165 | { | |||
|
166 | if(m_rubberBand){ | |||
|
167 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { | |||
|
168 | m_rubberBand->hide(); | |||
|
169 | QRect rect = m_rubberBand->geometry(); | |||
|
170 | m_chart->zoomInToRect(rect); | |||
|
171 | event->accept(); | |||
|
172 | } | |||
|
173 | ||||
|
174 | if(event->button()==Qt::RightButton) | |||
|
175 | m_chart->zoomReset(); | |||
|
176 | }else{ | |||
|
177 | QGraphicsView::mouseReleaseEvent(event); | |||
|
178 | } | |||
|
179 | } | |||
|
180 | ||||
|
181 | void QChartView::keyPressEvent(QKeyEvent *event) | |||
|
182 | { | |||
|
183 | switch (event->key()) { | |||
|
184 | case Qt::Key_Plus: | |||
|
185 | zoomIn(); | |||
|
186 | break; | |||
|
187 | case Qt::Key_Minus: | |||
|
188 | zoomOut(); | |||
|
189 | break; | |||
|
190 | default: | |||
|
191 | QGraphicsView::keyPressEvent(event); | |||
|
192 | break; | |||
|
193 | } | |||
|
194 | } | |||
|
195 | ||||
|
196 | void QChartView::setTheme(QChart::ChartThemeId theme) | |||
|
197 | { | |||
|
198 | m_chart->setTheme(theme); | |||
|
199 | } | |||
|
200 | ||||
|
201 | ||||
85 | QTCOMMERCIALCHART_END_NAMESPACE |
|
202 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -7,6 +7,7 | |||||
7 | #include <QGraphicsView> |
|
7 | #include <QGraphicsView> | |
8 |
|
8 | |||
9 | class QGraphicsScene; |
|
9 | class QGraphicsScene; | |
|
10 | class QRubberBand; | |||
10 |
|
11 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
13 | |||
@@ -15,6 +16,8 class QChart; | |||||
15 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView |
|
16 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView | |
16 | { |
|
17 | { | |
17 | public: |
|
18 | public: | |
|
19 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; | |||
|
20 | ||||
18 | explicit QChartView(QWidget *parent = 0); |
|
21 | explicit QChartView(QWidget *parent = 0); | |
19 | ~QChartView(); |
|
22 | ~QChartView(); | |
20 |
|
23 | |||
@@ -22,16 +25,17 public: | |||||
22 | void resizeEvent(QResizeEvent *event); |
|
25 | void resizeEvent(QResizeEvent *event); | |
23 |
|
26 | |||
24 | void addSeries(QChartSeries* series); |
|
27 | void addSeries(QChartSeries* series); | |
|
28 | ||||
25 | // Convenience function |
|
29 | // Convenience function | |
26 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
30 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
27 |
|
31 | |||
28 | int margin() const; |
|
32 | int margin() const; | |
|
33 | ||||
29 | void setTitle(const QString& title); |
|
34 | void setTitle(const QString& title); | |
30 |
|
35 | |||
31 | //Obsolete interface |
|
36 | //Obsolete interface | |
32 | void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, QChart::GradientOrientation orientation = QChart::VerticalGradientOrientation); |
|
37 | void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, QChart::GradientOrientation orientation = QChart::VerticalGradientOrientation); | |
33 |
|
38 | |||
34 |
|
||||
35 | void setChartBackgroundBrush(const QBrush& brush); |
|
39 | void setChartBackgroundBrush(const QBrush& brush); | |
36 | void setChartBackgroundPen(const QPen& pen); |
|
40 | void setChartBackgroundPen(const QPen& pen); | |
37 |
|
41 | |||
@@ -39,10 +43,25 public: | |||||
39 | void zoomIn(); |
|
43 | void zoomIn(); | |
40 | void zoomOut(); |
|
44 | void zoomOut(); | |
41 |
|
45 | |||
|
46 | void setRubberBandPolicy(const RubberBandPolicy ); | |||
|
47 | RubberBandPolicy rubberBandPolicy() const; | |||
|
48 | ||||
|
49 | void setTheme(QChart::ChartThemeId theme); | |||
|
50 | ||||
|
51 | protected: | |||
|
52 | void mousePressEvent(QMouseEvent *event); | |||
|
53 | void mouseMoveEvent(QMouseEvent *event); | |||
|
54 | void mouseReleaseEvent(QMouseEvent *event); | |||
|
55 | void keyPressEvent(QKeyEvent *event); | |||
|
56 | ||||
|
57 | ||||
42 | private: |
|
58 | private: | |
43 | QGraphicsScene *m_scene; |
|
59 | QGraphicsScene *m_scene; | |
44 | QChart* m_chart; |
|
60 | QChart* m_chart; | |
45 |
QPoint m_ |
|
61 | QPoint m_rubberBandOrigin; | |
|
62 | QRubberBand* m_rubberBand; | |||
|
63 | bool m_verticalRubberBand; | |||
|
64 | bool m_horizonalRubberBand; | |||
46 | Q_DISABLE_COPY(QChartView) |
|
65 | Q_DISABLE_COPY(QChartView) | |
47 |
|
66 | |||
48 |
|
67 |
@@ -28,7 +28,6 SOURCES += \ | |||||
28 | qpieseries.cpp \ |
|
28 | qpieseries.cpp \ | |
29 | qchart.cpp \ |
|
29 | qchart.cpp \ | |
30 | axisitem.cpp \ |
|
30 | axisitem.cpp \ | |
31 | qchartwidget.cpp \ |
|
|||
32 | pieslice.cpp \ |
|
31 | pieslice.cpp \ | |
33 | qchartview.cpp \ |
|
32 | qchartview.cpp \ | |
34 | qchartseries.cpp \ |
|
33 | qchartseries.cpp \ | |
@@ -63,7 +62,6 PUBLIC_HEADERS += \ | |||||
63 | qscatterseries.h \ |
|
62 | qscatterseries.h \ | |
64 | qpieseries.h \ |
|
63 | qpieseries.h \ | |
65 | qchart.h \ |
|
64 | qchart.h \ | |
66 | qchartwidget.h \ |
|
|||
67 | qchartglobal.h \ |
|
65 | qchartglobal.h \ | |
68 | xylinechart/qxychartseries.h \ |
|
66 | xylinechart/qxychartseries.h \ | |
69 | barchart/barchartseries.h \ |
|
67 | barchart/barchartseries.h \ |
@@ -23,7 +23,8 QTCOMMERCIALCHART_USE_NAMESPACE | |||||
23 | MainWidget::MainWidget(QWidget *parent) : |
|
23 | MainWidget::MainWidget(QWidget *parent) : | |
24 | QWidget(parent) |
|
24 | QWidget(parent) | |
25 | { |
|
25 | { | |
26 |
m_chartWidget = new QChart |
|
26 | m_chartWidget = new QChartView(this); | |
|
27 | m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand); | |||
27 |
|
28 | |||
28 | // Grid layout for the controls for configuring the chart widget |
|
29 | // Grid layout for the controls for configuring the chart widget | |
29 | QGridLayout *grid = new QGridLayout(); |
|
30 | QGridLayout *grid = new QGridLayout(); |
@@ -2,7 +2,7 | |||||
2 | #define MAINWIDGET_H |
|
2 | #define MAINWIDGET_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 |
#include <qchart |
|
5 | #include <qchartview.h> | |
6 | #include <QWidget> |
|
6 | #include <QWidget> | |
7 |
|
7 | |||
8 | class QSpinBox; |
|
8 | class QSpinBox; | |
@@ -41,7 +41,7 private slots: | |||||
41 | void setPiePosition(int position); |
|
41 | void setPiePosition(int position); | |
42 |
|
42 | |||
43 | private: |
|
43 | private: | |
44 |
QChart |
|
44 | QChartView *m_chartWidget; | |
45 | QCheckBox *m_autoScaleCheck; |
|
45 | QCheckBox *m_autoScaleCheck; | |
46 | QSpinBox *m_xMinSpin; |
|
46 | QSpinBox *m_xMinSpin; | |
47 | QSpinBox *m_xMaxSpin; |
|
47 | QSpinBox *m_xMaxSpin; |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now