sortfilterproxymodel.h
#ifndef SORTFILTERPROXYMODEL_H
#define SORTFILTERPROXYMODEL_H
#include <QSortFilterProxyModel>
namespace CerSimpleDynamics
{
namespace Models
{
{
Q_OBJECT
public:
explicit SortFilterProxyModel
(QObject *parent
= 0);
void setFilterKeyColumns(const QList<qint32> &filterColumns);
void addFilterFixedString
(qint32 column,
const QString &pattern
);
protected:
bool filterAcceptsRow
(int sourceRow,
const QModelIndex &sourceParent
) const;
private:
QMap<qint32, QString> m_columnPatterns;
};
}
}
#endif // SORTFILTERPROXYMODEL_H
#ifndef SORTFILTERPROXYMODEL_H
#define SORTFILTERPROXYMODEL_H
#include <QSortFilterProxyModel>
namespace CerSimpleDynamics
{
namespace Models
{
class SortFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit SortFilterProxyModel(QObject *parent = 0);
void setFilterKeyColumns(const QList<qint32> &filterColumns);
void addFilterFixedString(qint32 column, const QString &pattern);
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
private:
QMap<qint32, QString> m_columnPatterns;
};
}
}
#endif // SORTFILTERPROXYMODEL_H
To copy to clipboard, switch view to plain text mode
sortfilterproxymodel.cpp
#include "sortfilterproxymodel.h"
namespace CerSimpleDynamics
{
namespace Models
{
{
}
void SortFilterProxyModel::setFilterKeyColumns(const QList<qint32> &filterColumns)
{
m_columnPatterns.clear();
foreach(qint32 column, filterColumns)
m_columnPatterns.
insert(column,
QString());
}
void SortFilterProxyModel
::addFilterFixedString(qint32 column,
const QString &pattern
) {
if(!m_columnPatterns.contains(column))
return;
m_columnPatterns[column] = pattern;
}
bool SortFilterProxyModel
::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent
) const {
if(m_columnPatterns.isEmpty())
return true;
bool ret = false;
for(QMap<qint32, QString>::const_iterator iter = m_columnPatterns.constBegin();
iter != m_columnPatterns.constEnd();
++iter)
{
QModelIndex index
= sourceModel
()->index
(sourceRow, iter.
key(), sourceParent
);
ret = (index.data().toString() == iter.value());
if(!ret)
return ret;
}
return ret;
}
}
}
#include "moc_sortfilterproxymodel.cpp"
#include "sortfilterproxymodel.h"
namespace CerSimpleDynamics
{
namespace Models
{
SortFilterProxyModel::SortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
{
}
void SortFilterProxyModel::setFilterKeyColumns(const QList<qint32> &filterColumns)
{
m_columnPatterns.clear();
foreach(qint32 column, filterColumns)
m_columnPatterns.insert(column, QString());
}
void SortFilterProxyModel::addFilterFixedString(qint32 column, const QString &pattern)
{
if(!m_columnPatterns.contains(column))
return;
m_columnPatterns[column] = pattern;
}
bool SortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
if(m_columnPatterns.isEmpty())
return true;
bool ret = false;
for(QMap<qint32, QString>::const_iterator iter = m_columnPatterns.constBegin();
iter != m_columnPatterns.constEnd();
++iter)
{
QModelIndex index = sourceModel()->index(sourceRow, iter.key(), sourceParent);
ret = (index.data().toString() == iter.value());
if(!ret)
return ret;
}
return ret;
}
}
}
#include "moc_sortfilterproxymodel.cpp"
To copy to clipboard, switch view to plain text mode
Best Regards
NoRulez
Bookmarks