diff options
Diffstat (limited to 'src/dictionary/IDictionary.cpp')
-rw-r--r-- | src/dictionary/IDictionary.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/dictionary/IDictionary.cpp b/src/dictionary/IDictionary.cpp new file mode 100644 index 0000000..20bac26 --- /dev/null +++ b/src/dictionary/IDictionary.cpp @@ -0,0 +1,59 @@ +#include "IDictionary.h" +#include "DicRecord.h" +#include "CardPack.h" + +IDictionary::~IDictionary() +{ + foreach(DicRecord* record, records) + delete record; +} + +void IDictionary::addRecord(DicRecord* record) +{ + records << record; + notifyRecordsInserted(records.size() - 1, 1); +} + +void IDictionary::addRecords(const QList<DicRecord*>& records) +{ + this->records << records; + notifyRecordsInserted(records.size() - records.size(), records.size()); +} + +QString IDictionary::extendImagePaths(QString text) const +{ + text = replaceImagePaths(text, "%", QFileInfo(filePath).path()); + text = replaceImagePaths(text, "%%", getImagesPath()); + return text; +} + +QString IDictionary::getImagesPath() const +{ + QString path = QFileInfo(filePath).path(); + QString baseName = QFileInfo(filePath).completeBaseName(); + return QDir(path).filePath(baseName); +} + +QString IDictionary::replaceImagePaths(QString text, const QString& shortDir, + const QString& replacingPath) +{ + QRegExp imgRx(QString("(<img src=\")%1([/\\\\])").arg(shortDir)); + text.replace(imgRx, QString("\\1%1\\2").arg(replacingPath)); + return text; +} + +int IDictionary::countTodaysAllCards() const + { + int num = 0; + foreach(CardPack* pack, m_cardPacks) + num += pack->getTodayReviewedCardsNum(); + return num; + } + +int IDictionary::countTodaysNewCards() const + { + int num = 0; + foreach(CardPack* pack, m_cardPacks) + num += pack->getTodayNewCardsNum(); + return num; + } |