Browse Source

- use input to filter logs by any str.

- format exceptions coming from Executive.cpp
cl-refactor
yann300 10 years ago
parent
commit
c22df42b0b
  1. 66
      mix/qml/LogsPane.qml
  2. 23
      mix/qml/StatusPane.qml
  3. 64
      mix/sortfilterproxymodel.cpp
  4. 18
      mix/sortfilterproxymodel.h

66
mix/qml/LogsPane.qml

@ -12,6 +12,7 @@ Rectangle
_content = _content.replace(/\n/g, " ") _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 }); logsModel.insert(0, { "type": _type, "date": Qt.formatDateTime(new Date(), "hh:mm:ss dd.MM.yyyy"), "content": _content, "level": _level });
} }
anchors.fill: parent anchors.fill: parent
radius: 5 radius: 5
color: "#f7f7f7" 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 { ListModel {
id: logsModel id: logsModel
} }
TableView { TableView {
@ -171,17 +186,41 @@ Rectangle
model: SortFilterProxyModel { model: SortFilterProxyModel {
id: proxyModel id: proxyModel
source: logsModel source: logsModel
property var roles: ["-", "javascript", "run", "state"]
Component.onCompleted: {
filterType = regEx(proxyModel.roles);
}
function search(_value)
{
filterContent = _value;
}
function toogleFilter(_value) function toogleFilter(_value)
{ {
if (filterString.indexOf('_' + _value) !== -1) var count = roles.length;
filterString = filterString.replace('_' + _value, _value); for (var i in roles)
else {
filterString = filterString.replace(_value, '_' + _value); if (roles[i] === _value)
{
roles.splice(i, 1);
break;
}
}
if (count === roles.length)
roles.push(_value);
filterType = regEx(proxyModel.roles);
} }
filterRole: "type" function regEx(_value)
filterString: "(?:javascript|run|state)" {
console.log("(?:" + roles.join('|') + ")");
return "(?:" + roles.join('|') + ")";
}
filterType: "(?:javascript|run|state)"
filterContent: ""
filterSyntax: SortFilterProxyModel.RegExp filterSyntax: SortFilterProxyModel.RegExp
filterCaseSensitivity: Qt.CaseInsensitive filterCaseSensitivity: Qt.CaseInsensitive
} }
@ -214,20 +253,7 @@ Rectangle
text: styleData.value; text: styleData.value;
font.family: "sans serif" font.family: "sans serif"
font.pointSize: Style.absoluteSize(-1) font.pointSize: Style.absoluteSize(-1)
color: { color: "#808080"
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"
}
} }
} }
} }

23
mix/qml/StatusPane.qml

@ -59,9 +59,28 @@ Rectangle {
Connections { Connections {
target:clientModel target:clientModel
onRunStarted: infoMessage(qsTr("Running transactions..."), "run"); 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"); onRunComplete: infoMessage(qsTr("Run complete"), "run");
onNewBlock: infoMessage(qsTr("New block created"), "state"); onNewBlock: infoMessage(qsTr("New block created"), "state");
function format(_message)
{
var formatted = _message.match(/(?:<dev::eth::)(.+)(?:>)/);
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 { Connections {
target:projectModel target:projectModel
@ -82,7 +101,7 @@ Rectangle {
Rectangle { Rectangle {
id: statusContainer id: statusContainer
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenterw
radius: 3 radius: 3
width: 500 width: 500
height: 30 height: 30

64
mix/sortfilterproxymodel.cpp

@ -80,15 +80,15 @@ void SortFilterProxyModel::setSortOrder(Qt::SortOrder order)
QSortFilterProxyModel::sort(0, order); QSortFilterProxyModel::sort(0, order);
} }
QByteArray SortFilterProxyModel::filterRole() const /*QByteArray SortFilterProxyModel::filterRole() const
{ {
return roleNames().value(QSortFilterProxyModel::filterRole()); return roleNames().value(QSortFilterProxyModel::filterRole());
} }*/
void SortFilterProxyModel::setFilterRole(const QByteArray &role) /*void SortFilterProxyModel::setFilterRole(const QByteArray &role)
{ {
QSortFilterProxyModel::setFilterRole(roleKey(role)); QSortFilterProxyModel::setFilterRole(roleKey(role));
} }*/
QString SortFilterProxyModel::filterString() const QString SortFilterProxyModel::filterString() const
{ {
@ -146,10 +146,11 @@ QHash<int, QByteArray> SortFilterProxyModel::roleNames() const
bool SortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const bool SortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{ {
QRegExp rx = filterRegExp(); /*QRegExp rx = filterRegExp();
if (rx.isEmpty()) if (rx.isEmpty())
return true; return true;
QAbstractItemModel *model = sourceModel(); QAbstractItemModel *model = sourceModel();
if (filterRole().isEmpty()) { if (filterRole().isEmpty()) {
QHash<int, QByteArray> roles = roleNames(); QHash<int, QByteArray> roles = roleNames();
QHashIterator<int, QByteArray> it(roles); QHashIterator<int, QByteArray> it(roles);
@ -157,14 +158,61 @@ bool SortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &so
it.next(); it.next();
QModelIndex sourceIndex = model->index(sourceRow, 0, sourceParent); QModelIndex sourceIndex = model->index(sourceRow, 0, sourceParent);
QString key = model->data(sourceIndex, it.key()).toString(); QString key = model->data(sourceIndex, it.key()).toString();
if (key.contains(rx)) if (key.contains(rx))data
return true; return true;
} }
return false; 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); QModelIndex sourceIndex = model->index(sourceRow, 0, sourceParent);
if (!sourceIndex.isValid()) if (!sourceIndex.isValid())
return true; return true;
QString key = model->data(sourceIndex, roleKey(filterRole())).toString(); for (auto role: filterR)
return key.contains(rx); {
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<QRegExp::PatternSyntax>(filterSyntax()));
setFilterRegExp(_type);
}
QString SortFilterProxyModel::filterType() const
{
return m_filterType.pattern();
} }
void SortFilterProxyModel::setFilterContent(const QString &_content)
{
m_filterContent = QRegExp(_content, filterCaseSensitivity(), static_cast<QRegExp::PatternSyntax>(filterSyntax()));
setFilterRegExp(_content);
}
QString SortFilterProxyModel::filterContent() const
{
return m_filterContent.pattern();
}

18
mix/sortfilterproxymodel.h

@ -58,7 +58,8 @@ class SortFilterProxyModel : public QSortFilterProxyModel
Q_PROPERTY(QByteArray sortRole READ sortRole WRITE setSortRole) Q_PROPERTY(QByteArray sortRole READ sortRole WRITE setSortRole)
Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder) 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(QString filterString READ filterString WRITE setFilterString)
Q_PROPERTY(FilterSyntax filterSyntax READ filterSyntax WRITE setFilterSyntax) Q_PROPERTY(FilterSyntax filterSyntax READ filterSyntax WRITE setFilterSyntax)
@ -75,9 +76,14 @@ public:
void setSortOrder(Qt::SortOrder order); void setSortOrder(Qt::SortOrder order);
QByteArray filterRole() const; QString filterContent() const;
void setFilterRole(const QByteArray &role); void setFilterContent(const QString &_content);
QString filterType() const;
void setFilterType(const QString &_type);
/*QStringList filterRoles() const;
void setFilterRoles(const QStringList &roles);
*/
QString filterString() const; QString filterString() const;
void setFilterString(const QString &filter); void setFilterString(const QString &filter);
@ -100,6 +106,12 @@ protected:
int roleKey(const QByteArray &role) const; int roleKey(const QByteArray &role) const;
QHash<int, QByteArray> roleNames() const; QHash<int, QByteArray> roleNames() const;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
private:
QRegExp m_filterType;
QRegExp m_filterContent;
const QString type = "type";
const QString content = "content";
}; };
} }

Loading…
Cancel
Save