diff --git a/qmlplugin/declarativebarseries.cpp b/qmlplugin/declarativebarseries.cpp index e76e49e..540d414 100644 --- a/qmlplugin/declarativebarseries.cpp +++ b/qmlplugin/declarativebarseries.cpp @@ -65,18 +65,18 @@ void DeclarativeBarSeries::componentComplete() } } -void DeclarativeBarSeries::setBarCategories(QStringList categories) +void DeclarativeBarSeries::setBarCategories(QStringList /*categories*/) { - m_categories = categories; - if (m_series) { - // Replace categories of the QBarSeries with the new categories - for (int i(0); i < m_categories.count(); i++) { - if (m_series->categories().at(i) != m_categories.at(i)) - m_series->insertCategory(m_series->categoryCount(), m_categories.at(i)); - } - while (m_series->categoryCount() > m_categories.count()) - m_series->removeCategory(m_series->categoryCount() - 1); - } +// m_categories = categories; +// if (m_series) { +// // Replace categories of the QBarSeries with the new categories +// for (int i(0); i < m_categories.count(); i++) { +// if (m_series->categories().at(i) != m_categories.at(i)) +// m_series->insertCategory(m_series->categoryCount(), m_categories.at(i)); +// } +// while (m_series->categoryCount() > m_categories.count()) +// m_series->removeCategory(m_series->categoryCount() - 1); +// } } QStringList DeclarativeBarSeries::barCategories() diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index c96221f..1e9361a 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -170,27 +170,6 @@ void QBarSeries::insertBarSet(int i, QBarSet *set) } /*! - Inserts new \a category on the \a i position. - The category that is currently at this postion is moved to postion i + 1 - \sa removeCategory() -*/ -void QBarSeries::insertCategory(int i, QString category) -{ - Q_D(QBarSeries); - d->m_internalModel->insertCategory(i, category); -} - -/*! - Removes the category specified by \a i - \sa insertCategory() -*/ -void QBarSeries::removeCategory(int i) -{ - Q_D(QBarSeries); - d->m_internalModel->removeCategory(i); -} - -/*! Returns number of sets in series. */ int QBarSeries::barsetCount() const @@ -251,7 +230,7 @@ QBarCategories QBarSeries::categories() const QBarCategories categories; int count = d->m_internalModel->categoryCount(); for (int i=1; i <= count; i++) { - categories.insert(i, d->m_internalModel->categoryName(i - 1)); + categories.insert(i, d->m_internalModel->categoryName(i - 1)); } return categories; @@ -276,8 +255,6 @@ QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : m_mapCategories(-1), m_mapBarBottom(-1), m_mapBarTop(-1), - m_mapFirst(0), - m_mapCount(0), m_mapOrientation(Qt::Vertical) { } @@ -341,8 +318,6 @@ bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) m_mapCategories = -1; m_mapBarBottom = -1; m_mapBarTop = -1; - m_mapFirst = 0; - m_mapCount = 0; m_mapOrientation = Qt::Vertical; } @@ -369,51 +344,35 @@ void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int t m_mapCategories = categories; m_mapBarBottom = bottomBoundry; m_mapBarTop = topBoundry; -// m_mapFirst = 1; m_mapOrientation = orientation; // connect the signals - if (m_mapOrientation == Qt::Vertical) { - m_mapCount = m_model->rowCount() - m_mapFirst; - connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), - this, SLOT(modelUpdated(QModelIndex,QModelIndex))); - connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), - this, SLOT(modelDataAdded(QModelIndex,int,int))); - connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), - this, SLOT(modelDataRemoved(QModelIndex,int,int))); - } else { - m_mapCount = m_model->columnCount() - m_mapFirst; - connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), - this, SLOT(modelUpdated(QModelIndex,QModelIndex))); - connect(m_model,SIGNAL(columnsInserted(QModelIndex,int,int)), - this, SLOT(modelDataAdded(QModelIndex,int,int))); - connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), - this, SLOT(modelDataRemoved(QModelIndex,int,int))); - } + connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), + this, SLOT(modelUpdated(QModelIndex,QModelIndex))); // create the initial bars delete m_internalModel; if (m_mapOrientation == Qt::Vertical) { QStringList categories; - for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) + for (int k = 0; k < m_model->rowCount(); k++) categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); m_internalModel = new BarChartModel(categories, this); for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); - for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) + for(int m = 0; m < m_model->rowCount(); m++) *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); q->appendBarSet(barSet); } } else { QStringList categories; - for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) + for (int k = 0; k < m_model->columnCount(); k++) categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); m_internalModel = new BarChartModel(categories, this); for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); - for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) + for(int m = 0; m < m_model->columnCount(); m++) *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); q->appendBarSet(barSet); } @@ -427,47 +386,15 @@ void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRigh if (m_mapOrientation == Qt::Vertical) { // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries - if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) - barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); + if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) + barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); } else { // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries - if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) - barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); - } -} - -void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) -{ - Q_Q(QBarSeries); - - if (m_mapOrientation == Qt::Vertical) { - q->insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); - for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { - barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); - } - } else { - q->insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); - for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { - barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); - } - } - emit restructuredBars(); -} - -void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) -{ - Q_Q(QBarSeries); - Q_UNUSED(parent) - Q_UNUSED(end) - - q->removeCategory(start - m_mapFirst); - for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) - { - barsetAt(i)->removeValue(start - m_mapFirst); + if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) + barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); } - emit restructuredBars(); } void QBarSeriesPrivate::barsetChanged() diff --git a/src/barchart/qbarseries.h b/src/barchart/qbarseries.h index 1676ccf..b02239d 100644 --- a/src/barchart/qbarseries.h +++ b/src/barchart/qbarseries.h @@ -50,8 +50,6 @@ public: void appendBarSets(QList sets); void removeBarSets(QList sets); void insertBarSet(int i, QBarSet *set); - void insertCategory(int i, QString category); - void removeCategory(int i); int barsetCount() const; int categoryCount() const; QList barSets() const; diff --git a/src/barchart/qbarseries_p.h b/src/barchart/qbarseries_p.h index 7254338..5eef36d 100644 --- a/src/barchart/qbarseries_p.h +++ b/src/barchart/qbarseries_p.h @@ -44,8 +44,6 @@ Q_SIGNALS: private Q_SLOTS: // slots for updating bars when data in model changes void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); - void modelDataAdded(QModelIndex parent, int start, int end); - void modelDataRemoved(QModelIndex parent, int start, int end); void barsetChanged(); protected: @@ -54,8 +52,6 @@ protected: int m_mapCategories; int m_mapBarBottom; int m_mapBarTop; - int m_mapFirst; - int m_mapCount; Qt::Orientation m_mapOrientation; private: Q_DECLARE_PUBLIC(QBarSeries) diff --git a/src/splinechart/qsplineseries.cpp b/src/splinechart/qsplineseries.cpp index 9449288..929d243 100644 --- a/src/splinechart/qsplineseries.cpp +++ b/src/splinechart/qsplineseries.cpp @@ -66,13 +66,6 @@ QPointF QSplineSeries::controlPoint(int index) const return d->m_controlPoints[index]; } -void QSplineSeries::setModelMappingRange(int first, int count) -{ - Q_D(QSplineSeries); - QLineSeries::setModelMappingRange(first, count); - d->calculateControlPoints(); -} - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q) @@ -186,30 +179,6 @@ void QSplineSeriesPrivate::updateControlPoints() } } -/*//! - \fn bool QSplineSeries::setModel(QAbstractItemModel *model) - Sets the \a model to be used as a data source - \sa setModelMapping(), setModelMappingRange() - */ -//bool QSplineSeries::setModel(QAbstractItemModel* model) -//{ -// QXYSeries::setModel(model); -//// calculateControlPoints(); -// return true; -//} - -/*//! - \fn bool QSplineSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) - Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used - as a data source for y coordinate. The \a orientation parameter specifies whether the data - is in columns or in rows. - */ -//void QSplineSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) -//{ -// QLineSeries::setModelMapping(modelX, modelY, orientation); -//// calculateControlPoints(); -//} - /*! \fn bool QSplineSeries::setModelMappingRange(int first, int count) Allows limiting the model mapping. diff --git a/src/splinechart/qsplineseries.h b/src/splinechart/qsplineseries.h index 22d54f1..ede2806 100644 --- a/src/splinechart/qsplineseries.h +++ b/src/splinechart/qsplineseries.h @@ -40,7 +40,6 @@ public: QAbstractSeries::QSeriesType type() const; QPointF controlPoint(int index) const; - void setModelMappingRange(int first, int count); private: Q_DECLARE_PRIVATE(QSplineSeries); diff --git a/src/xychart/qxyseries.cpp b/src/xychart/qxyseries.cpp index 60a9f7c..6d89792 100644 --- a/src/xychart/qxyseries.cpp +++ b/src/xychart/qxyseries.cpp @@ -76,19 +76,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! - \fn int QXYSeries::mapFirst() const - Returns the index of the model's item that is used as a first one for the series. - \sa mapCount() -*/ - -/*! - \fn int QXYSeries::mapCount() const - Returns the number of the items that are taken from the model. - If -1 it means all the items of the model following the first one are used. - \sa mapFirst() -*/ - -/*! \internal Constructs empty series object which is a child of \a parent. @@ -220,10 +207,10 @@ qreal QXYSeries::x(int pos) const if (d->m_model) { if (d->m_mapOrientation == Qt::Vertical) // consecutive data is read from model's column - return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapX), Qt::DisplayRole).toDouble(); + return d->m_model->data(d->m_model->index(pos, d->m_mapX), Qt::DisplayRole).toDouble(); else // consecutive data is read from model's row - return d->m_model->data(d->m_model->index(d->m_mapX, pos + d->m_mapFirst), Qt::DisplayRole).toDouble(); + return d->m_model->data(d->m_model->index(d->m_mapX, pos), Qt::DisplayRole).toDouble(); } else { // model is not specified, return the data from series' internal data store return d->m_x.at(pos); @@ -239,10 +226,10 @@ qreal QXYSeries::y(int pos) const if (d->m_model) { if (d->m_mapOrientation == Qt::Vertical) // consecutive data is read from model's column - return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapY), Qt::DisplayRole).toDouble(); + return d->m_model->data(d->m_model->index(pos, d->m_mapY), Qt::DisplayRole).toDouble(); else // consecutive data is read from model's row - return d->m_model->data(d->m_model->index(d->m_mapY, pos + d->m_mapFirst), Qt::DisplayRole).toDouble(); + return d->m_model->data(d->m_model->index(d->m_mapY, pos), Qt::DisplayRole).toDouble(); } else { // model is not specified, return the data from series' internal data store return d->m_y.at(pos); @@ -260,19 +247,11 @@ int QXYSeries::count() const if (d->m_model) { if (d->m_mapOrientation == Qt::Vertical) { - // data is in a column. Return the number of mapped items if the model's column have enough items - // or the number of items that can be mapped - if (d->m_mapLimited) - return qMin(d->m_mapCount, qMax(d->m_model->rowCount() - d->m_mapFirst, 0)); - else - return qMax(d->m_model->rowCount() - d->m_mapFirst, 0); + // data is in a column. Return the number of mapped items + return d->m_model->rowCount(); } else { - // data is in a row. Return the number of mapped items if the model's row have enough items - // or the number of items that can be mapped - if (d->m_mapLimited) - return qMin(d->m_mapCount, qMax(d->m_model->columnCount() - d->m_mapFirst, 0)); - else - return qMax(d->m_model->columnCount() - d->m_mapFirst, 0); + // data is in a row. Return the number of mapped items + return d->m_model->columnCount(); } } @@ -386,145 +365,11 @@ void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) Q_UNUSED(bottomRight) Q_D(QXYSeries); if (d->m_mapOrientation == Qt::Vertical) { - if (topLeft.row() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.row() < d->m_mapFirst + d->m_mapCount)) - emit d->pointReplaced(topLeft.row() - d->m_mapFirst); - } else { - if (topLeft.column() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.column() < d->m_mapFirst + d->m_mapCount)) - emit d->pointReplaced(topLeft.column() - d->m_mapFirst); - } -} - -/*! - \internal - */ -void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end) -{ - Q_UNUSED(parent) - // Q_UNUSED(end) - Q_D(QXYSeries); - if (d->m_mapLimited) { - if (start >= d->m_mapFirst + d->m_mapCount) { - // the added data is below mapped area - // therefore it has no relevance - return; - } else { - // the added data is in the mapped area or before it and update is needed - - // check how many mapped items there is currently (before new items are added) - // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem - // internal storage before new ones can be added - - int itemsToRemove = qMin(count() - qMax(start - d->m_mapFirst, 0), end - start + 1); - if (d->m_mapCount == count()) { - for (int i = 0; i < itemsToRemove; i++) - emit d->pointRemoved(qMin(end, count()) - i); - } - } - } else { - // map is not limited (it includes all the items starting from m_mapFirst till the end of model) - // nothing to do - // emit pointAdded(qMax(start - m_mapFirst, 0)); - } -} - -/*! - \internal - */ -void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) -{ - Q_UNUSED(parent) - // Q_UNUSED(end) - Q_D(QXYSeries); - if (d->m_mapLimited) { - if (start >= d->m_mapFirst + d->m_mapCount) { - // the added data is below mapped area - // therefore it has no relevance - return; - } else { - // the added data is in the mapped area or before it - // update needed - if (count() > 0) { - int toBeAdded = qMin(d->m_mapCount - (start - d->m_mapFirst), end - start + 1); - for (int i = 0; i < toBeAdded; i++) - if (start + i >= d->m_mapFirst) - emit d->pointAdded(start + i); - } - } - } else { - // map is not limited (it included all the items starting from m_mapFirst till the end of model) - for (int i = 0; i < end - start + 1; i++) - emit d->pointAdded(start + i); - } -} - -/*! - \internal - */ -void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end) -{ - Q_UNUSED(parent) - // Q_UNUSED(end) - Q_D(QXYSeries); - if (d->m_mapLimited) { - if (start >= d->m_mapFirst + d->m_mapCount) { - // the removed data is below mapped area - // therefore it has no relevance - return; - } else { - // the removed data is in the mapped area or before it - // update needed - - // check how many items need to be removed from the xychartitem storage - // the number equals the number of items that are removed and that lay before - // or in the mapped area. Items that lay beyond the map do not count - // the max is the current number of items in storage (count()) - int itemsToRemove = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1); - for (int i = 0; i < itemsToRemove; i++) - emit d->pointRemoved(start); - } - } else { - // map is not limited (it included all the items starting from m_mapFirst till the end of model) - for (int i = 0; i < end - start + 1; i++) - emit d->pointRemoved(start); - } -} - -/*! - \internal - */ -void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) -{ - - Q_UNUSED(parent) - Q_UNUSED(end) - Q_D(QXYSeries); - // how many items there were before data was removed - // int oldCount = count() - 1; - - if (d->m_mapLimited) { - if (start >= d->m_mapFirst + d->m_mapCount) { - // the removed data is below mapped area - // therefore it has no relevance - return; - } else { - // if the current items count in the whole model is bigger than the index of the last item - // that was removed than it means there are some extra items available - - int removedItemsCount = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1); - int extraItemsAvailable = 0; - if (d->m_mapOrientation == Qt::Vertical) { - extraItemsAvailable = qMax(d->m_model->rowCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0); - } else { - extraItemsAvailable = qMax(d->m_model->columnCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0); - } - - // if there are excess items available (below the mapped area) use them to repopulate mapped area - int toBeAdded = qMin(extraItemsAvailable, removedItemsCount); - for (int k = 0; k < toBeAdded; k++) - emit d->pointAdded(d->m_mapFirst + d->m_mapCount - removedItemsCount + k); - } + if (topLeft.column() == d->m_mapX || topLeft.column() == d->m_mapY) + emit d->pointReplaced(topLeft.row()); } else { - // data was removed from XYSeries interal storage. Nothing more to do + if (topLeft.row() == d->m_mapX || topLeft.row() == d->m_mapY) + emit d->pointReplaced(topLeft.column()); } } @@ -541,9 +386,6 @@ bool QXYSeries::setModel(QAbstractItemModel *model) QObject::disconnect(d->m_model, 0, this, 0); d->m_mapX = -1; d->m_mapY = -1; - d->m_mapFirst = 0; - d->m_mapCount = 0; - d->m_mapLimited = false; d->m_mapOrientation = Qt::Vertical; } @@ -571,63 +413,16 @@ void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientat return; d->m_mapX = modelX; d->m_mapY = modelY; - d->m_mapFirst = 0; d->m_mapOrientation = orientation; - if (d->m_mapOrientation == Qt::Vertical) { - connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); - connect(d->m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); - connect(d->m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); - connect(d->m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); - connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); - } else { - connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); - connect(d->m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); - connect(d->m_model,SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); - connect(d->m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); - connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); - } -} - -/*! - \fn bool QXYSeries::setModelMappingRange(int first, int count) - Allows limiting the model mapping. - Parameter \a first specifies which element of the model should be used as a first one of the series. - Parameter \a count specifies how many elements should be mapped. If count is not specified (defaults to -1) - then all the items following \a first item in a model are used. - \sa setModel(), setModelMapping() - */ -void QXYSeries::setModelMappingRange(int first, int count) -{ - Q_D(QXYSeries); - d->m_mapFirst = first; - if (count == 0) { - d->m_mapLimited = false; - } else { - d->m_mapCount = count; - d->m_mapLimited = true; - } -} - -int QXYSeries::mapFirst() const -{ - Q_D(const QXYSeries); - return d->m_mapFirst; -} - -int QXYSeries::mapCount() const -{ - Q_D(const QXYSeries); - return d->m_mapCount; + connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : QAbstractSeriesPrivate(q), m_mapX(-1), m_mapY(-1), - m_mapFirst(0), - m_mapCount(0), - m_mapLimited(false), m_mapOrientation( Qt::Vertical), m_pointsVisible(false) { diff --git a/src/xychart/qxyseries.h b/src/xychart/qxyseries.h index 3312d08..e0a8500 100644 --- a/src/xychart/qxyseries.h +++ b/src/xychart/qxyseries.h @@ -68,18 +68,10 @@ public: bool pointsVisible() const; bool setModel(QAbstractItemModel *model); - virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); - virtual void setModelMappingRange(int first, int count = 0); - int mapFirst() const; - int mapCount() const; private Q_SLOTS: void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); - void modelDataAboutToBeAdded(QModelIndex parent, int start, int end); - void modelDataAdded(QModelIndex parent, int start, int end); - void modelDataAboutToBeRemoved(QModelIndex parent, int start, int end); - void modelDataRemoved(QModelIndex parent, int start, int end); Q_SIGNALS: void clicked(const QPointF &point); diff --git a/src/xychart/qxyseries_p.h b/src/xychart/qxyseries_p.h index 734d053..18fc64b 100644 --- a/src/xychart/qxyseries_p.h +++ b/src/xychart/qxyseries_p.h @@ -61,11 +61,7 @@ protected: int m_mapX; int m_mapY; - int m_mapFirst; - int m_mapCount; - bool m_mapLimited; Qt::Orientation m_mapOrientation; - int tempItemsRemoved; bool m_pointsVisible; private: diff --git a/src/xychart/xychartitem.cpp b/src/xychart/xychartitem.cpp index 291c4e2..fb88149 100644 --- a/src/xychart/xychartitem.cpp +++ b/src/xychart/xychartitem.cpp @@ -108,44 +108,20 @@ void XYChartItem::handlePointAdded(int index) { QVector points = m_points; QPointF point; - if (m_series->model()) { - point = calculateGeometryPoint(index - m_series->mapFirst()); - if (index < m_series->mapFirst()) { - points.insert(0, point); - updateLayout(m_points, points, 0); - } - else { - points.insert(index - m_series->mapFirst(), point); - updateLayout(m_points, points, index - m_series->mapFirst()); - } - } - else { - // this checks do not work correctly if model is set - Q_ASSERT(indexcount()); - Q_ASSERT(index>=0); - point = calculateGeometryPoint(index); - points.insert(index, point); - updateLayout(m_points, points, index); - } + Q_ASSERT(indexcount()); + Q_ASSERT(index>=0); + point = calculateGeometryPoint(index); + points.insert(index, point); + updateLayout(m_points, points, index); update(); } void XYChartItem::handlePointRemoved(int index) { QVector points = m_points; - if (m_series->model()) { - if (index < m_series->mapFirst()) - points.remove(0); - else - points.remove(index - m_series->mapFirst()); - updateLayout(m_points, points, index - m_series->mapFirst()); - } - else { - // this checks do not work correctly if model is set - Q_ASSERT(indexcount() + 1); - Q_ASSERT(index>=0); - points.remove(index); - updateLayout(m_points, points, index); - } + Q_ASSERT(indexcount() + 1); + Q_ASSERT(index>=0); + points.remove(index); + updateLayout(m_points, points, index); update(); } diff --git a/test/tablemodelchart/tablewidget.cpp b/test/tablemodelchart/tablewidget.cpp index da5bd76..70501c0 100644 --- a/test/tablemodelchart/tablewidget.cpp +++ b/test/tablemodelchart/tablewidget.cpp @@ -166,7 +166,7 @@ void TableWidget::updateChartType(bool toggle) m_series = new QLineSeries; m_series->setModel(m_model); m_series->setModelMapping(0,1, Qt::Vertical); - m_series->setModelMappingRange(1, 4); +// m_series->setModelMappingRange(1, 4); m_chart->addSeries(m_series); seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); @@ -183,7 +183,7 @@ void TableWidget::updateChartType(bool toggle) m_series = new QLineSeries; m_series->setModel(m_model); m_series->setModelMapping(4,5, Qt::Vertical); - m_series->setModelMappingRange(2, 0); +// m_series->setModelMappingRange(2, 0); m_chart->addSeries(m_series); seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); @@ -194,7 +194,7 @@ void TableWidget::updateChartType(bool toggle) m_series = new QSplineSeries; m_series->setModel(m_model); m_series->setModelMapping(0,1, Qt::Vertical); - m_series->setModelMappingRange(1, 4); +// m_series->setModelMappingRange(1, 4); // series->setModelMapping(0,1, Qt::Horizontal); m_chart->addSeries(m_series); seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); @@ -204,7 +204,7 @@ void TableWidget::updateChartType(bool toggle) m_series = new QSplineSeries; m_series->setModel(m_model); m_series->setModelMapping(2,3, Qt::Vertical); - m_series->setModelMappingRange(0, 0); +// m_series->setModelMappingRange(0, 0); // series->setModelMapping(2,3, Qt::Horizontal); m_chart->addSeries(m_series); seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); @@ -214,7 +214,7 @@ void TableWidget::updateChartType(bool toggle) m_series = new QSplineSeries; m_series->setModel(m_model); m_series->setModelMapping(4,5, Qt::Vertical); - m_series->setModelMappingRange(2, 0); +// m_series->setModelMappingRange(2, 0); // series->setModelMapping(4,5, Qt::Horizontal); m_chart->addSeries(m_series); seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); @@ -226,7 +226,7 @@ void TableWidget::updateChartType(bool toggle) m_series = new QScatterSeries; m_series->setModel(m_model); m_series->setModelMapping(0,1, Qt::Vertical); - m_series->setModelMappingRange(2, 0); +// m_series->setModelMappingRange(2, 0); // series->setModelMapping(0,1, Qt::Horizontal); m_chart->addSeries(m_series); @@ -237,7 +237,7 @@ void TableWidget::updateChartType(bool toggle) m_series = new QScatterSeries; m_series->setModel(m_model); m_series->setModelMapping(2,3, Qt::Vertical); - m_series->setModelMappingRange(1, 6); +// m_series->setModelMappingRange(1, 6); // series->setModelMapping(2,3, Qt::Horizontal); m_chart->addSeries(m_series); @@ -297,7 +297,7 @@ void TableWidget::updateChartType(bool toggle) QLineSeries* upperLineSeries = new QLineSeries; upperLineSeries->setModel(m_model); upperLineSeries->setModelMapping(0, 1, Qt::Vertical); - upperLineSeries->setModelMappingRange(1, 5); +// upperLineSeries->setModelMappingRange(1, 5); QLineSeries* lowerLineSeries = new QLineSeries; lowerLineSeries->setModel(m_model); lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);