From c82178b4ef053e118f68051670c03a7943d25660 2012-02-20 14:45:27 From: Michal Klocek Date: 2012-02-20 14:45:27 Subject: [PATCH] Refactors axis handling * drops pass by value handling * qaxischart is qobject * adds axis ticks handling * adds scale stubs --- diff --git a/src/axisitem.cpp b/src/axisitem.cpp index f2823cf..a642ac8 100644 --- a/src/axisitem.cpp +++ b/src/axisitem.cpp @@ -9,7 +9,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) : ChartItem(parent), -m_ticks(4), m_type(type), m_labelsAngle(0), m_shadesEnabled(true), @@ -20,7 +19,6 @@ m_labels(parent) //initial initialization m_shades.setZValue(0); m_grid.setZValue(2); - createItems(); } AxisItem::~AxisItem() @@ -32,9 +30,9 @@ QRectF AxisItem::boundingRect() const return m_rect; } -void AxisItem::createItems() +void AxisItem::createItems(int count) { - for (int i = 0; i <= m_ticks; ++i) { + for (int i = 0; i < count; ++i) { m_grid.addToGroup(new QGraphicsLineItem(this)); m_labels.addToGroup(new QGraphicsSimpleTextItem(this)); if(i%2) m_shades.addToGroup(new QGraphicsRectItem(this)); @@ -55,6 +53,8 @@ void AxisItem::clear() delete item; } + m_thicksList.clear(); + } void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -62,7 +62,7 @@ void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, } -void AxisItem::updateDomain() +void AxisItem::updateItem(int count) { QList lines = m_grid.childItems(); @@ -73,21 +73,16 @@ void AxisItem::updateDomain() { case X_AXIS: { - const qreal deltaX = m_rect.width() / m_ticks; + const qreal deltaX = m_rect.width() / (count-1); m_axis.setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); - for (int i = 0; i <= m_ticks; ++i) { - + for (int i = 0; i < count; ++i) { int x = i * deltaX + m_rect.left(); - - qreal label = m_domain.m_minX + (i * m_domain.spanX()/ m_ticks); - QGraphicsLineItem *lineItem = static_cast(lines.at(i)); lineItem->setLine(x, m_rect.top(), x, m_rect.bottom()); - QGraphicsSimpleTextItem *labelItem = static_cast(labels.at(i)); - labelItem->setText(QString::number(label)); + labelItem->setText(m_thicksList.at(i)); QPointF center = labelItem->boundingRect().center(); labelItem->setTransformOriginPoint(center.x(), center.y()); labelItem->setPos(x - center.x(), m_rect.bottom() + label_padding); @@ -103,26 +98,19 @@ void AxisItem::updateDomain() case Y_AXIS: { - const qreal deltaY = m_rect.height()/ m_ticks; + const qreal deltaY = m_rect.height()/ (count-1); m_axis.setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); - for (int i = 0; i <= m_ticks; ++i) { - + for (int i = 0; i < count; ++i) { int y = i * -deltaY + m_rect.bottom(); - - qreal label = m_domain.m_minY + (i * m_domain.spanY()/ m_ticks); - QGraphicsLineItem *lineItem = static_cast(lines.at(i)); lineItem->setLine(m_rect.left() , y, m_rect.right(), y); - QGraphicsSimpleTextItem *labelItem = static_cast(labels.at(i)); - labelItem->setText(QString::number(label)); + labelItem->setText(m_thicksList.at(i)); QPointF center = labelItem->boundingRect().center(); labelItem->setTransformOriginPoint(center.x(), center.y()); labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , y-center.y()); - - if(i%2){ QGraphicsRectItem *rectItem = static_cast(shades.at(i/2)); rectItem->setRect(m_rect.left(),y,m_rect.width(),deltaY); @@ -137,23 +125,23 @@ void AxisItem::updateDomain() } } -void AxisItem::handleAxisChanged(const QChartAxis& axis) +void AxisItem::handleAxisUpdate(QChartAxis* axis) { - if(axis.isAxisVisible()) { + if(axis->isAxisVisible()) { setAxisOpacity(100); } else { setAxisOpacity(0); } - if(axis.isGridVisible()) { + if(axis->isGridVisible()) { setGridOpacity(100); } else { setGridOpacity(0); } - if(axis.isLabelsVisible()) + if(axis->isLabelsVisible()) { setLabelsOpacity(100); } @@ -161,49 +149,48 @@ void AxisItem::handleAxisChanged(const QChartAxis& axis) setLabelsOpacity(0); } - if(axis.isShadesVisible()) { - setShadesOpacity(axis.shadesOpacity()); + if(axis->isShadesVisible()) { + setShadesOpacity(axis->shadesOpacity()); } else { setShadesOpacity(0); } - switch(axis.labelsOrientation()) - { - case QChartAxis::LabelsOrientationHorizontal: - setLabelsAngle(0); - break; - case QChartAxis::LabelsOrientationVertical: - setLabelsAngle(90); - break; - case QChartAxis::LabelsOrientationSlide: - setLabelsAngle(-45); - break; - default: - break; - } - - setAxisPen(axis.axisPen()); - setLabelsPen(axis.labelsPen()); - setLabelsBrush(axis.labelsBrush()); - setLabelsFont(axis.labelFont()); - setGridPen(axis.gridPen()); - setShadesPen(axis.shadesPen()); - setShadesBrush(axis.shadesBrush()); - + setLabelsAngle(axis->labelsAngle()); + setAxisPen(axis->axisPen()); + setLabelsPen(axis->labelsPen()); + setLabelsBrush(axis->labelsBrush()); + setLabelsFont(axis->labelFont()); + setGridPen(axis->gridPen()); + setShadesPen(axis->shadesPen()); + setShadesBrush(axis->shadesBrush()); } -void AxisItem::handleDomainChanged(const Domain& domain) +void AxisItem::handleLabelsChanged(const QStringList& labels) { - m_domain = domain; - updateDomain(); + m_thicksList=labels; + QList items = m_labels.childItems(); + if(items.size()!=m_thicksList.size()){ + clear(); + m_thicksList=labels; + createItems(m_thicksList.size()); + items = m_labels.childItems(); + } + + Q_ASSERT(items.size()==m_thicksList.size()); + + int i=0; + foreach(QGraphicsItem* item, items){ + static_cast(item)->setText(m_thicksList.at(i)); + i++; + } update(); } void AxisItem::handleGeometryChanged(const QRectF& rect) { m_rect = rect; - updateDomain(); + updateItem(m_thicksList.size()); update(); } @@ -305,14 +292,6 @@ void AxisItem::setGridPen(const QPen& pen) } } -void AxisItem::setTicks(int count) -{ - if(count!=m_ticks){ - clear(); - m_ticks=count; - createItems(); - } -} //TODO "nice numbers algorithm" #include "moc_axisitem_p.cpp" diff --git a/src/axisitem_p.h b/src/axisitem_p.h index fc21bf1..4732df2 100644 --- a/src/axisitem_p.h +++ b/src/axisitem_p.h @@ -39,9 +39,6 @@ public: void setLabelsAngle(int angle); int labelsAngle()const { return m_labelsAngle; } - void setTicks(int count); - int ticks() const { return m_ticks;} - void setShadesBrush(const QBrush& brush); void setShadesPen(const QPen& pen); @@ -53,18 +50,16 @@ public: void setLabelsFont(const QFont& font); public slots: - void handleAxisChanged(const QChartAxis& axis); - void handleDomainChanged(const Domain& domain); + void handleAxisUpdate(QChartAxis* axis); + void handleLabelsChanged(const QStringList& labels); void handleGeometryChanged(const QRectF& size); protected: - void updateDomain(); + void updateItem(int count); private: void clear(); - void createItems(); + void createItems(int count); private: AxisType m_type; - int m_ticks; - Domain m_domain; QRectF m_rect; int m_labelsAngle; bool m_shadesEnabled; @@ -72,6 +67,7 @@ private: QGraphicsItemGroup m_shades; QGraphicsItemGroup m_labels; QGraphicsLineItem m_axis; + QStringList m_thicksList; }; diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index 8cdce58..772a113 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -1,4 +1,5 @@ #include "chartdataset_p.h" +#include "qchartaxis.h" //series #include "qlinechartseries.h" #include "qbarchartseries.h" @@ -9,10 +10,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -ChartDataSet::ChartDataSet(QObject *parent):QObject(parent) +ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), +m_axisX(new QChartAxis(this)), +m_axisY(new QChartAxis(this)), +m_domainIndex(0), +m_axisXInitialized(false) { - Domain domain; - m_domains<setParent(this); // take ownership - m_domainIndex = 0; - m_domains.resize(1); - Domain& domain = m_domains[m_domainIndex]; + clearDomains(); + + if(axisY==0) axisY = m_axisY; + + QList seriesList = m_seriesMap.values(axisY); + + QList domainList = m_domainMap.values(axisY); + + Q_ASSERT(domainList.size()<=1); + + Domain domain; + + if(domainList.size()>0) domain = domainList.at(0); switch(series->type()) { @@ -113,15 +130,60 @@ void ChartDataSet::addSeries(QChartSeries* series) } + if(!m_domainMap.contains(axisY)) + { + emit axisAdded(axisY); + QObject::connect(axisY,SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); + QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); + QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); + } + m_domainMap.replace(axisY,domain); + m_seriesMap.insert(axisY,series); + + if(!m_axisXInitialized) + { + emit axisAdded(axisX()); + QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); + QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); + QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); + m_axisXInitialized=true; + } + + emit seriesAdded(series); - emit domainChanged(domain); + QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY); + QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX); + emit axisLabelsChanged(axisY,ylabels); + emit axisLabelsChanged(axisX(),xlabels); + emit seriesDomainChanged(series,domain); + +} + +void ChartDataSet::removeSeries(QChartSeries* series) +{ + QList keys = m_seriesMap.uniqueKeys(); + foreach(QChartAxis* axis , keys) { + if(m_seriesMap.contains(axis,series)){ + emit seriesRemoved(series); + m_seriesMap.remove(axis,series); + //remove axis if no longer there + if(!m_seriesMap.contains(axis) && axis != m_axisY){ + emit axisRemoved(axis); + m_domainMap.remove(axis); + delete axis; + } + break; + } + } } bool ChartDataSet::nextDomain() { - if (m_domainIndex < m_domains.count() - 1) { + int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; + + if (m_domainIndex < limit) { m_domainIndex++; - emit domainChanged(m_domains[m_domainIndex]); + setDomain(m_domainIndex); return true; } else { @@ -133,7 +195,7 @@ bool ChartDataSet::previousDomain() { if (m_domainIndex > 0) { m_domainIndex--; - emit domainChanged(m_domains[m_domainIndex]); + setDomain(m_domainIndex); return true; } else { @@ -141,21 +203,129 @@ bool ChartDataSet::previousDomain() } } -void ChartDataSet::clearDomains() +void ChartDataSet::setDomain(int index) { - if (m_domainIndex > 0) { - m_domainIndex = 0; - emit domainChanged(m_domains[m_domainIndex]); + QList domainList = m_domainMap.uniqueKeys(); + foreach (QChartAxis* axis , domainList) { + int i = m_domainMap.count(axis) - index -1; + Q_ASSERT(i>=0); + Domain domain = m_domainMap.values(axis).at(i); + QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); + QList seriesList = m_seriesMap.values(axis); + foreach(QChartSeries* series, seriesList) { + emit seriesDomainChanged(series,domain); + } + emit axisLabelsChanged(axis,labels); + } + + Domain domain = m_domainMap.value(axisY()); + QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); + emit axisLabelsChanged(axisX(),labels); +} + +void ChartDataSet::clearDomains(int toIndex) +{ + Q_ASSERT(toIndex>=0); + + m_domainIndex = toIndex; + + QList keys = m_domainMap.uniqueKeys(); + + foreach (QChartAxis* key , keys) + { + QList domains = m_domainMap.values(key); + m_domainMap.remove(key); + int i = domains.size() - toIndex - 1; + while(i--){ + domains.removeFirst(); + } + for(int j=domains.size()-1; j>=0 ;j--) + m_domainMap.insert(key,domains.at(j)); } } -void ChartDataSet::addDomain(const Domain& domain) +void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) { - m_domains.resize(m_domainIndex + 1); - m_domains << domain; + Q_ASSERT(rect.isValid()); + Q_ASSERT(viewport.isValid()); + + clearDomains(m_domainIndex); + + QList domainList = m_domainMap.uniqueKeys(); + + foreach (QChartAxis* axis , domainList){ + Domain domain(m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height())); + QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); + QList seriesList = m_seriesMap.values(axis); + foreach(QChartSeries* series, seriesList){ + emit seriesDomainChanged(series,domain); + } + emit axisLabelsChanged(axis,labels); + m_domainMap.insert(axis,domain); + } + + Domain domain = m_domainMap.value(axisY()); + QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); + emit axisLabelsChanged(axisX(),labels); + m_domainIndex++; +} + +QChartAxis* ChartDataSet::axisY(QChartSeries* series) const +{ + if(series == 0) return m_axisY; + + QList keys = m_seriesMap.uniqueKeys(); + + foreach(QChartAxis* axis , keys) { + if(m_seriesMap.contains(axis,series)){ + return axis; + } + } + return 0; +} + +QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) +{ + Q_ASSERT(max>=min); - emit domainChanged(domain); + QStringList labels; + + int ticks = axis->ticksCount(); + + for(int i=0; i<= ticks; i++){ + qreal value = min + (i * (max - min)/ ticks); + QString label = axis->axisTickLabel(value); + if(label.isEmpty()){ + labels << QString::number(value); + }else{ + labels << label; + } + } + return labels; +} + + +void ChartDataSet::handleMinChanged(qreal min) +{ + +} + +void ChartDataSet::handleMaxChanged(qreal max) +{ + +} + +void ChartDataSet::handleTickChanged(QChartAxis* axis) +{ + Domain domain = m_domainMap.value(axisY()); + if(axis==axisX()){ + QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); + emit axisLabelsChanged(axis,labels); + }else{ + QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); + emit axisLabelsChanged(axis,labels); + } } #include "moc_chartdataset_p.cpp" diff --git a/src/chartdataset_p.h b/src/chartdataset_p.h index 4bb533c..c350b04 100644 --- a/src/chartdataset_p.h +++ b/src/chartdataset_p.h @@ -1,34 +1,57 @@ -#ifndef CHARTENGINE_P_H_ -#define CHARTENGINE_P_H_ +#ifndef CHARTDATASET_P_H_ +#define CHARTDATASET_P_H_ -#include +#include "qchartseries.h" #include "domain_p.h" #include QTCOMMERCIALCHART_BEGIN_NAMESPACE +class QChartAxis; + class ChartDataSet : public QObject { Q_OBJECT public: - ChartDataSet(QObject* parent =0); + ChartDataSet(QObject* parent=0); virtual ~ChartDataSet(); - void addSeries(QChartSeries* series); - void addDomain(const Domain& domain); + void addSeries(QChartSeries* series,QChartAxis *axisY = 0); + void removeSeries(QChartSeries* series); + void addDomain(const QRectF& rect, const QRectF& viewport); bool nextDomain(); bool previousDomain(); - void clearDomains(); - const Domain& domain() const; + void clearDomains(int toIndex =0); + const Domain domain(QChartAxis *axisY) const; + int domainIndex() const {return m_domainIndex;} + + QChartAxis* axisX() const { return m_axisX;}; + QChartAxis* axisY(QChartSeries* series = 0) const; signals: void seriesAdded(QChartSeries* series); - void domainChanged(const Domain& domain); + void seriesRemoved(QChartSeries* series); + void axisAdded(QChartAxis* axis); + void axisRemoved(QChartAxis* axis); + void axisLabelsChanged(QChartAxis* axis, const QStringList& labels); + void seriesDomainChanged(QChartSeries* series,const Domain& domain); + +private slots: + void handleMinChanged(qreal min); + void handleMaxChanged(qreal max); + void handleTickChanged(QChartAxis*); + +private: + void setDomain(int index); + QStringList createLabels(QChartAxis* axis,qreal min, qreal max); private: - QList m_chartSeries; - QVector m_domains; + QMultiMap m_domainMap; + QMultiMap m_seriesMap; + QChartAxis* m_axisX; + QChartAxis* m_axisY; int m_domainIndex; + bool m_axisXInitialized; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/chartitem_p.h b/src/chartitem_p.h index 0d01c8d..0d5dcaf 100644 --- a/src/chartitem_p.h +++ b/src/chartitem_p.h @@ -13,6 +13,9 @@ class ChartItem : public QGraphicsItem enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM}; public: ChartItem(QGraphicsItem* parent = 0):QGraphicsItem(parent){}; + //TODO make pure + virtual void handleGeometryChanged(const QRectF&){}; + virtual void handleDomainChanged(const Domain& domain){}; virtual ~ChartItem(){}; }; diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 6969772..e14bc23 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -26,14 +26,12 @@ ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(char m_chart(chart), m_dataset(dataset), m_chartTheme(0), -m_axisXItem(new AxisItem(AxisItem::X_AXIS,m_chart)), -m_axisYItem(new AxisItem(AxisItem::Y_AXIS,m_chart)), -m_domainIndex(0), m_marginSize(0), m_rect(QRectF(QPoint(0,0),m_chart->size())) { + createConnections(); setChartTheme(QChart::ChartThemeDefault); - createConnections(); + } ChartPresenter::~ChartPresenter() @@ -44,10 +42,17 @@ void ChartPresenter::createConnections() { QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); - QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisXItem,SLOT(handleGeometryChanged(const QRectF&))); - QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisXItem,SLOT(handleDomainChanged(const Domain&))); - QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisYItem,SLOT(handleGeometryChanged(const QRectF&))); - QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisYItem,SLOT(handleDomainChanged(const Domain&))); + QObject::connect(m_dataset,SIGNAL(seriesRemoved(QChartSeries*)),this,SLOT(handleSeriesRemoved(QChartSeries*))); + QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*))); + QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); + QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QChartSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QChartSeries*,const Domain&))); + QObject::connect(m_dataset,SIGNAL(axisLabelsChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisLabelsChanged(QChartAxis*,const QStringList&))); +} + + +QRectF ChartPresenter::geometry() const +{ + return m_rect; } void ChartPresenter::handleGeometryChanged() @@ -68,9 +73,31 @@ void ChartPresenter::setMargin(int margin) m_marginSize = margin; } +void ChartPresenter::handleAxisAdded(QChartAxis* axis) +{ + AxisItem* item ; + + if(axis==m_dataset->axisX()){ + item = new AxisItem(AxisItem::X_AXIS,m_chart); + }else{ + item = new AxisItem(AxisItem::Y_AXIS,m_chart); + } + QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); + QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*))); + m_chartTheme->decorate(axis,item); + m_axisItems.insert(axis,item); +} + +void ChartPresenter::handleAxisRemoved(QChartAxis* axis) +{ + AxisItem* item = m_axisItems.take(axis); + Q_ASSERT(item); + delete item; +} + + void ChartPresenter::handleSeriesAdded(QChartSeries* series) { - qDebug() << " ChartPresenter::handleSeriesAdded"; switch(series->type()) { case QChartSeries::SeriesTypeLine: { @@ -78,7 +105,6 @@ void ChartPresenter::handleSeriesAdded(QChartSeries* series) LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); - QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); m_chartItems.insert(series,item); break; @@ -89,7 +115,6 @@ void ChartPresenter::handleSeriesAdded(QChartSeries* series) BarPresenter* item = new BarPresenter(barSeries->model(),m_chart); m_chartTheme->decorate(item,barSeries,m_chartItems.count()); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); - QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); m_chartItems.insert(series,item); // m_axisXItem->setVisible(false); @@ -102,7 +127,6 @@ void ChartPresenter::handleSeriesAdded(QChartSeries* series) StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries->model(),m_chart); m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); - QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); m_chartItems.insert(series,item); break; @@ -114,7 +138,6 @@ void ChartPresenter::handleSeriesAdded(QChartSeries* series) PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries->model(),m_chart); m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); - QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); m_chartItems.insert(series,item); break; @@ -124,8 +147,6 @@ void ChartPresenter::handleSeriesAdded(QChartSeries* series) ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); - QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), - scatterPresenter, SLOT(handleDomainChanged(const Domain&))); m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); m_chartItems.insert(scatterSeries, scatterPresenter); break; @@ -135,7 +156,6 @@ void ChartPresenter::handleSeriesAdded(QChartSeries* series) PiePresenter* pie = new PiePresenter(m_chart, s); m_chartTheme->decorate(pie, s, m_chartItems.count()); QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); - QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); m_chartItems.insert(series, pie); break; } @@ -148,40 +168,25 @@ void ChartPresenter::handleSeriesAdded(QChartSeries* series) if(m_rect.isValid()) emit geometryChanged(m_rect); } -void ChartPresenter::handleSeriesChanged(QChartSeries* series) -{ - //TODO: -} - -void ChartPresenter::zoomInToRect(const QRectF& rect) +void ChartPresenter::handleSeriesRemoved(QChartSeries* series) { - if(!rect.isValid()) return; - QRectF r = rect.normalized(); - r.translate(-m_marginSize, -m_marginSize); - Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); - m_dataset->addDomain(domain); + ChartItem* item = m_chartItems.take(series); + delete item; } -void ChartPresenter::zoomIn() +void ChartPresenter::handleSeriesChanged(QChartSeries* series) { - if (!m_dataset->nextDomain()) { - QRectF rect = m_rect; - rect.setWidth(rect.width()/2); - rect.setHeight(rect.height()/2); - rect.moveCenter(m_rect.center()); - Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); - m_dataset->addDomain(domain); - } + //TODO: } -void ChartPresenter::zoomOut() +void ChartPresenter::handleSeriesDomainChanged(QChartSeries* series, const Domain& domain) { - m_dataset->previousDomain(); + m_chartItems.value(series)->handleDomainChanged(domain); } -void ChartPresenter::zoomReset() +void ChartPresenter::handleAxisLabelsChanged(QChartAxis* axis,const QStringList& labels) { - m_dataset->clearDomains(); + m_axisItems.value(axis)->handleLabelsChanged(labels); } void ChartPresenter::setChartTheme(QChart::ChartTheme theme) @@ -200,69 +205,18 @@ void ChartPresenter::setChartTheme(QChart::ChartTheme theme) m_chartTheme->decorate(i.value(),i.key(),index); } - m_chartTheme->decorate(m_axisX, m_axisXItem); - m_chartTheme->decorate(m_axisY, m_axisYItem); - + QMapIterator j(m_axisItems); + while (j.hasNext()) { + j.next(); + m_chartTheme->decorate(j.key(),j.value()); + } } - QChart::ChartTheme ChartPresenter::chartTheme() { return m_chartTheme->id(); } -void ChartPresenter::setDefaultAxisX(const QChartAxis& axis) -{ - //if(m_axisX != axis) { - m_axisX = axis; - m_axisXItem->handleAxisChanged(m_axisX); - //} -} - -void ChartPresenter::setDefaultAxisY(const QChartAxis& axis) -{ - // if(m_axisY != axis) { - m_axisY = axis; - m_axisYItem->handleAxisChanged(m_axisY); - //} -} - -QChartAxis ChartPresenter::defaultAxisX() const -{ - return m_axisX; -} - -QChartAxis ChartPresenter::defaultAxisY() const -{ - return m_axisY; -} - -QChartAxis ChartPresenter::axisY(int id) const -{ - return m_axis.value(id); -} - -int ChartPresenter::addAxisY(const QChartAxis& axis) -{ - int key =0 ; - - while(m_axis.contains(key)){ - key++; - //TODO overflow - } - - m_axis.insert(key,axis); - m_axisItems.insert(key,new AxisItem(AxisItem::Y_AXIS,m_chart)); - - return key; -} - - -void ChartPresenter::removeAxisY(int id) -{ - m_axis.remove(id); - delete m_axisItems.take(id); -} #include "moc_chartpresenter_p.cpp" diff --git a/src/chartpresenter_p.h b/src/chartpresenter_p.h index b999918..8088d6e 100644 --- a/src/chartpresenter_p.h +++ b/src/chartpresenter_p.h @@ -26,46 +26,31 @@ public: void setMargin(int margin); int margin() const; - void zoomInToRect(const QRectF& rectangle); - void zoomIn(); - void zoomOut(); - void zoomReset(); + QRectF geometry() const; void setChartTheme(QChart::ChartTheme theme); QChart::ChartTheme chartTheme(); - void setDefaultAxisX(const QChartAxis& axis); - void setDefaultAxisY(const QChartAxis& axis); - QChartAxis defaultAxisX() const; - QChartAxis defaultAxisY() const; - QChartAxis axisY(int id) const; - int addAxisY(const QChartAxis& axis); - void removeAxisY(int id); - private: void createConnections(); public slots: void handleSeriesAdded(QChartSeries* series); - void handleSeriesRemoved(QChartSeries* series){}; + void handleSeriesRemoved(QChartSeries* series); + void handleAxisAdded(QChartAxis* axis); + void handleAxisRemoved(QChartAxis* axis); + void handleSeriesDomainChanged(QChartSeries* series, const Domain& domain); + void handleAxisLabelsChanged(QChartAxis* axis, const QStringList& labels); void handleSeriesChanged(QChartSeries* series); - //void handleDomainChanged(Domain oldDomain,Domain newDomain); void handleGeometryChanged(); signals: void geometryChanged(const QRectF& rect); private: QMap m_chartItems; - QMap m_axisItems; - QMap m_axis; + QMap m_axisItems; QChart* m_chart; ChartDataSet* m_dataset; - QVector m_domains; ChartTheme *m_chartTheme; - QChartAxis m_axisX; - AxisItem* m_axisXItem; - QChartAxis m_axisY; - AxisItem* m_axisYItem; - int m_domainIndex; int m_marginSize; QRectF m_rect; diff --git a/src/charttheme.cpp b/src/charttheme.cpp index 243f84b..1ba027c 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -217,15 +217,13 @@ void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) } -void ChartTheme::decorate(QChartAxis& axis,AxisItem* item) +void ChartTheme::decorate(QChartAxis* axis,AxisItem* item) { //TODO: dummy defults for now - - axis.setLabelsBrush(Qt::black); - axis.setLabelsPen(Qt::NoPen); - axis.setShadesPen(Qt::NoPen); - axis.setShadesOpacity(0.5); - item->handleAxisChanged(axis); + axis->setLabelsBrush(Qt::black); + axis->setLabelsPen(Qt::NoPen); + axis->setShadesPen(Qt::NoPen); + axis->setShadesOpacity(0.5); } QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/charttheme_p.h b/src/charttheme_p.h index 90aad26..86eeb20 100644 --- a/src/charttheme_p.h +++ b/src/charttheme_p.h @@ -37,7 +37,7 @@ public: void decorate(PercentBarPresenter* item, QPercentBarChartSeries* series,int count); void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count); void decorate(PiePresenter* item, QPieSeries* series, int count); - void decorate(QChartAxis& axis,AxisItem* item); + void decorate(QChartAxis* axis,AxisItem* item); protected: QChart::ChartTheme m_id; diff --git a/src/qchart.cpp b/src/qchart.cpp index 49afbce..c567dc0 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -3,6 +3,7 @@ #include "chartpresenter_p.h" #include "chartdataset_p.h" +<<<<<<< HEAD //series #include "qbarchartseries.h" #include "qstackedbarchartseries.h" @@ -11,7 +12,6 @@ #include "qscatterseries.h" //#include "scatterseries_p.h" #include "qpieseries.h" - #include #include #include @@ -28,86 +28,55 @@ m_presenter(new ChartPresenter(this,m_dataset)) QChart::~QChart() {} -void QChart::addSeries(QChartSeries* series) -{ - m_dataset->addSeries(series); -} - -//TODO on review, is it really needed ?? -QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) -{ - QChartSeries *series(0); - - switch (type) { - case QChartSeries::SeriesTypeLine: { - series = new QLineChartSeries(this); - break; - } - case QChartSeries::SeriesTypeBar: { - //series = new BarChartSeries(this); - break; - } - case QChartSeries::SeriesTypeStackedBar: { - //series = new StackedBarChartSeries(this); - break; - } - case QChartSeries::SeriesTypePercentBar: { - //series = new PercentBarChartSeries(this); - break; - } - case QChartSeries::SeriesTypeScatter: { - series = new QScatterSeries(this); - break; - } - case QChartSeries::SeriesTypePie: { - series = new QPieSeries(this); - break; - } - default: - Q_ASSERT(false); - break; - } +void QChart::addSeries(QChartSeries* series,QChartAxis* axisY) +{ + m_dataset->addSeries(series,axisY); +} - addSeries(series); - return series; +void QChart::removeSeries(QChartSeries* series) +{ + m_dataset->removeSeries(series); } void QChart::setChartBackgroundBrush(const QBrush& brush) { - - if(!m_backgroundItem) { - m_backgroundItem = new QGraphicsRectItem(this); - m_backgroundItem->setZValue(-1); - } - + createChartBackgroundItem(); m_backgroundItem->setBrush(brush); m_backgroundItem->update(); } void QChart::setChartBackgroundPen(const QPen& pen) { - - if(!m_backgroundItem) { - m_backgroundItem = new QGraphicsRectItem(this); - m_backgroundItem->setZValue(-1); - } - + createChartBackgroundItem(); m_backgroundItem->setPen(pen); m_backgroundItem->update(); } void QChart::setChartTitle(const QString& title) { - if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); + createChartTitleItem(); m_titleItem->setPlainText(title); } void QChart::setChartTitleFont(const QFont& font) { - if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); + createChartTitleItem(); m_titleItem->setFont(font); } +void QChart::createChartBackgroundItem() +{ + if(!m_backgroundItem) { + m_backgroundItem = new QGraphicsRectItem(this); + m_backgroundItem->setZValue(-1); + } +} + +void QChart::createChartTitleItem() +{ + if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); +} + int QChart::margin() const { return m_presenter->margin(); @@ -128,59 +97,44 @@ QChart::ChartTheme QChart::chartTheme() const return m_presenter->chartTheme(); } -void QChart::zoomInToRect(const QRectF& rectangle) +void QChart::zoomIn() { - m_presenter->zoomInToRect(rectangle); + if (!m_dataset->nextDomain()) { + QRectF rect = m_presenter->geometry(); + rect.setWidth(rect.width()/2); + rect.setHeight(rect.height()/2); + rect.moveCenter(m_presenter->geometry().center()); + zoomIn(rect); + } } -void QChart::zoomIn() +void QChart::zoomIn(const QRectF& rect) { - m_presenter->zoomIn(); + if(!rect.isValid()) return; + QRectF r = rect.normalized(); + int margin = m_presenter->margin(); + r.translate(-margin, -margin); + m_dataset->addDomain(r,m_presenter->geometry()); } void QChart::zoomOut() { - m_presenter->zoomOut(); + m_dataset->previousDomain(); } void QChart::zoomReset() { - m_presenter->zoomReset(); -} - -void QChart::setDefaultAxisX(const QChartAxis& axis) -{ - m_presenter->setDefaultAxisX(axis); -} - -void QChart::setDefaultAxisY(const QChartAxis& axis) -{ - m_presenter->setDefaultAxisY(axis); -} - -QChartAxis QChart::defaultAxisX() const -{ - return m_presenter->defaultAxisX(); -} - -QChartAxis QChart::defaultAxisY() const -{ - return m_presenter->defaultAxisY(); -} - -int QChart::addAxisY(const QChartAxis& axis) -{ - return m_presenter->addAxisY(axis); + m_dataset->clearDomains(); } -QChartAxis QChart::axisY(int id) const +QChartAxis* QChart::axisX() const { - return m_presenter->axisY(id); + return m_dataset->axisX(); } -void QChart::removeAxisY(int id) +QChartAxis* QChart::axisY() const { - m_presenter->removeAxisY(id); + return m_dataset->axisY(); } void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) diff --git a/src/qchart.h b/src/qchart.h index 5c551dc..f0d98a1 100644 --- a/src/qchart.h +++ b/src/qchart.h @@ -21,11 +21,6 @@ class ChartItem; class ChartDataSet; class ChartPresenter; -// TODO: We don't need to have QChart tied to QGraphicsItem: -//class QTCOMMERCIALCHART_EXPORT QChart -//class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { -// public: QChartGraphicsItem(QChart &chart); - /*! * TODO: define the responsibilities */ @@ -47,11 +42,8 @@ public: QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); ~QChart(); - void addSeries(QChartSeries* series); - - //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); - // TODO: who owns the series now? maybe owned by chart and returned a reference instead... - QChartSeries* createSeries(QChartSeries::QChartSeriesType type); + void addSeries(QChartSeries* series,QChartAxis *axisY=0); + void removeSeries(QChartSeries* series); void setMargin(int margin); int margin() const; @@ -63,23 +55,22 @@ public: void setChartBackgroundBrush(const QBrush& brush); void setChartBackgroundPen(const QPen& pen); - void zoomInToRect(const QRectF& rectangle); void zoomIn(); + void zoomIn(const QRectF& rect); void zoomOut(); void zoomReset(); - void setDefaultAxisX(const QChartAxis& axis); - void setDefaultAxisY(const QChartAxis& axis); - QChartAxis defaultAxisX() const; - QChartAxis defaultAxisY() const; - QChartAxis axisY(int id) const; - int addAxisY(const QChartAxis& axis); - void removeAxisY(int id); + QChartAxis* axisX() const; + QChartAxis* axisY() const; protected: void resizeEvent(QGraphicsSceneResizeEvent *event); private: + inline void createChartBackgroundItem(); + inline void createChartTitleItem(); + +private: Q_DISABLE_COPY(QChart) QGraphicsRectItem* m_backgroundItem; QGraphicsTextItem* m_titleItem; diff --git a/src/qchartaxis.cpp b/src/qchartaxis.cpp index b5f18d3..819b26b 100644 --- a/src/qchartaxis.cpp +++ b/src/qchartaxis.cpp @@ -2,85 +2,153 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -QChartAxis::QChartAxis(): +QChartAxis::QChartAxis(QObject* parent):QObject(parent), m_axisVisible(true), m_gridVisible(true), m_labelsVisible(true), +m_labelsAngle(0), m_shadesVisible(true), -m_shadesOpacity(1.0) +m_shadesOpacity(1.0), +m_min(0), +m_max(0), +m_ticksCount(4) { - // TODO Auto-generated constructor stub } QChartAxis::~QChartAxis() { - // TODO Auto-generated destructor stub } void QChartAxis::setAxisPen(const QPen& pen) { m_axisPen=pen; + emit update(this); } void QChartAxis::setAxisVisible(bool visible) { m_axisVisible=visible; + emit update(this); } void QChartAxis::setGridVisible(bool visible) { m_gridVisible=visible; + emit update(this); } void QChartAxis::setGridPen(const QPen& pen) { m_gridPen=pen; + emit update(this); } void QChartAxis::setLabelsVisible(bool visible) { m_labelsVisible=visible; + emit update(this); } void QChartAxis::setLabelsPen(const QPen& pen) { m_labelsPen=pen; + emit update(this); } void QChartAxis::setLabelsBrush(const QBrush& brush) { m_labelsBrush=brush; + emit update(this); } void QChartAxis::setLabelsFont(const QFont& font) { m_labelsFont=font; + emit update(this); } -void QChartAxis::setLabelsOrientation(LabelsOrientation orientation) +void QChartAxis::setLabelsAngle(int angle) { - m_labelsOrientation=orientation; + m_labelsAngle=angle; + emit update(this); } void QChartAxis::setShadesVisible(bool visible) { m_shadesVisible=visible; + emit update(this); } void QChartAxis::setShadesPen(const QPen& pen) { m_shadesPen=pen; + emit update(this); } void QChartAxis::setShadesBrush(const QBrush& brush) { m_shadesBrush=brush; + emit update(this); } void QChartAxis::setShadesOpacity(qreal opacity) { m_shadesOpacity=opacity; + emit update(this); } +void QChartAxis::setMin(qreal min) +{ + if(m_min!=min){ + m_min=min; + emit minChanged(m_min); + } +} + +void QChartAxis::setMax(qreal max) +{ + if(m_max!=max){ + m_max=max; + emit maxChanged(m_max); + } +} + +void QChartAxis::setRange(qreal min, qreal max) +{ + setMin(min); + setMax(max); +} + +void QChartAxis::setTicksCount(int count) +{ + m_ticksCount=count; + emit ticksChanged(this); +} + +void QChartAxis::addAxisTickLabel(qreal value,const QString& label) +{ + m_ticks.insert(value,label); + emit ticksChanged(this); +} + +void QChartAxis::removeAxisTickLabel(qreal value) +{ + m_ticks.remove(value); + emit ticksChanged(this); +} + +QString QChartAxis::axisTickLabel(qreal value) const +{ + return m_ticks.value(value); +} + +void QChartAxis::clearAxisTickLabels() +{ + m_ticks.clear(); + emit ticksChanged(this); +} + +#include "moc_qchartaxis.cpp" + QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/qchartaxis.h b/src/qchartaxis.h index 557bf36..addde7f 100644 --- a/src/qchartaxis.h +++ b/src/qchartaxis.h @@ -8,15 +8,14 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -class QTCOMMERCIALCHART_EXPORT QChartAxis +class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject { + Q_OBJECT public: - enum LabelsOrientation{ LabelsOrientationHorizontal, LabelsOrientationVertical , LabelsOrientationSlide }; + QChartAxis(QObject* parent =0); + ~QChartAxis(); - QChartAxis(); - virtual ~QChartAxis(); - - //axis + //axis handling bool isAxisVisible() const { return m_axisVisible;}; void setAxisVisible(bool visible); void setAxisPen(const QPen& pen); @@ -24,13 +23,13 @@ public: void setAxisBrush(const QBrush& brush); QBrush axisBrush() const { return m_axisBrush;}; - //grid + //grid handling bool isGridVisible() const { return m_gridVisible;}; void setGridVisible(bool visible); void setGridPen(const QPen& pen); QPen gridPen() const {return m_gridPen;} - //labels + //labels handling bool isLabelsVisible() const { return m_labelsVisible;}; void setLabelsVisible(bool visible); void setLabelsPen(const QPen& pen); @@ -39,10 +38,10 @@ public: QBrush labelsBrush() const { return m_labelsBrush;} void setLabelsFont(const QFont& font); QFont labelFont() const { return m_labelsFont;} - void setLabelsOrientation(LabelsOrientation orientation); - LabelsOrientation labelsOrientation() const { return m_labelsOrientation;}; + void setLabelsAngle(int angle); + int labelsAngle() const { return m_labelsAngle;}; - //shades + //shades handling bool isShadesVisible() const { return m_shadesVisible;}; void setShadesVisible(bool visible); void setShadesPen(const QPen& pen); @@ -52,10 +51,29 @@ public: void setShadesOpacity(qreal opacity); qreal shadesOpacity() const { return m_shadesOpacity;} - + //range handling + void setMin(qreal min); + qreal min() const { return m_min;}; + void setMax(qreal max); + qreal max() const { return m_max;}; + void setRange(qreal min, qreal max); + + //ticks handling + void setTicksCount(int count); + int ticksCount() const { return m_ticksCount;} + void addAxisTickLabel(qreal value,const QString& label); + void removeAxisTickLabel(qreal value); + QString axisTickLabel(qreal value) const ; + void clearAxisTickLabels(); + +signals: + void minChanged(qreal min); + void maxChanged(qreal max); +//private signal + void update(QChartAxis*); + void ticksChanged(QChartAxis*); private: - bool m_axisVisible; QPen m_axisPen; QBrush m_axisBrush; @@ -67,15 +85,18 @@ private: QPen m_labelsPen; QBrush m_labelsBrush; QFont m_labelsFont; + int m_labelsAngle; bool m_shadesVisible; QPen m_shadesPen; QBrush m_shadesBrush; - qreal m_shadesOpacity; + qreal m_min; + qreal m_max; - LabelsOrientation m_labelsOrientation; + int m_ticksCount; + QMap m_ticks; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/qchartview.cpp b/src/qchartview.cpp index a491fac..c0d439d 100644 --- a/src/qchartview.cpp +++ b/src/qchartview.cpp @@ -36,25 +36,19 @@ void QChartView::resizeEvent(QResizeEvent *event) QWidget::resizeEvent(event); } -void QChartView::addSeries(QChartSeries* series) +void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY) { - m_chart->addSeries(series); + m_chart->addSeries(series,axisY); } -QChartSeries* QChartView::createSeries(QChartSeries::QChartSeriesType type) +void QChartView::zoomIn() { - - return m_chart->createSeries(type); + m_chart->zoomIn(); } -void QChartView::zoomInToRect(const QRect& rectangle) +void QChartView::zoomIn(const QRect& rect) { - m_chart->zoomInToRect(rectangle); -} - -void QChartView::zoomIn() -{ - m_chart->zoomIn(); + m_chart->zoomIn(rect); } void QChartView::zoomOut() @@ -167,7 +161,7 @@ void QChartView::mouseReleaseEvent(QMouseEvent *event) if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { m_rubberBand->hide(); QRect rect = m_rubberBand->geometry(); - m_chart->zoomInToRect(rect); + m_chart->zoomIn(rect); event->accept(); } @@ -204,38 +198,14 @@ QChart::ChartTheme QChartView::chartTheme() const return m_chart->chartTheme(); } -void QChartView::setDefaultAxisX(const QChartAxis& axis) -{ - m_chart->setDefaultAxisX(axis); -} - -void QChartView::setDefaultAxisY(const QChartAxis& axis) +QChartAxis* QChartView::axisX() const { - m_chart->setDefaultAxisY(axis); + return m_chart->axisX(); } -QChartAxis QChartView::defaultAxisX() const +QChartAxis* QChartView::axisY() const { - return m_chart->defaultAxisX(); + return m_chart->axisY(); } -QChartAxis QChartView::defaultAxisY() const -{ - return m_chart->defaultAxisY(); -} - -int QChartView::addAxisY(const QChartAxis& axis) -{ - return m_chart->addAxisY(axis); -} - -QChartAxis QChartView::axisY(int id) const -{ - return m_chart->axisY(id); -} - -void QChartView::removeAxisY(int id) -{ - m_chart->removeAxisY(id); -} QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/qchartview.h b/src/qchartview.h index 85296ae..9541ccc 100644 --- a/src/qchartview.h +++ b/src/qchartview.h @@ -23,11 +23,9 @@ public: //implement from QWidget void resizeEvent(QResizeEvent *event); - - void addSeries(QChartSeries* series); // takes ownership - - // Convenience function - QChartSeries* createSeries(QChartSeries::QChartSeriesType type); + + void addSeries(QChartSeries* series,QChartAxis* axisY=0) ;// takes ownership + void removeSeries(QChartSeries* series); int margin() const; @@ -36,8 +34,8 @@ public: void setChartBackgroundBrush(const QBrush& brush); void setChartBackgroundPen(const QPen& pen); - void zoomInToRect(const QRect& rectangle); void zoomIn(); + void zoomIn(const QRect& rect); void zoomOut(); void setRubberBandPolicy(const RubberBandPolicy ); @@ -46,13 +44,8 @@ public: void setChartTheme(QChart::ChartTheme theme); QChart::ChartTheme chartTheme() const; - void setDefaultAxisX(const QChartAxis& axis); - void setDefaultAxisY(const QChartAxis& axis); - QChartAxis defaultAxisX() const; - QChartAxis defaultAxisY() const; - QChartAxis axisY(int id) const; - int addAxisY(const QChartAxis& axis); - void removeAxisY(int id); + QChartAxis* axisX() const; + QChartAxis* axisY() const; protected: void mousePressEvent(QMouseEvent *event);