diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 8a1949e51..031c650df 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -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 diff --git a/apps/opencs/model/filter/parser.cpp b/apps/opencs/model/filter/parser.cpp new file mode 100644 index 000000000..46052cec6 --- /dev/null +++ b/apps/opencs/model/filter/parser.cpp @@ -0,0 +1,33 @@ + +#include "parser.hpp" + +#include + +#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::Parser::getFilter() const +{ + if (mState!=State_End) + throw std::logic_error ("No filter available"); + + return mFilter; +} \ No newline at end of file diff --git a/apps/opencs/model/filter/parser.hpp b/apps/opencs/model/filter/parser.hpp new file mode 100644 index 000000000..72dc7d507 --- /dev/null +++ b/apps/opencs/model/filter/parser.hpp @@ -0,0 +1,39 @@ +#ifndef CSM_FILTER_PARSER_H +#define CSM_FILTER_PARSER_H + +#include + +#include "node.hpp" + +namespace CSMFilter +{ + class Parser + { + public: + + enum State + { + State_Begin, + State_End + }; + + private: + + State mState; + boost::shared_ptr mFilter; + + public: + + Parser(); + + void parse (const std::string& filter); + ///< Discards any previous calls to parse + + State getState() const; + + boost::shared_ptr getFilter() const; + ///< Throws an exception if getState()!=State_End + }; +} + +#endif diff --git a/apps/opencs/view/filter/editwidget.cpp b/apps/opencs/view/filter/editwidget.cpp new file mode 100644 index 000000000..8fc4a88ae --- /dev/null +++ b/apps/opencs/view/filter/editwidget.cpp @@ -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 + } +} \ No newline at end of file diff --git a/apps/opencs/view/filter/editwidget.hpp b/apps/opencs/view/filter/editwidget.hpp new file mode 100644 index 000000000..5959a8b16 --- /dev/null +++ b/apps/opencs/view/filter/editwidget.hpp @@ -0,0 +1,30 @@ +#ifndef CSV_FILTER_EDITWIDGET_H +#define CSV_FILTER_EDITWIDGET_H + +#include + +#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 diff --git a/apps/opencs/view/filter/recordfilterbox.cpp b/apps/opencs/view/filter/recordfilterbox.cpp index b0c195664..5e297ec38 100644 --- a/apps/opencs/view/filter/recordfilterbox.cpp +++ b/apps/opencs/view/filter/recordfilterbox.cpp @@ -2,9 +2,10 @@ #include "recordfilterbox.hpp" #include -#include #include +#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); } \ No newline at end of file