@@ -37,9 +37,9 int main(int argc, char *argv[]) | |||||
37 |
|
37 | |||
38 | //![2] |
|
38 | //![2] | |
39 | *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12, 6) |
|
39 | *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12, 6) | |
40 | << QPointF(16, 7) << QPointF(18, 5); |
|
40 | << QPointF(16, 7) << QPointF(18, 5); | |
41 | *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12, 3) |
|
41 | *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12, 3) | |
42 | << QPointF(16, 4) << QPointF(18, 3); |
|
42 | << QPointF(16, 4) << QPointF(18, 3); | |
43 | //![2] |
|
43 | //![2] | |
44 |
|
44 | |||
45 | //![3] |
|
45 | //![3] |
@@ -69,7 +69,7 int main(int argc, char *argv[]) | |||||
69 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
69 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
70 | axis->append(categories); |
|
70 | axis->append(categories); | |
71 | chart->createDefaultAxes(); |
|
71 | chart->createDefaultAxes(); | |
72 | chart->setAxisX(axis,series); |
|
72 | chart->setAxisX(axis, series); | |
73 | //![4] |
|
73 | //![4] | |
74 |
|
74 | |||
75 | //![5] |
|
75 | //![5] |
@@ -27,21 +27,19 | |||||
27 | CustomTableModel::CustomTableModel(QObject *parent) : |
|
27 | CustomTableModel::CustomTableModel(QObject *parent) : | |
28 | QAbstractTableModel(parent) |
|
28 | QAbstractTableModel(parent) | |
29 | { |
|
29 | { | |
30 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
30 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
31 |
|
31 | |||
32 | m_columnCount = 6; |
|
32 | m_columnCount = 6; | |
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 | { |
|
39 | if (k % 2 == 0) | |
41 | if (k%2 == 0) |
|
40 | dataVec->replace(k, i * 50 + qrand() % 20); | |
42 | dataVec->replace(k, i * 50 + qrand()%20); |
|
|||
43 | else |
|
41 | else | |
44 | dataVec->replace(k, qrand()%100); |
|
42 | dataVec->replace(k, qrand() % 100); | |
45 | } |
|
43 | } | |
46 | m_data.append(dataVec); |
|
44 | m_data.append(dataVec); | |
47 | } |
|
45 | } | |
@@ -59,35 +57,28 int CustomTableModel::columnCount(const QModelIndex & parent) const | |||||
59 | return m_columnCount; |
|
57 | return m_columnCount; | |
60 | } |
|
58 | } | |
61 |
|
59 | |||
62 |
QVariant CustomTableModel::headerData |
|
60 | QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation, int role) const | |
63 | { |
|
61 | { | |
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 | 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 |
|
|
80 | if (rect.contains(index.column(), index.row())) | |
90 |
|
|
81 | return QColor(m_mapping.key(rect)); | |
91 |
|
82 | |||
92 | // cell not mapped return white color |
|
83 | // cell not mapped return white color | |
93 | return QColor(Qt::white); |
|
84 | return QColor(Qt::white); | |
@@ -95,10 +86,9 QVariant CustomTableModel::data(const QModelIndex & index, int role) const | |||||
95 | return QVariant(); |
|
86 | return QVariant(); | |
96 | } |
|
87 | } | |
97 |
|
88 | |||
98 |
bool CustomTableModel::setData |
|
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; | |
@@ -106,7 +96,7 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & val | |||||
106 | return false; |
|
96 | return false; | |
107 | } |
|
97 | } | |
108 |
|
98 | |||
109 |
Qt::ItemFlags CustomTableModel::flags |
|
99 | Qt::ItemFlags CustomTableModel::flags(const QModelIndex & index) const | |
110 | { |
|
100 | { | |
111 | return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; |
|
101 | return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; | |
112 | } |
|
102 | } |
@@ -31,12 +31,12 class CustomTableModel : public QAbstractTableModel | |||||
31 | public: |
|
31 | public: | |
32 | explicit CustomTableModel(QObject *parent = 0); |
|
32 | explicit CustomTableModel(QObject *parent = 0); | |
33 |
|
33 | |||
34 |
int rowCount |
|
34 | int rowCount(const QModelIndex & parent = QModelIndex()) const; | |
35 |
int columnCount |
|
35 | int columnCount(const QModelIndex & parent = QModelIndex()) const; | |
36 |
QVariant headerData |
|
36 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; | |
37 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
37 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | |
38 |
bool setData |
|
38 | bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole); | |
39 |
Qt::ItemFlags flags |
|
39 | Qt::ItemFlags flags(const QModelIndex & index) const; | |
40 |
|
40 | |||
41 | void addMapping(QString color, QRect area); |
|
41 | void addMapping(QString color, QRect area); | |
42 | void clearMapping() { m_mapping.clear(); } |
|
42 | void clearMapping() { m_mapping.clear(); } |
@@ -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 | } |
@@ -89,7 +89,7 TableWidget::TableWidget(QWidget *parent) | |||||
89 | QStringList categories; |
|
89 | QStringList categories; | |
90 | categories << "April" << "May" << "June" << "July" << "August"; |
|
90 | categories << "April" << "May" << "June" << "July" << "August"; | |
91 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
91 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
92 |
axis->append(categories); |
|
92 | axis->append(categories); | |
93 | chart->createDefaultAxes(); |
|
93 | chart->createDefaultAxes(); | |
94 | chart->setAxisX(axis, series); |
|
94 | chart->setAxisX(axis, series); | |
95 | //! [6] |
|
95 | //! [6] |
@@ -26,7 +26,7 | |||||
26 | class TableWidget : public QWidget |
|
26 | class TableWidget : public QWidget | |
27 | { |
|
27 | { | |
28 | Q_OBJECT |
|
28 | Q_OBJECT | |
29 |
|
29 | |||
30 | public: |
|
30 | public: | |
31 | TableWidget(QWidget *parent = 0); |
|
31 | TableWidget(QWidget *parent = 0); | |
32 | }; |
|
32 | }; |
@@ -53,8 +53,8 int main(int argc, char *argv[]) | |||||
53 |
|
53 | |||
54 | // Customize chart background |
|
54 | // Customize chart background | |
55 | QLinearGradient backgroundGradient; |
|
55 | QLinearGradient backgroundGradient; | |
56 | backgroundGradient.setStart(QPointF(0,0)); |
|
56 | backgroundGradient.setStart(QPointF(0, 0)); | |
57 | backgroundGradient.setFinalStop(QPointF(0,1)); |
|
57 | backgroundGradient.setFinalStop(QPointF(0, 1)); | |
58 | backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1)); |
|
58 | backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1)); | |
59 | backgroundGradient.setColorAt(1.0, QRgb(0x4c4547)); |
|
59 | backgroundGradient.setColorAt(1.0, QRgb(0x4c4547)); | |
60 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
60 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
@@ -33,7 +33,7 QTCOMMERCIALCHART_USE_NAMESPACE | |||||
33 | int main(int argc, char *argv[]) |
|
33 | int main(int argc, char *argv[]) | |
34 | { |
|
34 | { | |
35 | QApplication a(argc, argv); |
|
35 | QApplication a(argc, argv); | |
36 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
36 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
37 |
|
37 | |||
38 | //![1] |
|
38 | //![1] | |
39 | QLineSeries* series = new QLineSeries(); |
|
39 | QLineSeries* series = new QLineSeries(); | |
@@ -62,7 +62,7 int main(int argc, char *argv[]) | |||||
62 | //![2] |
|
62 | //![2] | |
63 |
|
63 | |||
64 | //![3] |
|
64 | //![3] | |
65 |
QChart* chart = new QChart(); |
|
65 | QChart* chart = new QChart(); | |
66 | chart->addSeries(series); |
|
66 | chart->addSeries(series); | |
67 | chart->legend()->hide(); |
|
67 | chart->legend()->hide(); | |
68 | chart->createDefaultAxes(); |
|
68 | chart->createDefaultAxes(); |
@@ -24,7 +24,7 QTCOMMERCIALCHART_USE_NAMESPACE | |||||
24 |
|
24 | |||
25 | //![1] |
|
25 | //![1] | |
26 | DonutBreakdownChart::DonutBreakdownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
26 | DonutBreakdownChart::DonutBreakdownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
27 | :QChart(parent, wFlags) |
|
27 | : QChart(parent, wFlags) | |
28 | { |
|
28 | { | |
29 | // create the series for main center pie |
|
29 | // create the series for main center pie | |
30 | mainSeries = new QPieSeries(); |
|
30 | mainSeries = new QPieSeries(); |
@@ -72,6 +72,6 int main(int argc, char *argv[]) | |||||
72 | window.resize(800, 600); |
|
72 | window.resize(800, 600); | |
73 | window.show(); |
|
73 | window.show(); | |
74 | //![3] |
|
74 | //![3] | |
75 |
|
75 | |||
76 | return a.exec(); |
|
76 | return a.exec(); | |
77 | } |
|
77 | } |
@@ -69,7 +69,7 int main(int argc, char *argv[]) | |||||
69 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
69 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
70 | axis->append(categories); |
|
70 | axis->append(categories); | |
71 | chart->createDefaultAxes(); |
|
71 | chart->createDefaultAxes(); | |
72 | chart->setAxisY(axis,series); |
|
72 | chart->setAxisY(axis, series); | |
73 | //![4] |
|
73 | //![4] | |
74 |
|
74 | |||
75 | //![5] |
|
75 | //![5] |
@@ -70,7 +70,7 int main(int argc, char *argv[]) | |||||
70 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
70 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
71 | axis->append(categories); |
|
71 | axis->append(categories); | |
72 | chart->createDefaultAxes(); |
|
72 | chart->createDefaultAxes(); | |
73 | chart->setAxisY(axis,series); |
|
73 | chart->setAxisY(axis, series); | |
74 | //![4] |
|
74 | //![4] | |
75 |
|
75 | |||
76 | //![5] |
|
76 | //![5] |
@@ -70,7 +70,7 int main(int argc, char *argv[]) | |||||
70 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
70 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
71 | axis->append(categories); |
|
71 | axis->append(categories); | |
72 | chart->createDefaultAxes(); |
|
72 | chart->createDefaultAxes(); | |
73 | chart->setAxisY(axis,series); |
|
73 | chart->setAxisY(axis, series); | |
74 | //![4] |
|
74 | //![4] | |
75 |
|
75 | |||
76 | //![5] |
|
76 | //![5] |
@@ -94,7 +94,7 MainWidget::MainWidget(QWidget *parent) : | |||||
94 | // Create layout for grid and detached legend |
|
94 | // Create layout for grid and detached legend | |
95 | m_mainLayout = new QGridLayout(); |
|
95 | m_mainLayout = new QGridLayout(); | |
96 | m_mainLayout->addLayout(m_buttonLayout, 0, 0); |
|
96 | m_mainLayout->addLayout(m_buttonLayout, 0, 0); | |
97 | m_mainLayout->addLayout(fontLayout,1,0); |
|
97 | m_mainLayout->addLayout(fontLayout, 1, 0); | |
98 | m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
98 | m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
99 | setLayout(m_mainLayout); |
|
99 | setLayout(m_mainLayout); | |
100 |
|
100 | |||
@@ -155,8 +155,8 void MainWidget::toggleAttached() | |||||
155 | //![2] |
|
155 | //![2] | |
156 | legend->detachFromChart(); |
|
156 | legend->detachFromChart(); | |
157 | m_chart->legend()->setBackgroundVisible(true); |
|
157 | m_chart->legend()->setBackgroundVisible(true); | |
158 | m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128))); |
|
158 | m_chart->legend()->setBrush(QBrush(QColor(128, 128, 128, 128))); | |
159 | m_chart->legend()->setPen(QPen(QColor(192,192,192,192))); |
|
159 | m_chart->legend()->setPen(QPen(QColor(192, 192, 192, 192))); | |
160 | //![2] |
|
160 | //![2] | |
161 | showLegendSpinbox(); |
|
161 | showLegendSpinbox(); | |
162 | updateLegendLayout(); |
|
162 | updateLegendLayout(); | |
@@ -182,7 +182,7 void MainWidget::removeBarset() | |||||
182 | { |
|
182 | { | |
183 | QList<QBarSet*> sets = m_series->barSets(); |
|
183 | QList<QBarSet*> sets = m_series->barSets(); | |
184 | if (sets.count() > 0) { |
|
184 | if (sets.count() > 0) { | |
185 | m_series->remove(sets.at(sets.count()-1)); |
|
185 | m_series->remove(sets.at(sets.count() - 1)); | |
186 | } |
|
186 | } | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
@@ -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 |
|
|
242 | m_legendPosY->value(), | |
243 |
|
|
243 | m_legendWidth->value(), | |
244 |
|
|
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 |
@@ -60,12 +60,12 int main(int argc, char *argv[]) | |||||
60 | //![8] |
|
60 | //![8] | |
61 | QLineSeries* lineseries = new QLineSeries(); |
|
61 | QLineSeries* lineseries = new QLineSeries(); | |
62 |
|
62 | |||
63 | lineseries->append(QPoint(0,4)); |
|
63 | lineseries->append(QPoint(0, 4)); | |
64 | lineseries->append(QPoint(1,15)); |
|
64 | lineseries->append(QPoint(1, 15)); | |
65 | lineseries->append(QPoint(2,20)); |
|
65 | lineseries->append(QPoint(2, 20)); | |
66 | lineseries->append(QPoint(3,4)); |
|
66 | lineseries->append(QPoint(3, 4)); | |
67 | lineseries->append(QPoint(4,12)); |
|
67 | lineseries->append(QPoint(4, 12)); | |
68 | lineseries->append(QPoint(5,17)); |
|
68 | lineseries->append(QPoint(5, 17)); | |
69 | //![8] |
|
69 | //![8] | |
70 |
|
70 | |||
71 | //![3] |
|
71 | //![3] | |
@@ -80,14 +80,14 int main(int argc, char *argv[]) | |||||
80 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
80 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
81 | QBarCategoryAxis* axisX = new QBarCategoryAxis(); |
|
81 | QBarCategoryAxis* axisX = new QBarCategoryAxis(); | |
82 | axisX->append(categories); |
|
82 | axisX->append(categories); | |
83 | chart->setAxisX(axisX,lineseries); |
|
83 | chart->setAxisX(axisX, lineseries); | |
84 | chart->setAxisX(axisX,barseries); |
|
84 | chart->setAxisX(axisX, barseries); | |
85 | axisX->setRange(QString("Jan"),QString("Jun")); |
|
85 | axisX->setRange(QString("Jan"), QString("Jun")); | |
86 |
|
86 | |||
87 | QValueAxis* axisY = new QValueAxis(); |
|
87 | QValueAxis* axisY = new QValueAxis(); | |
88 | chart->setAxisY(axisY,lineseries); |
|
88 | chart->setAxisY(axisY, lineseries); | |
89 | chart->setAxisY(axisY,barseries); |
|
89 | chart->setAxisY(axisY, barseries); | |
90 | axisY->setRange(0,20); |
|
90 | axisY->setRange(0, 20); | |
91 | //![4] |
|
91 | //![4] | |
92 |
|
92 | |||
93 | //![5] |
|
93 | //![5] |
@@ -27,21 +27,19 | |||||
27 | CustomTableModel::CustomTableModel(QObject *parent) : |
|
27 | CustomTableModel::CustomTableModel(QObject *parent) : | |
28 | QAbstractTableModel(parent) |
|
28 | QAbstractTableModel(parent) | |
29 | { |
|
29 | { | |
30 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
30 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
31 |
|
31 | |||
32 | m_columnCount = 4; |
|
32 | m_columnCount = 4; | |
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 | { |
|
39 | if (k % 2 == 0) | |
41 | if (k%2 == 0) |
|
40 | dataVec->replace(k, i * 50 + qrand() % 20); | |
42 | dataVec->replace(k, i * 50 + qrand()%20); |
|
|||
43 | else |
|
41 | else | |
44 | dataVec->replace(k, qrand()%100); |
|
42 | dataVec->replace(k, qrand() % 100); | |
45 | } |
|
43 | } | |
46 | m_data.append(dataVec); |
|
44 | m_data.append(dataVec); | |
47 | } |
|
45 | } | |
@@ -59,49 +57,41 int CustomTableModel::columnCount(const QModelIndex & parent) const | |||||
59 | return m_columnCount; |
|
57 | return m_columnCount; | |
60 | } |
|
58 | } | |
61 |
|
59 | |||
62 |
QVariant CustomTableModel::headerData |
|
60 | QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation, int role) const | |
63 | { |
|
61 | { | |
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 | { |
|
66 | if (section % 2 == 0) | |
69 | 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); | |
|
72 | } | |||
76 | } |
|
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 | { |
|
83 | if (rect.contains(index.column(), index.row())) | |
90 | QRect rect; |
|
|||
91 | foreach(rect, m_mapping) |
|
|||
92 | 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 | } | |
98 | return QVariant(); |
|
89 | return QVariant(); | |
99 | } |
|
90 | } | |
100 |
|
91 | |||
101 |
bool CustomTableModel::setData |
|
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; | |
@@ -109,7 +99,7 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & val | |||||
109 | return false; |
|
99 | return false; | |
110 | } |
|
100 | } | |
111 |
|
101 | |||
112 |
Qt::ItemFlags CustomTableModel::flags |
|
102 | Qt::ItemFlags CustomTableModel::flags(const QModelIndex & index) const | |
113 | { |
|
103 | { | |
114 | return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; |
|
104 | return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; | |
115 | } |
|
105 | } |
@@ -31,12 +31,12 class CustomTableModel : public QAbstractTableModel | |||||
31 | public: |
|
31 | public: | |
32 | explicit CustomTableModel(QObject *parent = 0); |
|
32 | explicit CustomTableModel(QObject *parent = 0); | |
33 |
|
33 | |||
34 |
int rowCount |
|
34 | int rowCount(const QModelIndex & parent = QModelIndex()) const; | |
35 |
int columnCount |
|
35 | int columnCount(const QModelIndex & parent = QModelIndex()) const; | |
36 |
QVariant headerData |
|
36 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; | |
37 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
37 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | |
38 |
bool setData |
|
38 | bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole); | |
39 |
Qt::ItemFlags flags |
|
39 | Qt::ItemFlags flags(const QModelIndex & index) const; | |
40 |
|
40 | |||
41 | void addMapping(QString color, QRect area); |
|
41 | void addMapping(QString color, QRect area); | |
42 | void clearMapping() { m_mapping.clear(); } |
|
42 | void clearMapping() { m_mapping.clear(); } |
@@ -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 | } |
@@ -26,7 +26,7 | |||||
26 | class TableWidget : public QWidget |
|
26 | class TableWidget : public QWidget | |
27 | { |
|
27 | { | |
28 | Q_OBJECT |
|
28 | Q_OBJECT | |
29 |
|
29 | |||
30 | public: |
|
30 | public: | |
31 | TableWidget(QWidget *parent = 0); |
|
31 | TableWidget(QWidget *parent = 0); | |
32 | }; |
|
32 | }; |
@@ -32,7 +32,7 int main(int argc, char *argv[]) | |||||
32 | { |
|
32 | { | |
33 | QApplication a(argc, argv); |
|
33 | QApplication a(argc, argv); | |
34 |
|
34 | |||
35 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
35 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
36 |
|
36 | |||
37 | //![1] |
|
37 | //![1] | |
38 | QLineSeries* series; |
|
38 | QLineSeries* series; | |
@@ -42,18 +42,18 int main(int argc, char *argv[]) | |||||
42 | for (int i = 0; i < 5; i++) { |
|
42 | for (int i = 0; i < 5; i++) { | |
43 | series = new QLineSeries; |
|
43 | series = new QLineSeries; | |
44 | for (int k(0); k < 8; k++) |
|
44 | for (int k(0); k < 8; k++) | |
45 | series->append(i + k, qrand()%20); |
|
45 | series->append(i + k, qrand() % 20); | |
46 | chart->addSeries(series); |
|
46 | chart->addSeries(series); | |
47 |
|
47 | |||
48 | axisX = new QValueAxis; |
|
48 | axisX = new QValueAxis; | |
49 | axisX->setTickCount(7 + i); |
|
49 | axisX->setTickCount(7 + i); | |
50 | axisX->setLinePenColor(series->pen().color()); |
|
50 | axisX->setLinePenColor(series->pen().color()); | |
51 | if (i%2) |
|
51 | if (i % 2) | |
52 | axisX->setAlternativePlacement(true); |
|
52 | axisX->setAlternativePlacement(true); | |
53 | axisY = new QValueAxis; |
|
53 | axisY = new QValueAxis; | |
54 | axisY->setTickCount(7 + i); |
|
54 | axisY->setTickCount(7 + i); | |
55 | axisY->setLinePenColor(series->pen().color()); |
|
55 | axisY->setLinePenColor(series->pen().color()); | |
56 | if (i%2) |
|
56 | if (i % 2) | |
57 | axisY->setAlternativePlacement(true); |
|
57 | axisY->setAlternativePlacement(true); | |
58 |
|
58 | |||
59 | chart->setAxisX(axisX, series); |
|
59 | chart->setAxisX(axisX, series); |
@@ -68,7 +68,7 int main(int argc, char *argv[]) | |||||
68 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
68 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
69 | axis->append(categories); |
|
69 | axis->append(categories); | |
70 | chart->createDefaultAxes(); |
|
70 | chart->createDefaultAxes(); | |
71 | chart->setAxisX(axis,series); |
|
71 | chart->setAxisX(axis, series); | |
72 | //![4] |
|
72 | //![4] | |
73 |
|
73 | |||
74 | //![5] |
|
74 | //![5] |
@@ -23,8 +23,8 | |||||
23 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
23 | QTCOMMERCIALCHART_USE_NAMESPACE | |
24 |
|
24 | |||
25 | DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
25 | DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
26 | :QChart(parent, wFlags), |
|
26 | : QChart(parent, wFlags), | |
27 | m_currentSeries(0) |
|
27 | m_currentSeries(0) | |
28 | { |
|
28 | { | |
29 |
|
29 | |||
30 | } |
|
30 | } |
@@ -23,8 +23,8 | |||||
23 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
23 | QTCOMMERCIALCHART_USE_NAMESPACE | |
24 |
|
24 | |||
25 | DrilldownSlice::DrilldownSlice(qreal value, QString prefix, QAbstractSeries* drilldownSeries) |
|
25 | DrilldownSlice::DrilldownSlice(qreal value, QString prefix, QAbstractSeries* drilldownSeries) | |
26 | :m_drilldownSeries(drilldownSeries), |
|
26 | : m_drilldownSeries(drilldownSeries), | |
27 | m_prefix(prefix) |
|
27 | m_prefix(prefix) | |
28 | { |
|
28 | { | |
29 | setValue(value); |
|
29 | setValue(value); | |
30 | updateLabel(); |
|
30 | updateLabel(); | |
@@ -49,7 +49,7 void DrilldownSlice::updateLabel() | |||||
49 | label += " $"; |
|
49 | label += " $"; | |
50 | label += QString::number(this->value()); |
|
50 | label += QString::number(this->value()); | |
51 | label += ", "; |
|
51 | label += ", "; | |
52 | label += QString::number(this->percentage()*100, 'f', 1); |
|
52 | label += QString::number(this->percentage() * 100, 'f', 1); | |
53 | label += "%"; |
|
53 | label += "%"; | |
54 | setLabel(label); |
|
54 | setLabel(label); | |
55 | } |
|
55 | } |
@@ -33,7 +33,7 int main(int argc, char *argv[]) | |||||
33 | { |
|
33 | { | |
34 | QApplication a(argc, argv); |
|
34 | QApplication a(argc, argv); | |
35 |
|
35 | |||
36 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
36 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
37 |
|
37 | |||
38 | QMainWindow window; |
|
38 | QMainWindow window; | |
39 |
|
39 |
@@ -25,14 +25,14 | |||||
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 | { | |
33 | m_chart->setTitle("Charts presenter"); |
|
33 | m_chart->setTitle("Charts presenter"); | |
34 | m_chart->setDropShadowEnabled(false); |
|
34 | m_chart->setDropShadowEnabled(false); | |
35 | QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout())); |
|
35 | QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout())); | |
36 | m_timer.setInterval(3000); |
|
36 | m_timer.setInterval(3000); | |
37 |
|
37 | |||
38 | //![1] |
|
38 | //![1] | |
@@ -54,21 +54,21 ChartView::ChartView(QChart* chart,QWidget* parent): | |||||
54 |
|
54 | |||
55 | for (int x = 0; x <= numPoints; ++x) { |
|
55 | for (int x = 0; x <= numPoints; ++x) { | |
56 | qreal y = qrand() % 100; |
|
56 | qreal y = qrand() % 100; | |
57 | series0->append(x,y); |
|
57 | series0->append(x, y); | |
58 | series1->append(x,y); |
|
58 | series1->append(x, y); | |
59 | series2->append(x,y); |
|
59 | series2->append(x, y); | |
60 | } |
|
60 | } | |
61 | //![2] |
|
61 | //![2] | |
62 |
|
62 | |||
63 | //![3] |
|
63 | //![3] | |
64 | m_series<<series0; |
|
64 | m_series << series0; | |
65 | m_titles<< m_chart->title()+": LineChart"; |
|
65 | m_titles << m_chart->title() + ": LineChart"; | |
66 | m_series<<series1; |
|
66 | m_series << series1; | |
67 | m_titles<< m_chart->title()+": ScatterChart"; |
|
67 | m_titles << m_chart->title() + ": ScatterChart"; | |
68 | m_series<<series2; |
|
68 | m_series << series2; | |
69 | m_titles<< m_chart->title()+": SplineChart"; |
|
69 | m_titles << m_chart->title() + ": SplineChart"; | |
70 | m_series<<series3; |
|
70 | m_series << series3; | |
71 | m_titles<< m_chart->title()+": AreaChart"; |
|
71 | m_titles << m_chart->title() + ": AreaChart"; | |
72 | //![3] |
|
72 | //![3] | |
73 |
|
73 | |||
74 | m_timer.start(); |
|
74 | m_timer.start(); | |
@@ -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) |
|
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,8 +87,9 ChartView::~ChartView() | |||||
86 | //![4] |
|
87 | //![4] | |
87 | void ChartView::handleTimeout() |
|
88 | void ChartView::handleTimeout() | |
88 | { |
|
89 | { | |
89 |
if(m_series.size() == 0) |
|
90 | if (m_series.size() == 0) | |
90 | if(m_index >= 0) |
|
91 | return; | |
|
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++; | |
93 | m_index = m_index % m_series.size(); |
|
95 | m_index = m_index % m_series.size(); |
@@ -31,7 +31,7 class ChartView: public QChartView | |||||
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | public: |
|
33 | public: | |
34 | ChartView(QChart* chart,QWidget* parent = 0); |
|
34 | ChartView(QChart* chart, QWidget* parent = 0); | |
35 | virtual ~ChartView(); |
|
35 | virtual ~ChartView(); | |
36 |
|
36 | |||
37 | public slots: |
|
37 | public slots: |
@@ -27,7 +27,7 int main(int argc, char *argv[]) | |||||
27 | QApplication a(argc, argv); |
|
27 | QApplication a(argc, argv); | |
28 | QMainWindow window; |
|
28 | QMainWindow window; | |
29 | QChart* chart = new QChart(); |
|
29 | QChart* chart = new QChart(); | |
30 | ChartView chartView(chart,&window); |
|
30 | ChartView chartView(chart, &window); | |
31 | chartView.setRenderHint(QPainter::Antialiasing); |
|
31 | chartView.setRenderHint(QPainter::Antialiasing); | |
32 | chart->setAnimationOptions(QChart::SeriesAnimations); |
|
32 | chart->setAnimationOptions(QChart::SeriesAnimations); | |
33 | window.setCentralWidget(&chartView); |
|
33 | window.setCentralWidget(&chartView); |
@@ -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 |
@@ -35,8 +35,8 ChartView::ChartView(QWidget *parent) | |||||
35 |
|
35 | |||
36 | m_scatter = new QScatterSeries(); |
|
36 | m_scatter = new QScatterSeries(); | |
37 | m_scatter->setName("scatter1"); |
|
37 | m_scatter->setName("scatter1"); | |
38 | for(qreal x(0.5); x <= 4.0; x += 0.5) { |
|
38 | for (qreal x(0.5); x <= 4.0; x += 0.5) { | |
39 | for(qreal y(0.5); y <= 4.0; y += 0.5) { |
|
39 | for (qreal y(0.5); y <= 4.0; y += 0.5) { | |
40 | *m_scatter << QPointF(x, y); |
|
40 | *m_scatter << QPointF(x, y); | |
41 | } |
|
41 | } | |
42 | } |
|
42 | } | |
@@ -64,7 +64,7 void ChartView::handleClickedPoint(const QPointF& point) | |||||
64 | qreal distance(INT_MAX); |
|
64 | qreal distance(INT_MAX); | |
65 | foreach(QPointF currentPoint, m_scatter->points()) { |
|
65 | foreach(QPointF currentPoint, m_scatter->points()) { | |
66 | qreal currentDistance = sqrt((currentPoint.x() - clickedPoint.x()) * (currentPoint.x() - clickedPoint.x()) |
|
66 | qreal currentDistance = sqrt((currentPoint.x() - clickedPoint.x()) * (currentPoint.x() - clickedPoint.x()) | |
67 |
|
|
67 | + (currentPoint.y() - clickedPoint.y()) * (currentPoint.y() - clickedPoint.y())); | |
68 | if (currentDistance < distance) { |
|
68 | if (currentDistance < distance) { | |
69 | distance = currentDistance; |
|
69 | distance = currentDistance; | |
70 | closest = currentPoint; |
|
70 | closest = currentPoint; |
@@ -24,7 +24,7 | |||||
24 | #include <QGraphicsView> |
|
24 | #include <QGraphicsView> | |
25 |
|
25 | |||
26 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
26 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
27 | :QChart(parent, wFlags) |
|
27 | : QChart(parent, wFlags) | |
28 | { |
|
28 | { | |
29 | // Seems that QGraphicsView (QChartView) does not grab gestures. |
|
29 | // Seems that QGraphicsView (QChartView) does not grab gestures. | |
30 | // They can only be grabbed here in the QGraphicsWidget (QChart). |
|
30 | // They can only be grabbed here in the QGraphicsWidget (QChart). | |
@@ -49,7 +49,7 bool Chart::gestureEvent(QGestureEvent* event) | |||||
49 | { |
|
49 | { | |
50 | if (QGesture *gesture = event->gesture(Qt::PanGesture)) { |
|
50 | if (QGesture *gesture = event->gesture(Qt::PanGesture)) { | |
51 | QPanGesture *pan = static_cast<QPanGesture *>(gesture); |
|
51 | QPanGesture *pan = static_cast<QPanGesture *>(gesture); | |
52 | QChart::scroll(pan->delta().x(),pan->delta().y()); |
|
52 | QChart::scroll(pan->delta().x(), pan->delta().y()); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | if (QGesture *gesture = event->gesture(Qt::PinchGesture)) { |
|
55 | if (QGesture *gesture = event->gesture(Qt::PinchGesture)) { |
@@ -61,7 +61,7 void ChartView::mouseMoveEvent(QMouseEvent *event) | |||||
61 |
|
61 | |||
62 | if (m_isScrolling) { |
|
62 | if (m_isScrolling) { | |
63 | QPointF delta = m_origin - event->pos(); |
|
63 | QPointF delta = m_origin - event->pos(); | |
64 | chart()->scroll(delta.x(),-delta.y()); |
|
64 | chart()->scroll(delta.x(), -delta.y()); | |
65 | m_origin = event->pos(); |
|
65 | m_origin = event->pos(); | |
66 | } |
|
66 | } | |
67 |
|
67 |
@@ -68,7 +68,7 int main(int argc, char *argv[]) | |||||
68 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
68 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
69 | axis->append(categories); |
|
69 | axis->append(categories); | |
70 | chart->createDefaultAxes(); |
|
70 | chart->createDefaultAxes(); | |
71 | chart->setAxisX(axis,series); |
|
71 | chart->setAxisX(axis, series); | |
72 | //![4] |
|
72 | //![4] | |
73 |
|
73 | |||
74 | //![5] |
|
74 | //![5] |
@@ -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 |
|
|
28 | m_currentSeries(0) | |
29 | { |
|
29 | { | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
@@ -44,7 +44,7 void DrilldownChart::changeSeries(DrilldownBarSeries *series) | |||||
44 | addSeries(series); |
|
44 | addSeries(series); | |
45 |
|
45 | |||
46 | createDefaultAxes(); |
|
46 | createDefaultAxes(); | |
47 | setAxisX(axis,series); |
|
47 | setAxisX(axis, series); | |
48 |
|
48 | |||
49 | setTitle(series->name()); |
|
49 | setTitle(series->name()); | |
50 | } |
|
50 | } | |
@@ -52,7 +52,7 void DrilldownChart::changeSeries(DrilldownBarSeries *series) | |||||
52 | void DrilldownChart::handleClicked(int index, QBarSet *barset) |
|
52 | void DrilldownChart::handleClicked(int index, QBarSet *barset) | |
53 | { |
|
53 | { | |
54 | Q_UNUSED(barset) |
|
54 | Q_UNUSED(barset) | |
55 |
DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> |
|
55 | DrilldownBarSeries* series = static_cast<DrilldownBarSeries*>(sender()); | |
56 | changeSeries(series->drilldownSeries(index)); |
|
56 | changeSeries(series->drilldownSeries(index)); | |
57 | } |
|
57 | } | |
58 |
|
58 |
@@ -55,14 +55,14 int main(int argc, char *argv[]) | |||||
55 | seasonSeries->setName("Crop by month - Season"); |
|
55 | seasonSeries->setName("Crop by month - Season"); | |
56 |
|
56 | |||
57 | // Each month in season series has drilldown series for weekly data |
|
57 | // Each month in season series has drilldown series for weekly data | |
58 | for (int month=0; month < months.count(); month++) { |
|
58 | for (int month = 0; month < months.count(); month++) { | |
59 |
|
59 | |||
60 | // Create drilldown series for every week |
|
60 | // Create drilldown series for every week | |
61 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); |
|
61 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); | |
62 | seasonSeries->mapDrilldownSeries(month, weeklySeries); |
|
62 | seasonSeries->mapDrilldownSeries(month, weeklySeries); | |
63 |
|
63 | |||
64 | // Drilling down from weekly data brings us back to season data. |
|
64 | // Drilling down from weekly data brings us back to season data. | |
65 | for (int week=0; week < weeks.count(); week++) { |
|
65 | for (int week = 0; week < weeks.count(); week++) { | |
66 | weeklySeries->mapDrilldownSeries(week, seasonSeries); |
|
66 | weeklySeries->mapDrilldownSeries(week, seasonSeries); | |
67 | weeklySeries->setName(QString("Crop by week - " + months.at(month))); |
|
67 | weeklySeries->setName(QString("Crop by week - " + months.at(month))); | |
68 | } |
|
68 | } | |
@@ -79,11 +79,10 int main(int argc, char *argv[]) | |||||
79 | // Fill monthly and weekly series with data |
|
79 | // Fill monthly and weekly series with data | |
80 | foreach (QString plant, plants) { |
|
80 | foreach (QString plant, plants) { | |
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(); |
@@ -61,8 +61,8 int main(int argc, char *argv[]) | |||||
61 | QBarCategoryAxis* axis = new QBarCategoryAxis(); |
|
61 | QBarCategoryAxis* axis = new QBarCategoryAxis(); | |
62 | axis->append(categories); |
|
62 | axis->append(categories); | |
63 | chart->createDefaultAxes(); |
|
63 | chart->createDefaultAxes(); | |
64 | chart->setAxisX(axis,series); |
|
64 | chart->setAxisX(axis, series); | |
65 | chart->axisY(series)->setRange(-52,52); |
|
65 | chart->axisY(series)->setRange(-52, 52); | |
66 | //![4] |
|
66 | //![4] | |
67 |
|
67 | |||
68 | //![5] |
|
68 | //![5] |
@@ -24,7 +24,7 | |||||
24 | #include <QGraphicsView> |
|
24 | #include <QGraphicsView> | |
25 |
|
25 | |||
26 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
26 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
27 | :QChart(parent, wFlags) |
|
27 | : QChart(parent, wFlags) | |
28 | { |
|
28 | { | |
29 | // Seems that QGraphicsView (QChartView) does not grab gestures. |
|
29 | // Seems that QGraphicsView (QChartView) does not grab gestures. | |
30 | // They can only be grabbed here in the QGraphicsWidget (QChart). |
|
30 | // They can only be grabbed here in the QGraphicsWidget (QChart). | |
@@ -49,7 +49,7 bool Chart::gestureEvent(QGestureEvent* event) | |||||
49 | { |
|
49 | { | |
50 | if (QGesture *gesture = event->gesture(Qt::PanGesture)) { |
|
50 | if (QGesture *gesture = event->gesture(Qt::PanGesture)) { | |
51 | QPanGesture *pan = static_cast<QPanGesture *>(gesture); |
|
51 | QPanGesture *pan = static_cast<QPanGesture *>(gesture); | |
52 | QChart::scroll(pan->delta().x(),pan->delta().y()); |
|
52 | QChart::scroll(pan->delta().x(), pan->delta().y()); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | if (QGesture *gesture = event->gesture(Qt::PinchGesture)) { |
|
55 | if (QGesture *gesture = event->gesture(Qt::PinchGesture)) { |
@@ -82,16 +82,16 void ChartView::keyPressEvent(QKeyEvent *event) | |||||
82 | break; |
|
82 | break; | |
83 | //![1] |
|
83 | //![1] | |
84 | case Qt::Key_Left: |
|
84 | case Qt::Key_Left: | |
85 | chart()->scroll(-10,0); |
|
85 | chart()->scroll(-10, 0); | |
86 | break; |
|
86 | break; | |
87 | case Qt::Key_Right: |
|
87 | case Qt::Key_Right: | |
88 | chart()->scroll(10,0); |
|
88 | chart()->scroll(10, 0); | |
89 | break; |
|
89 | break; | |
90 | case Qt::Key_Up: |
|
90 | case Qt::Key_Up: | |
91 | chart()->scroll(0,10); |
|
91 | chart()->scroll(0, 10); | |
92 | break; |
|
92 | break; | |
93 | case Qt::Key_Down: |
|
93 | case Qt::Key_Down: | |
94 | chart()->scroll(0,-10); |
|
94 | chart()->scroll(0, -10); | |
95 | break; |
|
95 | break; | |
96 | default: |
|
96 | default: | |
97 | QGraphicsView::keyPressEvent(event); |
|
97 | QGraphicsView::keyPressEvent(event); |
@@ -33,7 +33,7 int main(int argc, char *argv[]) | |||||
33 |
|
33 | |||
34 | //![1] |
|
34 | //![1] | |
35 | QLineSeries* series = new QLineSeries(); |
|
35 | QLineSeries* series = new QLineSeries(); | |
36 | for (int i=0; i < 500; i++) { |
|
36 | for (int i = 0; i < 500; i++) { | |
37 | QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100); |
|
37 | QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100); | |
38 | p.ry() += qrand() % 20; |
|
38 | p.ry() += qrand() % 20; | |
39 | *series << p; |
|
39 | *series << p; |
General Comments 0
You need to be logged in to leave comments.
Login now