@@ -58,10 +58,12 TableWidget::TableWidget(QWidget *parent) | |||||
58 | lineRadioButton = new QRadioButton("Line"); |
|
58 | lineRadioButton = new QRadioButton("Line"); | |
59 | splineRadioButton = new QRadioButton("Spline"); |
|
59 | splineRadioButton = new QRadioButton("Spline"); | |
60 | scatterRadioButton = new QRadioButton("Scatter"); |
|
60 | scatterRadioButton = new QRadioButton("Scatter"); | |
|
61 | pieRadioButton = new QRadioButton("Pie"); | |||
61 |
|
62 | |||
62 | connect(lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
63 | connect(lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
63 | connect(splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
64 | connect(splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
64 | connect(scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
65 | connect(scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
|
66 | connect(pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |||
65 | lineRadioButton->setChecked(true); |
|
67 | lineRadioButton->setChecked(true); | |
66 |
|
68 | |||
67 | // radio buttons layout |
|
69 | // radio buttons layout | |
@@ -69,6 +71,7 TableWidget::TableWidget(QWidget *parent) | |||||
69 | radioLayout->addWidget(lineRadioButton); |
|
71 | radioLayout->addWidget(lineRadioButton); | |
70 | radioLayout->addWidget(splineRadioButton); |
|
72 | radioLayout->addWidget(splineRadioButton); | |
71 | radioLayout->addWidget(scatterRadioButton); |
|
73 | radioLayout->addWidget(scatterRadioButton); | |
|
74 | radioLayout->addWidget(pieRadioButton); | |||
72 |
|
75 | |||
73 | // create main layout |
|
76 | // create main layout | |
74 | QGridLayout* mainLayout = new QGridLayout; |
|
77 | QGridLayout* mainLayout = new QGridLayout; | |
@@ -107,8 +110,17 void TableWidget::updateChartType() | |||||
107 | series = new QLineSeries; |
|
110 | series = new QLineSeries; | |
108 | else if (splineRadioButton->isChecked()) |
|
111 | else if (splineRadioButton->isChecked()) | |
109 | series = new QSplineSeries; |
|
112 | series = new QSplineSeries; | |
110 | else |
|
113 | else if (scatterRadioButton->isChecked()) | |
111 | series = new QScatterSeries; |
|
114 | series = new QScatterSeries; | |
|
115 | else if (pieRadioButton->isChecked()) | |||
|
116 | { | |||
|
117 | QPieSeries* pieSeries = new QPieSeries; | |||
|
118 | pieSeries->setModel(m_model); | |||
|
119 | pieSeries->setModelMapping(0,2, Qt::Vertical); | |||
|
120 | pieSeries->setLabelsVisible(true); | |||
|
121 | chartView->addSeries(pieSeries); | |||
|
122 | return; | |||
|
123 | } | |||
112 |
|
124 | |||
113 | series->setModel(m_model); |
|
125 | series->setModel(m_model); | |
114 | series->setModelMapping(0,1, Qt::Vertical); |
|
126 | series->setModelMapping(0,1, Qt::Vertical); |
@@ -35,6 +35,7 public: | |||||
35 | QRadioButton* lineRadioButton; |
|
35 | QRadioButton* lineRadioButton; | |
36 | QRadioButton* splineRadioButton; |
|
36 | QRadioButton* splineRadioButton; | |
37 | QRadioButton* scatterRadioButton; |
|
37 | QRadioButton* scatterRadioButton; | |
|
38 | QRadioButton* pieRadioButton; | |||
38 | }; |
|
39 | }; | |
39 |
|
40 | |||
40 | #endif // TABLEWIDGET_H |
|
41 | #endif // TABLEWIDGET_H |
@@ -265,7 +265,7 QList<QPieSlice*> QPieSeries::slices() const | |||||
265 | void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition) |
|
265 | void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition) | |
266 | { |
|
266 | { | |
267 | if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 || |
|
267 | if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 || | |
268 | relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0) |
|
268 | relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0) | |
269 | return; |
|
269 | return; | |
270 |
|
270 | |||
271 | if (m_pieRelativeHorPos != relativeHorizontalPosition || m_pieRelativeVerPos != relativeVerticalPosition) { |
|
271 | if (m_pieRelativeHorPos != relativeHorizontalPosition || m_pieRelativeVerPos != relativeVerticalPosition) { | |
@@ -531,6 +531,71 void QPieSeries::updateDerivativeData() | |||||
531 | } |
|
531 | } | |
532 | } |
|
532 | } | |
533 |
|
533 | |||
|
534 | bool QPieSeries::setModel(QAbstractItemModel* model) | |||
|
535 | { | |||
|
536 | // disconnect signals from old model | |||
|
537 | if(m_model) | |||
|
538 | { | |||
|
539 | disconnect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), 0, 0); | |||
|
540 | disconnect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), 0, 0); | |||
|
541 | disconnect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), 0, 0); | |||
|
542 | } | |||
|
543 | ||||
|
544 | // set new model if not NULL and connect necessary signals from it | |||
|
545 | if(model) | |||
|
546 | { | |||
|
547 | m_model = model; | |||
|
548 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |||
|
549 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |||
|
550 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |||
|
551 | } | |||
|
552 | } | |||
|
553 | ||||
|
554 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) | |||
|
555 | { | |||
|
556 | m_mapValues = modelValuesLine; | |||
|
557 | m_mapLabels = modelLabelsLine; | |||
|
558 | m_mapOrientation = orientation; | |||
|
559 | ||||
|
560 | if (m_model == NULL) | |||
|
561 | return; | |||
|
562 | ||||
|
563 | if (m_mapOrientation == Qt::Vertical) | |||
|
564 | for (int i = 0; i < m_model->rowCount(); i++) | |||
|
565 | add(m_model->data(m_model->index(i, m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, m_mapLabels), Qt::DisplayRole).toString()); | |||
|
566 | else | |||
|
567 | for (int i = 0; i < m_model->columnCount(); i++) | |||
|
568 | add(m_model->data(m_model->index(m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(m_mapLabels, i), Qt::DisplayRole).toString()); | |||
|
569 | ||||
|
570 | ||||
|
571 | } | |||
|
572 | ||||
|
573 | void QPieSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |||
|
574 | { | |||
|
575 | if (m_mapOrientation == Qt::Vertical) | |||
|
576 | // slices().at(topLeft.row())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble()); | |||
|
577 | if (topLeft.column() == m_mapValues) | |||
|
578 | slices().at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |||
|
579 | else if (topLeft.column() == m_mapLabels) | |||
|
580 | slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |||
|
581 | else | |||
|
582 | // slices().at(topLeft.column())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble()); | |||
|
583 | if (topLeft.column() == m_mapValues) | |||
|
584 | slices().at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |||
|
585 | else if (topLeft.column() == m_mapLabels) | |||
|
586 | slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |||
|
587 | } | |||
|
588 | ||||
|
589 | void QPieSeries::modelDataAdded(QModelIndex parent, int start, int end) | |||
|
590 | { | |||
|
591 | // | |||
|
592 | } | |||
|
593 | ||||
|
594 | void QPieSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |||
|
595 | { | |||
|
596 | remove(slices().at(start)); | |||
|
597 | } | |||
|
598 | ||||
534 | #include "moc_qpieseries.cpp" |
|
599 | #include "moc_qpieseries.cpp" | |
535 |
|
600 | |||
536 | QTCOMMERCIALCHART_END_NAMESPACE |
|
601 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -82,6 +82,10 public: | |||||
82 | QPieSlice* add(qreal value, QString name); |
|
82 | QPieSlice* add(qreal value, QString name); | |
83 | void setLabelsVisible(bool visible = true); |
|
83 | void setLabelsVisible(bool visible = true); | |
84 |
|
84 | |||
|
85 | // data from model | |||
|
86 | bool setModel(QAbstractItemModel* model); | |||
|
87 | void setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation = Qt::Vertical); | |||
|
88 | ||||
85 | // TODO: find slices? |
|
89 | // TODO: find slices? | |
86 | // QList<QPieSlice*> findByValue(qreal value); |
|
90 | // QList<QPieSlice*> findByValue(qreal value); | |
87 | // ... |
|
91 | // ... | |
@@ -105,6 +109,11 private Q_SLOTS: // TODO: should be private and not visible in the interface at | |||||
105 | void sliceHoverEnter(); |
|
109 | void sliceHoverEnter(); | |
106 | void sliceHoverLeave(); |
|
110 | void sliceHoverLeave(); | |
107 |
|
111 | |||
|
112 | // slots for updating pie when data in model changes | |||
|
113 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |||
|
114 | void modelDataAdded(QModelIndex parent, int start, int end); | |||
|
115 | void modelDataRemoved(QModelIndex parent, int start, int end); | |||
|
116 | ||||
108 | private: |
|
117 | private: | |
109 | void updateDerivativeData(); |
|
118 | void updateDerivativeData(); | |
110 |
|
119 | |||
@@ -122,6 +131,11 private: | |||||
122 | qreal m_pieStartAngle; |
|
131 | qreal m_pieStartAngle; | |
123 | qreal m_pieEndAngle; |
|
132 | qreal m_pieEndAngle; | |
124 | qreal m_total; |
|
133 | qreal m_total; | |
|
134 | ||||
|
135 | // model map | |||
|
136 | int m_mapValues; | |||
|
137 | int m_mapLabels; | |||
|
138 | Qt::Orientation m_mapOrientation; | |||
125 | }; |
|
139 | }; | |
126 |
|
140 | |||
127 | QTCOMMERCIALCHART_END_NAMESPACE |
|
141 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -32,7 +32,7 public: | |||||
32 | };*/ |
|
32 | };*/ | |
33 |
|
33 | |||
34 | protected: |
|
34 | protected: | |
35 | QSeries(QObject *parent = 0) : QObject(parent) {} |
|
35 | QSeries(QObject *parent = 0) : QObject(parent) {m_model = NULL;} | |
36 |
|
36 | |||
37 | public: |
|
37 | public: | |
38 | virtual ~QSeries() {} |
|
38 | virtual ~QSeries() {} | |
@@ -44,6 +44,9 public: | |||||
44 | void setTitle(QString title) { m_title = title; } |
|
44 | void setTitle(QString title) { m_title = title; } | |
45 | QString title() { return m_title; } |
|
45 | QString title() { return m_title; } | |
46 |
|
46 | |||
|
47 | protected: | |||
|
48 | QAbstractItemModel* m_model; | |||
|
49 | ||||
47 | private: |
|
50 | private: | |
48 | QString m_title; |
|
51 | QString m_title; | |
49 | }; |
|
52 | }; |
@@ -50,7 +50,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
50 | */ |
|
50 | */ | |
51 | QXYSeries::QXYSeries(QObject* parent):QSeries(parent) |
|
51 | QXYSeries::QXYSeries(QObject* parent):QSeries(parent) | |
52 | { |
|
52 | { | |
53 | m_model = NULL; |
|
|||
54 | m_mapX = -1; |
|
53 | m_mapX = -1; | |
55 | m_mapY = -1; |
|
54 | m_mapY = -1; | |
56 | m_mapOrientation = Qt::Vertical; |
|
55 | m_mapOrientation = Qt::Vertical; | |
@@ -268,7 +267,10 QXYSeries& QXYSeries::operator<< (const QList<QPointF> points) | |||||
268 |
|
267 | |||
269 | void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
268 | void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
270 | { |
|
269 | { | |
271 | emit pointReplaced(topLeft.row()); |
|
270 | if (m_mapOrientation == Qt::Vertical) | |
|
271 | emit pointReplaced(topLeft.row()); | |||
|
272 | else | |||
|
273 | emit pointReplaced(topLeft.column()); | |||
272 | } |
|
274 | } | |
273 |
|
275 | |||
274 | void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) |
|
276 | void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) |
@@ -64,7 +64,7 protected: | |||||
64 | QPen m_pen; |
|
64 | QPen m_pen; | |
65 | QBrush m_brush; |
|
65 | QBrush m_brush; | |
66 |
|
66 | |||
67 | QAbstractItemModel* m_model; |
|
67 | // QAbstractItemModel* m_model; | |
68 | int m_mapX; |
|
68 | int m_mapX; | |
69 | Qt::Orientation m_mapOrientation; |
|
69 | Qt::Orientation m_mapOrientation; | |
70 | int m_mapY; |
|
70 | int m_mapY; |
General Comments 0
You need to be logged in to leave comments.
Login now