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:
parent
88e09159c4
commit
aa61948801
@ -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,
|
||||
|
@ -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");
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user