mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-01 17:15:34 +00:00
apply filter to table after filter text change
This commit is contained in:
parent
470f890a9a
commit
ea8b9ce45b
12 changed files with 98 additions and 7 deletions
|
@ -5,6 +5,10 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
#include <QMetaType>
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
class IdTable;
|
class IdTable;
|
||||||
|
@ -55,4 +59,6 @@ namespace CSMFilter
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE (boost::shared_ptr<CSMFilter::Node>)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,8 +1,23 @@
|
||||||
|
|
||||||
#include "idtableproxymodel.hpp"
|
#include "idtableproxymodel.hpp"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "idtable.hpp"
|
#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)
|
CSMWorld::IdTableProxyModel::IdTableProxyModel (QObject *parent)
|
||||||
: QSortFilterProxyModel (parent)
|
: QSortFilterProxyModel (parent)
|
||||||
{}
|
{}
|
||||||
|
@ -11,3 +26,11 @@ QModelIndex CSMWorld::IdTableProxyModel::getModelIndex (const std::string& id, i
|
||||||
{
|
{
|
||||||
return mapFromSource (dynamic_cast<IdTable&> (*sourceModel()).getModelIndex (id, column));
|
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
|
#ifndef CSM_WOLRD_IDTABLEPROXYMODEL_H
|
||||||
#define CSM_WOLRD_IDTABLEPROXYMODEL_H
|
#define CSM_WOLRD_IDTABLEPROXYMODEL_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
#include <string>
|
#include "../filter/node.hpp"
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
|
@ -11,11 +15,21 @@ namespace CSMWorld
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
boost::shared_ptr<CSMFilter::Node> mFilter;
|
||||||
|
std::string mUserValue;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
bool filterAcceptsRow (int sourceRow, const QModelIndex& sourceParent) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
IdTableProxyModel (QObject *parent = 0);
|
IdTableProxyModel (QObject *parent = 0);
|
||||||
|
|
||||||
virtual QModelIndex getModelIndex (const std::string& id, int column) const;
|
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());
|
mParser.parse (text.toUtf8().constData());
|
||||||
|
|
||||||
if (mParser.getState()==CSMFilter::Parser::State_End)
|
if (mParser.getState()==CSMFilter::Parser::State_End)
|
||||||
emit filterChanged();
|
emit filterChanged (mParser.getFilter(), "");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/// \todo error handling
|
/// \todo error handling
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
#ifndef CSV_FILTER_EDITWIDGET_H
|
#ifndef CSV_FILTER_EDITWIDGET_H
|
||||||
#define CSV_FILTER_EDITWIDGET_H
|
#define CSV_FILTER_EDITWIDGET_H
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
|
||||||
#include "../../model/filter/parser.hpp"
|
#include "../../model/filter/parser.hpp"
|
||||||
|
#include "../../model/filter/node.hpp"
|
||||||
|
|
||||||
namespace CSVFilter
|
namespace CSVFilter
|
||||||
{
|
{
|
||||||
|
@ -19,7 +22,8 @@ namespace CSVFilter
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void filterChanged();
|
void filterChanged (boost::shared_ptr<CSMFilter::Node> filter,
|
||||||
|
const std::string& userValue);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,13 @@ CSVFilter::FilterBox::FilterBox (QWidget *parent)
|
||||||
|
|
||||||
layout->setContentsMargins (0, 0, 0, 0);
|
layout->setContentsMargins (0, 0, 0, 0);
|
||||||
|
|
||||||
layout->addWidget (new RecordFilterBox (this));
|
RecordFilterBox *recordFilterBox = new RecordFilterBox (this);
|
||||||
|
|
||||||
|
layout->addWidget (recordFilterBox);
|
||||||
|
|
||||||
setLayout (layout);
|
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 <QWidget>
|
||||||
|
|
||||||
|
#include "../../model/filter/node.hpp"
|
||||||
|
|
||||||
namespace CSVFilter
|
namespace CSVFilter
|
||||||
{
|
{
|
||||||
class FilterBox : public QWidget
|
class FilterBox : public QWidget
|
||||||
|
@ -12,6 +14,11 @@ namespace CSVFilter
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FilterBox (QWidget *parent = 0);
|
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 QLabel ("Record Filter", this));
|
||||||
|
|
||||||
layout->addWidget (new EditWidget (this));
|
EditWidget *editWidget = new EditWidget (this);
|
||||||
|
|
||||||
|
layout->addWidget (editWidget);
|
||||||
|
|
||||||
setLayout (layout);
|
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
|
#ifndef CSV_FILTER_RECORDFILTERBOX_H
|
||||||
#define CSV_FILTER_RECORDFILTERBOX_H
|
#define CSV_FILTER_RECORDFILTERBOX_H
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
|
||||||
|
#include "../../model/filter/node.hpp"
|
||||||
|
|
||||||
namespace CSVFilter
|
namespace CSVFilter
|
||||||
{
|
{
|
||||||
class RecordFilterBox : public QWidget
|
class RecordFilterBox : public QWidget
|
||||||
|
@ -14,6 +18,11 @@ namespace CSVFilter
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RecordFilterBox (QWidget *parent = 0);
|
RecordFilterBox (QWidget *parent = 0);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
void filterChanged (boost::shared_ptr<CSMFilter::Node> filter,
|
||||||
|
const std::string& userValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,3 +293,9 @@ void CSVWorld::Table::requestFocus (const std::string& id)
|
||||||
if (index.isValid())
|
if (index.isValid())
|
||||||
scrollTo (index, QAbstractItemView::PositionAtTop);
|
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 <QTableView>
|
||||||
|
|
||||||
|
#include "../../model/filter/node.hpp"
|
||||||
|
|
||||||
class QUndoStack;
|
class QUndoStack;
|
||||||
class QAction;
|
class QAction;
|
||||||
|
|
||||||
|
@ -85,6 +87,8 @@ namespace CSVWorld
|
||||||
|
|
||||||
void requestFocus (const std::string& id);
|
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 =
|
layout->insertWidget (0, mTable =
|
||||||
new Table (id, document.getData(), document.getUndoStack(), mBottom->canCreateAndDelete()), 2);
|
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;
|
QWidget *widget = new QWidget;
|
||||||
|
|
||||||
|
@ -48,6 +50,10 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D
|
||||||
|
|
||||||
connect (mBottom, SIGNAL (requestFocus (const std::string&)),
|
connect (mBottom, SIGNAL (requestFocus (const std::string&)),
|
||||||
mTable, SLOT (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)
|
void CSVWorld::TableSubView::setEditLock (bool locked)
|
||||||
|
|
Loading…
Reference in a new issue