Implement range marker support in MarkerListModel (c6620073) · Commits · Multimedia / Kdenlive · GitLab
Admin message
Join us at
Akademy
to celebrate KDE's 30th anniversary!
Travel support requests
are open till May 31st.
Register now
Commit
c6620073
authored
May 26, 2025
by
Ajay Chauhan
Committed by
Jean-Baptiste Mardelle
Sep 12, 2025
Browse files
parent
70c1db71
Loading
Loading
Loading
Loading
Original line number
Diff line number
Diff line
@@ -230,8 +230,9 @@ bool MarkerListModel::addMarker(GenTime pos, const QString &comment, int type, F
if
hasMarker
pos
))
// In this case we simply change the comment and type
CommentedTime
current
marker
pos
);
local_undo
changeComment_lambda
pos
current
comment
(),
current
markerType
());
local_redo
changeComment_lambda
pos
comment
type
);
// For a simple point marker update, duration should be 0 (point marker)
local_undo
addOrUpdateRangeMarker_lambda
pos
current
duration
(),
current
comment
(),
current
markerType
(),
current
);
local_redo
addOrUpdateRangeMarker_lambda
pos
GenTime
),
comment
type
current
);
// Force duration to 0 for point markers
else
// In this case we create one
local_redo
addMarker_lambda
pos
comment
type
);
@@ -328,7 +329,22 @@ bool MarkerListModel::editMarker(GenTime oldPos, GenTime pos, QString comment, i
if
type
==
type
current
markerType
();
if
oldPos
==
pos
&&
current
comment
()
==
comment
&&
current
markerType
()
==
type
return
true
// Preserve existing duration when not explicitly specified
return
editMarker
oldPos
pos
comment
type
current
duration
());
bool
MarkerListModel
::
editMarker
GenTime
oldPos
GenTime
pos
QString
comment
int
type
GenTime
duration
QWriteLocker
locker
m_lock
);
Q_ASSERT
hasMarker
oldPos
));
CommentedTime
current
marker
oldPos
);
if
comment
isEmpty
())
comment
current
comment
();
if
type
==
type
current
markerType
();
if
oldPos
==
pos
&&
current
comment
()
==
comment
&&
current
markerType
()
==
type
&&
current
duration
()
==
duration
return
true
Fun
undo
[]()
return
true
};
Fun
redo
[]()
return
true
};
bool
res
true
@@ -336,7 +352,7 @@ bool MarkerListModel::editMarker(GenTime oldPos, GenTime pos, QString comment, i
res
removeMarker
oldPos
undo
redo
);
if
res
res
addMarker
pos
comment
type
undo
redo
);
res
add
Range
Marker
pos
duration
comment
type
undo
redo
);
if
res
PUSH_UNDO
undo
redo
i18n
"Edit marker"
));
@@ -477,6 +493,33 @@ Fun MarkerListModel::addMarker_lambda(GenTime pos, const QString &comment, int t
};
Fun
MarkerListModel
::
addOrUpdateRangeMarker_lambda
GenTime
pos
GenTime
duration
const
QString
comment
int
type
const
CommentedTime
existingMarker
QWriteLocker
locker
m_lock
);
return
pos
duration
comment
type
existingMarker
this
]()
int
mid
if
existingMarker
// Update existing marker
mid
getIdFromPos
pos
);
Q_ASSERT
mid
!=
);
int
row
getRowfromId
mid
);
m_markerList
mid
].
setComment
comment
);
m_markerList
mid
].
setMarkerType
type
);
m_markerList
mid
].
setDuration
duration
);
Q_EMIT
dataChanged
index
row
),
index
row
),
CommentRole
ColorRole
DurationRole
EndPosRole
HasRangeRole
});
else
// Add new marker
Q_ASSERT
hasMarker
pos
==
false
);
mid
TimelineModel
::
getNextId
();
int
insertionRow
static_cast
int
m_markerList
size
());
beginInsertRows
QModelIndex
(),
insertionRow
insertionRow
);
m_markerList
mid
CommentedTime
pos
comment
type
duration
);
m_markerPositions
insert
pos
frames
pCore
->
getCurrentFps
()),
mid
);
endInsertRows
();
addSnapPoint
pos
);
return
true
};
Fun
MarkerListModel
::
deleteMarker_lambda
GenTime
pos
QWriteLocker
locker
m_lock
);
@@ -507,6 +550,11 @@ QHash MarkerListModel::roleNames() const
roles
ColorRole
"color"
roles
TypeRole
"type"
roles
IdRole
"id"
roles
TCRole
"timecode"
roles
ClipIdRole
"clipId"
roles
DurationRole
"duration"
roles
EndPosRole
"endPos"
roles
HasRangeRole
"hasRange"
return
roles
@@ -567,6 +615,12 @@ QVariant MarkerListModel::data(const QModelIndex &index, int role) const
return
pCore
->
timecode
().
getDisplayTimecode
it
->
second
time
(),
false
);
case
ClipIdRole
return
m_clipId
case
DurationRole
return
it
->
second
duration
().
seconds
();
case
EndPosRole
return
it
->
second
endTime
().
seconds
();
case
HasRangeRole
return
it
->
second
hasRange
();
return
QVariant
();
@@ -971,3 +1025,46 @@ void MarkerListModel::exportGuidesGui(QWidget *parent, GenTime projectDuration)
QScopedPointer
ExportGuidesDialog
dialog
new
ExportGuidesDialog
this
projectDuration
parent
));
dialog
->
exec
();
bool
MarkerListModel
::
addRangeMarker
GenTime
pos
GenTime
duration
const
QString
comment
int
type
QWriteLocker
locker
m_lock
);
Fun
undo
[]()
return
true
};
Fun
redo
[]()
return
true
};
bool
res
addRangeMarker
pos
duration
comment
type
undo
redo
);
if
res
if
hasMarker
pos
&&
marker
pos
).
duration
().
seconds
()
// If it was an update to an existing range marker
PUSH_UNDO
undo
redo
i18n
"Update range marker"
));
else
if
hasMarker
pos
))
// If it was an update from a point marker to a range marker
PUSH_UNDO
undo
redo
i18n
"Convert to range marker"
));
else
PUSH_UNDO
undo
redo
i18n
"Add range marker"
));
return
res
bool
MarkerListModel
::
addRangeMarker
GenTime
pos
GenTime
duration
const
QString
comment
int
type
Fun
undo
Fun
redo
QWriteLocker
locker
m_lock
);
Fun
local_undo
[]()
return
true
};
Fun
local_redo
[]()
return
true
};
if
type
==
type
KdenliveSettings
::
default_marker_type
();
Q_ASSERT
pCore
->
markerTypes
contains
type
));
if
hasMarker
pos
))
CommentedTime
current
marker
pos
);
local_undo
addOrUpdateRangeMarker_lambda
pos
current
duration
(),
current
comment
(),
current
markerType
(),
current
);
local_redo
addOrUpdateRangeMarker_lambda
pos
duration
comment
type
current
);
else
// Create new range marker
local_redo
addOrUpdateRangeMarker_lambda
pos
duration
comment
type
nullptr
);
local_undo
deleteMarker_lambda
pos
);
if
local_redo
())
UPDATE_UNDO_REDO
local_redo
local_undo
undo
redo
);
return
true
return
false
Original line number
Diff line number
Diff line
@@ -38,7 +38,7 @@ public:
/** @brief Construct a marker list bound to the bin clip with given id */
explicit
MarkerListModel
QString
clipId
std
::
weak_ptr
DocUndoStack
undo_stack
QObject
parent
nullptr
);
enum
CommentRole
Qt
::
UserRole
PosRole
FrameRole
ColorRole
TypeRole
IdRole
TCRole
ClipIdRole
};
enum
CommentRole
Qt
::
UserRole
PosRole
FrameRole
ColorRole
TypeRole
IdRole
TCRole
ClipIdRole
DurationRole
EndPosRole
HasRangeRole
};
/** @brief Adds a marker at the given position. If there is already one, the comment will be overridden
@param pos defines the position of the marker, relative to the clip
@@ -47,12 +47,21 @@ public:
*/
bool
addMarker
GenTime
pos
const
QString
comment
int
type
);
bool
addMarkers
const
QMap
GenTime
QString
markers
int
type
);
/** @brief Adds a range marker
@param pos defines the position of the marker, relative to the clip
@param duration is the duration of the marker
@param comment is the text associated with the marker
@param type is the type (color) associated with the marker. If -1 is passed, then the value is pulled from kdenlive's defaults
*/
bool
addRangeMarker
GenTime
pos
GenTime
duration
const
QString
comment
int
type
);
/** @brief Returns the model's owner clip id */
const
QString
ownerId
()
const
protected
/** @brief Same function but accumulates undo/redo */
bool
addMarker
GenTime
pos
const
QString
comment
int
type
Fun
undo
Fun
redo
);
/** @brief Same function but for range markers and accumulates undo/redo */
bool
addRangeMarker
GenTime
pos
GenTime
duration
const
QString
comment
int
type
Fun
undo
Fun
redo
);
public
/** @brief Removes the marker at the given position.
@@ -74,6 +83,15 @@ public:
*/
bool
editMarker
GenTime
oldPos
GenTime
pos
QString
comment
QString
(),
int
type
);
/** @brief Edit a marker with duration support
@param oldPos is the old position of the marker
@param pos defines the new position of the marker, relative to the clip
@param comment is the text associated with the marker
@param type is the type (color) associated with the marker. If -1 is passed, then the value is pulled from kdenlive's defaults
@param duration is the duration of the marker (0 for point markers)
*/
bool
editMarker
GenTime
oldPos
GenTime
pos
QString
comment
int
type
GenTime
duration
);
/** @brief Moves all markers from on to another position
@param markers list of markers to move
@param fromPos
@@ -197,6 +215,8 @@ protected:
/** @brief Helper function that generate a lambda to add given marker */
Fun
addMarker_lambda
GenTime
pos
const
QString
comment
int
type
);
/** @brief Helper function that generate a lambda to add or update a given range marker */
Fun
addOrUpdateRangeMarker_lambda
GenTime
pos
GenTime
duration
const
QString
comment
int
type
const
CommentedTime
existingMarker
nullptr
);
/** @brief Helper function that generate a lambda to remove given marker */
Fun
deleteMarker_lambda
GenTime
pos
);
Loading