Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Multimedia
Kdenlive
Commits
077d48b9
Commit
077d48b9
authored
Jun 15, 2020
by
Sashmita Raghav
Browse files
Add custom roles to model
parent
92dc2891
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/bin/model/subtitlemodel.cpp
View file @
077d48b9
...
...
@@ -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
src/bin/model/subtitlemodel.hpp
View file @
077d48b9
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment