1 //  This file is part of Qt Bitcoin Trader
2 //      https://github.com/JulyIGHOR/QtBitcoinTrader
3 //  Copyright (C) 2013-2021 July Ighor <julyighor@gmail.com>
4 //
5 //  This program is free software: you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation, either version 3 of the License, or
8 //  (at your option) any later version.
9 //
10 //  In addition, as a special exception, the copyright holders give
11 //  permission to link the code of portions of this program with the
12 //  OpenSSL library under certain conditions as described in each
13 //  individual source file, and distribute linked combinations including
14 //  the two.
15 //
16 //  You must obey the GNU General Public License in all respects for all
17 //  of the code used other than OpenSSL. If you modify file(s) with this
18 //  exception, you may extend this exception to your version of the
19 //  file(s), but you are not obligated to do so. If you do not wish to do
20 //  so, delete this exception statement from your version. If you delete
21 //  this exception statement from all source files in the program, then
22 //  also delete it here.
23 //
24 //  This program is distributed in the hope that it will be useful,
25 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
26 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 //  GNU General Public License for more details.
28 //
29 //  You should have received a copy of the GNU General Public License
30 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31 
32 #ifndef ORDERSMODEL_H
33 #define ORDERSMODEL_H
34 
35 #include <QAbstractItemModel>
36 #include <QStringList>
37 #include "orderitem.h"
38 
39 class OrdersModel : public QAbstractItemModel
40 {
41     Q_OBJECT
42 
43 public:
44     int getAsksCount() const;
45     int getRowNum(int row);
46     QByteArray getRowOid(int row);
47     quint32 getRowDate(int row);
48     int getRowType(int row);
49     int getRowStatus(int row);
50     double getRowPrice(int row);
51     double getRowVolume(int row);
52     double getRowTotal(int row);
53 
54     QMap<double, bool> currentAsksPrices;
55     QMap<double, bool> currentBidsPrices;
56 
57     bool checkDuplicatedOID;
58     void ordersCancelAll(const QString& pair = 0);
59     void ordersCancelBids(const QString& pair = 0);
60     void ordersCancelAsks(const QString& pair = 0);
61     void setOrderCanceled(QByteArray);
62 
63     void filterSymbolChanged(const QString& filterSymbol = "");
64 
65     void clear();
66 
67     OrdersModel();
68     ~OrdersModel();
69 
70     void orderBookChanged(QList<OrderItem>* ordersRcv);
71 
72     void setHorizontalHeaderLabels(QStringList list);
73 
74     QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
75     QModelIndex parent(const QModelIndex& index) const;
76 
77     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
78     Qt::ItemFlags flags(const QModelIndex& index) const;
79     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
80 
81     int rowCount(const QModelIndex& parent = QModelIndex()) const;
82     int columnCount(const QModelIndex& parent = QModelIndex()) const;
83 
84     QList<OrderItem> orders;
85 
86 signals:
87     void cancelOrder(const QString&, const QByteArray&);
88     void ordersIsAvailable();
89     void volumeAmountChanged(double, double);
90 
91 private:
92     void ordersCountChanged();
93     void ordersAsksCountChanged();
94     void ordersBidsCountChanged();
95 
96     int lastOrdersCount;
97     int lastAsksCount;
98     int lastBidsCount;
99 
100     int asksCount;
101 
102     QHash<QByteArray, quint32> oidMapForCheckingDuplicates;
103     QStringList textStatusList;
104     QString textAsk;
105     QString textBid;
106 
107     bool haveOrders;
108 
109     int countWidth;
110     int columnsCount;
111     int dateWidth;
112     int typeWidth;
113     int statusWidth;
114 
115     QStringList headerLabels;
116 
117     QList<QByteArray> oidList;
118 
119     QList<quint32> dateList;
120     QStringList dateStrList;
121 
122     QList<bool> typesList;
123 
124     QList<int> statusList;
125 
126     QList<double> amountList;
127     QStringList amountStrList;
128 
129     QList<double> priceList;
130     QStringList priceStrList;
131 
132     QList<double> totalList;
133     QStringList totalStrList;
134 
135     QStringList symbolList;
136 };
137 
138 #endif // ORDERSMODEL_H
139