##// END OF EJS Templates
Removes QChartWidget...
Michal Klocek -
r136:adef258de74b
parent child
Show More
@@ -2,7 +2,7
2 2 #include <QMainWindow>
3 3 #include <cmath>
4 4 #include <qchartglobal.h>
5 #include <qchartwidget.h>
5 #include <qchartview.h>
6 6 #include <qpieseries.h>
7 7
8 8 QTCOMMERCIALCHART_USE_NAMESPACE
@@ -12,7 +12,7 int main(int argc, char *argv[])
12 12 QApplication a(argc, argv);
13 13
14 14 // Create widget and scatter series
15 QChartWidget *chartWidget = new QChartWidget();
15 QChartView *chartWidget = new QChartView();
16 16 QPieSeries *series = qobject_cast<QPieSeries *>(chartWidget->createSeries(QChartSeries::SeriesTypePie));
17 17 Q_ASSERT(series);
18 18
@@ -2,7 +2,7
2 2 #include <QMainWindow>
3 3 #include <cmath>
4 4 #include <qchartglobal.h>
5 #include <qchartwidget.h>
5 #include <qchartview.h>
6 6 #include <qscatterseries.h>
7 7
8 8 QTCOMMERCIALCHART_USE_NAMESPACE
@@ -12,7 +12,7 int main(int argc, char *argv[])
12 12 QApplication a(argc, argv);
13 13
14 14 // Create widget and scatter series
15 QChartWidget *chartWidget = new QChartWidget();
15 QChartView *chartWidget = new QChartView();
16 16 QScatterSeries *scatter =
17 17 qobject_cast<QScatterSeries *>(chartWidget->createSeries(QChartSeries::SeriesTypeScatter));
18 18 Q_ASSERT(scatter);
@@ -11,7 +11,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 11 QChartView::QChartView(QWidget *parent) :
12 12 QGraphicsView(parent),
13 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 19 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
17 20 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@@ -82,4 +85,118 void QChartView::setChartBackgroundPen(const QPen& pen)
82 85 {
83 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 202 QTCOMMERCIALCHART_END_NAMESPACE
@@ -7,6 +7,7
7 7 #include <QGraphicsView>
8 8
9 9 class QGraphicsScene;
10 class QRubberBand;
10 11
11 12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 13
@@ -15,6 +16,8 class QChart;
15 16 class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView
16 17 {
17 18 public:
19 enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand };
20
18 21 explicit QChartView(QWidget *parent = 0);
19 22 ~QChartView();
20 23
@@ -22,16 +25,17 public:
22 25 void resizeEvent(QResizeEvent *event);
23 26
24 27 void addSeries(QChartSeries* series);
28
25 29 // Convenience function
26 30 QChartSeries* createSeries(QChartSeries::QChartSeriesType type);
27 31
28 32 int margin() const;
33
29 34 void setTitle(const QString& title);
30 35
31 36 //Obsolete interface
32 37 void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, QChart::GradientOrientation orientation = QChart::VerticalGradientOrientation);
33 38
34
35 39 void setChartBackgroundBrush(const QBrush& brush);
36 40 void setChartBackgroundPen(const QPen& pen);
37 41
@@ -39,10 +43,25 public:
39 43 void zoomIn();
40 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 58 private:
43 59 QGraphicsScene *m_scene;
44 60 QChart* m_chart;
45 QPoint m_origin;
61 QPoint m_rubberBandOrigin;
62 QRubberBand* m_rubberBand;
63 bool m_verticalRubberBand;
64 bool m_horizonalRubberBand;
46 65 Q_DISABLE_COPY(QChartView)
47 66
48 67
@@ -28,7 +28,6 SOURCES += \
28 28 qpieseries.cpp \
29 29 qchart.cpp \
30 30 axisitem.cpp \
31 qchartwidget.cpp \
32 31 pieslice.cpp \
33 32 qchartview.cpp \
34 33 qchartseries.cpp \
@@ -63,7 +62,6 PUBLIC_HEADERS += \
63 62 qscatterseries.h \
64 63 qpieseries.h \
65 64 qchart.h \
66 qchartwidget.h \
67 65 qchartglobal.h \
68 66 xylinechart/qxychartseries.h \
69 67 barchart/barchartseries.h \
@@ -23,7 +23,8 QTCOMMERCIALCHART_USE_NAMESPACE
23 23 MainWidget::MainWidget(QWidget *parent) :
24 24 QWidget(parent)
25 25 {
26 m_chartWidget = new QChartWidget(this);
26 m_chartWidget = new QChartView(this);
27 m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand);
27 28
28 29 // Grid layout for the controls for configuring the chart widget
29 30 QGridLayout *grid = new QGridLayout();
@@ -2,7 +2,7
2 2 #define MAINWIDGET_H
3 3
4 4 #include <qchartglobal.h>
5 #include <qchartwidget.h>
5 #include <qchartview.h>
6 6 #include <QWidget>
7 7
8 8 class QSpinBox;
@@ -41,7 +41,7 private slots:
41 41 void setPiePosition(int position);
42 42
43 43 private:
44 QChartWidget *m_chartWidget;
44 QChartView *m_chartWidget;
45 45 QCheckBox *m_autoScaleCheck;
46 46 QSpinBox *m_xMinSpin;
47 47 QSpinBox *m_xMaxSpin;
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now