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