Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Kdenlive
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
259
Issues
259
List
Boards
Labels
Service Desk
Milestones
Merge Requests
14
Merge Requests
14
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Multimedia
Kdenlive
Commits
077d48b9
Commit
077d48b9
authored
Jun 15, 2020
by
Sashmita Raghav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add custom roles to model
parent
92dc2891
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
2 deletions
+41
-2
src/bin/model/subtitlemodel.cpp
src/bin/model/subtitlemodel.cpp
+36
-0
src/bin/model/subtitlemodel.hpp
src/bin/model/subtitlemodel.hpp
+5
-2
No files found.
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