From c22df42b0b44830011bce256faf62eb824c5d63d Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 9 Mar 2015 13:11:02 +0100 Subject: [PATCH] - use input to filter logs by any str. - format exceptions coming from Executive.cpp --- mix/qml/LogsPane.qml | 66 +++++++++++++++++++++++++----------- mix/qml/StatusPane.qml | 23 +++++++++++-- mix/sortfilterproxymodel.cpp | 64 +++++++++++++++++++++++++++++----- mix/sortfilterproxymodel.h | 18 ++++++++-- 4 files changed, 138 insertions(+), 33 deletions(-) diff --git a/mix/qml/LogsPane.qml b/mix/qml/LogsPane.qml index 9fa15f250..ca78b3854 100644 --- a/mix/qml/LogsPane.qml +++ b/mix/qml/LogsPane.qml @@ -12,6 +12,7 @@ Rectangle _content = _content.replace(/\n/g, " ") logsModel.insert(0, { "type": _type, "date": Qt.formatDateTime(new Date(), "hh:mm:ss dd.MM.yyyy"), "content": _content, "level": _level }); } + anchors.fill: parent radius: 5 color: "#f7f7f7" @@ -150,10 +151,24 @@ Rectangle } } } + + DefaultTextField + { + id: searchBox + height: 30 + anchors.verticalCenter: parent.verticalCenter + width: 200 + font.family: "sans serif" + font.pointSize: Style.absoluteSize(-3) + onTextChanged: { + proxyModel.search(text); + } + } } ListModel { id: logsModel + } TableView { @@ -171,17 +186,41 @@ Rectangle model: SortFilterProxyModel { id: proxyModel source: logsModel + property var roles: ["-", "javascript", "run", "state"] + + Component.onCompleted: { + filterType = regEx(proxyModel.roles); + } + + function search(_value) + { + filterContent = _value; + } function toogleFilter(_value) { - if (filterString.indexOf('_' + _value) !== -1) - filterString = filterString.replace('_' + _value, _value); - else - filterString = filterString.replace(_value, '_' + _value); + var count = roles.length; + for (var i in roles) + { + if (roles[i] === _value) + { + roles.splice(i, 1); + break; + } + } + if (count === roles.length) + roles.push(_value); + + filterType = regEx(proxyModel.roles); } - filterRole: "type" - filterString: "(?:javascript|run|state)" + function regEx(_value) + { + console.log("(?:" + roles.join('|') + ")"); + return "(?:" + roles.join('|') + ")"; + } + filterType: "(?:javascript|run|state)" + filterContent: "" filterSyntax: SortFilterProxyModel.RegExp filterCaseSensitivity: Qt.CaseInsensitive } @@ -214,20 +253,7 @@ Rectangle text: styleData.value; font.family: "sans serif" font.pointSize: Style.absoluteSize(-1) - color: { - if (styleData.row > -1) - { - var l = logsModel.get(styleData.row).level - if (l === "error") - return "red" - else if (l === "warning") - return "orange" - else if (l === "info") - return "#808080" - } - else - return "#808080" - } + color: "#808080" } } } diff --git a/mix/qml/StatusPane.qml b/mix/qml/StatusPane.qml index 141d45a48..2a2eeb910 100644 --- a/mix/qml/StatusPane.qml +++ b/mix/qml/StatusPane.qml @@ -59,9 +59,28 @@ Rectangle { Connections { target:clientModel onRunStarted: infoMessage(qsTr("Running transactions..."), "run"); - onRunFailed: errorMessage(qsTr("Error running transactions: " + _message), "run"); + onRunFailed: errorMessage(format(_message), "run"); onRunComplete: infoMessage(qsTr("Run complete"), "run"); onNewBlock: infoMessage(qsTr("New block created"), "state"); + + function format(_message) + { + var formatted = _message.match(/(?:)/); + if (formatted.length > 1) + formatted = formatted[1] + ": "; + var exceptionInfos = _message.match(/(tag_)(.+)/g); + console.log("hh " + exceptionInfos.length); + for (var k in exceptionInfos) + { + formatted += " " + exceptionInfos[k].replace("*]", "").replace("tag_", ""); + console.log(k); + if (k === exceptionInfos.length - 1) + formatted += "." + else + formatted += "," + } + return formatted; + } } Connections { target:projectModel @@ -82,7 +101,7 @@ Rectangle { Rectangle { id: statusContainer anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter + anchors.verticalCenter: parent.verticalCenterw radius: 3 width: 500 height: 30 diff --git a/mix/sortfilterproxymodel.cpp b/mix/sortfilterproxymodel.cpp index 75a50ea59..04e403738 100644 --- a/mix/sortfilterproxymodel.cpp +++ b/mix/sortfilterproxymodel.cpp @@ -80,15 +80,15 @@ void SortFilterProxyModel::setSortOrder(Qt::SortOrder order) QSortFilterProxyModel::sort(0, order); } -QByteArray SortFilterProxyModel::filterRole() const +/*QByteArray SortFilterProxyModel::filterRole() const { return roleNames().value(QSortFilterProxyModel::filterRole()); -} +}*/ -void SortFilterProxyModel::setFilterRole(const QByteArray &role) +/*void SortFilterProxyModel::setFilterRole(const QByteArray &role) { QSortFilterProxyModel::setFilterRole(roleKey(role)); -} +}*/ QString SortFilterProxyModel::filterString() const { @@ -146,10 +146,11 @@ QHash SortFilterProxyModel::roleNames() const bool SortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { - QRegExp rx = filterRegExp(); + /*QRegExp rx = filterRegExp(); if (rx.isEmpty()) return true; QAbstractItemModel *model = sourceModel(); + if (filterRole().isEmpty()) { QHash roles = roleNames(); QHashIterator it(roles); @@ -157,14 +158,61 @@ bool SortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &so it.next(); QModelIndex sourceIndex = model->index(sourceRow, 0, sourceParent); QString key = model->data(sourceIndex, it.key()).toString(); - if (key.contains(rx)) + if (key.contains(rx))data return true; } return false; + }*/ + + QRegExp rx = filterRegExp(); + QAbstractItemModel *model = sourceModel(); + QModelIndex sourceIndex = model->index(sourceRow, 0, sourceParent); + if (!sourceIndex.isValid()) + return true; + + QString keyType = model->data(sourceIndex, roleKey(type.toUtf8())).toString(); + QString keyContent = model->data(sourceIndex, roleKey(content.toUtf8())).toString(); + + return keyType.contains(m_filterType) && keyContent.contains(m_filterContent); +/* + for (auto filter: filterRoles()) + { + QString key = model->data(sourceIndex, roleKey(filter.toUtf8())).toString(); + if (!key.contains(rx)) + return false; } + return true; QModelIndex sourceIndex = model->index(sourceRow, 0, sourceParent); if (!sourceIndex.isValid()) return true; - QString key = model->data(sourceIndex, roleKey(filterRole())).toString(); - return key.contains(rx); + for (auto role: filterR) + { + QString key = model->data(sourceIndex, roleKey(role)).toString(); + if (key.contains(rx)) + return true; + } + return false;*/ +} + +void SortFilterProxyModel::setFilterType(const QString &_type) +{ + m_filterType = QRegExp(_type, filterCaseSensitivity(), static_cast(filterSyntax())); + setFilterRegExp(_type); +} + +QString SortFilterProxyModel::filterType() const +{ + return m_filterType.pattern(); } + +void SortFilterProxyModel::setFilterContent(const QString &_content) +{ + m_filterContent = QRegExp(_content, filterCaseSensitivity(), static_cast(filterSyntax())); + setFilterRegExp(_content); +} + +QString SortFilterProxyModel::filterContent() const +{ + return m_filterContent.pattern(); +} + diff --git a/mix/sortfilterproxymodel.h b/mix/sortfilterproxymodel.h index 2ff479413..8eae97a68 100644 --- a/mix/sortfilterproxymodel.h +++ b/mix/sortfilterproxymodel.h @@ -58,7 +58,8 @@ class SortFilterProxyModel : public QSortFilterProxyModel Q_PROPERTY(QByteArray sortRole READ sortRole WRITE setSortRole) Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder) - Q_PROPERTY(QByteArray filterRole READ filterRole WRITE setFilterRole) + Q_PROPERTY(QString filterContent READ filterContent WRITE setFilterContent) + Q_PROPERTY(QString filterType READ filterType WRITE setFilterType) Q_PROPERTY(QString filterString READ filterString WRITE setFilterString) Q_PROPERTY(FilterSyntax filterSyntax READ filterSyntax WRITE setFilterSyntax) @@ -75,9 +76,14 @@ public: void setSortOrder(Qt::SortOrder order); - QByteArray filterRole() const; - void setFilterRole(const QByteArray &role); + QString filterContent() const; + void setFilterContent(const QString &_content); + QString filterType() const; + void setFilterType(const QString &_type); + /*QStringList filterRoles() const; + void setFilterRoles(const QStringList &roles); +*/ QString filterString() const; void setFilterString(const QString &filter); @@ -100,6 +106,12 @@ protected: int roleKey(const QByteArray &role) const; QHash roleNames() const; bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; + +private: + QRegExp m_filterType; + QRegExp m_filterContent; + const QString type = "type"; + const QString content = "content"; }; }