apply filter to table after filter text change

pull/51/head
Marc Zinnschlag 12 years ago
parent 470f890a9a
commit ea8b9ce45b

@ -5,6 +5,10 @@
#include <map>
#include <vector>
#include <boost/shared_ptr.hpp>
#include <QMetaType>
namespace CSMWorld
{
class IdTable;
@ -55,4 +59,6 @@ namespace CSMFilter
};
}
Q_DECLARE_METATYPE (boost::shared_ptr<CSMFilter::Node>)
#endif

@ -1,8 +1,23 @@
#include "idtableproxymodel.hpp"
#include <map>
#include <vector>
#include "idtable.hpp"
bool CSMWorld::IdTableProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex& sourceParent)
const
{
if (!mFilter)
return true;
std::map<std::string, const CSMFilter::Node *> otherFilters; /// \todo get other filters;
std::map<int, int> columns; /// \todo get columns
return mFilter->test (dynamic_cast<IdTable&> (*sourceModel()), sourceRow, otherFilters, columns, mUserValue);
}
CSMWorld::IdTableProxyModel::IdTableProxyModel (QObject *parent)
: QSortFilterProxyModel (parent)
{}
@ -10,4 +25,12 @@ CSMWorld::IdTableProxyModel::IdTableProxyModel (QObject *parent)
QModelIndex CSMWorld::IdTableProxyModel::getModelIndex (const std::string& id, int column) const
{
return mapFromSource (dynamic_cast<IdTable&> (*sourceModel()).getModelIndex (id, column));
}
void CSMWorld::IdTableProxyModel::setFilter (const boost::shared_ptr<CSMFilter::Node>& filter,
const std::string& userValue)
{
mFilter = filter;
mUserValue = userValue;
invalidateFilter();
}

@ -1,9 +1,13 @@
#ifndef CSM_WOLRD_IDTABLEPROXYMODEL_H
#define CSM_WOLRD_IDTABLEPROXYMODEL_H
#include <string>
#include <boost/shared_ptr.hpp>
#include <QSortFilterProxyModel>
#include <string>
#include "../filter/node.hpp"
namespace CSMWorld
{
@ -11,11 +15,21 @@ namespace CSMWorld
{
Q_OBJECT
boost::shared_ptr<CSMFilter::Node> mFilter;
std::string mUserValue;
private:
bool filterAcceptsRow (int sourceRow, const QModelIndex& sourceParent) const;
public:
IdTableProxyModel (QObject *parent = 0);
virtual QModelIndex getModelIndex (const std::string& id, int column) const;
void setFilter (const boost::shared_ptr<CSMFilter::Node>& filter,
const std::string& userValue);
};
}

@ -12,7 +12,7 @@ void CSVFilter::EditWidget::textChanged (const QString& text)
mParser.parse (text.toUtf8().constData());
if (mParser.getState()==CSMFilter::Parser::State_End)
emit filterChanged();
emit filterChanged (mParser.getFilter(), "");
else
{
/// \todo error handling

@ -1,9 +1,12 @@
#ifndef CSV_FILTER_EDITWIDGET_H
#define CSV_FILTER_EDITWIDGET_H
#include <boost/shared_ptr.hpp>
#include <QLineEdit>
#include "../../model/filter/parser.hpp"
#include "../../model/filter/node.hpp"
namespace CSVFilter
{
@ -19,7 +22,8 @@ namespace CSVFilter
signals:
void filterChanged();
void filterChanged (boost::shared_ptr<CSMFilter::Node> filter,
const std::string& userValue);
private slots:

@ -12,7 +12,13 @@ CSVFilter::FilterBox::FilterBox (QWidget *parent)
layout->setContentsMargins (0, 0, 0, 0);
layout->addWidget (new RecordFilterBox (this));
RecordFilterBox *recordFilterBox = new RecordFilterBox (this);
layout->addWidget (recordFilterBox);
setLayout (layout);
connect (recordFilterBox,
SIGNAL (filterChanged (boost::shared_ptr<CSMFilter::Node>, const std::string&)),
this, SIGNAL (recordFilterChanged (boost::shared_ptr<CSMFilter::Node>, const std::string&)));
}

@ -3,6 +3,8 @@
#include <QWidget>
#include "../../model/filter/node.hpp"
namespace CSVFilter
{
class FilterBox : public QWidget
@ -12,6 +14,11 @@ namespace CSVFilter
public:
FilterBox (QWidget *parent = 0);
signals:
void recordFilterChanged (boost::shared_ptr<CSMFilter::Node> filter,
const std::string& userValue);
};
}

@ -15,7 +15,13 @@ CSVFilter::RecordFilterBox::RecordFilterBox (QWidget *parent)
layout->addWidget (new QLabel ("Record Filter", this));
layout->addWidget (new EditWidget (this));
EditWidget *editWidget = new EditWidget (this);
layout->addWidget (editWidget);
setLayout (layout);
}
connect (
editWidget, SIGNAL (filterChanged (boost::shared_ptr<CSMFilter::Node>, const std::string&)),
this, SIGNAL (filterChanged (boost::shared_ptr<CSMFilter::Node>, const std::string&)));
}

@ -1,10 +1,14 @@
#ifndef CSV_FILTER_RECORDFILTERBOX_H
#define CSV_FILTER_RECORDFILTERBOX_H
#include <boost/shared_ptr.hpp>
#include <QWidget>
#include <QHBoxLayout>
#include "../../model/filter/node.hpp"
namespace CSVFilter
{
class RecordFilterBox : public QWidget
@ -14,6 +18,11 @@ namespace CSVFilter
public:
RecordFilterBox (QWidget *parent = 0);
signals:
void filterChanged (boost::shared_ptr<CSMFilter::Node> filter,
const std::string& userValue);
};
}

@ -292,4 +292,10 @@ void CSVWorld::Table::requestFocus (const std::string& id)
if (index.isValid())
scrollTo (index, QAbstractItemView::PositionAtTop);
}
void CSVWorld::Table::recordFilterChanged (boost::shared_ptr<CSMFilter::Node> filter,
const std::string& userValue)
{
mProxyModel->setFilter (filter, userValue);
}

@ -6,6 +6,8 @@
#include <QTableView>
#include "../../model/filter/node.hpp"
class QUndoStack;
class QAction;
@ -85,6 +87,8 @@ namespace CSVWorld
void requestFocus (const std::string& id);
void recordFilterChanged (boost::shared_ptr<CSMFilter::Node> filter,
const std::string& userValue);
};
}

@ -25,7 +25,9 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D
layout->insertWidget (0, mTable =
new Table (id, document.getData(), document.getUndoStack(), mBottom->canCreateAndDelete()), 2);
layout->insertWidget (0, new CSVFilter::FilterBox (this));
CSVFilter::FilterBox *filterBox = new CSVFilter::FilterBox (this);
layout->insertWidget (0, filterBox);
QWidget *widget = new QWidget;
@ -48,6 +50,10 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D
connect (mBottom, SIGNAL (requestFocus (const std::string&)),
mTable, SLOT (requestFocus (const std::string&)));
connect (filterBox,
SIGNAL (recordFilterChanged (boost::shared_ptr<CSMFilter::Node>, const std::string&)),
mTable, SLOT (recordFilterChanged (boost::shared_ptr<CSMFilter::Node>, const std::string&)));
}
void CSVWorld::TableSubView::setEditLock (bool locked)

Loading…
Cancel
Save