##// END OF EJS Templates
Adds view menu to chartviewer
Michal Klocek -
r2128:d151d861ee2a
parent child
Show More
@@ -31,6 +31,8 Grid::Grid(int size,QGraphicsItem *parent):QGraphicsWidget(parent),
31 m_valueCount(7),
31 m_valueCount(7),
32 m_size(size),
32 m_size(size),
33 m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)),
33 m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)),
34 m_state(NoState),
35 m_currentState(NoState),
34 m_rubberBand(new QGraphicsRectItem()),
36 m_rubberBand(new QGraphicsRectItem()),
35 m_gridLayout(new QGraphicsGridLayout())
37 m_gridLayout(new QGraphicsGridLayout())
36 {
38 {
@@ -45,28 +47,6 Grid::~Grid()
45
47
46 }
48 }
47
49
48 void Grid::createCharts()
49 {
50 clear();
51
52 Charts::ChartList list = Charts::chartList();
53
54 for (int i = 0; i < m_size * m_size; ++i) {
55 QChart *chart = 0;
56 if (i < list.size()) {
57 chart = list.at(i)->createChart(m_dataTable);
58 }
59 else {
60 chart = new QChart();
61 chart->setTitle(QObject::tr("Empty"));
62 }
63
64 m_gridLayout->addItem(chart, i / m_size, i % m_size);
65 m_chartHash[chart] = i;
66 }
67
68 }
69
70 void Grid::createCharts(const QString& category)
50 void Grid::createCharts(const QString& category)
71 {
51 {
72 clear();
52 clear();
@@ -74,23 +54,42 void Grid::createCharts(const QString& category)
74 QChart *qchart(0);
54 QChart *qchart(0);
75 Charts::ChartList list = Charts::chartList();
55 Charts::ChartList list = Charts::chartList();
76
56
77 int j = 0;
57 if (category.isEmpty()) {
78 for (int i = 0; i < list.size(); ++i) {
58
79 Chart *chart = list.at(i);
59 for (int i = 0; i < m_size * m_size; ++i) {
80 if (chart->category() == category && j < m_size * m_size) {
60 QChart *chart = 0;
81 qchart = list.at(i)->createChart(m_dataTable);
61 if (i < list.size()) {
62 chart = list.at(i)->createChart(m_dataTable);
63 }
64 else {
65 chart = new QChart();
66 chart->setTitle(QObject::tr("Empty"));
67 }
68
69 m_gridLayout->addItem(chart, i / m_size, i % m_size);
70 m_chartHash[chart] = i;
71 }
72 }
73 else {
74
75 int j = 0;
76 for (int i = 0; i < list.size(); ++i) {
77 Chart *chart = list.at(i);
78 if (chart->category() == category && j < m_size * m_size) {
79 qchart = list.at(i)->createChart(m_dataTable);
80 m_gridLayout->addItem(qchart, j / m_size, j % m_size);
81 m_chartHash[qchart] = j;
82 j++;
83 }
84 }
85 for (; j < m_size * m_size; ++j) {
86 qchart = new QChart();
87 qchart->setTitle(QObject::tr("Empty"));
82 m_gridLayout->addItem(qchart, j / m_size, j % m_size);
88 m_gridLayout->addItem(qchart, j / m_size, j % m_size);
83 m_chartHash[qchart] = j;
89 m_chartHash[qchart] = j;
84 j++;
85 }
90 }
86 }
91 }
87 for (; j < m_size * m_size; ++j) {
92 m_category = category;
88 qchart = new QChart();
89 qchart->setTitle(QObject::tr("Empty"));
90 m_gridLayout->addItem(qchart, j / m_size, j % m_size);
91 m_chartHash[qchart] = j;
92 }
93
94 m_gridLayout->activate();
93 m_gridLayout->activate();
95 }
94 }
96
95
@@ -114,6 +113,15 void Grid::setState(State state)
114 m_state = state;
113 m_state = state;
115 }
114 }
116
115
116 void Grid::setSize(int size)
117 {
118 if(m_size !=size)
119 {
120 m_size = size;
121 createCharts(m_category);
122 }
123 }
124
117 void Grid::setRubberPen(const QPen& pen)
125 void Grid::setRubberPen(const QPen& pen)
118 {
126 {
119 m_rubberBand->setPen(pen);
127 m_rubberBand->setPen(pen);
@@ -26,7 +26,6
26 #include <QChartGlobal>
26 #include <QChartGlobal>
27
27
28 class QGraphicsGridLayout;
28 class QGraphicsGridLayout;
29 class GridControl;
30 class Chart;
29 class Chart;
31
30
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -43,12 +42,13 public:
43 Grid(int size , QGraphicsItem *parent = 0 );
42 Grid(int size , QGraphicsItem *parent = 0 );
44 ~Grid();
43 ~Grid();
45 QList<QChart*> charts();
44 QList<QChart*> charts();
46 void createCharts();
45 void createCharts(const QString& category = QString());
47 void createCharts(const QString& category);
48 void replaceChart(QChart* oldChart, Chart* newChart);
46 void replaceChart(QChart* oldChart, Chart* newChart);
49 void setState(State state);
47 void setState(State state);
50 State state(){ return m_state; };
48 State state() const { return m_state; };
51 void setRubberPen(const QPen& pen);
49 void setRubberPen(const QPen& pen);
50 void setSize(int size);
51 int size() const {return m_size;}
52 Q_SIGNAL
52 Q_SIGNAL
53 void chartSelected(QChart* chart);
53 void chartSelected(QChart* chart);
54 protected:
54 protected:
@@ -64,12 +64,12 private:
64 int m_size;
64 int m_size;
65 DataTable m_dataTable;
65 DataTable m_dataTable;
66 QHash<QChart *, int> m_chartHash;
66 QHash<QChart *, int> m_chartHash;
67 GridControl* m_control;
68 State m_state;
67 State m_state;
69 State m_currentState;
68 State m_currentState;
70 QPointF m_origin;
69 QPointF m_origin;
71 QGraphicsRectItem *m_rubberBand;
70 QGraphicsRectItem *m_rubberBand;
72 QGraphicsGridLayout* m_gridLayout;
71 QGraphicsGridLayout* m_gridLayout;
72 QString m_category;
73 };
73 };
74
74
75 #endif /* GRID_H_ */
75 #endif /* GRID_H_ */
@@ -39,6 +39,7
39 #include <QApplication>
39 #include <QApplication>
40 #include <QDebug>
40 #include <QDebug>
41 #include <QMenu>
41 #include <QMenu>
42 #include <QPushButton>
42
43
43 Window::Window(const QVariantHash& parameters,QWidget *parent) :
44 Window::Window(const QVariantHash& parameters,QWidget *parent) :
44 QMainWindow(parent),
45 QMainWindow(parent),
@@ -50,21 +51,25 Window::Window(const QVariantHash& parameters,QWidget *parent) :
50 m_animatedComboBox(0),
51 m_animatedComboBox(0),
51 m_legendComboBox(0),
52 m_legendComboBox(0),
52 m_templateComboBox(0),
53 m_templateComboBox(0),
54 m_viewComboBox(0),
53 m_openGLCheckBox(0),
55 m_openGLCheckBox(0),
54 m_zoomCheckBox(0),
56 m_zoomCheckBox(0),
55 m_scrollCheckBox(0),
57 m_scrollCheckBox(0),
56 m_baseLayout(new QGraphicsLinearLayout()),
58 m_baseLayout(new QGraphicsLinearLayout()),
57 m_menu(createMenu()),
59 m_menu(createMenu()),
58 m_template(0),
60 m_template(0),
59 m_grid(new Grid(3))
61 m_grid(new Grid(1))
60 {
62 {
61 createProxyWidgets();
63 createProxyWidgets();
62 // create layout
64 // create layout
63 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
65 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
66
64 settingsLayout->setOrientation(Qt::Vertical);
67 settingsLayout->setOrientation(Qt::Vertical);
65 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
68 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
66 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
69 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
67 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
70 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
71 settingsLayout->addItem(m_widgetHash["viewLabel"]);
72 settingsLayout->addItem(m_widgetHash["viewComboBox"]);
68 settingsLayout->addItem(m_widgetHash["themeLabel"]);
73 settingsLayout->addItem(m_widgetHash["themeLabel"]);
69 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
74 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
70 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
75 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
@@ -94,6 +99,7 Window::Window(const QVariantHash& parameters,QWidget *parent) :
94 m_antialiasCheckBox->setChecked(true);
99 m_antialiasCheckBox->setChecked(true);
95 initializeFromParamaters(parameters);
100 initializeFromParamaters(parameters);
96 updateUI();
101 updateUI();
102 handleGeometryChanged();
97 setCentralWidget(m_view);
103 setCentralWidget(m_view);
98
104
99 connectSignals();
105 connectSignals();
@@ -106,6 +112,7 Window::~Window()
106 void Window::connectSignals()
112 void Window::connectSignals()
107 {
113 {
108 QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged()));
114 QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged()));
115 QObject::connect(m_viewComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
109 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
116 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
110 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
117 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
111 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
118 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
@@ -120,6 +127,7 void Window::connectSignals()
120 void Window::createProxyWidgets()
127 void Window::createProxyWidgets()
121 {
128 {
122 m_themeComboBox = createThemeBox();
129 m_themeComboBox = createThemeBox();
130 m_viewComboBox = createViewBox();
123 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
131 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
124 m_animatedComboBox = createAnimationBox();
132 m_animatedComboBox = createAnimationBox();
125 m_legendComboBox = createLegendBox();
133 m_legendComboBox = createLegendBox();
@@ -127,6 +135,8 void Window::createProxyWidgets()
127 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
135 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
128 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
136 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
129 m_templateComboBox = createTempleteBox();
137 m_templateComboBox = createTempleteBox();
138 m_widgetHash["viewLabel"] = m_scene->addWidget(new QLabel("View"));
139 m_widgetHash["viewComboBox"] = m_scene->addWidget(m_viewComboBox);
130 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
140 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
131 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
141 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
132 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
142 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
@@ -139,7 +149,6 void Window::createProxyWidgets()
139 m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox);
149 m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox);
140 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
150 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
141 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
151 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
142
143 }
152 }
144
153
145 QComboBox *Window::createThemeBox()
154 QComboBox *Window::createThemeBox()
@@ -155,6 +164,16 QComboBox *Window::createThemeBox()
155 return themeComboBox;
164 return themeComboBox;
156 }
165 }
157
166
167 QComboBox *Window::createViewBox()
168 {
169 QComboBox *viewComboBox = new ComboBox(this);
170 viewComboBox->addItem("1 chart", 1);
171 viewComboBox->addItem("4 charts", 2);
172 viewComboBox->addItem("9 charts", 3);
173 viewComboBox->addItem("16 charts", 4);
174 return viewComboBox;
175 }
176
158 QComboBox *Window::createAnimationBox()
177 QComboBox *Window::createAnimationBox()
159 {
178 {
160 QComboBox *animationComboBox = new ComboBox(this);
179 QComboBox *animationComboBox = new ComboBox(this);
@@ -235,11 +254,22 void Window::initializeFromParamaters(const QVariantHash& parameters)
235 }
254 }
236 }
255 }
237 }
256 }
257 if (parameters.contains("view")) {
258 int t = parameters["view"].toInt();
259 for (int i = 0; i < m_viewComboBox->count(); ++i) {
260 if (m_viewComboBox->itemData(i).toInt() == t) {
261
262 m_viewComboBox->setCurrentIndex(i);
263 break;
264 }
265 }
266 }
238 }
267 }
239
268
240 void Window::updateUI()
269 void Window::updateUI()
241 {
270 {
242 checkTemplate();
271 checkTemplate();
272 checkView();
243 checkOpenGL();
273 checkOpenGL();
244 checkTheme();
274 checkTheme();
245 checkAnimationOptions();
275 checkAnimationOptions();
@@ -247,6 +277,12 void Window::updateUI()
247 checkState();
277 checkState();
248 }
278 }
249
279
280 void Window::checkView()
281 {
282 int count(m_viewComboBox->itemData(m_viewComboBox->currentIndex()).toInt());
283 m_grid->setSize(count);
284 }
285
250 void Window::checkLegend()
286 void Window::checkLegend()
251 {
287 {
252 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
288 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
@@ -33,6 +33,7 class View;
33 class QGraphicsLinearLayout;
33 class QGraphicsLinearLayout;
34 class Chart;
34 class Chart;
35 class Grid;
35 class Grid;
36 class QPushButton;
36
37
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 class QChart;
39 class QChart;
@@ -53,6 +54,7 private Q_SLOTS:
53 void handleGeometryChanged();
54 void handleGeometryChanged();
54 void handleChartSelected(QChart *chart);
55 void handleChartSelected(QChart *chart);
55 private:
56 private:
57 QComboBox *createViewBox();
56 QComboBox *createThemeBox();
58 QComboBox *createThemeBox();
57 QComboBox *createAnimationBox();
59 QComboBox *createAnimationBox();
58 QComboBox *createLegendBox();
60 QComboBox *createLegendBox();
@@ -61,6 +63,7 private:
61 void createProxyWidgets();
63 void createProxyWidgets();
62 void comboBoxFocused(QComboBox *combox);
64 void comboBoxFocused(QComboBox *combox);
63 inline void checkAnimationOptions();
65 inline void checkAnimationOptions();
66 inline void checkView();
64 inline void checkLegend();
67 inline void checkLegend();
65 inline void checkOpenGL();
68 inline void checkOpenGL();
66 inline void checkTheme();
69 inline void checkTheme();
@@ -70,11 +73,6 private:
70 QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
73 QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
71 void initializeFromParamaters(const QVariantHash& parameters);
74 void initializeFromParamaters(const QVariantHash& parameters);
72
75
73 protected:
74 //void mousePressEvent(QMouseEvent *event);
75 //void mouseMoveEvent(QMouseEvent *event);
76 //void mouseReleaseEvent(QMouseEvent *event);
77
78 private:
76 private:
79 QGraphicsScene *m_scene;
77 QGraphicsScene *m_scene;
80 View *m_view;
78 View *m_view;
@@ -86,6 +84,7 private:
86 QComboBox *m_animatedComboBox;
84 QComboBox *m_animatedComboBox;
87 QComboBox *m_legendComboBox;
85 QComboBox *m_legendComboBox;
88 QComboBox *m_templateComboBox;
86 QComboBox *m_templateComboBox;
87 QComboBox *m_viewComboBox;
89 QCheckBox *m_openGLCheckBox;
88 QCheckBox *m_openGLCheckBox;
90 QCheckBox *m_zoomCheckBox;
89 QCheckBox *m_zoomCheckBox;
91 QCheckBox *m_scrollCheckBox;
90 QCheckBox *m_scrollCheckBox;
General Comments 0
You need to be logged in to leave comments. Login now