##// END OF EJS Templates
Adds chart parser to cherviewer options
Michal Klocek -
r2135:c8d5b77f686a
parent child
Show More
@@ -57,15 +57,11 void Grid::createCharts(const QString &category)
57 57
58 58 if (category.isEmpty()) {
59 59 for (int i = 0; i < m_size * m_size; ++i) {
60 QChart *chart = 0;
61 if (i < list.size()) {
62 chart = list.at(i)->createChart(m_dataTable);
63 } else {
64 chart = new QChart();
60 QChart *chart = new QChart();
65 61 chart->setTitle(QObject::tr("Empty"));
66 }
67 62 m_gridLayout->addItem(chart, i / m_size, i % m_size);
68 63 m_chartHash[chart] = i;
64 m_chartHashRev[i] = chart;
69 65 }
70 66 } else {
71 67 int j = 0;
@@ -75,6 +71,7 void Grid::createCharts(const QString &category)
75 71 qchart = list.at(i)->createChart(m_dataTable);
76 72 m_gridLayout->addItem(qchart, j / m_size, j % m_size);
77 73 m_chartHash[qchart] = j;
74 m_chartHashRev[j] = qchart;
78 75 j++;
79 76 }
80 77 }
@@ -83,19 +80,58 void Grid::createCharts(const QString &category)
83 80 qchart->setTitle(QObject::tr("Empty"));
84 81 m_gridLayout->addItem(qchart, j / m_size, j % m_size);
85 82 m_chartHash[qchart] = j;
83 m_chartHashRev[j] = qchart;
86 84 }
87 85 }
88 m_category = category;
86 m_gridLayout->activate();
87 }
88
89 void Grid::createCharts(const QString &category, const QString &subcategory, const QString &name)
90 {
91 clear();
92
93 QChart *qchart(0);
94 Charts::ChartList list = Charts::chartList();
95 Chart *chart;
96
97 //find chart
98 for (int i = 0; i < list.size(); ++i) {
99
100 chart = list.at(i);
101 if (chart->category() == category &&
102 chart->subCategory() == subcategory &&
103 chart->name() == name) {
104 break;
105 }
106 chart = 0;
107 }
108
109 //create charts
110 for (int j = 0; j < m_size * m_size; ++j) {
111
112 if(!chart){
113 qchart = new QChart();
114 }else{
115 qchart = chart->createChart(m_dataTable);
116 }
117 qchart->setTitle(QObject::tr("Empty"));
118 m_gridLayout->addItem(qchart, j / m_size, j % m_size);
119 m_chartHash[qchart] = j;
120 m_chartHashRev[j] = qchart;
121 }
122
89 123 m_gridLayout->activate();
90 124 }
91 125
92 126 void Grid::clear()
93 127 {
94 for (int i = 0; i < m_gridLayout->count(); ++i)
95 m_gridLayout->removeAt(i);
128 int count = m_gridLayout->count();
129 for (int i = 0; i < count; ++i)
130 m_gridLayout->removeAt(0);
96 131
97 132 qDeleteAll(m_chartHash.keys());
98 133 m_chartHash.clear();
134 m_chartHashRev.clear();
99 135 }
100 136
101 137 QList<QChart *> Grid::charts()
@@ -111,8 +147,40 void Grid::setState(State state)
111 147 void Grid::setSize(int size)
112 148 {
113 149 if (m_size != size) {
150
151 //remove old;
152 int count = m_gridLayout->count();
153 for (int i = 0; i < count; ++i) {
154 m_gridLayout->removeAt(0);
155 }
156
157
158 QChart* qchart = 0;
159 int j = 0;
160
161 for (; j < size * size; ++j) {
162
163 qchart = m_chartHashRev[j];
164
165 if (!qchart){
166 qchart = new QChart();
167 qchart->setTitle(QObject::tr("Empty"));
168 }
169
170 m_chartHash[qchart] = j;
171 m_chartHashRev[j] = qchart;
172 m_gridLayout->addItem(qchart, j / size, j % size);
173 }
174
175 //delete rest
176 while (j < m_size * m_size) {
177 QChart* qchart = m_chartHashRev.take(j);
178 delete(qchart);
179 m_chartHash.remove(qchart);
180 j++;
181 }
182
114 183 m_size = size;
115 createCharts(m_category);
116 184 }
117 185 }
118 186
@@ -132,9 +200,11 void Grid::replaceChart(QChart *oldChart, Chart *newChart)
132 200 }
133 201 }
134 202 m_chartHash.remove(oldChart);
203 m_chartHashRev.remove(index);
135 204 QChart *chart = newChart->createChart(m_dataTable);
136 205 m_gridLayout->addItem(chart, index / m_size, index % m_size);
137 206 m_chartHash[chart] = index;
207 m_chartHashRev[index] = chart;
138 208 delete oldChart;
139 209 }
140 210
@@ -45,6 +45,7 public:
45 45
46 46 QList<QChart *> charts();
47 47 void createCharts(const QString &category = QString());
48 void createCharts(const QString &category, const QString &subcategory, const QString &name);
48 49 void replaceChart(QChart *oldChart, Chart *newChart);
49 50 void setState(State state);
50 51 State state() const { return m_state; };
@@ -70,12 +71,12 private:
70 71 int m_size;
71 72 DataTable m_dataTable;
72 73 QHash<QChart *, int> m_chartHash;
74 QHash<int, QChart *> m_chartHashRev;
73 75 State m_state;
74 76 State m_currentState;
75 77 QPointF m_origin;
76 78 QGraphicsRectItem *m_rubberBand;
77 79 QGraphicsGridLayout *m_gridLayout;
78 QString m_category;
79 80 };
80 81
81 82 #endif /* GRID_H_ */
@@ -58,7 +58,7 Window::Window(const QVariantHash &parameters, QWidget *parent)
58 58 m_baseLayout(new QGraphicsLinearLayout()),
59 59 m_menu(createMenu()),
60 60 m_template(0),
61 m_grid(new Grid(1))
61 m_grid(new Grid(-1))
62 62 {
63 63 createProxyWidgets();
64 64 // create layout
@@ -82,8 +82,6 Window::Window(const QVariantHash &parameters, QWidget *parent)
82 82 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
83 83 settingsLayout->addStretch();
84 84
85 m_grid->createCharts();
86
87 85 m_baseLayout->setOrientation(Qt::Horizontal);
88 86 m_baseLayout->addItem(m_grid);
89 87 m_baseLayout->addItem(settingsLayout);
@@ -99,6 +97,10 Window::Window(const QVariantHash &parameters, QWidget *parent)
99 97 m_antialiasCheckBox->setChecked(true);
100 98 initializeFromParamaters(parameters);
101 99 updateUI();
100 if(!m_category.isEmpty() && !m_subcategory.isEmpty() && !m_name.isEmpty())
101 m_grid->createCharts(m_category,m_subcategory,m_name);
102
103
102 104 handleGeometryChanged();
103 105 setCentralWidget(m_view);
104 106
@@ -214,8 +216,29 QComboBox *Window::createTempleteBox()
214 216
215 217 void Window::initializeFromParamaters(const QVariantHash &parameters)
216 218 {
219 if (parameters.contains("view")) {
220 int t = parameters["view"].toInt();
221 for (int i = 0; i < m_viewComboBox->count(); ++i) {
222 if (m_viewComboBox->itemData(i).toInt() == t) {
223 m_viewComboBox->setCurrentIndex(i);
224 break;
225 }
226 }
227 }
228
217 229 if (parameters.contains("chart")) {
218 230 QString t = parameters["chart"].toString();
231
232 QRegExp rx("([a-zA-Z0-9_]*)::([a-zA-Z0-9_]*)::([a-zA-Z0-9_]*)");
233 int pos = rx.indexIn(t);
234
235 if (pos > -1) {
236 m_category = rx.cap(1);
237 m_subcategory = rx.cap(2);
238 m_name = rx.cap(3);
239 m_templateComboBox->setCurrentIndex(0);
240 }
241 else {
219 242 for (int i = 0; i < m_templateComboBox->count(); ++i) {
220 243 if (m_templateComboBox->itemText(i) == t) {
221 244 m_templateComboBox->setCurrentIndex(i);
@@ -223,6 +246,7 void Window::initializeFromParamaters(const QVariantHash &parameters)
223 246 }
224 247 }
225 248 }
249 }
226 250 if (parameters.contains("opengl")) {
227 251 bool checked = parameters["opengl"].toBool();
228 252 m_openGLCheckBox->setChecked(checked);
@@ -254,21 +278,12 void Window::initializeFromParamaters(const QVariantHash &parameters)
254 278 }
255 279 }
256 280 }
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 m_viewComboBox->setCurrentIndex(i);
262 break;
263 }
264 }
265 }
266 281 }
267 282
268 283 void Window::updateUI()
269 284 {
270 checkTemplate();
271 285 checkView();
286 checkTemplate();
272 287 checkOpenGL();
273 288 checkTheme();
274 289 checkAnimationOptions();
@@ -279,7 +294,10 void Window::updateUI()
279 294 void Window::checkView()
280 295 {
281 296 int count(m_viewComboBox->itemData(m_viewComboBox->currentIndex()).toInt());
297 if(m_grid->size()!=count){
282 298 m_grid->setSize(count);
299 m_template = 0;
300 }
283 301 }
284 302
285 303 void Window::checkLegend()
@@ -92,6 +92,9 private:
92 92 QMenu *m_menu;
93 93 int m_template;
94 94 Grid *m_grid;
95 QString m_category;
96 QString m_subcategory;
97 QString m_name;
95 98
96 99 friend class ComboBox;
97 100 };
General Comments 0
You need to be logged in to leave comments. Login now