Skip to content
Snippets Groups Projects
Commit da381f49 authored by Evgenii Tagiltsev's avatar Evgenii Tagiltsev
Browse files

[*] fixed last actions widget

parent 1a913cd8
No related branches found
No related tags found
1 merge request!38Features 2607
Pipeline #1260 passed with stage
in 22 minutes
......@@ -3,7 +3,7 @@
DapChainWalletModel::DapChainWalletModel(QObject *parent)
: QAbstractListModel(parent)
{
m_currentWallet = "private";
}
DapChainWalletModel& DapChainWalletModel::instance()
......@@ -24,12 +24,12 @@ QVariant DapChainWalletModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) return QVariant();
switch (role) {
case WalletListDisplayRole: return walletList();
case WalletNameDisplayRole: return m_walletList[index.row()].first.Name;
case WalletAddressDisplayRole: return m_walletList[index.row()].first.Address;
case WalletIconDisplayRole: return m_walletList[index.row()].first.IconPath;
case NetworkDisplayRole: return m_walletList[index.row()].first.Network;
case WalletTokenListDisplayRole:
qDebug() << "search item list by address" << m_walletList[index.row()].first.Address;
return QVariant::fromValue<QList<QObject*>>(tokeListByIndex(index.row()));
default: break;
}
......@@ -45,23 +45,28 @@ QHash<int, QByteArray> DapChainWalletModel::roleNames() const
roles[WalletIconDisplayRole] = "walletIconDisplayRole";
roles[WalletTokenListDisplayRole] = "walletTokenListDisplayRole";
roles[NetworkDisplayRole] = "networkDisplayRole";
roles[WalletListDisplayRole] = "walletListDisplayRole";
return roles;
}
double DapChainWalletModel::walletBalance(const QString& aAddress) const
QStringList DapChainWalletModel::walletList() const
{
return m_wallets;
}
double DapChainWalletModel::walletBalance(const QString& aName) const
{
double balance = 0.0;
for(int i = 0; i < m_walletList.count(); i++)
{
if(m_walletList[i].first.Address == aAddress)
if(m_walletList[i].first.Name == aName || aName == TITLE_ALL_WALLETS)
{
DapChainWalletTokenItemList tokenList = m_walletList[i].second;
for(int m = 0; m < tokenList.count(); m++)
{
balance += tokenList[i]->balance();
balance += tokenList[m]->balance();
}
break;
}
}
......@@ -108,39 +113,12 @@ QList<QObject*> DapChainWalletModel::tokeListByIndex(const int aIndex) const
return tokenList;
}
double DapChainWalletModel::walletBalance() const
{
return m_walletBalance;
}
QList<QObject*> DapChainWalletModel::tokenList() const
{
return m_tokenList;
}
void DapChainWalletModel::setCurrentWallet(const QString& aWalletAddress)
{
if(aWalletAddress == m_currentWallet) return;
beginResetModel();
m_currentWallet = aWalletAddress;
m_walletBalance = walletBalance(aWalletAddress);
m_tokenList = tokeListByWallet(aWalletAddress);
endResetModel();
emit walletBalanceChanged(m_walletBalance);
emit tokenListChanged(m_tokenList);
}
void DapChainWalletModel::setCurrentWallet(const int aWalletIndex)
{
QString address = m_walletList[aWalletIndex].first.Address;
setCurrentWallet(address);
}
void DapChainWalletModel::setWalletData(const QByteArray& aData)
{
beginResetModel();
// m_walletList.clear();
m_walletList.clear();
m_wallets.clear();
m_wallets << TITLE_ALL_WALLETS;
QList<QPair<DapChainWalletData, QList<DapChainWalletTokenData>>> walletData;
QDataStream in(aData);
in >> walletData;
......@@ -149,19 +127,18 @@ void DapChainWalletModel::setWalletData(const QByteArray& aData)
{
DapChainWalletPair walletPair(walletData[i].first, DapChainWalletTokenItemList());
QList<DapChainWalletTokenData> tokeData = walletData[i].second;
if(!m_wallets.contains(walletData[i].first.Name))
m_wallets.append(walletData[i].first.Name);
for(int m = 0; m < tokeData.count(); m++)
{
qDebug() << "network: " << walletPair.first.Network;
walletPair.second.append(new DapChainWalletTokenItem(walletData[i].first.Address, tokeData[m], this));
qDebug() << "wallet: " << walletPair.first.Name << walletPair.first.Address;
qDebug() << "token: " << walletPair.second.last()->name() << walletPair.second.last()->balance();
qDebug() << "-----------------------";
}
m_walletList.append(walletPair);
}
emit walletListChanged(m_wallets);
endResetModel();
}
......
......@@ -5,12 +5,12 @@
#include <QDebug>
#include "DapChainWallet.h"
#define TITLE_ALL_WALLETS tr("all wallets")
class DapChainWalletModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(double walletBalance READ walletBalance NOTIFY walletBalanceChanged)
Q_PROPERTY(QList<QObject*> tokenList READ tokenList NOTIFY tokenListChanged)
Q_PROPERTY(QStringList wallets READ walletList NOTIFY walletListChanged)
public:
enum {
......@@ -18,14 +18,14 @@ public:
WalletAddressDisplayRole,
WalletIconDisplayRole,
WalletTokenListDisplayRole,
WalletListDisplayRole,
NetworkDisplayRole,
};
private:
QString m_currentWallet;
double m_walletBalance;
QStringList m_wallets;
QList<DapChainWalletPair> m_walletList;
QList<QObject*> m_tokenList;
public:
explicit DapChainWalletModel(QObject *parent = nullptr);
......@@ -38,7 +38,9 @@ public:
QHash<int, QByteArray> roleNames() const override;
double walletBalance(const QString& aAddress) const;
Q_INVOKABLE QStringList walletList() const;
Q_INVOKABLE double walletBalance(const QString& aName) const;
Q_INVOKABLE double walletBalance(const int aWalletIndex) const;
......@@ -46,16 +48,8 @@ public:
QList<QObject*> tokeListByIndex(const int aIndex) const;
double walletBalance() const;
QList<QObject*> tokenList() const;
public slots:
Q_INVOKABLE void setCurrentWallet(const QString& aWalletAddress);
Q_INVOKABLE void setCurrentWallet(const int aWalletIndex);
void setWalletData(const QByteArray& aData);
void appendWallet(const DapChainWalletData& aWallet);
......@@ -67,10 +61,9 @@ public slots:
void removeWallet(const int aWalletIndex);
signals:
void walletBalanceChanged(double walletBalance);
void sigAppendWallet(QString name);
void sigRemoveWallet(QString address);
void tokenListChanged(QList<QObject*> tokenList);
void walletListChanged(QStringList walletList);
};
#endif // DAPCHAINWALLETMODEL_H
......@@ -42,7 +42,7 @@ Page {
id: listViewToken
Layout.fillWidth: true
Layout.fillHeight: true
model: dapWalletModel
model: dapWalletFilterModel
section.property: "networkDisplayRole"
section.criteria: ViewSection.FullString
section.delegate: Rectangle {
......@@ -122,42 +122,36 @@ Page {
anchors.fill: parent
anchors.topMargin: 1
Row {
anchors.fill: parent
spacing: 16 * pt
Label {
anchors.left: parent.left
verticalAlignment: Qt.AlignVCenter
height: parent.height
font.family: fontRobotoRegular.name
font.pixelSize: 18 * pt
color: "#070023"
text: model.modelData.name
}
Label {
anchors.horizontalCenter: parent.horizontalCenter
width: 300
height: parent.height
verticalAlignment: Qt.AlignVCenter
font.family: fontRobotoRegular.name
font.pixelSize: 12 * pt
color: "#070023"
text: model.modelData.balance + " " + model.modelData.name
}
Label {
anchors.right: parent.right
height: parent.height
verticalAlignment: Qt.AlignVCenter
horizontalAlignment: Qt.AlignRight
font.family: fontRobotoRegular.name
font.pixelSize: 12 * pt
color: "#757184"
text: "$ " + model.modelData.balance + " USD"
}
Label {
anchors.left: parent.left
verticalAlignment: Qt.AlignVCenter
height: parent.height
font.family: fontRobotoRegular.name
font.pixelSize: 18 * pt
color: "#070023"
text: model.modelData.name
}
Label {
anchors.horizontalCenter: parent.horizontalCenter
width: 1
height: parent.height
verticalAlignment: Qt.AlignVCenter
font.family: fontRobotoRegular.name
font.pixelSize: 12 * pt
color: "#070023"
text: model.modelData.balance + " " + model.modelData.name
}
Label {
anchors.right: parent.right
height: parent.height
verticalAlignment: Qt.AlignVCenter
horizontalAlignment: Qt.AlignRight
font.family: fontRobotoRegular.name
font.pixelSize: 12 * pt
color: "#757184"
text: "$ " + model.modelData.balance + " USD"
}
}
......
......@@ -109,42 +109,39 @@ Page {
}
focus: true
// DapUiQmlWidgetStatusBar {
// id: rectangleStatusBar
// anchors.left: rectangleTabsBorder.right
// anchors.top: parent.top
// anchors.right: parent.right
// color: "#B5B5B5"
// height: 60 * pt
}
}
Rectangle {
id: mainDashboard
anchors.left: rectangleTabsBorder.right
anchors.top: rectangleStatusBar.bottom
anchors.bottom: parent.bottom
anchors.right: parent.right
border.color: "whitesmoke"
Rectangle {
id: mainDashboard
anchors.left: rectangleTabsBorder.right
anchors.top: rectangleStatusBar.bottom
Loader {
id: stackViewScreenDashboard
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.right: parent.right
border.color: "whitesmoke"
Loader {
id: stackViewScreenDashboard
clip: true
anchors.fill: parent
source: "DapUiQmlScreenDialog.qml"
}
anchors.top: parent.top
anchors.right: lastActionWidget.left
clip: true
source: "DapUiQmlScreenDialog.qml"
}
// DapUiQmlWidgetLastActions {
// viewModel: dapHistoryModel
// viewDelegate: DapUiQmlWidgetLastActionsDelegateForm {}
// viewSection.property: "date"
// viewSection.criteria: ViewSection.FullString
// viewSection.delegate: DapUiQmlWidgetLastActionsSectionForm {
// width: parent.width
// height: 30 * pt
// }
// }
DapUiQmlWidgetLastActions {
id: lastActionWidget
viewModel: dapHistoryModel
viewDelegate: DapUiQmlWidgetLastActionsDelegateForm {}
viewSection.property: "date"
viewSection.criteria: ViewSection.FullString
viewSection.delegate: DapUiQmlWidgetLastActionsSectionForm {
width: parent.width
height: 30 * pt
}
}
}
}
//}
......
......@@ -57,7 +57,8 @@ Rectangle {
font.family: fontRobotoRegular.name
font.pixelSize: 16 * pt
color: "#FFFFFF"
text: dapChainConvertor.toConvertCurrency(dapWalletModel.walletBalance)
text: dapChainConvertor.toConvertCurrency(
dapWalletModel.walletBalance(comboboxWallet.currentText))
}
}
......
......@@ -7,19 +7,14 @@ import QtQml 2.13
DapUiQmlWidgetStatusBarComboBoxWalletForm {
property Label fieldBalance: Label {}
// model: dapChainWalletsModel
model: dapWalletModel
textRole: "walletNameDisplayRole"
model: dapWalletModel.wallets
delegate: DapUiQmlWidgetStatusBarComboBoxDelegate {
delegateContentText: walletNameDisplayRole
delegateContentText: modelData
}
onCurrentIndexChanged: {
dapWalletModel.setCurrentWallet(currentIndex);
// var money = 0.0
// for(var i = 0; i < dapChainWalletsModel.get(currentIndex).count; i += 3)
// money += parseFloat(dapChainWalletsModel.get(currentIndex).tokens[i]);
// fieldBalance.text = money;
onCurrentTextChanged: {
dapWalletFilterModel.setWalletFilter(currentText);
}
}
#include "DapWalletFilterModel.h"
DapWalletFilterModel::DapWalletFilterModel(QObject *parent) : QSortFilterProxyModel(parent)
DapWalletFilterModel::DapWalletFilterModel(QObject *parent) :
QSortFilterProxyModel(parent),
m_filterWalletName(TITLE_ALL_WALLETS)
{
sort(0, Qt::DescendingOrder);
}
......@@ -11,9 +13,26 @@ DapWalletFilterModel& DapWalletFilterModel::instance()
return instance;
}
void DapWalletFilterModel::setWalletFilter(const QString& aName)
{
if(m_filterWalletName == aName) return;
m_filterWalletName = aName;
setFilterKeyColumn(0);
}
bool DapWalletFilterModel::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const
{
QString first = source_left.data(DapChainWalletModel::NetworkDisplayRole).toString();
QString second = source_right.data(DapChainWalletModel::NetworkDisplayRole).toString();
return first < second;
}
bool DapWalletFilterModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
if(m_filterWalletName == TITLE_ALL_WALLETS) return true;
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
QString wallet = index.data(DapChainWalletModel::WalletNameDisplayRole).toString();
return wallet == m_filterWalletName;
}
......@@ -8,13 +8,20 @@ class DapWalletFilterModel : public QSortFilterProxyModel
{
Q_OBJECT
private:
QString m_filterWalletName;
protected:
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const;
// bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
public:
explicit DapWalletFilterModel(QObject *parent = nullptr);
static DapWalletFilterModel& instance();
public slots:
Q_INVOKABLE void setWalletFilter(const QString& aName);
};
#endif // DAPWALLETFILTERMODEL_H
......@@ -90,7 +90,8 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty("dapHistoryModel", &DapScreenHistoryFilterModel::getInstance());
engine.rootContext()->setContextProperty("dapSettingsNetworkModel", &DapSettingsNetworkModel::getInstance());
engine.rootContext()->setContextProperty("dapChainConvertor", &DapChainConvertor::getInstance());
engine.rootContext()->setContextProperty("dapWalletModel", &DapWalletFilterModel::instance());
engine.rootContext()->setContextProperty("dapWalletFilterModel", &DapWalletFilterModel::instance());
engine.rootContext()->setContextProperty("dapWalletModel", &DapChainWalletModel::instance());
engine.rootContext()->setContextProperty("pt", 1.3);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment