forked from mirror/openmw-tes3mp
added parser and custom filter edit widget (parser not functional yet; always returns a false boolean node)
This commit is contained in:
parent
236dc9fc43
commit
c38860fa72
6 changed files with 127 additions and 4 deletions
|
@ -108,7 +108,7 @@ opencs_units_noqt (model/settings
|
|||
)
|
||||
|
||||
opencs_units_noqt (model/filter
|
||||
node unarynode narynode leafnode booleannode
|
||||
node unarynode narynode leafnode booleannode parser
|
||||
)
|
||||
|
||||
opencs_hdrs_noqt (model/filter
|
||||
|
@ -116,7 +116,7 @@ opencs_hdrs_noqt (model/filter
|
|||
)
|
||||
|
||||
opencs_units (view/filter
|
||||
filtercreator filterbox recordfilterbox
|
||||
filtercreator filterbox recordfilterbox editwidget
|
||||
)
|
||||
|
||||
set (OPENCS_US
|
||||
|
|
33
apps/opencs/model/filter/parser.cpp
Normal file
33
apps/opencs/model/filter/parser.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
|
||||
#include "parser.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "booleannode.hpp"
|
||||
|
||||
CSMFilter::Parser::Parser() : mState (State_Begin) {}
|
||||
|
||||
void CSMFilter::Parser::parse (const std::string& filter)
|
||||
{
|
||||
// reset
|
||||
mState = State_Begin;
|
||||
mFilter.reset();
|
||||
|
||||
|
||||
// for now we ignore the filter string
|
||||
mFilter.reset (new BooleanNode (false));
|
||||
mState = State_End;
|
||||
}
|
||||
|
||||
CSMFilter::Parser::State CSMFilter::Parser::getState() const
|
||||
{
|
||||
return mState;
|
||||
}
|
||||
|
||||
boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::getFilter() const
|
||||
{
|
||||
if (mState!=State_End)
|
||||
throw std::logic_error ("No filter available");
|
||||
|
||||
return mFilter;
|
||||
}
|
39
apps/opencs/model/filter/parser.hpp
Normal file
39
apps/opencs/model/filter/parser.hpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#ifndef CSM_FILTER_PARSER_H
|
||||
#define CSM_FILTER_PARSER_H
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "node.hpp"
|
||||
|
||||
namespace CSMFilter
|
||||
{
|
||||
class Parser
|
||||
{
|
||||
public:
|
||||
|
||||
enum State
|
||||
{
|
||||
State_Begin,
|
||||
State_End
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
State mState;
|
||||
boost::shared_ptr<Node> mFilter;
|
||||
|
||||
public:
|
||||
|
||||
Parser();
|
||||
|
||||
void parse (const std::string& filter);
|
||||
///< Discards any previous calls to parse
|
||||
|
||||
State getState() const;
|
||||
|
||||
boost::shared_ptr<Node> getFilter() const;
|
||||
///< Throws an exception if getState()!=State_End
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
20
apps/opencs/view/filter/editwidget.cpp
Normal file
20
apps/opencs/view/filter/editwidget.cpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
#include "editwidget.hpp"
|
||||
|
||||
CSVFilter::EditWidget::EditWidget (QWidget *parent)
|
||||
: QLineEdit (parent)
|
||||
{
|
||||
connect (this, SIGNAL (textChanged (const QString&)), this, SLOT (textChanged (const QString&)));
|
||||
}
|
||||
|
||||
void CSVFilter::EditWidget::textChanged (const QString& text)
|
||||
{
|
||||
mParser.parse (text.toUtf8().constData());
|
||||
|
||||
if (mParser.getState()==CSMFilter::Parser::State_End)
|
||||
emit filterChanged();
|
||||
else
|
||||
{
|
||||
/// \todo error handling
|
||||
}
|
||||
}
|
30
apps/opencs/view/filter/editwidget.hpp
Normal file
30
apps/opencs/view/filter/editwidget.hpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#ifndef CSV_FILTER_EDITWIDGET_H
|
||||
#define CSV_FILTER_EDITWIDGET_H
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
#include "../../model/filter/parser.hpp"
|
||||
|
||||
namespace CSVFilter
|
||||
{
|
||||
class EditWidget : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
CSMFilter::Parser mParser;
|
||||
|
||||
public:
|
||||
|
||||
EditWidget (QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
|
||||
void filterChanged();
|
||||
|
||||
private slots:
|
||||
|
||||
void textChanged (const QString& text);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -2,9 +2,10 @@
|
|||
#include "recordfilterbox.hpp"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QLabel>
|
||||
|
||||
#include "editwidget.hpp"
|
||||
|
||||
CSVFilter::RecordFilterBox::RecordFilterBox (QWidget *parent)
|
||||
: QWidget (parent)
|
||||
{
|
||||
|
@ -14,7 +15,7 @@ CSVFilter::RecordFilterBox::RecordFilterBox (QWidget *parent)
|
|||
|
||||
layout->addWidget (new QLabel ("Record Filter", this));
|
||||
|
||||
layout->addWidget (new QLineEdit (this));
|
||||
layout->addWidget (new EditWidget (this));
|
||||
|
||||
setLayout (layout);
|
||||
}
|
Loading…
Reference in a new issue