diff --git a/apps/opencs/model/filter/node.hpp b/apps/opencs/model/filter/node.hpp index 09bc3cd42..9743034ba 100644 --- a/apps/opencs/model/filter/node.hpp +++ b/apps/opencs/model/filter/node.hpp @@ -5,6 +5,10 @@ #include #include +#include + +#include + namespace CSMWorld { class IdTable; @@ -55,4 +59,6 @@ namespace CSMFilter }; } +Q_DECLARE_METATYPE (boost::shared_ptr) + #endif diff --git a/apps/opencs/model/world/idtableproxymodel.cpp b/apps/opencs/model/world/idtableproxymodel.cpp index e99e1575c..e2c862270 100644 --- a/apps/opencs/model/world/idtableproxymodel.cpp +++ b/apps/opencs/model/world/idtableproxymodel.cpp @@ -1,8 +1,23 @@ #include "idtableproxymodel.hpp" +#include +#include + #include "idtable.hpp" +bool CSMWorld::IdTableProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex& sourceParent) + const +{ + if (!mFilter) + return true; + + std::map otherFilters; /// \todo get other filters; + std::map columns; /// \todo get columns + + return mFilter->test (dynamic_cast (*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 (*sourceModel()).getModelIndex (id, column)); +} + +void CSMWorld::IdTableProxyModel::setFilter (const boost::shared_ptr& filter, + const std::string& userValue) +{ + mFilter = filter; + mUserValue = userValue; + invalidateFilter(); } \ No newline at end of file diff --git a/apps/opencs/model/world/idtableproxymodel.hpp b/apps/opencs/model/world/idtableproxymodel.hpp index 200b99fe2..c7dcd345a 100644 --- a/apps/opencs/model/world/idtableproxymodel.hpp +++ b/apps/opencs/model/world/idtableproxymodel.hpp @@ -1,9 +1,13 @@ #ifndef CSM_WOLRD_IDTABLEPROXYMODEL_H #define CSM_WOLRD_IDTABLEPROXYMODEL_H +#include + +#include + #include -#include +#include "../filter/node.hpp" namespace CSMWorld { @@ -11,11 +15,21 @@ namespace CSMWorld { Q_OBJECT + boost::shared_ptr 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& filter, + const std::string& userValue); }; } diff --git a/apps/opencs/view/filter/editwidget.cpp b/apps/opencs/view/filter/editwidget.cpp index 8fc4a88ae..b8853ffa3 100644 --- a/apps/opencs/view/filter/editwidget.cpp +++ b/apps/opencs/view/filter/editwidget.cpp @@ -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 diff --git a/apps/opencs/view/filter/editwidget.hpp b/apps/opencs/view/filter/editwidget.hpp index 5959a8b16..9c4b1fa16 100644 --- a/apps/opencs/view/filter/editwidget.hpp +++ b/apps/opencs/view/filter/editwidget.hpp @@ -1,9 +1,12 @@ #ifndef CSV_FILTER_EDITWIDGET_H #define CSV_FILTER_EDITWIDGET_H +#include + #include #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 filter, + const std::string& userValue); private slots: diff --git a/apps/opencs/view/filter/filterbox.cpp b/apps/opencs/view/filter/filterbox.cpp index f3f17706b..9da08d3ba 100644 --- a/apps/opencs/view/filter/filterbox.cpp +++ b/apps/opencs/view/filter/filterbox.cpp @@ -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, const std::string&)), + this, SIGNAL (recordFilterChanged (boost::shared_ptr, const std::string&))); } \ No newline at end of file diff --git a/apps/opencs/view/filter/filterbox.hpp b/apps/opencs/view/filter/filterbox.hpp index 969a43cd7..5f260003a 100644 --- a/apps/opencs/view/filter/filterbox.hpp +++ b/apps/opencs/view/filter/filterbox.hpp @@ -3,6 +3,8 @@ #include +#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 filter, + const std::string& userValue); }; } diff --git a/apps/opencs/view/filter/recordfilterbox.cpp b/apps/opencs/view/filter/recordfilterbox.cpp index 5e297ec38..c4b516f03 100644 --- a/apps/opencs/view/filter/recordfilterbox.cpp +++ b/apps/opencs/view/filter/recordfilterbox.cpp @@ -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); -} \ No newline at end of file + + connect ( + editWidget, SIGNAL (filterChanged (boost::shared_ptr, const std::string&)), + this, SIGNAL (filterChanged (boost::shared_ptr, const std::string&))); +} diff --git a/apps/opencs/view/filter/recordfilterbox.hpp b/apps/opencs/view/filter/recordfilterbox.hpp index 3a411f808..8fc1e263b 100644 --- a/apps/opencs/view/filter/recordfilterbox.hpp +++ b/apps/opencs/view/filter/recordfilterbox.hpp @@ -1,10 +1,14 @@ #ifndef CSV_FILTER_RECORDFILTERBOX_H #define CSV_FILTER_RECORDFILTERBOX_H +#include + #include #include +#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 filter, + const std::string& userValue); }; } diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 4ae25d10b..cc84e612d 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -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 filter, + const std::string& userValue) +{ + mProxyModel->setFilter (filter, userValue); } \ No newline at end of file diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index 0c24e7b54..2e24e46a5 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -6,6 +6,8 @@ #include +#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 filter, + const std::string& userValue); }; } diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index df95940c9..cb6f430c1 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -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, const std::string&)), + mTable, SLOT (recordFilterChanged (boost::shared_ptr, const std::string&))); } void CSVWorld::TableSubView::setEditLock (bool locked)