Commit 077d48b9 authored by Sashmita Raghav's avatar Sashmita Raghav

Add custom roles to model

parent 92dc2891
......@@ -190,4 +190,40 @@ void SubtitleModel::addSubtitle(GenTime start, GenTime end, QString str)
model->beginInsertRows(QModelIndex(), insertRow, insertRow);
model->m_subtitleList[start] = {str, end};
model->endInsertRows();
}
QHash<int, QByteArray> SubtitleModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[SubtitleRole] = "subtitle";
roles[StartPosRole] = "startposition";
roles[EndPosRole] = "endposition";
roles[StartFrameRole] = "startframe";
roles[EndFrameRole] = "endframe";
return roles;
}
QVariant SubtitleModel::data(const QModelIndex& index, int role) const
{
if (index.row() < 0 || index.row() >= static_cast<int>(m_subtitleList.size()) || !index.isValid()) {
return QVariant();
}
auto it = m_subtitleList.begin();
std::advance(it, index.row());
switch (role) {
case Qt::DisplayRole:
case Qt::EditRole:
case SubtitleRole:
return it->second.first;
case StartPosRole:
return it->first.seconds();
case EndPosRole:
return it->second.second.seconds();
case StartFrameRole:
case Qt::UserRole:
return it->first.frames(pCore->getCurrentFps());
case EndFrameRole:
return it->second.second.frames(pCore->getCurrentFps());
}
return QVariant();
}
\ No newline at end of file
......@@ -26,11 +26,14 @@ class SubtitleModel:public QAbstractListModel
public:
/* @brief Construct a subtitle list bound to the timeline */
SubtitleModel(std::weak_ptr<DocUndoStack> undo_stack, QObject *parent = nullptr);
enum { SubtitleRole = Qt::UserRole + 1, StartPosRole, EndPosRole, StartFrameRole, EndFrameRole };
/** @brief Function that parses through a subtitle file */
void parseSubtitle();
void addSubtitle(GenTime start,GenTime end, QString str);
GenTime stringtoTime(QString str);
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;// overide the same function of QAbstractListModel
private:
std::weak_ptr<DocUndoStack> m_undoStack;
......@@ -38,10 +41,10 @@ private:
//To get subtitle file from effects parameter:
//std::unique_ptr<Mlt::Properties> m_asset;
//std::shared_ptr<AssetParameterModel> m_model;
protected:
/** @brief Helper function that retrieves a pointer to the subtitle model*/
static std::shared_ptr<SubtitleModel> getModel();
};
Q_DECLARE_METATYPE(SubtitleModel *)
#endif // SUBTITLEMODEL_HPP
\ No newline at end of file
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