yann300
10 years ago
11 changed files with 522 additions and 30 deletions
@ -0,0 +1,143 @@ |
|||
import QtQuick 2.0 |
|||
import QtQuick.Layouts 1.0 |
|||
import QtQuick.Controls 1.1 |
|||
import org.ethereum.qml.SortFilterProxyModel 1.0 |
|||
import "." |
|||
|
|||
Rectangle |
|||
{ |
|||
function push(_level, _type, _content) |
|||
{ |
|||
_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" |
|||
border.color: "#808080" |
|||
border.width: 2 |
|||
ColumnLayout { |
|||
height: parent.height - 4 |
|||
width: parent.width - 2 |
|||
spacing: 0 |
|||
Row |
|||
{ |
|||
id: rowAction |
|||
Layout.preferredHeight: 35 |
|||
height: 35 |
|||
anchors.leftMargin: 10 |
|||
anchors.left: parent.left |
|||
spacing: 5 |
|||
Button |
|||
{ |
|||
height: 30 |
|||
anchors.verticalCenter: parent.verticalCenter |
|||
action: clearAction |
|||
iconSource: "qrc:/qml/img/broom.png" |
|||
} |
|||
|
|||
Action { |
|||
id: clearAction |
|||
enabled: logsModel.count > 0 |
|||
tooltip: qsTr("Clear") |
|||
onTriggered: { |
|||
logsModel.clear() |
|||
} |
|||
} |
|||
|
|||
Button |
|||
{ |
|||
height: 30 |
|||
anchors.verticalCenter: parent.verticalCenter |
|||
action: copytoClipBoardAction |
|||
iconSource: "qrc:/qml/img/copy.png" |
|||
} |
|||
|
|||
Action { |
|||
id: copytoClipBoardAction |
|||
enabled: logsModel.count > 0 |
|||
tooltip: qsTr("Copy to Clipboard") |
|||
onTriggered: { |
|||
var content = ""; |
|||
for (var k = 0; k < logsModel.count; k++) |
|||
{ |
|||
var log = logsModel.get(k); |
|||
content += log.type + "\t" + log.level + "\t" + log.date + "\t" + log.content; |
|||
} |
|||
appContext.toClipboard(content); |
|||
} |
|||
} |
|||
} |
|||
|
|||
ListModel { |
|||
id: logsModel |
|||
} |
|||
|
|||
TableView { |
|||
id: logsTable |
|||
clip: true |
|||
Layout.fillWidth: true |
|||
Layout.preferredHeight: parent.height - rowAction.height |
|||
headerVisible : false |
|||
onDoubleClicked: |
|||
{ |
|||
var log = logsModel.get((logsTable.currentRow)); |
|||
appContext.toClipboard(log.type + " " + log.level + " " + log.date + " " + log.content); |
|||
} |
|||
|
|||
model: SortFilterProxyModel { |
|||
id: proxyModel |
|||
source: logsModel |
|||
|
|||
filterRole: "" |
|||
filterString: "" |
|||
filterSyntax: SortFilterProxyModel.Wildcard |
|||
filterCaseSensitivity: Qt.CaseInsensitive |
|||
} |
|||
TableViewColumn |
|||
{ |
|||
role: "date" |
|||
title: qsTr("date") |
|||
width: 150 |
|||
delegate: itemDelegate |
|||
} |
|||
TableViewColumn |
|||
{ |
|||
role: "type" |
|||
title: qsTr("type") |
|||
width: 100 |
|||
delegate: itemDelegate |
|||
} |
|||
TableViewColumn |
|||
{ |
|||
role: "content" |
|||
title: qsTr("content") |
|||
width: 700 |
|||
delegate: itemDelegate |
|||
} |
|||
} |
|||
|
|||
Component { |
|||
id: itemDelegate |
|||
DefaultLabel { |
|||
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" |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
After Width: | Height: | Size: 501 B |
After Width: | Height: | Size: 342 B |
@ -0,0 +1,170 @@ |
|||
/****************************************************************************
|
|||
** |
|||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
|||
** Contact: http://www.qt-project.org/legal
|
|||
** |
|||
** This file is part of the examples of the Qt Toolkit. |
|||
** |
|||
** $QT_BEGIN_LICENSE:BSD$ |
|||
** You may use this file under the terms of the BSD license as follows: |
|||
** |
|||
** "Redistribution and use in source and binary forms, with or without |
|||
** modification, are permitted provided that the following conditions are |
|||
** met: |
|||
** * Redistributions of source code must retain the above copyright |
|||
** notice, this list of conditions and the following disclaimer. |
|||
** * Redistributions in binary form must reproduce the above copyright |
|||
** notice, this list of conditions and the following disclaimer in |
|||
** the documentation and/or other materials provided with the |
|||
** distribution. |
|||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names |
|||
** of its contributors may be used to endorse or promote products derived |
|||
** from this software without specific prior written permission. |
|||
** |
|||
** |
|||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
|||
** |
|||
** $QT_END_LICENSE$ |
|||
** |
|||
****************************************************************************/ |
|||
|
|||
#include "sortfilterproxymodel.h" |
|||
#include <QtDebug> |
|||
#include <QtQml> |
|||
|
|||
using namespace dev::mix; |
|||
|
|||
SortFilterProxyModel::SortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent) |
|||
{ |
|||
connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(countChanged())); |
|||
connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(countChanged())); |
|||
} |
|||
|
|||
int SortFilterProxyModel::count() const |
|||
{ |
|||
return rowCount(); |
|||
} |
|||
|
|||
QObject *SortFilterProxyModel::source() const |
|||
{ |
|||
return sourceModel(); |
|||
} |
|||
|
|||
void SortFilterProxyModel::setSource(QObject *source) |
|||
{ |
|||
setSourceModel(qobject_cast<QAbstractItemModel *>(source)); |
|||
} |
|||
|
|||
QByteArray SortFilterProxyModel::sortRole() const |
|||
{ |
|||
return roleNames().value(QSortFilterProxyModel::sortRole()); |
|||
} |
|||
|
|||
void SortFilterProxyModel::setSortRole(const QByteArray &role) |
|||
{ |
|||
QSortFilterProxyModel::setSortRole(roleKey(role)); |
|||
} |
|||
|
|||
void SortFilterProxyModel::setSortOrder(Qt::SortOrder order) |
|||
{ |
|||
QSortFilterProxyModel::sort(0, order); |
|||
} |
|||
|
|||
QByteArray SortFilterProxyModel::filterRole() const |
|||
{ |
|||
return roleNames().value(QSortFilterProxyModel::filterRole()); |
|||
} |
|||
|
|||
void SortFilterProxyModel::setFilterRole(const QByteArray &role) |
|||
{ |
|||
QSortFilterProxyModel::setFilterRole(roleKey(role)); |
|||
} |
|||
|
|||
QString SortFilterProxyModel::filterString() const |
|||
{ |
|||
return filterRegExp().pattern(); |
|||
} |
|||
|
|||
void SortFilterProxyModel::setFilterString(const QString &filter) |
|||
{ |
|||
setFilterRegExp(QRegExp(filter, filterCaseSensitivity(), static_cast<QRegExp::PatternSyntax>(filterSyntax()))); |
|||
} |
|||
|
|||
SortFilterProxyModel::FilterSyntax SortFilterProxyModel::filterSyntax() const |
|||
{ |
|||
return static_cast<FilterSyntax>(filterRegExp().patternSyntax()); |
|||
} |
|||
|
|||
void SortFilterProxyModel::setFilterSyntax(SortFilterProxyModel::FilterSyntax syntax) |
|||
{ |
|||
setFilterRegExp(QRegExp(filterString(), filterCaseSensitivity(), static_cast<QRegExp::PatternSyntax>(syntax))); |
|||
} |
|||
|
|||
QJSValue SortFilterProxyModel::get(int idx) const |
|||
{ |
|||
QJSEngine *engine = qmlEngine(this); |
|||
QJSValue value = engine->newObject(); |
|||
if (idx >= 0 && idx < count()) { |
|||
QHash<int, QByteArray> roles = roleNames(); |
|||
QHashIterator<int, QByteArray> it(roles); |
|||
while (it.hasNext()) { |
|||
it.next(); |
|||
value.setProperty(QString::fromUtf8(it.value()), data(index(idx, 0), it.key()).toString()); |
|||
} |
|||
} |
|||
return value; |
|||
} |
|||
|
|||
int SortFilterProxyModel::roleKey(const QByteArray &role) const |
|||
{ |
|||
QHash<int, QByteArray> roles = roleNames(); |
|||
QHashIterator<int, QByteArray> it(roles); |
|||
while (it.hasNext()) { |
|||
it.next(); |
|||
if (it.value() == role) |
|||
return it.key(); |
|||
} |
|||
return -1; |
|||
} |
|||
|
|||
QHash<int, QByteArray> SortFilterProxyModel::roleNames() const |
|||
{ |
|||
if (QAbstractItemModel *source = sourceModel()) |
|||
return source->roleNames(); |
|||
return QHash<int, QByteArray>(); |
|||
} |
|||
|
|||
bool SortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const |
|||
{ |
|||
QRegExp rx = filterRegExp(); |
|||
if (rx.isEmpty()) |
|||
return true; |
|||
QAbstractItemModel *model = sourceModel(); |
|||
if (filterRole().isEmpty()) { |
|||
QHash<int, QByteArray> roles = roleNames(); |
|||
QHashIterator<int, QByteArray> it(roles); |
|||
while (it.hasNext()) { |
|||
it.next(); |
|||
QModelIndex sourceIndex = model->index(sourceRow, 0, sourceParent); |
|||
QString key = model->data(sourceIndex, it.key()).toString(); |
|||
if (key.contains(rx)) |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
QModelIndex sourceIndex = model->index(sourceRow, 0, sourceParent); |
|||
if (!sourceIndex.isValid()) |
|||
return true; |
|||
QString key = model->data(sourceIndex, roleKey(filterRole())).toString(); |
|||
return key.contains(rx); |
|||
} |
@ -0,0 +1,107 @@ |
|||
/****************************************************************************
|
|||
** |
|||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
|||
** Contact: http://www.qt-project.org/legal
|
|||
** |
|||
** This file is part of the examples of the Qt Toolkit. |
|||
** |
|||
** $QT_BEGIN_LICENSE:BSD$ |
|||
** You may use this file under the terms of the BSD license as follows: |
|||
** |
|||
** "Redistribution and use in source and binary forms, with or without |
|||
** modification, are permitted provided that the following conditions are |
|||
** met: |
|||
** * Redistributions of source code must retain the above copyright |
|||
** notice, this list of conditions and the following disclaimer. |
|||
** * Redistributions in binary form must reproduce the above copyright |
|||
** notice, this list of conditions and the following disclaimer in |
|||
** the documentation and/or other materials provided with the |
|||
** distribution. |
|||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names |
|||
** of its contributors may be used to endorse or promote products derived |
|||
** from this software without specific prior written permission. |
|||
** |
|||
** |
|||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
|||
** |
|||
** $QT_END_LICENSE$ |
|||
** |
|||
****************************************************************************/ |
|||
|
|||
#ifndef SORTFILTERPROXYMODEL_H |
|||
#define SORTFILTERPROXYMODEL_H |
|||
|
|||
#include <QtCore/qsortfilterproxymodel.h> |
|||
#include <QtQml/qjsvalue.h> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace mix |
|||
{ |
|||
|
|||
class SortFilterProxyModel : public QSortFilterProxyModel |
|||
{ |
|||
Q_OBJECT |
|||
Q_PROPERTY(int count READ count NOTIFY countChanged) |
|||
Q_PROPERTY(QObject *source READ source WRITE setSource) |
|||
|
|||
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 filterString READ filterString WRITE setFilterString) |
|||
Q_PROPERTY(FilterSyntax filterSyntax READ filterSyntax WRITE setFilterSyntax) |
|||
|
|||
Q_ENUMS(FilterSyntax) |
|||
|
|||
public: |
|||
explicit SortFilterProxyModel(QObject *parent = 0); |
|||
|
|||
QObject *source() const; |
|||
void setSource(QObject *source); |
|||
|
|||
QByteArray sortRole() const; |
|||
void setSortRole(const QByteArray &role); |
|||
|
|||
void setSortOrder(Qt::SortOrder order); |
|||
|
|||
QByteArray filterRole() const; |
|||
void setFilterRole(const QByteArray &role); |
|||
|
|||
QString filterString() const; |
|||
void setFilterString(const QString &filter); |
|||
|
|||
enum FilterSyntax { |
|||
RegExp, |
|||
Wildcard, |
|||
FixedString |
|||
}; |
|||
|
|||
FilterSyntax filterSyntax() const; |
|||
void setFilterSyntax(FilterSyntax syntax); |
|||
|
|||
int count() const; |
|||
Q_INVOKABLE QJSValue get(int index) const; |
|||
|
|||
signals: |
|||
void countChanged(); |
|||
|
|||
protected: |
|||
int roleKey(const QByteArray &role) const; |
|||
QHash<int, QByteArray> roleNames() const; |
|||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; |
|||
}; |
|||
|
|||
} |
|||
} |
|||
#endif // SORTFILTERPROXYMODEL_H
|
Loading…
Reference in new issue