##// END OF EJS Templates
Added insert pie slice function to QPieSeries
Marek Rosa -
r604:e52d5440d618
parent child
Show More
@@ -120,8 +120,8 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & pare
120 beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1);
120 beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1);
121 for (int i = row; i < row + count; i++)
121 for (int i = row; i < row + count; i++)
122 {
122 {
123 m_points.insert(row, QPointF());
123 m_points.insert(row, QPointF(10,20));
124 m_labels.insert(row,(""));
124 m_labels.insert(row,("a"));
125 }
125 }
126 endInsertRows();
126 endInsertRows();
127 return true;
127 return true;
@@ -195,6 +195,22 QPieSlice* QPieSeries::add(qreal value, QString name)
195 return slice;
195 return slice;
196 }
196 }
197
197
198 void QPieSeries::insert(int i, QPieSlice* slice)
199 {
200 Q_ASSERT(i <= m_slices.count());
201 slice->setParent(this);
202 m_slices.insert(i, slice);
203
204 updateDerivativeData();
205
206 connect(slice, SIGNAL(changed()), this, SLOT(sliceChanged()));
207 connect(slice, SIGNAL(clicked()), this, SLOT(sliceClicked()));
208 connect(slice, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
209 connect(slice, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
210
211 emit changed();
212 }
213
198 /*!
214 /*!
199 Removes a single \a slice from the series and deletes the slice.
215 Removes a single \a slice from the series and deletes the slice.
200
216
@@ -573,22 +589,39 void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::O
573 void QPieSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
589 void QPieSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
574 {
590 {
575 if (m_mapOrientation == Qt::Vertical)
591 if (m_mapOrientation == Qt::Vertical)
592 {
576 // slices().at(topLeft.row())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
593 // slices().at(topLeft.row())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
577 if (topLeft.column() == m_mapValues)
594 if (topLeft.column() == m_mapValues)
578 slices().at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
595 slices().at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
579 else if (topLeft.column() == m_mapLabels)
596 else if (topLeft.column() == m_mapLabels)
580 slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
597 slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
581 else
598 }
582 // slices().at(topLeft.column())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
599 else
583 if (topLeft.column() == m_mapValues)
600 {
584 slices().at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
601 // slices().at(topLeft.column())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
585 else if (topLeft.column() == m_mapLabels)
602 if (topLeft.column() == m_mapValues)
586 slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
603 slices().at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
604 else if (topLeft.column() == m_mapLabels)
605 slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
606 }
587 }
607 }
588
608
589 void QPieSeries::modelDataAdded(QModelIndex parent, int start, int end)
609 void QPieSeries::modelDataAdded(QModelIndex parent, int start, int end)
590 {
610 {
591 //
611 QPieSlice* newSlice = new QPieSlice;
612 newSlice->setLabelVisible(true);
613 if (m_mapOrientation == Qt::Vertical)
614 {
615 newSlice->setValue(m_model->data(m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble());
616 newSlice->setLabel(m_model->data(m_model->index(start, m_mapLabels), Qt::DisplayRole).toString());
617 }
618 else
619 {
620 newSlice->setValue(m_model->data(m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble());
621 newSlice->setLabel(m_model->data(m_model->index(m_mapLabels, start), Qt::DisplayRole).toString());
622 }
623
624 insert(start, newSlice);
592 }
625 }
593
626
594 void QPieSeries::modelDataRemoved(QModelIndex parent, int start, int end)
627 void QPieSeries::modelDataRemoved(QModelIndex parent, int start, int end)
@@ -55,6 +55,7 public:
55 // slice setters
55 // slice setters
56 void add(QPieSlice* slice);
56 void add(QPieSlice* slice);
57 void add(QList<QPieSlice*> slices);
57 void add(QList<QPieSlice*> slices);
58 void insert(int i, QPieSlice* slice);
58 void replace(QList<QPieSlice*> slices);
59 void replace(QList<QPieSlice*> slices);
59 void remove(QPieSlice* slice);
60 void remove(QPieSlice* slice);
60 void clear();
61 void clear();
General Comments 0
You need to be logged in to leave comments. Login now