diff --git a/KelvinDashboardGUI/DapCommandController.cpp b/KelvinDashboardGUI/DapCommandController.cpp index e989edf3624214094fb7862b2e373e699213ed9a..f510a9e5165997751d56f28a444fb28054c8eb79 100755 --- a/KelvinDashboardGUI/DapCommandController.cpp +++ b/KelvinDashboardGUI/DapCommandController.cpp @@ -64,6 +64,12 @@ void DapCommandController::setNewHistory(const QVariant& aData) emit sendHistory(aData); } +void DapCommandController::requestConsole(const QString& aQueue) +{ + DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.getQueryResult", aQueue); + connect(reply, SIGNAL(finished()), this, SLOT(processResponseConsole())); +} + void DapCommandController::processChangedLog() { // QStringList tempLogModel; @@ -193,6 +199,13 @@ void DapCommandController::processGetHistory() emit sendHistory(result); } +void DapCommandController::processResponseConsole() +{ + DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); + QString result = reply->response().result().toVariant().toString(); + emit responseConsole(result); +} + /// Show or hide GUI client by clicking on the tray icon. /// @param aIsActivated Accepts true - when requesting to /// display a client, falso - when requesting to hide a client. diff --git a/KelvinDashboardGUI/DapCommandController.h b/KelvinDashboardGUI/DapCommandController.h index 05758ec7a5793bfa0a1b964bdaa3193f4bbb4282..59c6854f8f2164f27ad50c2158bb9b121ab1912c 100755 --- a/KelvinDashboardGUI/DapCommandController.h +++ b/KelvinDashboardGUI/DapCommandController.h @@ -49,6 +49,8 @@ signals: void sendHistory(const QVariant& aData); + void responseConsole(const QString& aResponse); + public: /// Overloaded constructor. /// @param apIODevice Data transfer device. @@ -78,6 +80,8 @@ private slots: void processGetHistory(); + void processResponseConsole(); + public slots: /// Show or hide GUI client by clicking on the tray icon. /// @param aIsActivated Accepts true - when requesting to @@ -113,6 +117,8 @@ public slots: void getHistory(); void setNewHistory(const QVariant& aData); + + void requestConsole(const QString& aQueue); }; #endif // COMMANDCONTROLLER_H diff --git a/KelvinDashboardGUI/DapServiceController.cpp b/KelvinDashboardGUI/DapServiceController.cpp index de0442e0864b8602f52572651658e71248d5adbc..df1d1f18a7a08f34d4d9a73cc8a0e77b7dcf2f3c 100755 --- a/KelvinDashboardGUI/DapServiceController.cpp +++ b/KelvinDashboardGUI/DapServiceController.cpp @@ -59,6 +59,9 @@ void DapServiceController::init(DapServiceClient *apDapServiceClient) connect(m_pDapCommandController, SIGNAL(sendHistory(QVariant)), this, SLOT(processGetHistory(QVariant))); connect(m_pDapCommandController, &DapCommandController::sendHistory, &DapScreenHistoryModel::getInstance(), &DapScreenHistoryModel::receiveNewData); + + connect(&DapUiQmlWidgetConsoleModel::getInstance(), &DapUiQmlWidgetConsoleModel::sendRequest, m_pDapCommandController, &DapCommandController::requestConsole); + connect(m_pDapCommandController, &DapCommandController::responseConsole, &DapUiQmlWidgetConsoleModel::getInstance(), &DapUiQmlWidgetConsoleModel::receiveResponse); } QString DapServiceController::getBrand() const diff --git a/KelvinDashboardGUI/DapServiceController.h b/KelvinDashboardGUI/DapServiceController.h index 4ca69571e27416f8cb27a24fb9011766e9d67aa9..55fe6b2960333e099476070d1b50454b4bd80d08 100755 --- a/KelvinDashboardGUI/DapServiceController.h +++ b/KelvinDashboardGUI/DapServiceController.h @@ -15,6 +15,7 @@ #include "DapChainWalletsModel.h" #include "DapChainNodeNetworkModel.h" #include "DapScreenHistoryModel.h" +#include "DapUiQmlWidgetConsole.h" class DapServiceController : public QObject { diff --git a/KelvinDashboardGUI/DapUiQmlScreenConsoleForm.qml b/KelvinDashboardGUI/DapUiQmlScreenConsoleForm.qml index da8363d15d803d570e9082327c1e4d6db5aa2d2c..ec534c822a6ab3b287d192e49af46c995c56aa3b 100644 --- a/KelvinDashboardGUI/DapUiQmlScreenConsoleForm.qml +++ b/KelvinDashboardGUI/DapUiQmlScreenConsoleForm.qml @@ -4,88 +4,11 @@ import QtQuick.Controls 2.2 import QtQuick.Layouts 1.12 Page { + ScrollView { + anchors.fill: parent; - TextEdit { - id: txtCommands - property int positionLine: 2 - anchors.fill: parent - - text: "> " - wrapMode: TextEdit.WordWrap - - -// onTextChanged: { -// if(txtCommands.cursorPosition > txtCommands.positionLine) -// { -// txtCommands.text += " "; -// txtCommands.cursorPosition = txtCommands.text.length -// } -// } - - Keys.onPressed: { - - switch(event.key) - { -// case Qt.Key_Up: -// console.debug("UP"); -//// txtCommands.remove(positionLine, txtCommands.text.length); -//// txtCommands.text += dapConsoleController.getCommandUp(); -// txtCommands.cursorPosition = txtCommands.text.length; -// break; -// case Qt.Key_Down: console.debug("Down"); break; -// case Qt.Key_Left: -// if(txtCommands.cursorPosition <= txtCommands.positionLine) -// { -// console.debug(txtCommands.cursorPosition + ":" + txtCommands.positionLine + ":" + txtCommands.text.length); -// txtCommands.cursorPosition = txtCommands.text.length; -// } -// break; - case Qt.Key_Backspace: - console.debug("Remove"); - if(txtCommands.cursorPosition <= txtCommands.positionLine) - { - txtCommands.text += " "; - txtCommands.cursorPosition = txtCommands.text.length - } - - break; - default: break; - } - } - - Keys.onLeftPressed: { - - } - - Keys.onUpPressed: { - - } - - Keys.onDownPressed: { - - } - - Keys.onDeletePressed: { - console.debug("delete"); - } - - Keys.onBackPressed: { - console.debug("back"); - } - - Keys.onReturnPressed: { - txtCommands.readOnly = true; - dapConsoleController.receiveRequest(txtCommands.text.slice(positionLine, txtCommands.text.length)); - } - - Connections { - target: dapConsoleController - onSendResponse: { - txtCommands.readOnly = false; - txtCommands.append(response); - txtCommands.append("> "); - txtCommands.positionLine = txtCommands.cursorPosition; - } + DapUiQmlWidgetConsoleForm { + anchors.fill: parent } } } diff --git a/KelvinDashboardGUI/DapUiQmlWidgetConsole.cpp b/KelvinDashboardGUI/DapUiQmlWidgetConsole.cpp index 9737728817282427e0048d28eed03285a7c6d25f..c0e4a13cecd7e5c32bd090cfb3ec1361d3bca1c9 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetConsole.cpp +++ b/KelvinDashboardGUI/DapUiQmlWidgetConsole.cpp @@ -1,35 +1,39 @@ #include "DapUiQmlWidgetConsole.h" -DapUiQmlWidgetConsole::DapUiQmlWidgetConsole(QObject *parent) : QObject(parent) +DapUiQmlWidgetConsoleModel::DapUiQmlWidgetConsoleModel(QObject *parent) : QObject(parent) { } -DapUiQmlWidgetConsole& DapUiQmlWidgetConsole::getInstance() +DapUiQmlWidgetConsoleModel& DapUiQmlWidgetConsoleModel::getInstance() { - static DapUiQmlWidgetConsole instance; + static DapUiQmlWidgetConsoleModel instance; return instance; } -void DapUiQmlWidgetConsole::receiveResponse(const QString& aResponse) +void DapUiQmlWidgetConsoleModel::receiveResponse(const QString& aResponse) { emit sendResponse(aResponse); } -QString DapUiQmlWidgetConsole::getCommandUp() const +QString DapUiQmlWidgetConsoleModel::getCommandUp() { - if(m_CommandIterator -1 != m_CommandList.begin()) return QString::fromStdString(m_CommandIterator->toStdString()); - return QString::fromStdString(m_CommandIterator->toStdString()); + if(m_CommandList.isEmpty()) return QString(); + if(m_CommandIndex > m_CommandList.begin()) m_CommandIndex--; + return *m_CommandIndex; } -QString DapUiQmlWidgetConsole::getCommandDown() const +QString DapUiQmlWidgetConsoleModel::getCommandDown() { - return QString(); + if(m_CommandList.isEmpty()) return QString(); + if(m_CommandIndex < m_CommandList.end() -1) m_CommandIndex++; + else return QString(); + return *m_CommandIndex; } -void DapUiQmlWidgetConsole::receiveRequest(const QString& aCommand) +void DapUiQmlWidgetConsoleModel::receiveRequest(const QString& aCommand) { m_CommandList.append(aCommand); - m_CommandIterator = m_CommandList.end(); - emit sendResponse(aCommand); + m_CommandIndex = m_CommandList.end(); + emit sendRequest(aCommand); } diff --git a/KelvinDashboardGUI/DapUiQmlWidgetConsole.h b/KelvinDashboardGUI/DapUiQmlWidgetConsole.h index 95fc82f668cedda9f50cef96743cce51ac6c4dc5..79a7e1c11c44b409d0309dae1a66d65d08255315 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetConsole.h +++ b/KelvinDashboardGUI/DapUiQmlWidgetConsole.h @@ -1,26 +1,27 @@ #ifndef DAPUIQMLSCREENCONSOLEFORM_H #define DAPUIQMLSCREENCONSOLEFORM_H +#include <QDebug> #include <QObject> -#include <QPlainTextEdit> +#include <QStringList> -class DapUiQmlWidgetConsole : public QObject +class DapUiQmlWidgetConsoleModel : public QObject { Q_OBJECT private: QStringList m_CommandList; - QStringList::iterator m_CommandIterator; + QStringList::iterator m_CommandIndex; public: - explicit DapUiQmlWidgetConsole(QObject *parent = nullptr); + explicit DapUiQmlWidgetConsoleModel(QObject *parent = nullptr); public slots: void receiveResponse(const QString& aResponse); - Q_INVOKABLE static DapUiQmlWidgetConsole& getInstance(); - Q_INVOKABLE QString getCommandUp() const; - Q_INVOKABLE QString getCommandDown() const; + Q_INVOKABLE static DapUiQmlWidgetConsoleModel& getInstance(); + Q_INVOKABLE QString getCommandUp(); + Q_INVOKABLE QString getCommandDown(); Q_INVOKABLE void receiveRequest(const QString& aCommand); signals: diff --git a/KelvinDashboardGUI/DapUiQmlWidgetConsoleForm.qml b/KelvinDashboardGUI/DapUiQmlWidgetConsoleForm.qml new file mode 100644 index 0000000000000000000000000000000000000000..fffc18ba5711532003fba62c6dd0f9399aef5657 --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlWidgetConsoleForm.qml @@ -0,0 +1,56 @@ +import QtQuick 2.13 + +TextEdit { + property int positionLine: 2 + + id: txtCommands + anchors.fill: parent + + text: "> " + wrapMode: TextEdit.WordWrap + + Keys.onPressed: { + + switch(event.key) + { + case Qt.Key_Backspace: + event.accepted = (txtCommands.cursorPosition <= txtCommands.positionLine); + return; + default: break; + } + } + + Keys.onUpPressed: { + if(txtCommands.positionLine != txtCommands.text.length) + txtCommands.remove(txtCommands.positionLine, txtCommands.text.length); + txtCommands.text += dapConsoleController.getCommandUp(); + } + + Keys.onDownPressed: { + if(txtCommands.positionLine != txtCommands.text.length) + txtCommands.remove(txtCommands.positionLine, txtCommands.text.length); + txtCommands.text += dapConsoleController.getCommandDown(); + } + + Keys.onReturnPressed: { + txtCommands.readOnly = true; + dapConsoleController.receiveRequest(txtCommands.text.slice(positionLine, txtCommands.text.length)); + } + + onCursorPositionChanged: { + if(txtCommands.cursorPosition <= txtCommands.positionLine) { + txtCommands.cursorPosition = txtCommands.positionLine; + } + } + + Connections { + target: dapConsoleController + onSendResponse: { + txtCommands.readOnly = false; + txtCommands.append(response); + txtCommands.append("> "); + txtCommands.positionLine = txtCommands.cursorPosition; + } + } +} + diff --git a/KelvinDashboardGUI/DapUiQmlWidgetConsoleLastActionsForm.qml b/KelvinDashboardGUI/DapUiQmlWidgetConsoleLastActionsForm.qml new file mode 100644 index 0000000000000000000000000000000000000000..ca3e3e8b45ff2b18f4b4372c8a9ec65518fd4fee --- /dev/null +++ b/KelvinDashboardGUI/DapUiQmlWidgetConsoleLastActionsForm.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Rectangle { + +} diff --git a/KelvinDashboardGUI/main.cpp b/KelvinDashboardGUI/main.cpp index d7583618104d7e2aa45fdeb938b432126cf91572..1f7922df0de359790d20d404240e2bb6a47deae0 100755 --- a/KelvinDashboardGUI/main.cpp +++ b/KelvinDashboardGUI/main.cpp @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) // qmlRegisterType<DapScreenHistoryModel>("") qmlRegisterSingletonType<DapUiQmlWidgetModel>("KelvinDashboard", 1, 0, "DapUiQmlWidgetModel", DapUiQmlWidgetModel::singletonProvider); qmlRegisterType<DapScreenHistoryModel>("DapTransactionHistory", 1, 0, "DapTransactionModel"); - qmlRegisterType<DapUiQmlWidgetConsole>("QmlWidgetConsole", 1, 0, "DapUiQmlWidgetConsoleModel"); + qmlRegisterType<DapUiQmlWidgetConsoleModel>("QmlWidgetConsole", 1, 0, "DapUiQmlWidgetConsoleModel"); QQmlApplicationEngine engine; // qreal dpi = QGuiApplication::primaryScreen()->physicalDotsPerInch(); @@ -75,7 +75,7 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty("dapLogModel", &DapLogModel::getInstance()); engine.rootContext()->setContextProperty("dapChainWalletsModel", &DapChainWalletsModel::getInstance()); engine.rootContext()->setContextProperty("dapNodeNetworkModel", &DapChainNodeNetworkModel::getInstance()); - engine.rootContext()->setContextProperty("dapConsoleController", &DapUiQmlWidgetConsole::getInstance()); + engine.rootContext()->setContextProperty("dapConsoleController", &DapUiQmlWidgetConsoleModel::getInstance()); engine.rootContext()->setContextProperty("dapHistoryModel", &DapScreenHistoryFilterModel::getInstance()); engine.rootContext()->setContextProperty("pt", 1.3 /* *dpi */); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); diff --git a/KelvinDashboardGUI/qml.qrc b/KelvinDashboardGUI/qml.qrc index 4c6ab326cce99e3d573f373d41f8ede21195da29..5373110621342b0bb65e0e07e642c673ef8c78c4 100755 --- a/KelvinDashboardGUI/qml.qrc +++ b/KelvinDashboardGUI/qml.qrc @@ -28,5 +28,7 @@ <file>DapUiQmlScreenHistory.qml</file> <file>Resources/Icons/defaul_icon.png</file> <file>DapUiQmlScreenConsoleForm.qml</file> + <file>DapUiQmlWidgetConsoleForm.qml</file> + <file>DapUiQmlWidgetConsoleLastActionsForm.qml</file> </qresource> </RCC>