forked from teamnwah/openmw-tes3coop
relaxed rules for new IDs when ID is also a user visible text
This commit is contained in:
parent
88e09159c4
commit
aa61948801
5 changed files with 23 additions and 10 deletions
|
@ -19,7 +19,7 @@ void CSVWorld::DialogueCreator::configureCreateCommand (CSMWorld::CreateCommand&
|
||||||
|
|
||||||
CSVWorld::DialogueCreator::DialogueCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
CSVWorld::DialogueCreator::DialogueCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
const CSMWorld::UniversalId& id, int type)
|
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,
|
CSVWorld::Creator *CSVWorld::TopicCreatorFactory::makeCreator (CSMWorld::Data& data,
|
||||||
|
|
|
@ -57,14 +57,14 @@ const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
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)
|
: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false)
|
||||||
{
|
{
|
||||||
mLayout = new QHBoxLayout;
|
mLayout = new QHBoxLayout;
|
||||||
mLayout->setContentsMargins (0, 0, 0, 0);
|
mLayout->setContentsMargins (0, 0, 0, 0);
|
||||||
|
|
||||||
mId = new QLineEdit;
|
mId = new QLineEdit;
|
||||||
mId->setValidator (new IdValidator (this));
|
mId->setValidator (new IdValidator (relaxedIdRules, this));
|
||||||
mLayout->addWidget (mId, 1);
|
mLayout->addWidget (mId, 1);
|
||||||
|
|
||||||
mCreate = new QPushButton ("Create");
|
mCreate = new QPushButton ("Create");
|
||||||
|
|
|
@ -51,7 +51,7 @@ namespace CSVWorld
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
const CSMWorld::UniversalId& id);
|
const CSMWorld::UniversalId& id, bool relaxedIdRules = false);
|
||||||
|
|
||||||
virtual void setEditLock (bool locked);
|
virtual void setEditLock (bool locked);
|
||||||
|
|
||||||
|
|
|
@ -12,15 +12,25 @@ bool CSVWorld::IdValidator::isValid (const QChar& c, bool first) const
|
||||||
return false;
|
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
|
QValidator::State CSVWorld::IdValidator::validate (QString& input, int& pos) const
|
||||||
{
|
{
|
||||||
bool first = true;
|
if (mRelaxed)
|
||||||
|
{
|
||||||
for (QString::const_iterator iter (input.begin()); iter!=input.end(); ++iter, first = false)
|
if (input.indexOf ('"')!=-1 || input.indexOf ("::")!=-1)
|
||||||
if (!isValid (*iter, first))
|
|
||||||
return QValidator::Invalid;
|
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;
|
return QValidator::Acceptable;
|
||||||
}
|
}
|
|
@ -7,13 +7,16 @@ namespace CSVWorld
|
||||||
{
|
{
|
||||||
class IdValidator : public QValidator
|
class IdValidator : public QValidator
|
||||||
{
|
{
|
||||||
|
bool mRelaxed;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool isValid (const QChar& c, bool first) const;
|
bool isValid (const QChar& c, bool first) const;
|
||||||
|
|
||||||
public:
|
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;
|
virtual State validate (QString& input, int& pos) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue