Commit 2cb43162 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

When deleting a guides category, also remove all clip markers using it

parent 6c1ac094
Pipeline #260661 failed with stage
in 6 minutes and 22 seconds
......@@ -5488,3 +5488,35 @@ void Bin::processMultiStream(const QString &clipId, QList<int> videoStreams, QLi
pCore->pushUndo(undo, redo, i18np("Add additional stream for clip", "Add additional streams for clip", importedStreams));
}
}
int Bin::getAllClipMarkers(int category) const
{
int markersCount = 0;
QList<std::shared_ptr<ProjectClip>> clipList = m_itemModel->getRootFolder()->childClips();
for (const std::shared_ptr<ProjectClip> &clip : qAsConst(clipList)) {
markersCount += clip->getMarkerModel()->getAllMarkers(category).count();
}
return markersCount;
}
void Bin::removeMarkerCategories(QList<int> toRemove)
{
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool found = false;
QList<std::shared_ptr<ProjectClip>> clipList = m_itemModel->getRootFolder()->childClips();
for (const std::shared_ptr<ProjectClip> &clip : qAsConst(clipList)) {
for (int i : toRemove) {
QList<CommentedTime> toDelete = clip->getMarkerModel()->getAllMarkers(i);
if (!found && toDelete.count() > 0) {
found = true;
}
for (CommentedTime c : toDelete) {
clip->getMarkerModel()->removeMarker(c.time(), undo, redo);
}
}
}
if (found) {
pCore->pushUndo(undo, redo, i18n("Remove clip markers"));
}
}
......@@ -243,6 +243,12 @@ public:
/** @brief Add markers on clip \@param binId at \@param positions with @comments text if given */
void addClipMarker(const QString &binId, const QList<int> &positions, const QStringList &comments = {});
/** @brief Get the count of all markers in all clips using this category */
int getAllClipMarkers(int category) const;
/** @brief Remove all clip markers using a category */
void removeMarkerCategories(QList<int> toRemove);
/** @brief Returns a list of selected clip ids.
* @param allowSubClips: if true, will include subclip ids in the form: "master clip id/in/out"
*/
......
......@@ -381,6 +381,22 @@ const QStringList KdenliveDoc::guidesCategories() const
void KdenliveDoc::updateGuideCategories(const QStringList &categories)
{
const QStringList currentCategories = m_documentProperties.value(QStringLiteral("guidesCategories")).split(QLatin1Char('\n'));
// Check if a guide category was removed
QList<int> currentIndexes;
QList<int> updatedIndexes;
for (auto &cat : currentCategories) {
currentIndexes << cat.section(QLatin1Char(':'), -2, -2).toInt();
}
for (auto &cat : categories) {
updatedIndexes << cat.section(QLatin1Char(':'), -2, -2).toInt();
}
for (auto &i : updatedIndexes) {
currentIndexes.removeAll(i);
}
if (!currentIndexes.isEmpty()) {
// A marker category was removed, delete all Bin clip markers using it
pCore->bin()->removeMarkerCategories(currentIndexes);
}
m_guideModel->loadCategoriesWithUndo(categories, currentCategories);
}
......
......@@ -113,6 +113,7 @@ GuideCategories::GuideCategories(KdenliveDoc *doc, QWidget *parent)
// Check usage
if (doc) {
int count = doc->getGuideModel()->getAllMarkers(ix).count();
count += pCore->bin()->getAllClipMarkers(ix);
item->setData(Qt::UserRole + 2, count);
}
guides_list->addItem(item);
......
Supports Markdown
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