added parser and custom filter edit widget (parser not functional yet; always returns a false boolean node)

actorid
Marc Zinnschlag 12 years ago
parent 236dc9fc43
commit c38860fa72

@ -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

@ -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;
}

@ -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

@ -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
}
}

@ -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…
Cancel
Save