From d24f813f3f2a05c112e803e4256b53535895fc98 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Wed, 14 Jul 2021 11:49:10 +1200 Subject: Initial mirror commit --- src/dictionary/DicRecord.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/dictionary/DicRecord.cpp (limited to 'src/dictionary/DicRecord.cpp') diff --git a/src/dictionary/DicRecord.cpp b/src/dictionary/DicRecord.cpp new file mode 100644 index 0000000..91cebca --- /dev/null +++ b/src/dictionary/DicRecord.cpp @@ -0,0 +1,62 @@ +#include "DicRecord.h" +#include "Field.h" +#include "ICardPack.h" + +DicRecord::DicRecord() + { + } + +DicRecord::DicRecord( const DicRecord& aOther ): + QObject(0) + { + fields = aOther.fields; + m_id04 = aOther.m_id04; + } + +void DicRecord::setField( QString aField, QString aValue ) + { + fields[aField] = aValue; + emit valueChanged( aField ); + } + +void DicRecord::renameField( const QString aOldFieldName, const QString aNewFieldName ) + { + if( !fields.keys().contains( aOldFieldName ) ) + return; + QString value = fields.value( aOldFieldName ); + fields.remove( aOldFieldName ); + fields[ aNewFieldName ] = value; +} + +bool DicRecord::isValid(const QString& qstFieldName) const +{ + return !fields.value(qstFieldName).isEmpty() && + hasNonEmptyAnswerField( qstFieldName ); +} + +bool DicRecord::hasNonEmptyAnswerField(const QString& qstFieldName) const +{ + foreach(QString name, fields.keys()) + if(name != qstFieldName && !fields.value(name).isEmpty()) + return true; + return false; +} + +QStringList DicRecord::getFieldElements(const QString& fieldName) const +{ + QString value = fields.value(fieldName); + QStringList elements = value.split(ICardPack::SynonymDelimiter, QString::SkipEmptyParts); + QStringList trimmedElements; + foreach(QString element, elements) + trimmedElements << element.trimmed(); + return trimmedElements; +} + +QString DicRecord::getPreviewQuestionForPack(ICardPack* pack) const +{ + if(!pack) + return QString(); + QString fieldName = pack->getQuestionField()->name(); + QString questionFieldValue = getFieldValue(fieldName); + return questionFieldValue.split(ICardPack::SynonymDelimiter).first().trimmed(); +} -- cgit