Commit 5927cd3b authored by Sashmita Raghav's avatar Sashmita Raghav

Add function to export subtitle model items to JSON

parent 73716f89
Pipeline #37457 canceled with stage
......@@ -4,6 +4,10 @@
#include "project/projectmanager.h"
#include "timeline2/model/snapmodel.hpp"
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
SubtitleModel::SubtitleModel(std::weak_ptr<DocUndoStack> undo_stack, QObject *parent)
: QAbstractListModel(parent)
, m_undoStack(std::move(undo_stack))
......@@ -355,3 +359,20 @@ void SubtitleModel::moveSubtitle(GenTime oldPos, GenTime newPos)
addSubtitle(newPos, endPos, subtitleText);
return;
}
QString SubtitleModel::toJson()
{
qDebug()<< "to JSON";
QJsonArray list;
for (const auto &subtitle : m_subtitleList) {
QJsonObject currentSubtitle;
currentSubtitle.insert(QLatin1String("startPos"), QJsonValue(subtitle.first.seconds()));
currentSubtitle.insert(QLatin1String("dialogue"), QJsonValue(subtitle.second.first));
currentSubtitle.insert(QLatin1String("endPos"), QJsonValue(subtitle.second.second.seconds()));
list.push_back(currentSubtitle);
qDebug()<<subtitle.first.seconds();
}
QJsonDocument jsonDoc(list);
qDebug()<<QString(jsonDoc.toJson());
return QString(jsonDoc.toJson());
}
\ No newline at end of file
......@@ -68,6 +68,9 @@ public:
*/
void moveSubtitle(GenTime oldPos, GenTime newPos);
/** @brief Exports the subtitle model to json */
QString toJson();
public slots:
/** @brief Function that parses through a subtitle file */
void parseSubtitle();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment