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

[+] added sort and filter

parent 03a7d7e3
No related branches found
No related tags found
1 merge request!8Features 2442
Pipeline #611 passed with stage
in 2 minutes and 55 seconds
...@@ -52,6 +52,12 @@ void DapCommandController::getNodeLogs() ...@@ -52,6 +52,12 @@ void DapCommandController::getNodeLogs()
connect(reply, SIGNAL(finished()), this, SLOT(processGetNodeLogs())); connect(reply, SIGNAL(finished()), this, SLOT(processGetNodeLogs()));
} }
void DapCommandController::setListenerHistory()
{
DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getHistory");
connect(reply, SIGNAL(finished()), this, SLOT(processGetHistory()));
}
void DapCommandController::processChangedLog() void DapCommandController::processChangedLog()
{ {
// QStringList tempLogModel; // QStringList tempLogModel;
...@@ -173,6 +179,13 @@ void DapCommandController::processExecuteCommand() ...@@ -173,6 +179,13 @@ void DapCommandController::processExecuteCommand()
emit executeCommandChanged(result); emit executeCommandChanged(result);
} }
void DapCommandController::processGetHistory()
{
qInfo() << "processGetHistory()";
DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender());
emit sendHistory(reply->response().result().toVariant());
}
/// Show or hide GUI client by clicking on the tray icon. /// Show or hide GUI client by clicking on the tray icon.
/// @param aIsActivated Accepts true - when requesting to /// @param aIsActivated Accepts true - when requesting to
/// display a client, falso - when requesting to hide a client. /// display a client, falso - when requesting to hide a client.
......
...@@ -46,6 +46,9 @@ signals: ...@@ -46,6 +46,9 @@ signals:
void onClearLogModel(); void onClearLogModel();
void onLogModel(); void onLogModel();
void sendHistory(const QVariant& aData);
public: public:
/// Overloaded constructor. /// Overloaded constructor.
/// @param apIODevice Data transfer device. /// @param apIODevice Data transfer device.
...@@ -72,6 +75,9 @@ private slots: ...@@ -72,6 +75,9 @@ private slots:
void processGetNodeStatus(); void processGetNodeStatus();
void processExecuteCommand(); void processExecuteCommand();
void processGetHistory();
public slots: public slots:
/// Show or hide GUI client by clicking on the tray icon. /// Show or hide GUI client by clicking on the tray icon.
/// @param aIsActivated Accepts true - when requesting to /// @param aIsActivated Accepts true - when requesting to
...@@ -103,6 +109,8 @@ public slots: ...@@ -103,6 +109,8 @@ public slots:
void clearLogModel(); void clearLogModel();
/// Get node logs. /// Get node logs.
void getNodeLogs(); void getNodeLogs();
void setListenerHistory();
}; };
#endif // COMMANDCONTROLLER_H #endif // COMMANDCONTROLLER_H
#include "DapScreenHistoryFilterModel.h"
DapScreenHistoryFilterModel::DapScreenHistoryFilterModel(QObject *parent) :
QSortFilterProxyModel(parent)
{
}
DapScreenHistoryFilterModel& DapScreenHistoryFilterModel::getInstance()
{
static DapScreenHistoryFilterModel instance;
return instance;
}
void DapScreenHistoryFilterModel::setFilterWallet(const QString& aWalletNumber)
{
if(m_walletNumber == aWalletNumber) return;
m_walletNumber = aWalletNumber;
}
void DapScreenHistoryFilterModel::setFilterDate(const QDateTime& aDateLeft, const QDateTime& aDateRight)
{
if(m_dateLeft == aDateLeft || m_dateRight == aDateRight) return;
m_dateLeft = aDateLeft;
m_dateRight = aDateRight;
}
void DapScreenHistoryFilterModel::setFilterStatus(const DapScreenHistoryModel::DapTransactionStatus aStatus)
{
if(m_status == aStatus) return;
m_status = aStatus;
}
bool DapScreenHistoryFilterModel::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const
{
QString first = source_left.data().toString();
QString second = source_right.data().toString();
return first < second;
}
bool DapScreenHistoryFilterModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
QDateTime time;
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
QString timeStr = index.data(DapScreenHistoryModel::DisplayDateRole).toString();
if(timeStr == tr("Today")) time = QDateTime::currentDateTime();
else time = QDateTime::fromString(MASK_FOR_MODEL);
return (index.data(DapScreenHistoryModel::DisplayNumberWalletRole).toString() == m_walletNumber) ||
(index.data(DapScreenHistoryModel::DisplayStatusRole).toInt() == m_status) ||
(time >= m_dateLeft && time <= m_dateRight);
}
#ifndef DAPSCREENHISTORYFILTERMODEL_H
#define DAPSCREENHISTORYFILTERMODEL_H
#include <QSortFilterProxyModel>
#include "DapScreenHistoryModel.h"
class DapScreenHistoryFilterModel : public QSortFilterProxyModel
{
Q_OBJECT
private:
QString m_walletNumber;
QDateTime m_dateLeft;
QDateTime m_dateRight;
int m_status;
protected:
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const;
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
public:
explicit DapScreenHistoryFilterModel(QObject *parent = nullptr);
static DapScreenHistoryFilterModel &getInstance();
public slots:
void setFilterWallet(const QString& aWalletNumber);
void setFilterDate(const QDateTime& aDateLeft, const QDateTime& aDateRight);
void setFilterStatus(const DapScreenHistoryModel::DapTransactionStatus aStatus);
};
#endif // DAPSCREENHISTORYFILTERMODEL_H
...@@ -3,38 +3,7 @@ ...@@ -3,38 +3,7 @@
DapScreenHistoryModel::DapScreenHistoryModel(QObject *parent) DapScreenHistoryModel::DapScreenHistoryModel(QObject *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
{ {
for(int i = 0; i < 5; i++)
{
DapTransactionItem element;
element.TokenName = QString("token %1").arg(i);
element.Date = "today";
element.WalletNumber = "number wallet";
element.Status = "Sent";
element.Currency = QString("$ 1020201010%1").arg(i);
element.Cryptocurrency = QString("KLV 4443222111%1").arg(i);
m_elementList.append(element);
}
for(int i = 0; i < 5; i++)
{
DapTransactionItem element;
element.TokenName = QString("token %1").arg(i);
element.Date = "yesterday";
element.WalletNumber = "number wallet";
element.Status = "Error";
element.Currency = QString("$ 15647475623820%1").arg(i);
element.Cryptocurrency = QString("KLV 454535453%1").arg(i);
m_elementList.append(element);
}
// DapTransactionItem element;
// element.TokenName = QString("token new");
// element.Date = "today";
// element.WalletNumber = "number wallet 1221";
// element.Status = "sent";
// element.Currency = QString("$ 1555444");
// element.Cryptocurrency = QString("KLV 44433");
// m_elementList.append(element);
} }
DapScreenHistoryModel& DapScreenHistoryModel::getInstance() DapScreenHistoryModel& DapScreenHistoryModel::getInstance()
...@@ -55,6 +24,36 @@ QHash<int, QByteArray> DapScreenHistoryModel::roleNames() const ...@@ -55,6 +24,36 @@ QHash<int, QByteArray> DapScreenHistoryModel::roleNames() const
return names; return names;
} }
void DapScreenHistoryModel::receiveNewData(const QVariant& aData)
{
beginResetModel();
QList<QVariant> dataList = aData.toList();
m_elementList.clear();
for(int i = 0; i < dataList.count(); i++)
{
// Description QStringList
// ------------------------
// 0: date
// 1: status
// 2: currency
// 3: token
// 4: wallet_to
// 5: wallet_from
QStringList dataItem = dataList.at(i).toStringList();
DapTransactionItem item;
item.Date = QDateTime::fromString(dataItem.at(0), "ddd MMM dd h:mm:ss YYYY");
item.Status = static_cast<DapTransactionStatus>(dataItem.at(1).toInt());
item.Cryptocurrency = dataItem.at(2);
item.TokenName = dataItem.at(3);
item.WalletNumber = dataItem.at(5);
item.Currency = "$ 0 USD"; // TODO:
m_elementList.append(item);
}
endResetModel();
}
int DapScreenHistoryModel::rowCount(const QModelIndex &parent) const int DapScreenHistoryModel::rowCount(const QModelIndex &parent) const
{ {
if (parent.isValid()) return 0; if (parent.isValid()) return 0;
...@@ -67,7 +66,13 @@ QVariant DapScreenHistoryModel::data(const QModelIndex &index, int role) const ...@@ -67,7 +66,13 @@ QVariant DapScreenHistoryModel::data(const QModelIndex &index, int role) const
switch (role) switch (role)
{ {
case DisplayDateRole: return m_elementList.at(index.row()).Date; case DisplayDateRole:
{
QDateTime currentTime = QDateTime::currentDateTime();
QDateTime itemDate = m_elementList.at(index.row()).Date;
if(currentTime == itemDate) return QString("Today");
return itemDate.toString(MASK_FOR_MODEL);
}
case DisplayNameTokenRole: return m_elementList.at(index.row()).TokenName; case DisplayNameTokenRole: return m_elementList.at(index.row()).TokenName;
case DisplayNumberWalletRole: return m_elementList.at(index.row()).WalletNumber; case DisplayNumberWalletRole: return m_elementList.at(index.row()).WalletNumber;
case DisplayStatusRole: return m_elementList.at(index.row()).Status; case DisplayStatusRole: return m_elementList.at(index.row()).Status;
......
...@@ -4,22 +4,33 @@ ...@@ -4,22 +4,33 @@
#include <QDebug> #include <QDebug>
#include <QImage> #include <QImage>
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QDateTime>
struct DapTransactionItem { #define MASK_FOR_MODEL QString("MMMM, dd")
QString Date;
QImage TokenPic;
QString Status;
QString TokenName;
QString WalletNumber;
QString Cryptocurrency;
QString Currency;
};
class DapScreenHistoryModel : public QAbstractListModel class DapScreenHistoryModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
private: public:
enum DapTransactionStatus {
Pending,
Sent,
Received,
Error
};
Q_ENUM(DapTransactionStatus)
struct DapTransactionItem {
QDateTime Date;
QImage TokenPic;
DapTransactionStatus Status;
QString TokenName;
QString WalletNumber;
QString Cryptocurrency;
QString Currency;
};
enum { enum {
DisplayDateRole = Qt::UserRole, DisplayDateRole = Qt::UserRole,
DisplayNameTokenRole, DisplayNameTokenRole,
...@@ -29,6 +40,7 @@ private: ...@@ -29,6 +40,7 @@ private:
DisplayCurrency DisplayCurrency
}; };
private:
QList<DapTransactionItem> m_elementList; QList<DapTransactionItem> m_elementList;
public: public:
...@@ -40,8 +52,7 @@ public: ...@@ -40,8 +52,7 @@ public:
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
public slots: public slots:
void receiveNewData(const QVariant& aData);
}; };
#endif // DAPSCREENHISTORYMODEL_H #endif // DAPSCREENHISTORYMODEL_H
...@@ -55,6 +55,8 @@ void DapServiceController::init(DapServiceClient *apDapServiceClient) ...@@ -55,6 +55,8 @@ void DapServiceController::init(DapServiceClient *apDapServiceClient)
connect(&DapChainNodeNetworkModel::getInstance(), SIGNAL(requestNodeNetwork()), this, SLOT(getNodeNetwork())); connect(&DapChainNodeNetworkModel::getInstance(), SIGNAL(requestNodeNetwork()), this, SLOT(getNodeNetwork()));
connect(&DapChainNodeNetworkModel::getInstance(), SIGNAL(requestNodeStatus(bool)), this, SLOT(setNodeStatus(bool))); connect(&DapChainNodeNetworkModel::getInstance(), SIGNAL(requestNodeStatus(bool)), this, SLOT(setNodeStatus(bool)));
connect(m_pDapCommandController, SIGNAL(sendHistory(QVariant)), this, SLOT(processGetHistory(QVariant)));
} }
QString DapServiceController::getBrand() const QString DapServiceController::getBrand() const
...@@ -231,6 +233,11 @@ void DapServiceController::processGetNodeNetwork(const QVariant& aData) ...@@ -231,6 +233,11 @@ void DapServiceController::processGetNodeNetwork(const QVariant& aData)
DapChainNodeNetworkModel::getInstance().receiveNewNetwork(aData); DapChainNodeNetworkModel::getInstance().receiveNewNetwork(aData);
} }
void DapServiceController::processGetHistory(const QVariant& aData)
{
DapScreenHistoryModel::getInstance().receiveNewData(aData);
}
/// Get an instance of a class. /// Get an instance of a class.
/// @return Instance of a class. /// @return Instance of a class.
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "DapLogModel.h" #include "DapLogModel.h"
#include "DapChainWalletsModel.h" #include "DapChainWalletsModel.h"
#include "DapChainNodeNetworkModel.h" #include "DapChainNodeNetworkModel.h"
#include "DapScreenHistoryModel.h"
class DapServiceController : public QObject class DapServiceController : public QObject
{ {
...@@ -113,6 +114,8 @@ private slots: ...@@ -113,6 +114,8 @@ private slots:
void processGetNodeNetwork(const QVariant& aData); void processGetNodeNetwork(const QVariant& aData);
void processGetHistory(const QVariant& aData);
public slots: public slots:
void getNodeNetwork(); void getNodeNetwork();
void setNodeStatus(const bool aIsOnline); void setNodeStatus(const bool aIsOnline);
......
import QtQuick 2.9 import QtQuick 2.9
import QtQml 2.12
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import DapTransactionHistory 1.0
Page { Page {
ListView { ListView {
id: dapListView id: dapListView
...@@ -117,10 +120,12 @@ Page { ...@@ -117,10 +120,12 @@ Page {
font.pointSize: 12 font.pointSize: 12
onTextChanged: { onTextChanged: {
if(text == "Error") color = "#00081B" switch(text) {
else if(text == "Received") color = "#454E63" case DapTransactionModel.Error: color = "#00081B"; break;
else if(text == "Sent") color = "#959CA6" case DapTransactionModel.Received: color = "#454E63"; break;
else if(text == "Pending") color = "#E3E3E3"; case DapTransactionModel.Sent: color = "#959CA6"; break;
case DapTransactionModel.Pending: color = "#E3E3E3"; break;
}
} }
} }
} }
......
...@@ -42,6 +42,7 @@ ICON = icon.ico ...@@ -42,6 +42,7 @@ ICON = icon.ico
SOURCES += \ SOURCES += \
DapChainNodeNetworkExplorer.cpp \ DapChainNodeNetworkExplorer.cpp \
DapChainNodeNetworkModel.cpp \ DapChainNodeNetworkModel.cpp \
DapScreenHistoryFilterModel.cpp \
DapScreenHistoryModel.cpp \ DapScreenHistoryModel.cpp \
DapUiQmlWidgetChainTransactions.cpp \ DapUiQmlWidgetChainTransactions.cpp \
main.cpp \ main.cpp \
...@@ -77,6 +78,7 @@ else: unix:!android: target.path = /opt/kelvin-dashboard/bin ...@@ -77,6 +78,7 @@ else: unix:!android: target.path = /opt/kelvin-dashboard/bin
HEADERS += \ HEADERS += \
DapChainNodeNetworkExplorer.h \ DapChainNodeNetworkExplorer.h \
DapChainNodeNetworkModel.h \ DapChainNodeNetworkModel.h \
DapScreenHistoryFilterModel.h \
DapScreenHistoryModel.h \ DapScreenHistoryModel.h \
DapUiQmlWidgetChainBallance.h \ DapUiQmlWidgetChainBallance.h \
DapUiQmlWidgetChainBlockExplorer.h \ DapUiQmlWidgetChainBlockExplorer.h \
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <QIcon> #include <QIcon>
#include <QSystemSemaphore> #include <QSystemSemaphore>
#include <QSharedMemory> #include <QSharedMemory>
#include <QScreen>
#include "DapHalper.h" #include "DapHalper.h"
#include "DapScreenDialog.h" #include "DapScreenDialog.h"
...@@ -21,8 +22,8 @@ ...@@ -21,8 +22,8 @@
#include "DapChainWalletsModel.h" #include "DapChainWalletsModel.h"
#include "DapChainNodeNetworkModel.h" #include "DapChainNodeNetworkModel.h"
#include "DapChainNodeNetworkExplorer.h" #include "DapChainNodeNetworkExplorer.h"
#include "DapScreenHistoryFilterModel.h"
#include "DapScreenHistoryModel.h"
#include <QRegExp> #include <QRegExp>
...@@ -52,6 +53,9 @@ int main(int argc, char *argv[]) ...@@ -52,6 +53,9 @@ int main(int argc, char *argv[])
dapServiceClient.init(); dapServiceClient.init();
controller.getNodeLogs(0, 100); controller.getNodeLogs(0, 100);
controller.getWallets(); controller.getWallets();
DapScreenHistoryFilterModel::getInstance()
.setSourceModel(&DapScreenHistoryModel::getInstance());
// controller.getNodeNetwork(); // controller.getNodeNetwork();
qmlRegisterType<DapScreenDialog>("KelvinDashboard", 1, 0, "DapScreenDialog"); qmlRegisterType<DapScreenDialog>("KelvinDashboard", 1, 0, "DapScreenDialog");
...@@ -60,14 +64,17 @@ int main(int argc, char *argv[]) ...@@ -60,14 +64,17 @@ int main(int argc, char *argv[])
qmlRegisterType<DapChainNodeNetworkExplorer>("NodeNetworkExplorer", 1, 0, "DapUiQmlWidgetNodeNetwork"); qmlRegisterType<DapChainNodeNetworkExplorer>("NodeNetworkExplorer", 1, 0, "DapUiQmlWidgetNodeNetwork");
// qmlRegisterType<DapScreenHistoryModel>("") // qmlRegisterType<DapScreenHistoryModel>("")
qmlRegisterSingletonType<DapUiQmlWidgetModel>("KelvinDashboard", 1, 0, "DapUiQmlWidgetModel", DapUiQmlWidgetModel::singletonProvider); qmlRegisterSingletonType<DapUiQmlWidgetModel>("KelvinDashboard", 1, 0, "DapUiQmlWidgetModel", DapUiQmlWidgetModel::singletonProvider);
qmlRegisterType<DapScreenHistoryModel>("DapTransactionHistory", 1, 0, "DapTransactionModel");
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
qreal dpi = QGuiApplication::primaryScreen()->physicalDotsPerInch();
engine.rootContext()->setContextProperty("dapServiceController", &DapServiceController::getInstance()); engine.rootContext()->setContextProperty("dapServiceController", &DapServiceController::getInstance());
engine.rootContext()->setContextProperty("dapUiQmlWidgetModel", &DapUiQmlWidgetModel::getInstance()); engine.rootContext()->setContextProperty("dapUiQmlWidgetModel", &DapUiQmlWidgetModel::getInstance());
engine.rootContext()->setContextProperty("dapLogModel", &DapLogModel::getInstance()); engine.rootContext()->setContextProperty("dapLogModel", &DapLogModel::getInstance());
engine.rootContext()->setContextProperty("dapChainWalletsModel", &DapChainWalletsModel::getInstance()); engine.rootContext()->setContextProperty("dapChainWalletsModel", &DapChainWalletsModel::getInstance());
engine.rootContext()->setContextProperty("dapNodeNetworkModel", &DapChainNodeNetworkModel::getInstance()); engine.rootContext()->setContextProperty("dapNodeNetworkModel", &DapChainNodeNetworkModel::getInstance());
engine.rootContext()->setContextProperty("dapHistoryModel", &DapScreenHistoryModel::getInstance()); engine.rootContext()->setContextProperty("dapHistoryModel", &DapScreenHistoryModel::getInstance());
engine.rootContext()->setContextProperty("pt", 1/72*dpi);
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
// DapSettings &settings = DapSettings::getInstance("Settings.json"); // DapSettings &settings = DapSettings::getInstance("Settings.json");
......
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