1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-18 13:12:50 +00:00

relaxed rules for new IDs when ID is also a user visible text

This commit is contained in:
Marc Zinnschlag 2013-10-22 11:08:37 +02:00
parent 88e09159c4
commit aa61948801
5 changed files with 23 additions and 10 deletions

View File

@ -19,7 +19,7 @@ void CSVWorld::DialogueCreator::configureCreateCommand (CSMWorld::CreateCommand&
CSVWorld::DialogueCreator::DialogueCreator (CSMWorld::Data& data, QUndoStack& undoStack,
const CSMWorld::UniversalId& id, int type)
: GenericCreator (data, undoStack, id), mType (type)
: GenericCreator (data, undoStack, id, true), mType (type)
{}
CSVWorld::Creator *CSVWorld::TopicCreatorFactory::makeCreator (CSMWorld::Data& data,

View File

@ -57,14 +57,14 @@ const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const
}
CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
const CSMWorld::UniversalId& id)
const CSMWorld::UniversalId& id, bool relaxedIdRules)
: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false)
{
mLayout = new QHBoxLayout;
mLayout->setContentsMargins (0, 0, 0, 0);
mId = new QLineEdit;
mId->setValidator (new IdValidator (this));
mId->setValidator (new IdValidator (relaxedIdRules, this));
mLayout->addWidget (mId, 1);
mCreate = new QPushButton ("Create");

View File

@ -51,7 +51,7 @@ namespace CSVWorld
public:
GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
const CSMWorld::UniversalId& id);
const CSMWorld::UniversalId& id, bool relaxedIdRules = false);
virtual void setEditLock (bool locked);

View File

@ -12,15 +12,25 @@ bool CSVWorld::IdValidator::isValid (const QChar& c, bool first) const
return false;
}
CSVWorld::IdValidator::IdValidator (QObject *parent) : QValidator (parent) {}
CSVWorld::IdValidator::IdValidator (bool relaxed, QObject *parent)
: QValidator (parent), mRelaxed (relaxed)
{}
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))
if (mRelaxed)
{
if (input.indexOf ('"')!=-1 || input.indexOf ("::")!=-1)
return QValidator::Invalid;
}
else
{
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;
}

View File

@ -7,13 +7,16 @@ namespace CSVWorld
{
class IdValidator : public QValidator
{
bool mRelaxed;
private:
bool isValid (const QChar& c, bool first) const;
public:
IdValidator (QObject *parent = 0);
IdValidator (bool relaxed = false, QObject *parent = 0);
///< \param relaxed Relaxed rules for IDs that also functino as user visible text
virtual State validate (QString& input, int& pos) const;