forked from mirror/openmw-tes3mp
validate IDs entered by the user
This commit is contained in:
parent
4f6e99c391
commit
32c697abc6
4 changed files with 53 additions and 1 deletions
|
@ -63,7 +63,7 @@ opencs_units (view/world
|
|||
opencs_units_noqt (view/world
|
||||
dialoguesubview subviews
|
||||
enumdelegate vartypedelegate recordstatusdelegate refidtypedelegate datadisplaydelegate
|
||||
scripthighlighter
|
||||
scripthighlighter idvalidator
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include "../../model/world/data.hpp"
|
||||
#include "../../model/world/idtable.hpp"
|
||||
|
||||
#include "idvalidator.hpp"
|
||||
|
||||
void CSVWorld::GenericCreator::update()
|
||||
{
|
||||
mErrors = getErrors();
|
||||
|
@ -27,6 +29,7 @@ CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undo
|
|||
layout->setContentsMargins (0, 0, 0, 0);
|
||||
|
||||
mId = new QLineEdit;
|
||||
mId->setValidator (new IdValidator (this));
|
||||
layout->addWidget (mId, 1);
|
||||
|
||||
mCreate = new QPushButton ("Create");
|
||||
|
|
26
apps/opencs/view/world/idvalidator.cpp
Normal file
26
apps/opencs/view/world/idvalidator.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
|
||||
#include "idvalidator.hpp"
|
||||
|
||||
bool CSVWorld::IdValidator::isValid (const QChar& c, bool first) const
|
||||
{
|
||||
if (c.isLetter() || c=='_')
|
||||
return true;
|
||||
|
||||
if (!first && (c.isDigit() || c.isSpace()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
CSVWorld::IdValidator::IdValidator (QObject *parent) : QValidator (parent) {}
|
||||
|
||||
QValidator::State CSVWorld::IdValidator::validate (QString& input, int& pos) const
|
||||
{
|
||||
bool first = true;
|
||||
|
||||
for (QString::const_iterator iter (input.begin()); iter!=input.end(); ++iter, first = false)
|
||||
if (!isValid (*iter, first))
|
||||
return QValidator::Invalid;
|
||||
|
||||
return QValidator::Acceptable;
|
||||
}
|
23
apps/opencs/view/world/idvalidator.hpp
Normal file
23
apps/opencs/view/world/idvalidator.hpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef CSV_WORLD_IDVALIDATOR_H
|
||||
#define CSV_WORLD_IDVALIDATOR_H
|
||||
|
||||
#include <QValidator>
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class IdValidator : public QValidator
|
||||
{
|
||||
private:
|
||||
|
||||
bool isValid (const QChar& c, bool first) const;
|
||||
|
||||
public:
|
||||
|
||||
IdValidator (QObject *parent = 0);
|
||||
|
||||
virtual State validate (QString& input, int& pos) const;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue