diff --git a/src/QBarChart/QBarChart.pro b/src/QBarChart/QBarChart.pro deleted file mode 100644 index 6b49c66..0000000 --- a/src/QBarChart/QBarChart.pro +++ /dev/null @@ -1,30 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2012-01-11T15:40:15 -# -#------------------------------------------------- - -QT += core gui - -TARGET = QBarChart -TEMPLATE = app - - -SOURCES += main.cpp\ - widget.cpp \ - qbarchart.cpp \ - qbarchartcontrol.cpp \ - qbarchartmodel.cpp \ - qbarchartbar.cpp \ - qbarchartview.cpp \ - qbarchartgrid.cpp \ - qchartview.cpp - -HEADERS += widget.h \ - qbarchart.h \ - qbarchartcontrol.h \ - qbarchartmodel.h \ - qbarchartbar.h \ - qbarchartview.h \ - qbarchartgrid.h \ - qchartview.h diff --git a/src/QBarChart/main.cpp b/src/QBarChart/main.cpp deleted file mode 100644 index c0d5f93..0000000 --- a/src/QBarChart/main.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -//QGraphicsScene *scene, QWidget *parent = 0#include -//#include "widget.h" -//#include "qbarchart.h" -#include "qchartview.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - - QGraphicsScene scene; - //QGraphicsView view(&scene); - QChartView view(&scene); -/* - QBarChart *barChart = new QBarChart(); - barChart->setSize(640,480); - scene.addItem(barChart); - - QList data; - data << 1; - data << 1; - data << 2; - data << 3; - data << 5; - data << 8; - data << 13; - data << 21; - data << 42; - barChart->addSeries(data); -*/ - view.resize(640, 480); - QPalette p(view.palette()); - p.setColor(QPalette::Base, QColor(0,0,0)); - view.setPalette(p); - view.show(); - - return a.exec(); -} diff --git a/src/QBarChart/qbarchart.cpp b/src/QBarChart/qbarchart.cpp deleted file mode 100644 index bfa3b29..0000000 --- a/src/QBarChart/qbarchart.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include "qbarchart.h" -#include "qbarchartbar.h" -#include - -QBarChart::QBarChart(QGraphicsItem *parent) : - QGraphicsItem(parent) - ,mBarDefaultWidth( 1 ) -{ -} - -void QBarChart::addSeries(QList data) -{ - mData.clear(); - mData.append(data); - dataChanged(); -} - -void QBarChart::setSize( int h, int w ) -{ - mHeight = h; - mWidth = w; - dataChanged(); // TODO: separate data from grid -} - -void QBarChart::setBarWidth( int w ) -{ - mBarDefaultWidth = w; -} - -void QBarChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - qDebug() << "QBarChart::paint"; -} - -QRectF QBarChart::boundingRect() const -{ - return QRectF(0,0,mWidth,mHeight); // TODO: size from layout -} - - -void QBarChart::dataChanged() -{ - int count = mData.count(); - - if (count <= 0) { - // No items - return; - } - - mMax = mData.at(0); - mMin = mData.at(0); - - // Find out min and max values. - for (int i=0; i mMax) { - mMax = mData.at(i); - } else if (mData.at(i) < mMin) { - mMin = mData.at(i); - } - } - - // Create items for data, delete old ones - foreach (QGraphicsItem* i, childItems()) { - delete i; - } - - gridChanged(); - - int posStep = (mWidth / count) / 2; // TODO: Why I need magical 2 here to get correct step? - - for (int i=0; isetSize(barHeight, mBarDefaultWidth * 3 * i); // TODO: widht settable by style or something. - bar->setColor(QColor(255 - i*25, i*10, i*15)); - bar->setPos(i*posStep, 0); - childItems().append(bar); - } -} - -void QBarChart::gridChanged() -{ - // Scale of grid has changed - QBarChartGrid *grid = new QBarChartGrid(this); - grid->setSize(mHeight, mWidth); - grid->setLimits(mMin,mMax); - grid->setHorizontalLineCount(5); - childItems().append(grid); -} - diff --git a/src/QBarChart/qbarchart.h b/src/QBarChart/qbarchart.h deleted file mode 100644 index 092bc9f..0000000 --- a/src/QBarChart/qbarchart.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef QBARCHART_H -#define QBARCHART_H - -#include - -#include "qbarchartbar.h" -#include "qbarchartcontrol.h" -#include "qbarchartview.h" -#include "qbarchartgrid.h" - -class QBarChart : public QGraphicsItem -{ - -public: - explicit QBarChart(QGraphicsItem *parent = 0); - - // Data "api" - void addSeries(QList data); // TODO: maybe some better structure - - // Layout "api" - void setSize( int h, int w ); - void setPos(qreal x, qreal y); - void setBarWidth( int w ); - - // From QGraphicsItem - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - QRectF boundingRect() const; - -private: - - void dataChanged(); - void gridChanged(); - -private: - - // Data - QList mData; // use ints for now.. - int mMin; // Min and max values of data. (updated when data is changed, used when drawing) - int mMax; - - // View components - QList mItems; // 2 first items in list are x and y axis, in that order - QBarChartGrid *mGrid; - - int mHeight; // Layout spesific - int mWidth; - int mBarDefaultWidth; - - // Controll stuff - QBarChartControl mBarControl; - - - -}; - -#endif // QBARCHART_H diff --git a/src/QBarChart/qbarchartcontrol.cpp b/src/QBarChart/qbarchartcontrol.cpp deleted file mode 100644 index b110f74..0000000 --- a/src/QBarChart/qbarchartcontrol.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "qbarchartcontrol.h" - -QBarChartControl::QBarChartControl(QObject *parent) : - QObject(parent) -{ -} diff --git a/src/QBarChart/qbarchartcontrol.h b/src/QBarChart/qbarchartcontrol.h deleted file mode 100644 index ea7ca8a..0000000 --- a/src/QBarChart/qbarchartcontrol.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef QBARCHARTCONTROL_H -#define QBARCHARTCONTROL_H - -#include - -class QBarChartControl : public QObject -{ - Q_OBJECT -public: - explicit QBarChartControl(QObject *parent = 0); - -signals: - -public slots: - -}; - -#endif // QBARCHARTCONTROL_H diff --git a/src/QBarChart/qbarchartgrid.cpp b/src/QBarChart/qbarchartgrid.cpp deleted file mode 100644 index 6be2801..0000000 --- a/src/QBarChart/qbarchartgrid.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "qbarchartgrid.h" -#include -#include - -QBarChartGrid::QBarChartGrid(QGraphicsItem *parent) : - QGraphicsItem(parent) -{ -} - - -void QBarChartGrid::setLimits( int min, int max ) -{ - mMin = min; - mMax = max; -} - -void QBarChartGrid::setHorizontalLineCount(int count) -{ - mHorizontalLineCount = count; -} - -void QBarChartGrid::setSize( int h, int w ) -{ - mHeight = h; - mWidth = w; -} - -void QBarChartGrid::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - qDebug() << "QBarChartGrid::paint w =" << mWidth << "h =" << mHeight; - - QPen p = painter->pen(); - p.setColor( QColor(0,255,0) ); - p.setWidth( 1 ); - painter->setPen(p); - - // Draw horizontal lines - if ( mHorizontalLineCount >0 ) { - int step = mHeight / mHorizontalLineCount; - if (step > 0) { - for (int y=0; ydrawLine(0,y,mWidth,y); - } - } - } -} - -QRectF QBarChartGrid::boundingRect() const -{ - QRectF r(scenePos().x(), scenePos().y(), scenePos().x() + mWidth, scenePos().y() + mHeight ); - return r; -} diff --git a/src/QBarChart/qbarchartgrid.h b/src/QBarChart/qbarchartgrid.h deleted file mode 100644 index 29becc2..0000000 --- a/src/QBarChart/qbarchartgrid.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef QBARCHARTGRID_H -#define QBARCHARTGRID_H - -#include - -class QBarChartGrid : public QGraphicsItem -{ - -public: - QBarChartGrid(QGraphicsItem *parent = 0); - - // Data api: - void setLimits( int min, int max ); - void setHorizontalLineCount( int count ); - - // Layout api: - void setSize( int h, int w ); - - // From QGraphicsItem - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - QRectF boundingRect() const; - -private: - - int mWidth; - int mHeight; - - int mMin; - int mMax; - int mHorizontalLineCount; // Draw this many horizontal lines to grid -}; - -#endif // QBARCHARTGRID_H diff --git a/src/QBarChart/qbarchartmodel.cpp b/src/QBarChart/qbarchartmodel.cpp deleted file mode 100644 index 5f72e83..0000000 --- a/src/QBarChart/qbarchartmodel.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "qbarchartmodel.h" - -QBarChartModel::QBarChartModel(QObject *parent) : - QAbstractItemModel(parent) -{ -} diff --git a/src/QBarChart/qbarchartmodel.h b/src/QBarChart/qbarchartmodel.h deleted file mode 100644 index ff86ca5..0000000 --- a/src/QBarChart/qbarchartmodel.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef QBARCHARTMODEL_H -#define QBARCHARTMODEL_H - -#include - -class QBarChartModel : public QAbstractItemModel -{ - Q_OBJECT -public: - explicit QBarChartModel(QObject *parent = 0); - -signals: - -public slots: - -}; - -#endif // QBARCHARTMODEL_H diff --git a/src/QBarChart/qbarchartview.cpp b/src/QBarChart/qbarchartview.cpp deleted file mode 100644 index 5e7c247..0000000 --- a/src/QBarChart/qbarchartview.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "qbarchartview.h" - -QBarChartView::QBarChartView() -{ -} diff --git a/src/QBarChart/qbarchartview.h b/src/QBarChart/qbarchartview.h deleted file mode 100644 index 9b4b2e6..0000000 --- a/src/QBarChart/qbarchartview.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef QBARCHARTVIEW_H -#define QBARCHARTVIEW_H - -class QBarChartView -{ -public: - QBarChartView(); -}; - -#endif // QBARCHARTVIEW_H diff --git a/src/QBarChart/qbarchartxaxis.cpp b/src/QBarChart/qbarchartxaxis.cpp deleted file mode 100644 index f9ac174..0000000 --- a/src/QBarChart/qbarchartxaxis.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "qbarchartxaxis.h" - -QBarChartXAxis::QBarChartXAxis(QGraphicsItem *parent) : - QGraphicsItem(parent) -{ -} - - -void QBarChartXAxis::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - -} - -QRectF QBarChartXAxis::boundingRect() const -{ - QRectF r(scenePos().x(), scenePos().y(), scenePos().x() + mWidth, scenePos().y() + mHeight ); - return r; -} diff --git a/src/QBarChart/qbarchartxaxis.h b/src/QBarChart/qbarchartxaxis.h deleted file mode 100644 index 07d50f5..0000000 --- a/src/QBarChart/qbarchartxaxis.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef QBARCHARTXAXIS_H -#define QBARCHARTXAXIS_H - -#include - -class QBarChartXAxis : public QGraphicsItem -{ - -public: - QBarChartXAxis(QGraphicsItem *parent = 0); - - // From QGraphicsItem - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - QRectF boundingRect() const; - -private: - - int mWidth; - int mHeight; -}; - -#endif // QBARCHARTXAXIS_H diff --git a/src/QBarChart/qchartview.cpp b/src/QBarChart/qchartview.cpp deleted file mode 100644 index 4019cf2..0000000 --- a/src/QBarChart/qchartview.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "qchartview.h" -#include "qbarchart.h" -#include - -QChartView::QChartView(QGraphicsScene *scene, QWidget *parent ) : - QGraphicsView(scene,parent) -{ - mChart = new QBarChart(); - mChart->setSize(640,480); - scene->addItem(mChart); - - QList data; - data << 1; - data << 1; - data << 2; - data << 3; - data << 5; - data << 8; - data << 13; - data << 21; - data << 42; - mChart->addSeries(data); - -} - - -void QChartView::resizeEvent(QResizeEvent *event) -{ - mChart->setSize(event->size().height(), event->size().width()); -} diff --git a/src/QBarChart/qchartview.h b/src/QBarChart/qchartview.h deleted file mode 100644 index 624fc0c..0000000 --- a/src/QBarChart/qchartview.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef QCHARTVIEW_H -#define QCHARTVIEW_H - -#include -#include "qbarchart.h" - -class QChartView : public QGraphicsView -{ - Q_OBJECT -public: - explicit QChartView(QGraphicsScene *scene, QWidget *parent = 0); - -signals: - -public slots: - -protected: - void resizeEvent(QResizeEvent *event); - -private: - - QBarChart *mChart; -}; - -#endif // QCHARTVIEW_H diff --git a/src/QBarChart/widget.cpp b/src/QBarChart/widget.cpp deleted file mode 100644 index d594626..0000000 --- a/src/QBarChart/widget.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "widget.h" - -Widget::Widget(QWidget *parent) - : QWidget(parent) -{ -} - -Widget::~Widget() -{ - -} diff --git a/src/QBarChart/widget.h b/src/QBarChart/widget.h deleted file mode 100644 index 41c3a9d..0000000 --- a/src/QBarChart/widget.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef WIDGET_H -#define WIDGET_H - -#include - -class Widget : public QWidget -{ - Q_OBJECT - -public: - Widget(QWidget *parent = 0); - ~Widget(); -}; - -#endif // WIDGET_H diff --git a/src/QBarChart/qbarchartbar.cpp b/src/barchart/bar.cpp similarity index 54% rename from src/QBarChart/qbarchartbar.cpp rename to src/barchart/bar.cpp index 5336667..b153872 100644 --- a/src/QBarChart/qbarchartbar.cpp +++ b/src/barchart/bar.cpp @@ -1,26 +1,32 @@ -#include "qbarchartbar.h" +#include "bar.h" #include #include -QBarChartBar::QBarChartBar(QGraphicsItem *parent) +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +Bar::Bar(QGraphicsItem *parent) : QGraphicsItem(parent) { } -void QBarChartBar::setSize( int h, int w ) +void Bar::resize( int w, int h ) { - mHeight = h; mWidth = w; + mHeight = h; } -void QBarChartBar::setColor( QColor col ) +void Bar::setColor( QColor col ) { mColor = col; } +void Bar::setPos(qreal x, qreal y) +{ + mXpos = x; + mYpos = y; +} -void QBarChartBar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - qDebug() << "QBarChartBar::paint" << scenePos(); // Set color for bar. TODO: gradients, textures etc QPen pen = painter->pen(); pen.setColor( mColor ); @@ -28,12 +34,17 @@ void QBarChartBar::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti painter->setPen(pen); // Draw bar - painter->drawLine(scenePos().x(), scenePos().y() + parentItem()->boundingRect().height(), - scenePos().x(), scenePos().y() + parentItem()->boundingRect().height() - mHeight ); + // TODO: Pen width affects bar height for now. This should be rect + painter->drawLine(scenePos().x() + mXpos, scenePos().y() + mYpos + parentItem()->boundingRect().height() - mHeight - mWidth, + scenePos().x() + mXpos, scenePos().y() + mYpos + parentItem()->boundingRect().height() - mWidth); } -QRectF QBarChartBar::boundingRect() const +QRectF Bar::boundingRect() const { - QRectF r(scenePos().x(), scenePos().y(), scenePos().x() + mWidth, scenePos().y() + mHeight ); + // TODO: check validity of this (I suppose there is easier way, and currently this bit incorrect :) +// QRectF r(scenePos().x()+mXpos, scenePos().y()+mYpos, scenePos().x() + mWidth, scenePos().y() + mHeight ); + QRectF r(mXpos, mYpos, mXpos + mWidth, mYpos + mHeight); return r; } + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/QBarChart/qbarchartbar.h b/src/barchart/bar.h similarity index 58% rename from src/QBarChart/qbarchartbar.h rename to src/barchart/bar.h index 7d75eaa..a1352a0 100644 --- a/src/QBarChart/qbarchartbar.h +++ b/src/barchart/bar.h @@ -1,18 +1,21 @@ -#ifndef QBARCHARTBAR_H -#define QBARCHARTBAR_H +#ifndef BAR_H +#define BAR_H #include +#include "qchartglobal.h" -// Single bar item of chart +QTCOMMERCIALCHART_BEGIN_NAMESPACE -class QBarChartBar : public QGraphicsItem +// Single bar item of chart +class Bar : public QGraphicsItem { public: - QBarChartBar(QGraphicsItem *parent=0); + Bar(QGraphicsItem *parent=0); // Layout Stuff - void setSize( int h, int w ); // Size of bar. in screen coordinates. - void setColor( QColor col ); // Color of bar + void resize( int w, int h ); // Size of bar. in screen coordinates. + void setColor( QColor col ); // Color of bar + void setPos(qreal x, qreal y); public: // From QGraphicsItem @@ -24,8 +27,11 @@ private: int mHeight; int mWidth; - QPointF mPos; + qreal mXpos; + qreal mYpos; QColor mColor; }; -#endif // QBARCHARTBAR_H +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // BAR_H diff --git a/src/barchart/barchartseries.cpp b/src/barchart/barchartseries.cpp new file mode 100644 index 0000000..d57e179 --- /dev/null +++ b/src/barchart/barchartseries.cpp @@ -0,0 +1,46 @@ +#include "barchartseries.h" +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +BarChartSeries::BarChartSeries(QList data, QObject *parent) + : QChartSeries(parent) + , mData(data) +{ +} + +int BarChartSeries::min() +{ + // TODO: make min and max members and update them when data changes. + // This is slower since they are checked every time, even if data is same since previous call. + int min = mData.at(0); + + for (int i=0; i max) { + max = mData.at(i); + } + } + return max; +} + +int BarChartSeries::count() +{ + return mData.count(); +} + +int BarChartSeries::valueAt(int i) +{ + return mData.at(i); +} + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/barchartseries.h b/src/barchart/barchartseries.h new file mode 100644 index 0000000..7ba8d1c --- /dev/null +++ b/src/barchart/barchartseries.h @@ -0,0 +1,34 @@ +#ifndef BARCHARTSERIES_H +#define BARCHARTSERIES_H + +#include +#include "qchartseries.h" +#include "qchartglobal.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +// Container for series +class QTCOMMERCIALCHART_EXPORT BarChartSeries : public QChartSeries +{ + +public: + BarChartSeries(QList data, QObject* parent=0); + + // from QChartSeries + static QChartSeries* create(QObject* parent = 0 ); + virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; } + + // Methods to find out minimum and maximum values of data + int min(); + int max(); + int count(); + int valueAt(int i); + +private: + + QList mData; +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // BARCHARTSERIES_H diff --git a/src/barchart/bargroup.cpp b/src/barchart/bargroup.cpp new file mode 100644 index 0000000..9e50cf8 --- /dev/null +++ b/src/barchart/bargroup.cpp @@ -0,0 +1,106 @@ +#include "bargroup.h" +#include "bar.h" +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) : + QGraphicsItem(parent) + ,mSeries(series) + ,mLayoutSet(false) + ,mLayoutDirty(true) +{ + dataChanged(); +} + +void BarGroup::resize( int w, int h ) +{ + qDebug() << "QBarChart::resize"; + mWidth = w; + mHeight = h; + layoutChanged(); + mLayoutSet = true; +} + +void BarGroup::setBarWidth( int w ) +{ + mBarDefaultWidth = w; +} + +void BarGroup::setColor( QColor color ) +{ + mColor = color; +} + +void BarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + if (!mLayoutSet) { + qDebug() << "QBarChart::paint called without layout set. Aborting."; + return; + } + if (mLayoutDirty) { + // Layout or data has changed. Need to redraw. + foreach(QGraphicsItem* i, childItems()) { + i->paint(painter,option,widget); + } + } +} + +QRectF BarGroup::boundingRect() const +{ + // TODO: correct this (currently ignores position) + return QRectF(0,0,mWidth,mHeight); +} + + +void BarGroup::dataChanged() +{ + qDebug() << "QBarChart::dataChanged mSeries"; + + // Find out maximum and minimum of all series + mMax = mSeries.max(); + mMin = mSeries.min(); + + // Delete old bars + // Is this correct way to delete childItems? + foreach (QGraphicsItem* item, childItems()) { + delete item; + } + + // Create new graphic items for bars + for (int i=0; i (childItems().at(i)); + + bar->resize(mBarDefaultWidth, barHeight); // TODO: width settable per bar + bar->setColor(mColor); + bar->setPos(i*posStep+startPos, 0); + } + mLayoutDirty = true; +} + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/bargroup.h b/src/barchart/bargroup.h new file mode 100644 index 0000000..85d0a19 --- /dev/null +++ b/src/barchart/bargroup.h @@ -0,0 +1,55 @@ +#ifndef QBARCHART_H +#define QBARCHART_H + +#include + +#include "bar.h" +//#include "qbarchartview.h" +#include "barchartseries.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +// TODO: Better name for this? The function of this class is to know where each bar in series is laid out. +// Class has knowledge of single series of data (owns vs reference?) +class BarGroup : public QGraphicsItem +{ + +public: + explicit BarGroup(BarChartSeries& series, QGraphicsItem *parent = 0); + + // Layout "api" + void resize( int w, int h ); // Size for whole series. Single bars are drawn inside this area + void setPos(qreal x, qreal y); + void setBarWidth( int w ); // Default width for each bar + void setColor( QColor color ); // Default color for each bar + + // From QGraphicsItem + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + QRectF boundingRect() const; + +private: + + void dataChanged(); // data of series has changed -> need to recalculate bar sizes + void layoutChanged(); // layout has changed -> need to recalculate bar sizes + +private: + + // Data + BarChartSeries& mSeries; + int mMin; // Min and max values of data. (updated when data is changed, used when drawing) + int mMax; + + int mHeight; // Layout spesific + int mWidth; + int mBarDefaultWidth; + + QColor mColor; + + bool mLayoutSet; // True, if component has been laid out. + bool mLayoutDirty; + +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QBARCHART_H diff --git a/src/qchart.cpp b/src/qchart.cpp index e70fe95..1e69918 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -4,6 +4,10 @@ #include "qscatterseries_p.h" #include "qpieseries.h" #include "qxychartseries.h" + +#include "barchartseries.h" +#include "bargroup.h" + #include "xylinechartitem_p.h" #include "xyplotdomain_p.h" #include "axis_p.h" @@ -74,6 +78,18 @@ void QChart::addSeries(QChartSeries* series) // } // break; // } + + case QChartSeries::SeriesTypeBar: { + + qDebug() << "barSeries added"; + BarChartSeries* barSeries = static_cast(series); + + // Who owns the series? + BarGroup* group = new BarGroup(*barSeries, this); + scene()->addItem(group); + m_BarGroupItems.append(group); // If we need to access group later + break; + } } } diff --git a/src/qchart.h b/src/qchart.h index cea8f0d..975b9d3 100644 --- a/src/qchart.h +++ b/src/qchart.h @@ -12,6 +12,7 @@ class XYGrid; class QChartSeries; class XYPlotDomain; class XYLineChartItem; +class BarGroup; // TODO: We don't need to have QChart tied to QGraphicsItem: //class QTCOMMERCIALCHART_EXPORT QChart @@ -57,6 +58,8 @@ private: QList m_items; int m_plotDataIndex; int m_marginSize; + + QList m_BarGroupItems; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/qchartseries.h b/src/qchartseries.h index 54d5d54..f16dd45 100644 --- a/src/qchartseries.h +++ b/src/qchartseries.h @@ -13,7 +13,7 @@ public: enum QChartSeriesType { SeriesTypeLine = 0, // SeriesTypeArea, -// SeriesTypeBar, + SeriesTypeBar, SeriesTypePie, SeriesTypeScatter // SeriesTypeSpline diff --git a/src/qchartwidget.h b/src/qchartwidget.h index 92f6b6d..f9af9fd 100644 --- a/src/qchartwidget.h +++ b/src/qchartwidget.h @@ -24,6 +24,7 @@ public: QSize sizeHint() const; // TODO: addSeries and createSeries are optional solutions + // TODO: currently createSeries assumes x, y value pairs. This isn't case with all charts. So is there another createSeries for other types (for example one list of ints)? void addSeries(QChartSeries* series); QChartSeries* createSeries(QList x, QList y, QChartSeries::QChartSeriesType type); diff --git a/src/src.pro b/src/src.pro index e597449..f9b78f4 100644 --- a/src/src.pro +++ b/src/src.pro @@ -11,7 +11,10 @@ QT += core \ CONFIG += debug_and_release CONFIG(debug, debug|release):TARGET = QtCommercialChartd -SOURCES += \ +SOURCES += \ + barchart/barchartseries.cpp \ + barchart/bargroup.cpp \ + barchart/bar.cpp \ xylinechart/qxychartseries.cpp \ xylinechart/xylinechartitem.cpp \ xylinechart/xygrid.cpp \ @@ -38,12 +41,15 @@ PUBLIC_HEADERS += \ qchart.h \ qchartwidget.h \ qchartglobal.h \ - xylinechart/qxychartseries.h - + xylinechart/qxychartseries.h \ + barchart/barchartseries.h \ + barchart/bargroup.h + HEADERS += $$PUBLIC_HEADERS HEADERS += $$PRIVATE_HEADERS INCLUDEPATH += xylinechart \ + barchart \ . OBJECTS_DIR = $$CHART_BUILD_DIR/lib