aboutsummaryrefslogtreecommitdiffstats
path: root/examples/declarative/canvas/stockchart/model.h
diff options
context:
space:
mode:
Diffstat (limited to 'examples/declarative/canvas/stockchart/model.h')
-rw-r--r--examples/declarative/canvas/stockchart/model.h58
1 files changed, 48 insertions, 10 deletions
diff --git a/examples/declarative/canvas/stockchart/model.h b/examples/declarative/canvas/stockchart/model.h
index fde99de223..c7a0235021 100644
--- a/examples/declarative/canvas/stockchart/model.h
+++ b/examples/declarative/canvas/stockchart/model.h
@@ -40,16 +40,54 @@
#include <QtCore/QAbstractListModel>
#include <QtCore/QDate>
-struct StockPrice
+class StockPrice : public QObject
{
- QDate date;
- qreal openPrice;
- qreal closePrice;
- qreal highPrice;
- qreal lowPrice;
- qint32 volume;
- qreal adjustedPrice;
+ Q_OBJECT
+ Q_PROPERTY(QDate date READ date)
+ Q_PROPERTY(qreal openPrice READ openPrice)
+ Q_PROPERTY(qreal closePrice READ closePrice)
+ Q_PROPERTY(qreal highPrice READ highPrice)
+ Q_PROPERTY(qreal lowPrice READ lowPrice)
+ Q_PROPERTY(qint32 volume READ volume)
+ Q_PROPERTY(qreal adjustedPrice READ adjustedPrice)
+public:
+
+ StockPrice(QObject *parent = 0)
+ : QObject(parent)
+ , _openPrice(-1)
+ , _closePrice(-1)
+ , _highPrice(-1)
+ , _lowPrice(-1)
+ , _volume(-1)
+ , _adjustedPrice(-1)
+ {
+ }
+ QDate date() const {return _date;}
+ qreal openPrice() const {return _openPrice; }
+ qreal closePrice() const {return _closePrice;}
+ qreal highPrice() const {return _highPrice;}
+ qreal lowPrice() const{return _lowPrice;}
+ qreal adjustedPrice() const{return _adjustedPrice;}
+ qint32 volume() const{return _volume;}
+
+ void setDate(const QDate& date){_date = date;}
+ void setOpenPrice(qreal price){_openPrice = price;}
+ void setClosePrice(qreal price){_closePrice = price;}
+ void setHighPrice(qreal price){_highPrice = price;}
+ void setLowPrice(qreal price){_lowPrice = price;}
+ void setAdjustedPrice(qreal price) {_adjustedPrice = price;}
+ void setVolume(qint32 volume) {_volume = volume;}
+
+private:
+ QDate _date;
+ qreal _openPrice;
+ qreal _closePrice;
+ qreal _highPrice;
+ qreal _lowPrice;
+ qint32 _volume;
+ qreal _adjustedPrice;
};
+
class QNetworkReply;
class QNetworkAccessManager;
class StockModel : public QAbstractListModel
@@ -107,13 +145,13 @@ signals:
public slots:
void requestData();
-
+ StockPrice* stockPriceAtIndex(int idx) const;
private slots:
void doRequest();
void update(QNetworkReply* reply);
private:
QString dataCycleString() const;
- QList<StockPrice> _prices;
+ QList<StockPrice*> _prices;
QString _stockName;
QDate _startDate;
QDate _endDate;