##// 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 28 public:
29 29 QString name() { return QObject::tr("HorizontalBarChart"); }
30 30 QString category() { return QObject::tr("BarSeries"); }
31 QString subCategory() { return QObject::tr("Vertical"); }
31 QString subCategory() { return QObject::tr("Horizontal"); }
32 32
33 33 QChart* createChart(const DataTable& table)
34 34 {
@@ -28,7 +28,7 class HorizontalStackedBarChart: public Chart
28 28 public:
29 29 QString name() { return QObject::tr("HorizontalStackedBarChart"); }
30 30 QString category() { return QObject::tr("BarSeries"); }
31 QString subCategory() { return QObject::tr("Vertical"); }
31 QString subCategory() { return QObject::tr("Horizontal"); }
32 32
33 33 QChart* createChart(const DataTable& table)
34 34 {
@@ -26,7 +26,7 class PieChart: public Chart
26 26 {
27 27 public:
28 28 QString name() { return QObject::tr("PieChart"); }
29 QString category() { return QString::null; }
29 QString category() { return QObject::tr("PieSeries"); }
30 30 QString subCategory() { return QString::null; }
31 31
32 32 QChart* createChart(const DataTable& table)
@@ -53,14 +53,16 Window::Window(QWidget* parent) :
53 53 m_antialiasCheckBox(0),
54 54 m_animatedComboBox(0),
55 55 m_legendComboBox(0),
56 m_templateComboBox(0),
56 57 m_openGLCheckBox(0),
57 58 m_zoomCheckBox(0),
58 59 m_scrollCheckBox(0),
59 60 m_rubberBand(new QGraphicsRectItem()),
60 61 m_baseLayout(new QGraphicsGridLayout()),
61 m_menu(new QMenu(this)),
62 m_menu(createMenu()),
62 63 m_state(NoState),
63 m_currentState(NoState)
64 m_currentState(NoState),
65 m_template(0)
64 66 {
65 67 createProxyWidgets();
66 68 connectSignals();
@@ -77,6 +79,8 Window::Window(QWidget* parent) :
77 79 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
78 80 settingsLayout->addItem(m_widgetHash["legendLabel"]);
79 81 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
82 settingsLayout->addItem(m_widgetHash["templateLabel"]);
83 settingsLayout->addItem(m_widgetHash["templateComboBox"]);
80 84 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
81 85 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
82 86 settingsLayout->addStretch();
@@ -85,16 +89,19 Window::Window(QWidget* parent) :
85 89 //create charts
86 90 Charts::ChartList list = Charts::chartList();
87 91
88 for (int i = 0; i < 9 && i < list.size(); ++i) {
89 QChart* chart = list.at(i)->createChart(m_dataTable);
92 for (int i = 0; i < 9; ++i) {
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 101 m_baseLayout->addItem(chart, i / 3, i % 3);
91 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 105 m_form = new QGraphicsWidget();
99 106 m_form->setLayout(m_baseLayout);
100 107 m_scene->addItem(m_form);
@@ -123,6 +130,7 void Window::connectSignals()
123 130 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
124 131 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
125 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 136 void Window::createProxyWidgets()
@@ -134,6 +142,7 void Window::createProxyWidgets()
134 142 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
135 143 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
136 144 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
145 m_templateComboBox= createTempleteBox();
137 146 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
138 147 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
139 148 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
@@ -142,8 +151,11 void Window::createProxyWidgets()
142 151 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
143 152 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
144 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 156 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
146 157 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
158
147 159 }
148 160
149 161 QComboBox* Window::createThemeBox()
@@ -180,8 +192,27 QComboBox* Window::createLegendBox()
180 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 213 void Window::updateUI()
184 214 {
215 checkTemplate();
185 216 checkOpenGL();
186 217 checkTheme();
187 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 337 void Window::checkTheme()
262 338 {
263 339 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
@@ -321,8 +397,8 void Window::mousePressEvent(QMouseEvent *event)
321 397 if (plotArea.contains(m_origin)) {
322 398 m_currentState = m_state;
323 399
324 if (m_currentState == NoState) {
325 showMenu(chart);
400 if (m_currentState == NoState && m_templateComboBox->currentIndex()==0) {
401 handleMenu(chart);
326 402 }
327 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 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 574 QAction* Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text,
452 575 const QVariant &data)
453 576 {
@@ -55,6 +55,7 private:
55 55 QComboBox* createThemeBox();
56 56 QComboBox* createAnimationBox();
57 57 QComboBox* createLegendBox();
58 QComboBox* createTempleteBox();
58 59 void connectSignals();
59 60 void createProxyWidgets();
60 61 void comboBoxFocused(QComboBox *combox);
@@ -63,7 +64,9 private:
63 64 inline void checkOpenGL();
64 65 inline void checkTheme();
65 66 inline void checkState();
66 void showMenu(QChart * chart);
67 inline void checkTemplate();
68 QMenu* createMenu();
69 void handleMenu(QChart * chart);
67 70 QAction* createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
68 71
69 72 protected:
@@ -86,6 +89,7 private:
86 89 QCheckBox *m_antialiasCheckBox;
87 90 QComboBox *m_animatedComboBox;
88 91 QComboBox *m_legendComboBox;
92 QComboBox *m_templateComboBox;
89 93 QCheckBox *m_openGLCheckBox;
90 94 QCheckBox *m_zoomCheckBox;
91 95 QCheckBox *m_scrollCheckBox;
@@ -95,6 +99,7 private:
95 99 QMenu* m_menu;
96 100 State m_state;
97 101 State m_currentState;
102 int m_template;
98 103
99 104 friend class ComboBox;
100 105 };
General Comments 0
You need to be logged in to leave comments. Login now