##// END OF EJS Templates
Adds charts templates to chartviewer
Michal Klocek -
r1864:011a4bf2614e
parent child
Show More
@@ -28,7 +28,7 class HorizontalBarChart: public Chart
28 public:
28 public:
29 QString name() { return QObject::tr("HorizontalBarChart"); }
29 QString name() { return QObject::tr("HorizontalBarChart"); }
30 QString category() { return QObject::tr("BarSeries"); }
30 QString category() { return QObject::tr("BarSeries"); }
31 QString subCategory() { return QObject::tr("Vertical"); }
31 QString subCategory() { return QObject::tr("Horizontal"); }
32
32
33 QChart* createChart(const DataTable& table)
33 QChart* createChart(const DataTable& table)
34 {
34 {
@@ -28,7 +28,7 class HorizontalStackedBarChart: public Chart
28 public:
28 public:
29 QString name() { return QObject::tr("HorizontalStackedBarChart"); }
29 QString name() { return QObject::tr("HorizontalStackedBarChart"); }
30 QString category() { return QObject::tr("BarSeries"); }
30 QString category() { return QObject::tr("BarSeries"); }
31 QString subCategory() { return QObject::tr("Vertical"); }
31 QString subCategory() { return QObject::tr("Horizontal"); }
32
32
33 QChart* createChart(const DataTable& table)
33 QChart* createChart(const DataTable& table)
34 {
34 {
@@ -26,7 +26,7 class PieChart: public Chart
26 {
26 {
27 public:
27 public:
28 QString name() { return QObject::tr("PieChart"); }
28 QString name() { return QObject::tr("PieChart"); }
29 QString category() { return QString::null; }
29 QString category() { return QObject::tr("PieSeries"); }
30 QString subCategory() { return QString::null; }
30 QString subCategory() { return QString::null; }
31
31
32 QChart* createChart(const DataTable& table)
32 QChart* createChart(const DataTable& table)
@@ -53,14 +53,16 Window::Window(QWidget* parent) :
53 m_antialiasCheckBox(0),
53 m_antialiasCheckBox(0),
54 m_animatedComboBox(0),
54 m_animatedComboBox(0),
55 m_legendComboBox(0),
55 m_legendComboBox(0),
56 m_templateComboBox(0),
56 m_openGLCheckBox(0),
57 m_openGLCheckBox(0),
57 m_zoomCheckBox(0),
58 m_zoomCheckBox(0),
58 m_scrollCheckBox(0),
59 m_scrollCheckBox(0),
59 m_rubberBand(new QGraphicsRectItem()),
60 m_rubberBand(new QGraphicsRectItem()),
60 m_baseLayout(new QGraphicsGridLayout()),
61 m_baseLayout(new QGraphicsGridLayout()),
61 m_menu(new QMenu(this)),
62 m_menu(createMenu()),
62 m_state(NoState),
63 m_state(NoState),
63 m_currentState(NoState)
64 m_currentState(NoState),
65 m_template(0)
64 {
66 {
65 createProxyWidgets();
67 createProxyWidgets();
66 connectSignals();
68 connectSignals();
@@ -77,6 +79,8 Window::Window(QWidget* parent) :
77 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
79 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
78 settingsLayout->addItem(m_widgetHash["legendLabel"]);
80 settingsLayout->addItem(m_widgetHash["legendLabel"]);
79 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
81 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
82 settingsLayout->addItem(m_widgetHash["templateLabel"]);
83 settingsLayout->addItem(m_widgetHash["templateComboBox"]);
80 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
84 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
81 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
85 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
82 settingsLayout->addStretch();
86 settingsLayout->addStretch();
@@ -85,16 +89,19 Window::Window(QWidget* parent) :
85 //create charts
89 //create charts
86 Charts::ChartList list = Charts::chartList();
90 Charts::ChartList list = Charts::chartList();
87
91
88 for (int i = 0; i < 9 && i < list.size(); ++i) {
92 for (int i = 0; i < 9; ++i) {
89 QChart* chart = list.at(i)->createChart(m_dataTable);
93 QChart* chart = 0;
94 if(i<list.size()){
95 chart = list.at(i)->createChart(m_dataTable);
96 }else{
97 chart = new QChart();
98 chart->setTitle(tr("Empty"));
99 }
100
90 m_baseLayout->addItem(chart, i / 3, i % 3);
101 m_baseLayout->addItem(chart, i / 3, i % 3);
91 m_chartHash[chart] = i;
102 m_chartHash[chart] = i;
92 }
103 }
93
104
94 foreach(Chart* chart, list) {
95 createMenuAction(m_menu, QIcon(), chart->name(), qVariantFromValue((void *) chart));
96 }
97
98 m_form = new QGraphicsWidget();
105 m_form = new QGraphicsWidget();
99 m_form->setLayout(m_baseLayout);
106 m_form->setLayout(m_baseLayout);
100 m_scene->addItem(m_form);
107 m_scene->addItem(m_form);
@@ -123,6 +130,7 void Window::connectSignals()
123 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
130 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
124 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
131 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
125 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
132 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
133 QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
126 }
134 }
127
135
128 void Window::createProxyWidgets()
136 void Window::createProxyWidgets()
@@ -134,6 +142,7 void Window::createProxyWidgets()
134 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
142 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
135 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
143 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
136 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
144 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
145 m_templateComboBox= createTempleteBox();
137 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
146 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
138 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
147 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
139 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
148 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
@@ -142,8 +151,11 void Window::createProxyWidgets()
142 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
151 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
143 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
152 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
144 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
153 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
154 m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template"));
155 m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox);
145 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
156 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
146 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
157 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
158
147 }
159 }
148
160
149 QComboBox* Window::createThemeBox()
161 QComboBox* Window::createThemeBox()
@@ -180,8 +192,27 QComboBox* Window::createLegendBox()
180 return legendComboBox;
192 return legendComboBox;
181 }
193 }
182
194
195 QComboBox* Window::createTempleteBox()
196 {
197 QComboBox* templateComboBox = new ComboBox(this);
198 templateComboBox->addItem("No Template", 0);
199
200 Charts::ChartList list = Charts::chartList();
201 QMultiMap<QString, Chart*> categoryMap;
202
203 foreach(Chart* chart, list) {
204 categoryMap.insertMulti(chart->category(), chart);
205 }
206 foreach(const QString& category, categoryMap.uniqueKeys()) {
207 templateComboBox->addItem(category, category);
208 }
209 return templateComboBox;
210 }
211
212
183 void Window::updateUI()
213 void Window::updateUI()
184 {
214 {
215 checkTemplate();
185 checkOpenGL();
216 checkOpenGL();
186 checkTheme();
217 checkTheme();
187 checkAnimationOptions();
218 checkAnimationOptions();
@@ -258,6 +289,51 void Window::checkState()
258 }
289 }
259 }
290 }
260
291
292 void Window::checkTemplate()
293 {
294
295 int index = m_templateComboBox->currentIndex();
296 if (m_template == index || index == 0)
297 return;
298
299 QString category = m_templateComboBox->itemData(index).toString();
300 Charts::ChartList list = Charts::chartList();
301
302 QList<QChart*> qchartList = m_chartHash.keys();
303
304 foreach(QChart* qchart,qchartList){
305 for(int i = 0 ; i < m_baseLayout->count();++i)
306 {
307 if(m_baseLayout->itemAt(i)==qchart){
308 m_baseLayout->removeAt(i);
309 break;
310 }
311 }
312 }
313
314 m_chartHash.clear();
315 qDeleteAll(qchartList);
316
317 QChart* qchart(0);
318
319 int j=0;
320 for (int i = 0; i < list.size(); ++i) {
321 Chart* chart = list.at(i);
322 if (chart->category() == category && j < 9) {
323 qchart = list.at(i)->createChart(m_dataTable);
324 m_baseLayout->addItem(qchart, j / 3, j % 3);
325 m_chartHash[qchart] = j;
326 j++;
327 }
328 }
329 for (; j < 9; ++j) {
330 qchart = new QChart();
331 qchart->setTitle(tr("Empty"));
332 m_baseLayout->addItem(qchart, j / 3, j % 3);
333 m_chartHash[qchart] = j;
334 }
335 }
336
261 void Window::checkTheme()
337 void Window::checkTheme()
262 {
338 {
263 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
339 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
@@ -321,8 +397,8 void Window::mousePressEvent(QMouseEvent *event)
321 if (plotArea.contains(m_origin)) {
397 if (plotArea.contains(m_origin)) {
322 m_currentState = m_state;
398 m_currentState = m_state;
323
399
324 if (m_currentState == NoState) {
400 if (m_currentState == NoState && m_templateComboBox->currentIndex()==0) {
325 showMenu(chart);
401 handleMenu(chart);
326 }
402 }
327 break;
403 break;
328 }
404 }
@@ -422,7 +498,7 void Window::comboBoxFocused(QComboBox *combobox)
422 }
498 }
423 }
499 }
424
500
425 void Window::showMenu(QChart* qchart)
501 void Window::handleMenu(QChart* qchart)
426 {
502 {
427 QAction *chosen = m_menu->exec(QCursor::pos());
503 QAction *chosen = m_menu->exec(QCursor::pos());
428
504
@@ -448,6 +524,53 void Window::showMenu(QChart* qchart)
448
524
449 }
525 }
450
526
527 QMenu* Window::createMenu()
528 {
529 Charts::ChartList list = Charts::chartList();
530 QMultiMap<QString, Chart*> categoryMap;
531
532 QMenu* result = new QMenu(this);
533
534 foreach(Chart* chart, list) {
535 categoryMap.insertMulti(chart->category(), chart);
536 }
537
538 foreach(const QString& category, categoryMap.uniqueKeys()) {
539 QMenu* menu(0);
540 QMultiMap<QString, Chart*> subCategoryMap;
541 if (category.isEmpty()) {
542 menu = result;
543 }
544 else {
545 menu = new QMenu(category, this);
546 result->addMenu(menu);
547 }
548
549 foreach(Chart* chart , categoryMap.values(category)) {
550 subCategoryMap.insert(chart->subCategory(), chart);
551 }
552
553 foreach(const QString& subCategory, subCategoryMap.uniqueKeys()) {
554 QMenu* subMenu(0);
555 if (subCategory.isEmpty()) {
556 subMenu = menu;
557 }
558 else {
559 subMenu = new QMenu(subCategory, this);
560 menu->addMenu(subMenu);
561 }
562
563 foreach(Chart* chart , subCategoryMap.values(subCategory)) {
564
565 createMenuAction(subMenu, QIcon(), chart->name(),
566 qVariantFromValue((void *) chart));
567 }
568 }
569 }
570
571 return result;
572 }
573
451 QAction* Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text,
574 QAction* Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text,
452 const QVariant &data)
575 const QVariant &data)
453 {
576 {
@@ -55,6 +55,7 private:
55 QComboBox* createThemeBox();
55 QComboBox* createThemeBox();
56 QComboBox* createAnimationBox();
56 QComboBox* createAnimationBox();
57 QComboBox* createLegendBox();
57 QComboBox* createLegendBox();
58 QComboBox* createTempleteBox();
58 void connectSignals();
59 void connectSignals();
59 void createProxyWidgets();
60 void createProxyWidgets();
60 void comboBoxFocused(QComboBox *combox);
61 void comboBoxFocused(QComboBox *combox);
@@ -63,7 +64,9 private:
63 inline void checkOpenGL();
64 inline void checkOpenGL();
64 inline void checkTheme();
65 inline void checkTheme();
65 inline void checkState();
66 inline void checkState();
66 void showMenu(QChart * chart);
67 inline void checkTemplate();
68 QMenu* createMenu();
69 void handleMenu(QChart * chart);
67 QAction* createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
70 QAction* createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
68
71
69 protected:
72 protected:
@@ -86,6 +89,7 private:
86 QCheckBox *m_antialiasCheckBox;
89 QCheckBox *m_antialiasCheckBox;
87 QComboBox *m_animatedComboBox;
90 QComboBox *m_animatedComboBox;
88 QComboBox *m_legendComboBox;
91 QComboBox *m_legendComboBox;
92 QComboBox *m_templateComboBox;
89 QCheckBox *m_openGLCheckBox;
93 QCheckBox *m_openGLCheckBox;
90 QCheckBox *m_zoomCheckBox;
94 QCheckBox *m_zoomCheckBox;
91 QCheckBox *m_scrollCheckBox;
95 QCheckBox *m_scrollCheckBox;
@@ -95,6 +99,7 private:
95 QMenu* m_menu;
99 QMenu* m_menu;
96 State m_state;
100 State m_state;
97 State m_currentState;
101 State m_currentState;
102 int m_template;
98
103
99 friend class ComboBox;
104 friend class ComboBox;
100 };
105 };
General Comments 0
You need to be logged in to leave comments. Login now