1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the examples of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
40 #include <QtCore/QAbstractListModel>
41 #include <QtCore/QDate>
43 class StockPrice : public QObject
46 Q_PROPERTY(QDate date READ date)
47 Q_PROPERTY(qreal openPrice READ openPrice)
48 Q_PROPERTY(qreal closePrice READ closePrice)
49 Q_PROPERTY(qreal highPrice READ highPrice)
50 Q_PROPERTY(qreal lowPrice READ lowPrice)
51 Q_PROPERTY(qint32 volume READ volume)
52 Q_PROPERTY(qreal adjustedPrice READ adjustedPrice)
55 StockPrice(QObject *parent = 0)
65 QDate date() const {return _date;}
66 qreal openPrice() const {return _openPrice; }
67 qreal closePrice() const {return _closePrice;}
68 qreal highPrice() const {return _highPrice;}
69 qreal lowPrice() const{return _lowPrice;}
70 qreal adjustedPrice() const{return _adjustedPrice;}
71 qint32 volume() const{return _volume;}
73 void setDate(const QDate& date){_date = date;}
74 void setOpenPrice(qreal price){_openPrice = price;}
75 void setClosePrice(qreal price){_closePrice = price;}
76 void setHighPrice(qreal price){_highPrice = price;}
77 void setLowPrice(qreal price){_lowPrice = price;}
78 void setAdjustedPrice(qreal price) {_adjustedPrice = price;}
79 void setVolume(qint32 volume) {_volume = volume;}
92 class QNetworkAccessManager;
93 class StockModel : public QAbstractListModel
97 Q_PROPERTY(QString stockName READ stockName WRITE setStockName NOTIFY stockNameChanged)
98 Q_PROPERTY(QDate startDate READ startDate WRITE setStartDate NOTIFY startDateChanged)
99 Q_PROPERTY(QDate endDate READ endDate WRITE setEndDate NOTIFY endDateChanged)
100 Q_PROPERTY(StockDataCycle dataCycle READ dataCycle WRITE setDataCycle NOTIFY dataCycleChanged)
102 Q_ENUMS(StockDataCycle)
104 enum StockDataCycle {
111 enum StockModelRoles {
112 DateRole = Qt::UserRole + 1,
122 StockModel(QObject *parent = 0);
124 QString stockName() const;
125 void setStockName(const QString& name);
127 QDate startDate() const;
128 void setStartDate(const QDate& date);
130 QDate endDate() const;
131 void setEndDate(const QDate& date);
133 StockDataCycle dataCycle() const;
134 void setDataCycle(StockDataCycle cycle);
136 int rowCount(const QModelIndex & parent = QModelIndex()) const;
138 QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
141 void stockNameChanged();
142 void startDateChanged();
143 void endDateChanged();
144 void dataCycleChanged();
148 StockPrice* stockPriceAtIndex(int idx) const;
151 void update(QNetworkReply* reply);
153 QString dataCycleString() const;
154 QList<StockPrice*> _prices;
158 StockDataCycle _dataCycle;
159 QNetworkAccessManager* _manager;