diff --git a/src/Lib/Ass/AssFactory.cc b/src/Lib/Ass/AssFactory.cc index 93f8a92dddfeaee1929db77d0ca3b74dcf58dab2..96c59b83d7d1fc8ca8bbeb99e797db3ad6f504c4 100644 --- a/src/Lib/Ass/AssFactory.cc +++ b/src/Lib/Ass/AssFactory.cc @@ -31,7 +31,6 @@ AssFactory::initFromStorage() noexcept } } - // Other lines else if (!currentSection.isEmpty()) { const int separatorIndex = line.indexOf(": "); const int baseValueIndex = separatorIndex + 2; @@ -154,7 +153,7 @@ AssFactory::getStyle(const QString &name) const noexcept return StyleWeakPtr(*styleIt); // Will be unable to lock - return StyleWeakPtr(spareNullStylePtr); + return StyleWeakPtr(); } bool diff --git a/src/Lib/Ass/AssFactory.hh b/src/Lib/Ass/AssFactory.hh index 98c8f3fea31fd3513f238b77c181f61f69b9e0e1..0f322347b2bb782f8d82159b49006e0d2c092053 100644 --- a/src/Lib/Ass/AssFactory.hh +++ b/src/Lib/Ass/AssFactory.hh @@ -27,8 +27,6 @@ private: QVector<LinePtr> assLines{}; QVector<StylePtr> assStyles{}; - StylePtr spareNullStylePtr{ nullptr }; - static inline const QString sectionScriptInfo = "Script Info"; static inline const QString sectionStyles = "V4+ Styles"; static inline const QString sectionEvents = "Events"; diff --git a/src/Lib/Ass/AssPrivate.hh b/src/Lib/Ass/AssPrivate.hh index 39d931a99d8c92c1d0d83d0d44de97cdaed20e38..cb9a720c547ee16ff2ea63a4369a96999eec2ec0 100644 --- a/src/Lib/Ass/AssPrivate.hh +++ b/src/Lib/Ass/AssPrivate.hh @@ -10,4 +10,7 @@ using LinePtr = std::shared_ptr<Line>; using StyleWeakPtr = std::weak_ptr<Style>; using LineWeakPtr = std::weak_ptr<Line>; + } + +Q_DECLARE_METATYPE(Vivy::Ass::LinePtr) diff --git a/src/Lib/Ass/Line.cc b/src/Lib/Ass/Line.cc index 652c3d64d651ecba8c5cf0804f170c1fb6570ee0..1bebb0bca2cd3e195eddd9611b6005d09a0156d1 100644 --- a/src/Lib/Ass/Line.cc +++ b/src/Lib/Ass/Line.cc @@ -1,8 +1,16 @@ #include "Line.hh" #include "AssFactory.hh" +#include "../../VivyApplication.hh" +#include "../../Lib/Document/VivyDocument.hh" + using namespace Vivy::Ass; +Line::Line() + : assFactory(currentVivyDocument->getAssSubDocument()->getFactory()) +{ +} + Line::Line(AssFactory *const factory, const QString &lineString) : assFactory(factory) { @@ -60,9 +68,11 @@ Line::Line(AssFactory *const factory, const QString &lineString) } void -Line::generateLineText() noexcept +Line::updateContent() noexcept { - // TODO : generate ___contentAsText from content + ___contentAsText = ""; + for (const auto &syl : content) + ___contentAsText.append(syl.getContent()); } void @@ -169,5 +179,5 @@ void Line::setContent(const QVector<Syl> &syls) noexcept { content = syls; - generateLineText(); + updateContent(); } diff --git a/src/Lib/Ass/Line.hh b/src/Lib/Ass/Line.hh index 8462b532979458df7ac337c7e5c298ad9c55b453..20fd4ac453a7cf4ca9ebeb30c849f2784efdc674 100644 --- a/src/Lib/Ass/Line.hh +++ b/src/Lib/Ass/Line.hh @@ -31,6 +31,8 @@ class Line final { public: //explicit Line(const Line &) = default; explicit Line(AssFactory *const, const QString &); + explicit Line(); + explicit Line(const Line &c) = default; Line &operator=(const Line &) = delete; ~Line() noexcept = default; @@ -53,6 +55,6 @@ public: private: void initSylFromString(const QString &) noexcept; - void generateLineText() noexcept; + void updateContent() noexcept; }; } diff --git a/src/Lib/Document/CRTPSubDocument.hh b/src/Lib/Document/CRTPSubDocument.hh index 7100a19ab30c7275d4cae86535dc0cd5c9f5c8c0..2d81aa0ce7756612fc3ada1c4a9f2d623ea49ec3 100644 --- a/src/Lib/Document/CRTPSubDocument.hh +++ b/src/Lib/Document/CRTPSubDocument.hh @@ -136,6 +136,7 @@ class AssSubDocument final : public CRTPSubDocument<AssDocumentType, AssSubDocum public: QString getElementName() const noexcept; QJsonDocument getProperties() const noexcept; + Ass::AssFactory *getFactory() noexcept; const QVector<Ass::LinePtr> &getLines() const noexcept; const QVector<Ass::StylePtr> &getStyles() const noexcept; @@ -143,5 +144,6 @@ public: private: QVector<Ass::StylePtr> styles; QVector<Ass::LinePtr> lines; + Ass::AssFactory *assFactory; }; } diff --git a/src/Lib/Document/CRTPSubDocument/AssSubDocument.cc b/src/Lib/Document/CRTPSubDocument/AssSubDocument.cc index b465093754d4fa0cf412182ce733eb34bdc1ff10..fdb709fbcf6210c5e6178b8ff50b5175b4e5713c 100644 --- a/src/Lib/Document/CRTPSubDocument/AssSubDocument.cc +++ b/src/Lib/Document/CRTPSubDocument/AssSubDocument.cc @@ -7,9 +7,11 @@ using namespace Vivy; void AssSubDocument::initFromPath(const QString &path) { - Ass::AssFactory factory(path); - factory.getStyles(styles); - factory.getLines(lines); + styles.clear(); + lines.clear(); + assFactory = new Ass::AssFactory(path); + assFactory->getStyles(styles); + assFactory->getLines(lines); } QString @@ -43,3 +45,9 @@ AssSubDocument::getProperties() const noexcept { "Styles", styleObject }, }); } + +Ass::AssFactory * +AssSubDocument::getFactory() noexcept +{ + return assFactory; +} diff --git a/src/UI/DocumentViews/AssLinesModel.cc b/src/UI/DocumentViews/AssLinesModel.cc index 47c1febe4ae537ea711aeeae2cfbaa81b4d6a92b..0ee7797bae519ebdc16024d364cdaf86ac13a23e 100644 --- a/src/UI/DocumentViews/AssLinesModel.cc +++ b/src/UI/DocumentViews/AssLinesModel.cc @@ -17,7 +17,7 @@ QString AssLinesModel::Item::getLineText() const noexcept { QString ret; - if (auto ptr = line.lock()) { + if (auto ptr = line.get()) { for (const auto &syl : ptr->getContent()) { ret.append(syl.getContent()); ret.append("("); @@ -33,7 +33,7 @@ AssLinesModel::Item::getLineText() const noexcept bool AssLinesModel::Item::getIsComment() const noexcept { - if (auto ptr = line.lock()) + if (auto ptr = line.get()) return ptr->getIsComment(); return false; } @@ -41,7 +41,7 @@ AssLinesModel::Item::getIsComment() const noexcept QString AssLinesModel::Item::getLineStyle() const noexcept { - if (auto ptr = line.lock()) { + if (auto ptr = line.get()) { if (auto style = ptr->getStyle().lock()) { return style->getElementName(); } @@ -50,7 +50,7 @@ AssLinesModel::Item::getLineStyle() const noexcept } void -AssLinesModel::Item::setLine(Ass::LineWeakPtr l) noexcept +AssLinesModel::Item::setLine(Ass::LinePtr l) noexcept { line = l; } @@ -86,14 +86,15 @@ AssLinesModel::data(const QModelIndex &index, int role) const noexcept } bool -AssLinesModel::setData(const QModelIndex &index, const QVariant & /* value */, int role) noexcept +AssLinesModel::setData(const QModelIndex &index, const QVariant &value, int role) noexcept { const int col = index.column(); if (col >= Utils::toUnderlying(Item::Field::TotalFieldCount)) return false; - if (Qt::EditRole == role) { - emit dataChanged(index, index, { Qt::EditRole }); + if (Qt::DisplayRole == role) { + childs[index.row()]->setLine(qvariant_cast<Ass::LinePtr>(value)); + emit dataChanged(index, index, { Qt::DisplayRole }); return true; } @@ -149,14 +150,12 @@ Qt::ItemFlags AssLinesModel::flags(const QModelIndex &index) const noexcept { [[maybe_unused]] const Item *item = static_cast<const Item *>(index.internalPointer()); - return Qt::ItemNeverHasChildren | Qt::ItemIsSelectable | QAbstractItemModel::flags(index); + return Qt::ItemIsEditable | Qt::ItemNeverHasChildren | Qt::ItemIsSelectable | + QAbstractItemModel::flags(index); } void AssLinesModel::updateLine(int lineIndex, Ass::LinePtr line) { - qDebug() << data(index(lineIndex, 0), Qt::DisplayRole); - childs[lineIndex]->setLine(line); - qDebug() << data(index(lineIndex, 0), Qt::DisplayRole); - qDebug() << ""; + setData(index(lineIndex, 0), QVariant::fromValue(line), Qt::DisplayRole); } diff --git a/src/UI/DocumentViews/AssLinesModel.hh b/src/UI/DocumentViews/AssLinesModel.hh index ad45d4bd5f7cac276492500d4db8203d66c0d8e5..5075ca18b6e7e6b6ed4219232151334c1d986ee6 100644 --- a/src/UI/DocumentViews/AssLinesModel.hh +++ b/src/UI/DocumentViews/AssLinesModel.hh @@ -27,10 +27,10 @@ private: QString getLineText() const noexcept; QString getLineStyle() const noexcept; - void setLine(Ass::LineWeakPtr) noexcept; + void setLine(Ass::LinePtr) noexcept; private: - Ass::LineWeakPtr line; + Ass::LinePtr line; }; static inline const QStringList headers{ "", "Style", "Text" };