@@ -54,6 +54,7 MainWidget::MainWidget(QWidget *parent) : | |||||
54 | m_chart = new QChart(); |
|
54 | m_chart = new QChart(); | |
55 | m_chartView = new QChartView(m_chart, this); |
|
55 | m_chartView = new QChartView(m_chart, this); | |
56 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
56 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); | |
|
57 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |||
57 | //![1] |
|
58 | //![1] | |
58 |
|
59 | |||
59 | // Create custom scene and view, where detached legend will be drawn |
|
60 | // Create custom scene and view, where detached legend will be drawn | |
@@ -142,8 +143,9 void MainWidget::addBarset() | |||||
142 |
|
143 | |||
143 | void MainWidget::removeBarset() |
|
144 | void MainWidget::removeBarset() | |
144 | { |
|
145 | { | |
145 | QList<QBarSet*> sets = m_series->barSets(); |
|
146 | m_series->clear(); | |
146 | if (sets.count() > 0) { |
|
147 | // QList<QBarSet*> sets = m_series->barSets(); | |
147 | m_series->remove(sets.at(sets.count()-1)); |
|
148 | // if (sets.count() > 0) { | |
148 | } |
|
149 | // m_series->remove(sets.at(sets.count()-1)); | |
|
150 | // } | |||
149 | } |
|
151 | } |
@@ -101,9 +101,12 void ChartAnimator::updateLayout(BarChartItem *item, const QVector<QRectF> &oldL | |||||
101 | { |
|
101 | { | |
102 | BarAnimation *animation = static_cast<BarAnimation *>(m_animations.value(item)); |
|
102 | BarAnimation *animation = static_cast<BarAnimation *>(m_animations.value(item)); | |
103 | Q_ASSERT(animation); |
|
103 | Q_ASSERT(animation); | |
|
104 | animation->stop(); | |||
104 | animation->setDuration(ChartAnimationDuration); |
|
105 | animation->setDuration(ChartAnimationDuration); | |
|
106 | animation->setStartValue(qVariantFromValue(oldLayout)); | |||
105 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); |
|
107 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | |
106 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); |
|
108 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); | |
|
109 | animation->setEndValue(qVariantFromValue(newLayout)); | |||
107 | QTimer::singleShot(0, animation, SLOT(start())); |
|
110 | QTimer::singleShot(0, animation, SLOT(start())); | |
108 | } |
|
111 | } | |
109 |
|
112 |
@@ -95,6 +95,7 void QBarModelMapper::setModel(QAbstractItemModel *model) | |||||
95 | d->initializeBarFromModel(); |
|
95 | d->initializeBarFromModel(); | |
96 | // connect signals from the model |
|
96 | // connect signals from the model | |
97 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
97 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
|
98 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); | |||
98 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
99 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
99 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
100 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
100 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
101 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
@@ -313,6 +314,27 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex botto | |||||
313 | blockSeriesSignals(false); |
|
314 | blockSeriesSignals(false); | |
314 | } |
|
315 | } | |
315 |
|
316 | |||
|
317 | void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) | |||
|
318 | { | |||
|
319 | if (m_model == 0 || m_series == 0) | |||
|
320 | return; | |||
|
321 | ||||
|
322 | if (m_modelSignalsBlock) | |||
|
323 | return; | |||
|
324 | ||||
|
325 | blockSeriesSignals(); | |||
|
326 | if (orientation != m_orientation) { | |||
|
327 | for (int section = first; section <= last; section++) { | |||
|
328 | if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) { | |||
|
329 | QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection); | |||
|
330 | if (bar) | |||
|
331 | bar->setName(m_model->headerData(section, orientation).toString()); | |||
|
332 | } | |||
|
333 | } | |||
|
334 | } | |||
|
335 | blockSeriesSignals(false); | |||
|
336 | } | |||
|
337 | ||||
316 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
338 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
317 | { |
|
339 | { | |
318 | Q_UNUSED(parent); |
|
340 | Q_UNUSED(parent); | |
@@ -408,7 +430,7 void QBarModelMapperPrivate::initializeBarFromModel() | |||||
408 | QModelIndex barIndex = barModelIndex(i, posInBar); |
|
430 | QModelIndex barIndex = barModelIndex(i, posInBar); | |
409 | // check if there is such model index |
|
431 | // check if there is such model index | |
410 | if (barIndex.isValid()) { |
|
432 | if (barIndex.isValid()) { | |
411 | QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString()); |
|
433 | QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString()); | |
412 | while (barIndex.isValid()) { |
|
434 | while (barIndex.isValid()) { | |
413 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); |
|
435 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); | |
414 | posInBar++; |
|
436 | posInBar++; |
@@ -49,6 +49,7 public: | |||||
49 | public Q_SLOTS: |
|
49 | public Q_SLOTS: | |
50 | // for the model |
|
50 | // for the model | |
51 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
51 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
|
52 | void modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last); | |||
52 | void modelRowsAdded(QModelIndex parent, int start, int end); |
|
53 | void modelRowsAdded(QModelIndex parent, int start, int end); | |
53 | void modelRowsRemoved(QModelIndex parent, int start, int end); |
|
54 | void modelRowsRemoved(QModelIndex parent, int start, int end); | |
54 | void modelColumnsAdded(QModelIndex parent, int start, int end); |
|
55 | void modelColumnsAdded(QModelIndex parent, int start, int end); |
General Comments 0
You need to be logged in to leave comments.
Login now