forked from mirror/openmw-tes3mp
fixed error detection and improved error reporting in IdValidator
This commit is contained in:
parent
3486da0fb0
commit
2b9395333a
3 changed files with 33 additions and 10 deletions
|
@ -154,16 +154,10 @@ std::string CSVWorld::GenericCreator::getErrors() const
|
|||
{
|
||||
std::string errors;
|
||||
|
||||
std::string id = getId();
|
||||
|
||||
if (id.empty())
|
||||
{
|
||||
errors = "Missing ID";
|
||||
}
|
||||
else if (mData.hasId (id))
|
||||
{
|
||||
if (!mId->hasAcceptableInput())
|
||||
errors = mValidator->getError();
|
||||
else if (mData.hasId (getId()))
|
||||
errors = "ID is already in use";
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ CSVWorld::IdValidator::IdValidator (bool relaxed, QObject *parent)
|
|||
|
||||
QValidator::State CSVWorld::IdValidator::validate (QString& input, int& pos) const
|
||||
{
|
||||
mError.clear();
|
||||
|
||||
if (mRelaxed)
|
||||
{
|
||||
if (input.indexOf ('"')!=-1 || input.indexOf ("::")!=-1 || input.indexOf ("#")!=-1)
|
||||
|
@ -27,6 +29,12 @@ QValidator::State CSVWorld::IdValidator::validate (QString& input, int& pos) con
|
|||
}
|
||||
else
|
||||
{
|
||||
if (input.isEmpty())
|
||||
{
|
||||
mError = "Missing ID";
|
||||
return QValidator::Intermediate;
|
||||
}
|
||||
|
||||
bool first = true;
|
||||
bool scope = false;
|
||||
bool prevScope = false;
|
||||
|
@ -88,8 +96,17 @@ QValidator::State CSVWorld::IdValidator::validate (QString& input, int& pos) con
|
|||
}
|
||||
}
|
||||
|
||||
if (scope)
|
||||
{
|
||||
mError = "ID ending with incomplete scope operator";
|
||||
return QValidator::Intermediate;
|
||||
}
|
||||
|
||||
if (prevScope)
|
||||
return QValidator::Intermediate; // ending with scope operator
|
||||
{
|
||||
mError = "ID ending with scope operator";
|
||||
return QValidator::Intermediate;
|
||||
}
|
||||
}
|
||||
|
||||
return QValidator::Acceptable;
|
||||
|
@ -98,4 +115,9 @@ QValidator::State CSVWorld::IdValidator::validate (QString& input, int& pos) con
|
|||
void CSVWorld::IdValidator::setNamespace (const std::string& namespace_)
|
||||
{
|
||||
mNamespace = Misc::StringUtils::lowerCase (namespace_);
|
||||
}
|
||||
|
||||
std::string CSVWorld::IdValidator::getError() const
|
||||
{
|
||||
return mError;
|
||||
}
|
|
@ -11,6 +11,7 @@ namespace CSVWorld
|
|||
{
|
||||
bool mRelaxed;
|
||||
std::string mNamespace;
|
||||
mutable std::string mError;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -25,6 +26,12 @@ namespace CSVWorld
|
|||
|
||||
void setNamespace (const std::string& namespace_);
|
||||
|
||||
/// Return a description of the error that resulted in the last call of validate
|
||||
/// returning QValidator::Intermediate. If the last call to validate returned
|
||||
/// a different value (or if there was no such call yet), an empty string is
|
||||
/// returned.
|
||||
std::string getError() const;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue