diff --git a/examples/tablemodelchart/customtablemodel.cpp b/examples/tablemodelchart/customtablemodel.cpp index 08c3048..6f26c1b 100644 --- a/examples/tablemodelchart/customtablemodel.cpp +++ b/examples/tablemodelchart/customtablemodel.cpp @@ -13,6 +13,8 @@ CustomTableModel::CustomTableModel(QObject *parent) : m_labels.append("Lemons"); m_points.append(QPointF(200, 150)); m_labels.append("Plums"); + m_points.append(QPointF(225, 75)); + m_labels.append("Pearls"); } int CustomTableModel::rowCount(const QModelIndex & parent) const @@ -22,7 +24,7 @@ int CustomTableModel::rowCount(const QModelIndex & parent) const int CustomTableModel::columnCount(const QModelIndex & parent) const { - return 3; + return 2; } QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const @@ -40,7 +42,8 @@ QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, return "y"; case 2: return "Fruit"; - default: "What?"; + default: + return "What?"; } } else @@ -105,8 +108,8 @@ bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & val Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const { - if (!index.isValid()) - return Qt::ItemIsEnabled; +// if (!index.isValid()) +// return Qt::ItemIsEnabled; return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; } diff --git a/examples/tablemodelchart/tablewidget.cpp b/examples/tablemodelchart/tablewidget.cpp index 53e183f..c5b1e15 100644 --- a/examples/tablemodelchart/tablewidget.cpp +++ b/examples/tablemodelchart/tablewidget.cpp @@ -26,8 +26,8 @@ TableWidget::TableWidget(QWidget *parent) // QLineSeries* series = new QLineSeries; QSplineSeries* series = new QSplineSeries; series->setModel(model); - series->setModelMappingX(0); - series->setModelMappingY(1); + series->setModelMapping(0,1, Qt::Vertical); +// series->setModelMappingY(1); // series->add(QPointF(150, 100)); // series->add(QPointF(200, 130)); diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index f95410c..dac0e68 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -68,7 +68,10 @@ void QBarSeries::removeBarSet(QBarSet *set) */ int QBarSeries::barsetCount() { - return mModel->barsetCount(); + if(m_model) + return m_mapBarTop - m_mapBarBottom; + else + return mModel->barsetCount(); } /*! @@ -222,6 +225,21 @@ bool QBarSeries::separatorsVisible() return mSeparatorsVisible; } +bool QBarSeries::setModel(QAbstractItemModel* model) +{ + m_model = model; +} + +void QBarSeries::setModelMappingCategories(int modelColumn) +{ + // +} + +void QBarSeries::setModelMappingBarRange(int bottomBoundry, int topBoundry) +{ + // +} + #include "moc_qbarseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/qbarseries.h b/src/barchart/qbarseries.h index 938f4ae..6cdec6b 100644 --- a/src/barchart/qbarseries.h +++ b/src/barchart/qbarseries.h @@ -26,6 +26,11 @@ public: QList barSets(); QList legendEntries(); + bool setModel(QAbstractItemModel* model); + QAbstractItemModel* modelExt() {return m_model;} + void setModelMappingCategories(int modelColumn); + void setModelMappingBarRange(int bottomBoundry, int topBoundry); + public: // TODO: Functions below this are not part of api and will be moved // to private implementation, when we start using it @@ -65,6 +70,11 @@ public Q_SLOTS: protected: BarChartModel* mModel; bool mSeparatorsVisible; + + QAbstractItemModel* m_model; + int m_mapCategories; + int m_mapBarBottom; + int m_mapBarTop; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/splinechart/qsplineseries.cpp b/src/splinechart/qsplineseries.cpp index ca3679e..81154ac 100644 --- a/src/splinechart/qsplineseries.cpp +++ b/src/splinechart/qsplineseries.cpp @@ -140,6 +140,12 @@ void QSplineSeries::updateControlPoints() bool QSplineSeries::setModel(QAbstractItemModel* model) { QXYSeries::setModel(model); +// calculateControlPoints(); +} + +void QSplineSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) +{ + QLineSeries::setModelMapping(modelX, modelY, orientation); calculateControlPoints(); } diff --git a/src/splinechart/qsplineseries.h b/src/splinechart/qsplineseries.h index 9df24f5..8a454fc 100644 --- a/src/splinechart/qsplineseries.h +++ b/src/splinechart/qsplineseries.h @@ -21,6 +21,8 @@ public: QPointF controlPoint(int index) const {return m_controlPoints[index];} bool setModel(QAbstractItemModel* model); + void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); + // TODO: allow the user to set custom control points // void setCustomControlPoints(QList controlPoints); // bool calculateControlPointsAutomatically(); diff --git a/src/xychart/qxyseries.cpp b/src/xychart/qxyseries.cpp index e4c1e0e..09f666e 100644 --- a/src/xychart/qxyseries.cpp +++ b/src/xychart/qxyseries.cpp @@ -45,9 +45,11 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ QXYSeries::QXYSeries(QObject* parent):QSeries(parent) { - m_model = 0; - m_mapX = 0; - m_mapY = 1; + m_model = NULL; + m_mapX = -1; + m_mapY = -1; + m_mapOrientation = Qt::Vertical; +// m_mapYOrientation = Qt::Vertical; } /*! Destroys the object. Series added to QChartView or QChart instances are owned by those, @@ -142,8 +144,14 @@ void QXYSeries::removeAll() qreal QXYSeries::x(int pos) const { if (m_model) - return m_model->data(m_model->index(pos, m_mapX), Qt::DisplayRole).toDouble(); + if (m_mapOrientation == Qt::Vertical) + // consecutive data is read from model's column + return m_model->data(m_model->index(pos, m_mapX), Qt::DisplayRole).toDouble(); + else + // consecutive data is read from model's row + return m_model->data(m_model->index(m_mapX, pos), Qt::DisplayRole).toDouble(); else + // model is not specified, return the data from series' internal data store return m_x.at(pos); } @@ -153,8 +161,14 @@ qreal QXYSeries::x(int pos) const qreal QXYSeries::y(int pos) const { if (m_model) - return m_model->data(m_model->index(pos, m_mapY), Qt::DisplayRole).toDouble(); + if (m_mapOrientation == Qt::Vertical) + // consecutive data is read from model's column + return m_model->data(m_model->index(pos, m_mapY), Qt::DisplayRole).toDouble(); + else + // consecutive data is read from model's row + return m_model->data(m_model->index(m_mapY, pos), Qt::DisplayRole).toDouble(); else + // model is not specified, return the data from series' internal data store return m_y.at(pos); } @@ -165,10 +179,15 @@ int QXYSeries::count() const { Q_ASSERT(m_x.size() == m_y.size()); -// int k = m_model->rowCount(); if (m_model) - return m_model->rowCount(); + if (m_mapOrientation == Qt::Vertical) + // data is in a column, so return the number of items in single column + return m_model->rowCount(); + else + // data is in a row, so return the number of items in single row + m_model->columnCount(); else + // model is not specified, return the number of points in the series internal data store return m_x.size(); } @@ -243,12 +262,25 @@ void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) bool QXYSeries::setModel(QAbstractItemModel* model) { m_model = model; - for (int i = 0; i < m_model->rowCount(); i++) - emit pointAdded(i); + // for (int i = 0; i < m_model->rowCount(); i++) + // emit pointAdded(i); connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); -// connect(m_model,SIGNAL(), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); + // connect(m_model,SIGNAL(), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); } +void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) +{ + m_mapX = modelX; + m_mapY = modelY; + m_mapOrientation = orientation; +} + +//void QXYSeries::setModelMappingY(int modelLineIndex, Qt::Orientation orientation) +//{ +// m_mapY = modelLineIndex; +// m_mapYOrientation = orientation; +//} + #include "moc_qxyseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/xychart/qxyseries.h b/src/xychart/qxyseries.h index 258488f..25fb837 100644 --- a/src/xychart/qxyseries.h +++ b/src/xychart/qxyseries.h @@ -42,8 +42,8 @@ public: bool setModel(QAbstractItemModel* model); QAbstractItemModel* model() {return m_model;} - void setModelMappingX(int modelColumn) {m_mapX = modelColumn;} - void setModelMappingY(int modelColumn) {m_mapY = modelColumn;} + void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); +// void setModelMappingY(int modelLineIndex, Qt::Orientation orientation = Qt::Vertical); private slots: void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); @@ -63,7 +63,9 @@ protected: QAbstractItemModel* m_model; int m_mapX; + Qt::Orientation m_mapOrientation; int m_mapY; +// Qt::Orientation m_mapYOrientation; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/xychart/xychartitem.cpp b/src/xychart/xychartitem.cpp index 5e77410..cf70d6a 100644 --- a/src/xychart/xychartitem.cpp +++ b/src/xychart/xychartitem.cpp @@ -100,8 +100,8 @@ void XYChartItem::handlePointReplaced(int index) Q_ASSERT(index>=0); QPointF point = calculateGeometryPoint(index); QVector points = m_points; - m_points.replace(index,point); - updatePoint(m_points); + points.replace(index,point); + updatePoint(points); update(); }