forked from teamnwah/openmw-tes3coop
added error reporting in the filter edit widget (change the text colour for now)
This commit is contained in:
parent
c7e97a83e1
commit
c87a279444
4 changed files with 66 additions and 4 deletions
|
@ -5,6 +5,37 @@
|
|||
|
||||
#include "booleannode.hpp"
|
||||
|
||||
namespace CSMFilter
|
||||
{
|
||||
struct Token
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
Type_EOS,
|
||||
Type_None
|
||||
};
|
||||
|
||||
Type mType;
|
||||
|
||||
Token (Type type);
|
||||
};
|
||||
|
||||
Token::Token (Type type) : mType (type) {}
|
||||
}
|
||||
|
||||
CSMFilter::Token CSMFilter::Parser::getNextToken (const std::string& filter, int& index) const
|
||||
{
|
||||
if (index>=static_cast<int> (filter.size()))
|
||||
return Token (Token::Type_EOS);
|
||||
|
||||
return Token (Token::Type_None);
|
||||
}
|
||||
|
||||
bool CSMFilter::Parser::isEndState() const
|
||||
{
|
||||
return mState==State_End || mState==State_UnexpectedCharacter;
|
||||
}
|
||||
|
||||
CSMFilter::Parser::Parser() : mState (State_Begin) {}
|
||||
|
||||
void CSMFilter::Parser::parse (const std::string& filter)
|
||||
|
@ -12,11 +43,24 @@ void CSMFilter::Parser::parse (const std::string& filter)
|
|||
// reset
|
||||
mState = State_Begin;
|
||||
mFilter.reset();
|
||||
int index = 0;
|
||||
|
||||
while (!isEndState())
|
||||
{
|
||||
Token token = getNextToken (filter, index);
|
||||
|
||||
// for now we ignore the filter string
|
||||
mFilter.reset (new BooleanNode (false));
|
||||
mState = State_End;
|
||||
switch (token.mType)
|
||||
{
|
||||
case Token::Type_None: mState = State_UnexpectedCharacter; break;
|
||||
case Token::Type_EOS: mState = State_End; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (mState==State_End && !mFilter)
|
||||
{
|
||||
// Empty filter string equals to filter "true".
|
||||
mFilter.reset (new BooleanNode (true));
|
||||
}
|
||||
}
|
||||
|
||||
CSMFilter::Parser::State CSMFilter::Parser::getState() const
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace CSMFilter
|
||||
{
|
||||
struct Token;
|
||||
|
||||
class Parser
|
||||
{
|
||||
public:
|
||||
|
@ -14,6 +16,7 @@ namespace CSMFilter
|
|||
enum State
|
||||
{
|
||||
State_Begin,
|
||||
State_UnexpectedCharacter,
|
||||
State_End
|
||||
};
|
||||
|
||||
|
@ -22,6 +25,11 @@ namespace CSMFilter
|
|||
State mState;
|
||||
boost::shared_ptr<Node> mFilter;
|
||||
|
||||
Token getNextToken (const std::string& filter, int& index) const;
|
||||
|
||||
bool isEndState() const;
|
||||
///< This includes error states.
|
||||
|
||||
public:
|
||||
|
||||
Parser();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
CSVFilter::EditWidget::EditWidget (QWidget *parent)
|
||||
: QLineEdit (parent)
|
||||
{
|
||||
mPalette = palette();
|
||||
connect (this, SIGNAL (textChanged (const QString&)), this, SLOT (textChanged (const QString&)));
|
||||
}
|
||||
|
||||
|
@ -12,9 +13,16 @@ void CSVFilter::EditWidget::textChanged (const QString& text)
|
|||
mParser.parse (text.toUtf8().constData());
|
||||
|
||||
if (mParser.getState()==CSMFilter::Parser::State_End)
|
||||
{
|
||||
setPalette (mPalette);
|
||||
emit filterChanged (mParser.getFilter(), "");
|
||||
}
|
||||
else
|
||||
{
|
||||
/// \todo error handling
|
||||
QPalette palette (mPalette);
|
||||
palette.setColor (QPalette::Text, Qt::red);
|
||||
setPalette (palette);
|
||||
|
||||
/// \todo improve error reporting; mark only the faulty part
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QPalette>
|
||||
|
||||
#include "../../model/filter/parser.hpp"
|
||||
#include "../../model/filter/node.hpp"
|
||||
|
@ -15,6 +16,7 @@ namespace CSVFilter
|
|||
Q_OBJECT
|
||||
|
||||
CSMFilter::Parser mParser;
|
||||
QPalette mPalette;
|
||||
|
||||
public:
|
||||
|
||||
|
|
Loading…
Reference in a new issue