yann300
10 years ago
4 changed files with 122 additions and 156 deletions
@ -1,44 +1,27 @@ |
|||||
/****************************************************************************
|
/*
|
||||
** |
This file is part of cpp-ethereum. |
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
|
||||
** Contact: http://www.qt-project.org/legal
|
cpp-ethereum is free software: you can redistribute it and/or modify |
||||
** |
it under the terms of the GNU General Public License as published by |
||||
** This file is part of the examples of the Qt Toolkit. |
the Free Software Foundation, either version 3 of the License, or |
||||
** |
(at your option) any later version. |
||||
** $QT_BEGIN_LICENSE:BSD$ |
|
||||
** You may use this file under the terms of the BSD license as follows: |
cpp-ethereum is distributed in the hope that it will be useful, |
||||
** |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
** "Redistribution and use in source and binary forms, with or without |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
** modification, are permitted provided that the following conditions are |
GNU General Public License for more details. |
||||
** met: |
|
||||
** * Redistributions of source code must retain the above copyright |
You should have received a copy of the GNU General Public License |
||||
** notice, this list of conditions and the following disclaimer. |
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
** * 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 |
* @author Yann <yann@ethdev.com> |
||||
** distribution. |
* @date 2015 |
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names |
* Proxy used to filter a QML TableView. |
||||
** of its contributors may be used to endorse or promote products derived |
*/ |
||||
** from this software without specific prior written permission. |
|
||||
** |
|
||||
** |
#include "Sortfilterproxymodel.h" |
||||
** 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 <QtDebug> |
||||
#include <QtQml> |
#include <QtQml> |
||||
|
|
@ -0,0 +1,97 @@ |
|||||
|
/*
|
||||
|
This file is part of cpp-ethereum. |
||||
|
|
||||
|
cpp-ethereum is free software: you can redistribute it and/or modify |
||||
|
it under the terms of the GNU General Public License as published by |
||||
|
the Free Software Foundation, either version 3 of the License, or |
||||
|
(at your option) any later version. |
||||
|
|
||||
|
cpp-ethereum is distributed in the hope that it will be useful, |
||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
GNU General Public License for more details. |
||||
|
|
||||
|
You should have received a copy of the GNU General Public License |
||||
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
/**
|
||||
|
* @author Yann <yann@ethdev.com> |
||||
|
* @date 2015 |
||||
|
* Proxy used to filter a QML TableView. |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#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(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) |
||||
|
|
||||
|
Q_ENUMS(FilterSyntax) |
||||
|
|
||||
|
public: |
||||
|
explicit SortFilterProxyModel(QObject* _parent = 0); |
||||
|
|
||||
|
QObject* source() const; |
||||
|
void setSource(QObject* _source); |
||||
|
|
||||
|
QByteArray sortRole() const; |
||||
|
void setSortRole(QByteArray const& _role); |
||||
|
|
||||
|
void setSortOrder(Qt::SortOrder _order); |
||||
|
|
||||
|
QString filterContent() const; |
||||
|
void setFilterContent(QString const& _content); |
||||
|
QString filterType() const; |
||||
|
void setFilterType(QString const& _type); |
||||
|
|
||||
|
QString filterString() const; |
||||
|
void setFilterString(QString const& _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(QByteArray const& _role) const; |
||||
|
QHash<int, QByteArray> roleNames() const; |
||||
|
bool filterAcceptsRow(int _sourceRow, QModelIndex const& _sourceParent) const; |
||||
|
|
||||
|
private: |
||||
|
QRegExp m_filterType; |
||||
|
QRegExp m_filterContent; |
||||
|
const QString type = "type"; |
||||
|
const QString content = "content"; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
} |
@ -1,114 +0,0 @@ |
|||||
/****************************************************************************
|
|
||||
** |
|
||||
** 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$ |
|
||||
** |
|
||||
****************************************************************************/ |
|
||||
|
|
||||
#pragma once |
|
||||
|
|
||||
#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(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) |
|
||||
|
|
||||
Q_ENUMS(FilterSyntax) |
|
||||
|
|
||||
public: |
|
||||
explicit SortFilterProxyModel(QObject* _parent = 0); |
|
||||
|
|
||||
QObject* source() const; |
|
||||
void setSource(QObject* _source); |
|
||||
|
|
||||
QByteArray sortRole() const; |
|
||||
void setSortRole(QByteArray const& _role); |
|
||||
|
|
||||
void setSortOrder(Qt::SortOrder _order); |
|
||||
|
|
||||
QString filterContent() const; |
|
||||
void setFilterContent(QString const& _content); |
|
||||
QString filterType() const; |
|
||||
void setFilterType(QString const& _type); |
|
||||
|
|
||||
QString filterString() const; |
|
||||
void setFilterString(QString const& _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(QByteArray const& _role) const; |
|
||||
QHash<int, QByteArray> roleNames() const; |
|
||||
bool filterAcceptsRow(int _sourceRow, QModelIndex const& _sourceParent) const; |
|
||||
|
|
||||
private: |
|
||||
QRegExp m_filterType; |
|
||||
QRegExp m_filterContent; |
|
||||
const QString type = "type"; |
|
||||
const QString content = "content"; |
|
||||
}; |
|
||||
|
|
||||
} |
|
||||
} |
|
Loading…
Reference in new issue