diff --git a/KelvinDashboardGUI/DapConsoleModel.cpp b/KelvinDashboardGUI/DapConsoleModel.cpp index 631ac4483004d94d38a15b497e4e08482553a05b..01d0ad78a6a60f5ca25964bc7d4342da5b9ce6dc 100644 --- a/KelvinDashboardGUI/DapConsoleModel.cpp +++ b/KelvinDashboardGUI/DapConsoleModel.cpp @@ -82,15 +82,20 @@ QString DapConsoleModel::getCmdHistory() void DapConsoleModel::receiveCmdHistory(const QString& aHistory) { - m_History.append(aHistory); - QRegExp rx("^([\\w+\\s+])$"); - - int pos = 0; - while ((pos = rx.indexIn(m_History, pos)) != -1) - { - if(!m_CommandList.contains(rx.cap(1))) - m_CommandList.append(rx.cap(1)); - pos += rx.matchedLength(); + m_History = aHistory; + QRegularExpression rx("^> (.+)$"); + rx.setPatternOptions(QRegularExpression::MultilineOption); + + QRegularExpressionMatchIterator i = rx.globalMatch(m_History); + + while (i.hasNext()) { + QRegularExpressionMatch match = i.next(); + QString cmd = match.captured(1).remove(QChar('\r'), Qt::CaseInsensitive); + if(!m_CommandList.contains(cmd)) + m_CommandList.append(cmd); } + + if(!m_CommandList.isEmpty()) + m_CommandIndex = m_CommandList.end(); emit cmdHistoryChanged(m_History); } diff --git a/KelvinDashboardGUI/DapConsoleModel.h b/KelvinDashboardGUI/DapConsoleModel.h index 1eb9b3322ae0c1586700f28cb9640bb0ad345b3b..428983a4494730d0710e18aad5ec4cd05044c10e 100644 --- a/KelvinDashboardGUI/DapConsoleModel.h +++ b/KelvinDashboardGUI/DapConsoleModel.h @@ -4,6 +4,7 @@ #include <QDebug> #include <QAbstractListModel> #include <QStringList> +#include <QRegularExpression> /// Model for DAP console class DapConsoleModel : public QAbstractListModel diff --git a/KelvinDashboardGUI/DapUiQmlScreenConsoleForm.qml b/KelvinDashboardGUI/DapUiQmlScreenConsoleForm.qml index e748059e1831a889658efe1571e0124b42b89bd4..86238fb7694a7203711deb25b686ddb78d598ddd 100644 --- a/KelvinDashboardGUI/DapUiQmlScreenConsoleForm.qml +++ b/KelvinDashboardGUI/DapUiQmlScreenConsoleForm.qml @@ -9,71 +9,13 @@ Page { anchors.top: parent.top anchors.bottom: parent.bottom anchors.left: parent.left - anchors.right: lastActionsPanel.right + anchors.right: lastActionsPanel.left anchors.topMargin: 30 * pt anchors.leftMargin: 30 * pt anchors.rightMargin: 30 * pt } -// Text { -// id: promt -// anchors.left: parent.left -// anchors.top: consoleCmd.top -// anchors.bottom: parent.bottom -// verticalAlignment: Qt.AlignVCenter -// text: ">" -// color: "#707070" -// font.family: "Roboto" -// font.pixelSize: 20 * pt -// anchors.leftMargin: 30 * pt -// } - -// TextArea { -// id: consoleCmd -// anchors.left: promt.right -// anchors.bottom: parent.bottom -// anchors.right: lastActionsPanel.left -// height: contentChildren.height -// wrapMode: TextArea.Wrap -// color: "#707070" -// font.family: "Roboto" -// font.pixelSize: 20 * pt -// anchors.rightMargin: 30 * pt -// focus: true - -// Keys.onUpPressed: { -// consoleCmd.text = dapConsoleModel.getCommandUp(); -// } - -// Keys.onDownPressed: { -// consoleCmd.text = dapConsoleModel.getCommandDown(); -// } - -// Keys.onReturnPressed: { -// dapConsoleModel.receiveRequest(consoleCmd.text); -// txtCommand.append("> " + consoleCmd.text); -// } -// } - -// Flickable { -// anchors.left: parent.left -// anchors.top: parent.top -// anchors.right: lastActionsPanel.left -// anchors.bottom: consoleCmd.top - -// leftMargin: 30 * pt -// topMargin: 30 * pt -// rightMargin: 30 * pt - -// TextArea.flickable: DapUiQmlWidgetConsoleForm -// { -// id: txtCommand -// } - -// ScrollBar.vertical: ScrollBar{} -// } - DapUiQmlWidgetConsoleLastActionsForm { id: lastActionsPanel } diff --git a/KelvinDashboardGUI/DapUiQmlWidgetConsoleForm.qml b/KelvinDashboardGUI/DapUiQmlWidgetConsoleForm.qml index 5c11bd902ac12f9961a0a491cbc6d5bf58248c52..159660d826b86d04731a212ebfd9d170e6b9ae2e 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetConsoleForm.qml +++ b/KelvinDashboardGUI/DapUiQmlWidgetConsoleForm.qml @@ -1,88 +1,99 @@ import QtQuick 2.13 import QtQuick.Controls 2.5 +import QtQuick.Layouts 1.13 + Rectangle { - Text { - id: promt - anchors.left: parent.left - anchors.top: consoleCmd.top - anchors.bottom: parent.bottom - verticalAlignment: Qt.AlignVCenter - text: ">" - color: "#707070" - font.family: "Roboto" - font.pixelSize: 20 * pt - } - TextArea { - id: consoleCmd - anchors.left: promt.right - anchors.bottom: parent.bottom - anchors.right: parent.right - height: contentChildren.height - wrapMode: TextArea.Wrap - color: "#707070" - font.family: "Roboto" - font.pixelSize: 20 * pt - focus: true - - Keys.onUpPressed: { - consoleCmd.text = dapConsoleModel.getCommandUp(); - } + ColumnLayout { + anchors.fill: parent - Keys.onDownPressed: { - consoleCmd.text = dapConsoleModel.getCommandDown(); - } + Flickable { + id: scrollCmdHistory + contentY: txtCommand.height - height + Layout.fillWidth: true + Layout.fillHeight: true + clip: true - Keys.onReturnPressed: { - dapConsoleModel.receiveRequest(consoleCmd.text); - txtCommand.append("> " + consoleCmd.text); - consoleCmd.text = ""; - } - } + TextArea.flickable: TextArea { + id: txtCommand + text: dapConsoleModel.getCmdHistory(); + selectByMouse: true + wrapMode: TextArea.WordWrap + color: "#707070" + font.family: "Roboto" + font.pixelSize: 20 * pt - ScrollView { - anchors.left: parent.left - anchors.top: parent.top - anchors.right: parent.right - anchors.bottom: consoleCmd.top - - /*TextArea.flickable: */TextArea { - id: txtCommand - text: dapConsoleModel.getCmdHistory(); - wrapMode: TextArea.Wrap - color: "#707070" - font.family: "Roboto" - font.pixelSize: 20 * pt - focus: false - -// Keys.onPressed: { -// switch(event.key) -// { -// case Qt.Key_Left: break; -// case Qt.Key_Right: break; -// case Qt.Key_Shift: break; -// case Qt.Key_Control: break; -// case Qt.Key_Up: break; -// case Qt.Key_Down: break; -// default: event.accepted = true; break; -// } -// } + Keys.onPressed: { + switch(event.key) + { + case Qt.Key_Left: break; + case Qt.Key_Right: break; + case Qt.Key_Up: break; + case Qt.Key_Down: break; + default: event.accepted = + !(event.modifiers & Qt.ControlModifier) || (event.key === Qt.Key_X); break; + } + } + } + ScrollBar.vertical: ScrollBar { } + ScrollBar.horizontal: ScrollBar { } } -// ScrollBar.vertical: ScrollBar{} + RowLayout { + spacing: 0 - Connections { - target: dapConsoleModel - onSendResponse: { - txtCommand.append(response); + Text { + id: promt + verticalAlignment: Qt.AlignVCenter + text: ">" + color: "#707070" + font.family: "Roboto" + font.pixelSize: 20 * pt } - onCmdHistoryChanged: { - txtCommand.append(history); + TextArea { + id: consoleCmd + + Layout.fillWidth: true + height: contentChildren.height + wrapMode: TextArea.Wrap + color: "#707070" + font.family: "Roboto" + font.pixelSize: 20 * pt + placeholderText: qsTr("Type here...") + selectByMouse: true + focus: true + + Keys.onUpPressed: { + consoleCmd.text = dapConsoleModel.getCommandUp(); + } + + Keys.onDownPressed: { + consoleCmd.text = dapConsoleModel.getCommandDown(); + } + + Keys.onReturnPressed: { + txtCommand.append("> " + consoleCmd.text); + if(consoleCmd.text === "") return; + dapConsoleModel.receiveRequest(consoleCmd.text); + consoleCmd.text = ""; + } } } + + } + + Connections { + target: dapConsoleModel + onSendResponse: { + txtCommand.append(response); + } + + onCmdHistoryChanged: { + txtCommand.append(history); + } } } diff --git a/KelvinDashboardGUI/DapUiQmlWidgetConsoleLastActionsDelegateForm.qml b/KelvinDashboardGUI/DapUiQmlWidgetConsoleLastActionsDelegateForm.qml index 65ae6d23b6144cd7954fcce735ba841e352a355b..5abde372b064a78ef8e4e5ccb1ba52160f887815 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetConsoleLastActionsDelegateForm.qml +++ b/KelvinDashboardGUI/DapUiQmlWidgetConsoleLastActionsDelegateForm.qml @@ -1,14 +1,32 @@ import QtQuick 2.0 +import QtQuick.Layouts 1.13 -Rectangle { - color: "transparent" +Component { + ColumnLayout { + anchors.left: parent.left + anchors.right: parent.right + anchors.leftMargin: 18 * pt + anchors.rightMargin: 18 * pt - Text { - anchors.fill: parent - verticalAlignment: Qt.AlignVCenter - text: lastCommand - color: "#5F5F63" - font.family: "Roboto Regular" - font.pixelSize: 14 * pt + Rectangle { + height: 18 * pt + } + + Text { + id: textLastCmd + Layout.fillWidth: true + verticalAlignment: Qt.AlignVCenter + wrapMode: Text.Wrap + text: lastCommand + color: "#5F5F63" + font.family: "Roboto Regular" + font.pixelSize: 14 * pt + clip: true + } + + Rectangle { + height: 18 * pt + } } + } diff --git a/KelvinDashboardGUI/DapUiQmlWidgetConsoleLastActionsForm.qml b/KelvinDashboardGUI/DapUiQmlWidgetConsoleLastActionsForm.qml index df9a98fedc1a4e1642d540aac80c5a1f3b018844..3b47528267e738a5aac4a9a83a3ae4aa546a823e 100644 --- a/KelvinDashboardGUI/DapUiQmlWidgetConsoleLastActionsForm.qml +++ b/KelvinDashboardGUI/DapUiQmlWidgetConsoleLastActionsForm.qml @@ -1,12 +1,48 @@ import QtQuick 2.0 +import QtQuick.Layouts 1.13 DapUiQmlWidgetLastActions { id: lastActionsPanel viewModel: dapConsoleModel - viewDelegate: DapUiQmlWidgetConsoleLastActionsDelegateForm { - width: lastActionsPanel.width - height: 50 * pt - anchors.left: parent.left - anchors.leftMargin: 18 * pt - } + viewDelegate: DapUiQmlWidgetConsoleLastActionsDelegateForm {} +// width: lastActionsPanel.width +// height: 60 * pt +// anchors.left: parent.left +// anchors.right: parent.right +// anchors.leftMargin: 18 * pt +// anchors.rightMargin: 18 * pt +// } + +// viewDelegate: Component { + +// ColumnLayout { +// anchors.left: parent.left +// anchors.right: parent.right +// anchors.leftMargin: 18 * pt +// anchors.rightMargin: 18 * pt + +// Rectangle { +// height: 18 * pt +// } + +// Text { +// id: textLastCmd +// Layout.fillWidth: true +//// anchors.fill: parent +// verticalAlignment: Qt.AlignVCenter +// wrapMode: Text.Wrap +// text: lastCommand +// color: "#5F5F63" +// font.family: "Roboto Regular" +// font.pixelSize: 14 * pt +// clip: true +// } + +// Rectangle { +// height: 18 * pt +// } +// } + +// } + } diff --git a/KelvinDashboardService/DapChainConsoleHandler.cpp b/KelvinDashboardService/DapChainConsoleHandler.cpp index ce3706d486c954a86115f07e14c0d153801d0fe5..c13b20ac7eda6d00de44bdeec7eb5c192845734c 100644 --- a/KelvinDashboardService/DapChainConsoleHandler.cpp +++ b/KelvinDashboardService/DapChainConsoleHandler.cpp @@ -16,13 +16,9 @@ QString DapChainConsoleHandler::getHistory() const while (m_File->pos() > 0) { QByteArray symbol = m_File->read(1); - if(symbol == ">") - { - ++countCmd; - if(countCmd == MAX_COUNT_CMD) break; - } - + if(symbol == ">") ++countCmd; m_File->seek(m_File->pos() - 2); + if(countCmd == MAX_COUNT_CMD) break; } QByteArray lastCmd = m_File->read(m_File->size() - m_File->pos());