##// END OF EJS Templates
Doc update
Marek Rosa -
r382:e98d5f6bcbb9
parent child
Show More
@@ -16,6 +16,7
16 <li><a href="example-barchart.html">Bar Chart example</a></li>
16 <li><a href="example-barchart.html">Bar Chart example</a></li>
17 <li><a href="example-linechart.html">Line Chart example</a></li>
17 <li><a href="example-linechart.html">Line Chart example</a></li>
18 <li><a href="example-piechart.html">Pie Chart example</a></li>
18 <li><a href="example-piechart.html">Pie Chart example</a></li>
19 <li><a href="example-gdpbarchart.html">GDP Chart example</a></li>
19 </ul>
20 </ul>
20 </td>
21 </td>
21 </tr>
22 </tr>
@@ -35,6 +35,7 Widget::Widget(QWidget *parent)
35 countrieslist = new QListWidget;
35 countrieslist = new QListWidget;
36 countrieslist->setSelectionMode(QAbstractItemView::MultiSelection);
36 countrieslist->setSelectionMode(QAbstractItemView::MultiSelection);
37
37
38 //list of years widget
38 yearslist = new QListWidget;
39 yearslist = new QListWidget;
39 yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection);
40 yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection);
40 for (int i = 1990; i < 2011; i++)
41 for (int i = 1990; i < 2011; i++)
@@ -101,7 +102,7 Widget::~Widget()
101 */
102 */
102 void Widget::refreshChart()
103 void Widget::refreshChart()
103 {
104 {
104 chartArea->removeAllSeries();
105 chartArea->removeAllSeries();
105
106
106 // selected countries items list is not sorted. copy the values to QStringlist and sort them.
107 // selected countries items list is not sorted. copy the values to QStringlist and sort them.
107 QStringList selectedCountriesStrings;
108 QStringList selectedCountriesStrings;
@@ -111,7 +112,7 void Widget::refreshChart()
111 selectedCountriesStrings.sort();
112 selectedCountriesStrings.sort();
112
113
113 QSqlQuery query;
114 QSqlQuery query;
114 // selected years items list is not sorted. copy the values to QList<Integer> and sort them.
115 // selected years items list is not sorted. copy the values to QList<int> and sort them.
115 QList<int> selectedYearsInts;
116 QList<int> selectedYearsInts;
116 QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems();
117 QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems();
117 for (int i = 0; i < selectedYearsItems.size(); i++)
118 for (int i = 0; i < selectedYearsItems.size(); i++)
@@ -119,12 +120,12 void Widget::refreshChart()
119 qSort(selectedYearsInts.begin(), selectedYearsInts.end(), qGreater<int>());
120 qSort(selectedYearsInts.begin(), selectedYearsInts.end(), qGreater<int>());
120
121
121 if (barChartRadioButton->isChecked())
122 if (barChartRadioButton->isChecked())
122 {
123 {
123 // use the sorted selected coutries list to initialize BarCategory
124 // use the sorted selected coutries list to initialize BarCategory
124 QBarCategory* category = new QBarCategory;
125 QBarCategory* category = new QBarCategory;
125 for (int i = 0; i < selectedCountriesStrings.size(); i++)
126 for (int i = 0; i < selectedCountriesStrings.size(); i++)
126 *category << selectedCountriesStrings[i];
127 *category << selectedCountriesStrings[i];
127 series0 = new QBarChartSeries(category);
128 QBarChartSeries* series0 = new QBarChartSeries(category);
128
129
129 // prepare the selected counries SQL query
130 // prepare the selected counries SQL query
130 QString countriesQuery = "country IN (";
131 QString countriesQuery = "country IN (";
@@ -162,14 +163,13 void Widget::refreshChart()
162 {
163 {
163 // data missing, put 0
164 // data missing, put 0
164 *barSet << 0.0f;
165 *barSet << 0.0f;
165 qDebug() << "Putting 0 for Bosnia" << " : " << QString("%1").arg(selectedYearsInts[i]);
166 qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]);
166 }
167 }
167 }
168 }
168 series0->addBarSet(barSet);
169 series0->addBarSet(barSet);
169 }
170 }
170 // add the serie to the chart
171 // add the serie to the chart
171 chartArea->addSeries(series0);
172 chartArea->addSeries(series0);
172
173 }
173 }
174 else if (scatterChartRadioButton->isChecked())
174 else if (scatterChartRadioButton->isChecked())
175 {
175 {
@@ -183,7 +183,7 void Widget::refreshChart()
183 yearsQuery.append(")");
183 yearsQuery.append(")");
184 }
184 }
185
185
186 // perform a query for each selected year
186 // perform a query for each selected country
187 for (int i = 0; i < selectedCountriesStrings.size(); i++)
187 for (int i = 0; i < selectedCountriesStrings.size(); i++)
188 {
188 {
189 query.exec("SELECT year,gdpvalue FROM gdp2 where country='" + selectedCountriesStrings[i] + "' AND " + yearsQuery);
189 query.exec("SELECT year,gdpvalue FROM gdp2 where country='" + selectedCountriesStrings[i] + "' AND " + yearsQuery);
@@ -203,7 +203,7 void Widget::refreshChart()
203 {
203 {
204 // data missing, put 0
204 // data missing, put 0
205 *series << QPointF(selectedYearsInts[k] , 0.0f);
205 *series << QPointF(selectedYearsInts[k] , 0.0f);
206 qDebug() << "Putting 0 for Bosnia" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt();
206 qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt();
207 }
207 }
208 }
208 }
209 // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1);
209 // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1);
@@ -28,7 +28,7 private:
28 QListWidget* countrieslist;
28 QListWidget* countrieslist;
29 QListWidget* yearslist;
29 QListWidget* yearslist;
30 QSqlDatabase db;
30 QSqlDatabase db;
31 QBarChartSeries* series0;
31 // QBarChartSeries* series0;
32 QRadioButton* barChartRadioButton;
32 QRadioButton* barChartRadioButton;
33 QRadioButton* scatterChartRadioButton;
33 QRadioButton* scatterChartRadioButton;
34 };
34 };
General Comments 0
You need to be logged in to leave comments. Login now