Implemented data filtering.
This commit is contained in:
@@ -9,14 +9,15 @@
|
||||
#include "define.h"
|
||||
#include "core_global.h"
|
||||
#include "exprevaluator.h"
|
||||
#include "itablemodel.h"
|
||||
|
||||
template<class T>
|
||||
class AutoTableModel : public QAbstractTableModel
|
||||
class AutoTableModel : public ITableModel
|
||||
{
|
||||
|
||||
public:
|
||||
explicit AutoTableModel(QObject *parent = NULL)
|
||||
:QAbstractTableModel(parent)
|
||||
:ITableModel(parent)
|
||||
{
|
||||
filtered = false;
|
||||
}
|
||||
@@ -141,8 +142,8 @@ public:
|
||||
m_list = list;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void filter(const QString &filter)
|
||||
protected:
|
||||
void handleFilter(const QString &filter) override
|
||||
{
|
||||
beginResetModel();
|
||||
if (!filtered)
|
||||
@@ -152,13 +153,13 @@ public slots:
|
||||
}
|
||||
|
||||
ExprEvaluator ev;
|
||||
m_list.clear();
|
||||
std::copy_if(ALL(m_fullList), m_list.begin(), [&filter, &ev](QSharedPointer<T> obj){ return ev.evaluate((QObject*)obj.pointer, filter); });
|
||||
auto it = std::copy_if(ALL(m_fullList), m_list.begin(), [&filter, &ev](QSharedPointer<T> obj){ return ev.evaluate((QObject*)obj.data(), filter); });
|
||||
m_list.erase(it, m_list.end());
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void restore()
|
||||
void handleRestore() override
|
||||
{
|
||||
if (filtered)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user