##// END OF EJS Templates
coding style fixes for examples
Jani Honkonen -
r2098:46e62d22b0b4
parent child
Show More
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -33,11 +33,9 CustomTableModel::CustomTableModel(QObject *parent) :
33 m_rowCount = 12;
33 m_rowCount = 12;
34
34
35 // m_data
35 // m_data
36 for (int i = 0; i < m_rowCount; i++)
36 for (int i = 0; i < m_rowCount; i++) {
37 {
38 QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount);
37 QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount);
39 for (int k = 0; k < dataVec->size(); k++)
38 for (int k = 0; k < dataVec->size(); k++) {
40 {
41 if (k%2 == 0)
39 if (k % 2 == 0)
42 dataVec->replace(k, i * 50 + qrand()%20);
40 dataVec->replace(k, i * 50 + qrand() % 20);
43 else
41 else
@@ -65,25 +63,18 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation,
65 return QVariant();
63 return QVariant();
66
64
67 if (orientation == Qt::Horizontal)
65 if (orientation == Qt::Horizontal)
68 {
69 return QString("201%1").arg(section);
66 return QString("201%1").arg(section);
70 }
71 else
67 else
72 return QString("%1").arg(section + 1);
68 return QString("%1").arg(section + 1);
73 }
69 }
74
70
75 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
71 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
76 {
72 {
77 if (role == Qt::DisplayRole)
73 if (role == Qt::DisplayRole) {
78 {
79 return m_data[index.row()]->at(index.column());
74 return m_data[index.row()]->at(index.column());
80 }
75 } else if (role == Qt::EditRole) {
81 else if (role == Qt::EditRole)
82 {
83 return m_data[index.row()]->at(index.column());
76 return m_data[index.row()]->at(index.column());
84 }
77 } else if (role == Qt::BackgroundRole) {
85 else if (role == Qt::BackgroundRole)
86 {
87 QRect rect;
78 QRect rect;
88 foreach(rect, m_mapping)
79 foreach(rect, m_mapping)
89 if(rect.contains(index.column(), index.row()))
80 if (rect.contains(index.column(), index.row()))
@@ -97,8 +88,7 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
97
88
98 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & value, int role)
89 bool CustomTableModel::setData(const QModelIndex & index, const QVariant & value, int role)
99 {
90 {
100 if (index.isValid() && role == Qt::EditRole)
91 if (index.isValid() && role == Qt::EditRole) {
101 {
102 m_data[index.row()]->replace(index.column(), value.toDouble());
92 m_data[index.row()]->replace(index.column(), value.toDouble());
103 emit dataChanged(index, index);
93 emit dataChanged(index, index);
104 return true;
94 return true;
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -26,6 +26,5 int main(int argc, char *argv[])
26 QApplication a(argc, argv);
26 QApplication a(argc, argv);
27 TableWidget w;
27 TableWidget w;
28 w.show();
28 w.show();
29
30 return a.exec();
29 return a.exec();
31 }
30 }
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -238,10 +238,10 void MainWidget::fontSizeChanged()
238 void MainWidget::updateLegendLayout()
238 void MainWidget::updateLegendLayout()
239 {
239 {
240 //![4]
240 //![4]
241 m_chart->legend()->setGeometry(QRectF(m_legendPosX->value()
241 m_chart->legend()->setGeometry(QRectF(m_legendPosX->value(),
242 ,m_legendPosY->value()
242 m_legendPosY->value(),
243 ,m_legendWidth->value()
243 m_legendWidth->value(),
244 ,m_legendHeight->value()));
244 m_legendHeight->value()));
245 m_chart->legend()->update();
245 m_chart->legend()->update();
246 //![4]
246 //![4]
247 }
247 }
@@ -43,9 +43,7 public:
43 void showLegendSpinbox();
43 void showLegendSpinbox();
44 void hideLegendSpinbox();
44 void hideLegendSpinbox();
45
45
46 signals:
46 public Q_SLOTS:
47
48 public slots:
49 void toggleAttached();
47 void toggleAttached();
50 void addBarset();
48 void addBarset();
51 void removeBarset();
49 void removeBarset();
@@ -58,9 +56,7 public slots:
58
56
59 void updateLegendLayout();
57 void updateLegendLayout();
60
58
61
62 private:
59 private:
63
64 QChart *m_chart;
60 QChart *m_chart;
65 QBarSeries *m_series;
61 QBarSeries *m_series;
66
62
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -33,11 +33,9 CustomTableModel::CustomTableModel(QObject *parent) :
33 m_rowCount = 15;
33 m_rowCount = 15;
34
34
35 // m_data
35 // m_data
36 for (int i = 0; i < m_rowCount; i++)
36 for (int i = 0; i < m_rowCount; i++) {
37 {
38 QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount);
37 QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount);
39 for (int k = 0; k < dataVec->size(); k++)
38 for (int k = 0; k < dataVec->size(); k++) {
40 {
41 if (k%2 == 0)
39 if (k % 2 == 0)
42 dataVec->replace(k, i * 50 + qrand()%20);
40 dataVec->replace(k, i * 50 + qrand() % 20);
43 else
41 else
@@ -64,34 +62,27 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation,
64 if (role != Qt::DisplayRole)
62 if (role != Qt::DisplayRole)
65 return QVariant();
63 return QVariant();
66
64
67 if (orientation == Qt::Horizontal)
65 if (orientation == Qt::Horizontal) {
68 {
69 if (section%2 == 0)
66 if (section % 2 == 0)
70 return "x";
67 return "x";
71 else
68 else
72 return "y";
69 return "y";
73 }
70 } else {
74 else
75 return QString("%1").arg(section + 1);
71 return QString("%1").arg(section + 1);
76 }
72 }
73 }
77
74
78 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
75 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
79 {
76 {
80 if (role == Qt::DisplayRole)
77 if (role == Qt::DisplayRole) {
81 {
82 return m_data[index.row()]->at(index.column());
78 return m_data[index.row()]->at(index.column());
83 }
79 } else if (role == Qt::EditRole) {
84 else if (role == Qt::EditRole)
85 {
86 return m_data[index.row()]->at(index.column());
80 return m_data[index.row()]->at(index.column());
87 }
81 } else if (role == Qt::BackgroundRole) {
88 else if (role == Qt::BackgroundRole)
82 foreach (QRect rect, m_mapping) {
89 {
90 QRect rect;
91 foreach(rect, m_mapping)
92 if(rect.contains(index.column(), index.row()))
83 if (rect.contains(index.column(), index.row()))
93 return QColor(m_mapping.key(rect));
84 return QColor(m_mapping.key(rect));
94
85 }
95 // cell not mapped return white color
86 // cell not mapped return white color
96 return QColor(Qt::white);
87 return QColor(Qt::white);
97 }
88 }
@@ -100,8 +91,7 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
100
91
101 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & value, int role)
92 bool CustomTableModel::setData(const QModelIndex & index, const QVariant & value, int role)
102 {
93 {
103 if (index.isValid() && role == Qt::EditRole)
94 if (index.isValid() && role == Qt::EditRole) {
104 {
105 m_data[index.row()]->replace(index.column(), value.toDouble());
95 m_data[index.row()]->replace(index.column(), value.toDouble());
106 emit dataChanged(index, index);
96 emit dataChanged(index, index);
107 return true;
97 return true;
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -26,6 +26,5 int main(int argc, char *argv[])
26 QApplication a(argc, argv);
26 QApplication a(argc, argv);
27 TableWidget w;
27 TableWidget w;
28 w.show();
28 w.show();
29
30 return a.exec();
29 return a.exec();
31 }
30 }
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -25,8 +25,8
25 #include <QAreaSeries>
25 #include <QAreaSeries>
26 #include <QTime>
26 #include <QTime>
27
27
28 ChartView::ChartView(QChart* chart,QWidget* parent):
28 ChartView::ChartView(QChart* chart, QWidget* parent)
29 QChartView(chart,parent),
29 : QChartView(chart, parent),
30 m_index(-1),
30 m_index(-1),
31 m_chart(chart)
31 m_chart(chart)
32 {
32 {
@@ -77,7 +77,8 ChartView::ChartView(QChart* chart,QWidget* parent):
77
77
78 ChartView::~ChartView()
78 ChartView::~ChartView()
79 {
79 {
80 if(m_series.size() == 0) return;
80 if (m_series.size() == 0)
81 return;
81 m_chart->removeSeries(m_series.at(m_index));
82 m_chart->removeSeries(m_series.at(m_index));
82 m_series.removeLast(); //remove QAreaSeries instance since they will be deleted when QLineSeries instance is gone
83 m_series.removeLast(); //remove QAreaSeries instance since they will be deleted when QLineSeries instance is gone
83 qDeleteAll(m_series);
84 qDeleteAll(m_series);
@@ -86,7 +87,8 ChartView::~ChartView()
86 //![4]
87 //![4]
87 void ChartView::handleTimeout()
88 void ChartView::handleTimeout()
88 {
89 {
89 if(m_series.size() == 0) return;
90 if (m_series.size() == 0)
91 return;
90 if(m_index >= 0)
92 if (m_index >= 0)
91 m_chart->removeSeries(m_series.at(m_index));
93 m_chart->removeSeries(m_series.at(m_index));
92 m_index++;
94 m_index++;
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -30,11 +30,6 class ChartView : public QChartView
30 Q_OBJECT
30 Q_OBJECT
31 public:
31 public:
32 explicit ChartView(QWidget *parent = 0);
32 explicit ChartView(QWidget *parent = 0);
33
34 signals:
35
36 public slots:
37
38 };
33 };
39
34
40 #endif // CHARTVIEW_H
35 #endif // CHARTVIEW_H
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -24,8 +24,8
24 QTCOMMERCIALCHART_USE_NAMESPACE
24 QTCOMMERCIALCHART_USE_NAMESPACE
25
25
26 DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
26 DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
27 : QChart(parent, wFlags)
27 : QChart(parent, wFlags),
28 ,m_currentSeries(0)
28 m_currentSeries(0)
29 {
29 {
30 }
30 }
31
31
@@ -81,9 +81,8 int main(int argc, char *argv[])
81 QBarSet* monthlyCrop = new QBarSet(plant);
81 QBarSet* monthlyCrop = new QBarSet(plant);
82 for (int month=0; month<months.count(); month++) {
82 for (int month = 0; month < months.count(); month++) {
83 QBarSet* weeklyCrop = new QBarSet(plant);
83 QBarSet* weeklyCrop = new QBarSet(plant);
84 for (int week=0; week<weeks.count(); week++) {
84 for (int week = 0; week < weeks.count(); week++)
85 *weeklyCrop << (qrand() % 20);
85 *weeklyCrop << (qrand() % 20);
86 }
87 // Get the drilldown series from season series and add crop to it.
86 // Get the drilldown series from season series and add crop to it.
88 seasonSeries->drilldownSeries(month)->append(weeklyCrop);
87 seasonSeries->drilldownSeries(month)->append(weeklyCrop);
89 *monthlyCrop << weeklyCrop->sum();
88 *monthlyCrop << weeklyCrop->sum();
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
General Comments 0
You need to be logged in to leave comments. Login now