summaryrefslogtreecommitdiff
path: root/src/dictionary/DicRecord.cpp
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2021-07-14 11:49:10 +1200
committerJedidiah Barber <contact@jedbarber.id.au>2021-07-14 11:49:10 +1200
commitd24f813f3f2a05c112e803e4256b53535895fc98 (patch)
tree601e6ae9a1cd44bcfdcf91739a5ca36aedd827c9 /src/dictionary/DicRecord.cpp
Initial mirror commitHEADmaster
Diffstat (limited to 'src/dictionary/DicRecord.cpp')
-rw-r--r--src/dictionary/DicRecord.cpp62
1 files changed, 62 insertions, 0 deletions
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();
+}