Commit 3593888f authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix sorting by date not working for newly inserted clips, other sorting issues.

CCBUG: 458784
parent a6cf7027
Pipeline #228787 passed with stage
in 9 minutes and 17 seconds
......@@ -117,14 +117,14 @@ int AbstractTreeModel::rowCount(const QModelIndex &parent) const
return parentItem->childCount();
}
QModelIndex AbstractTreeModel::getIndexFromItem(const std::shared_ptr<TreeItem> &item) const
QModelIndex AbstractTreeModel::getIndexFromItem(const std::shared_ptr<TreeItem> &item, int column) const
{
if (item == rootItem) {
return QModelIndex();
}
if (auto ptr = item->parentItem().lock()) {
auto parentIndex = getIndexFromItem(ptr);
return index(item->row(), 0, parentIndex);
return index(item->row(), column, parentIndex);
}
return QModelIndex();
}
......
......@@ -33,7 +33,7 @@ public:
~AbstractTreeModel() override;
/** @brief Given an item from the hierarchy, construct the corresponding ModelIndex */
QModelIndex getIndexFromItem(const std::shared_ptr<TreeItem> &item) const;
QModelIndex getIndexFromItem(const std::shared_ptr<TreeItem> &item, int column = 0) const;
/** @brief Given an item id, construct the corresponding ModelIndex */
QModelIndex getIndexFromId(int id) const;
......
......@@ -212,7 +212,7 @@ QVariant AbstractProjectItem::getData(DataType type) const
int AbstractProjectItem::supportedDataCount() const
{
return 8;
return 9;
}
QString AbstractProjectItem::name() const
......
......@@ -166,6 +166,7 @@ ProjectClip::ProjectClip(const QString &id, const QDomElement &description, cons
} else {
m_name = i18n("Untitled");
}
m_date = QFileInfo(m_temporaryUrl).lastModified();
m_boundaryTimer.setSingleShot(true);
m_boundaryTimer.setInterval(500);
connect(m_markerModel.get(), &MarkerListModel::modelChanged, this,
......@@ -552,7 +553,11 @@ bool ProjectClip::setProducer(std::shared_ptr<Mlt::Producer> producer, bool gene
if (m_name.isEmpty()) {
m_name = clipName();
}
m_date = date;
QVector<int> updateRoles;
if (m_date != date) {
m_date = date;
updateRoles << AbstractProjectItem::DataDate;
}
m_description = ClipController::description();
m_temporaryUrl.clear();
if (m_clipType == ClipType::Audio) {
......@@ -565,9 +570,8 @@ bool ProjectClip::setProducer(std::shared_ptr<Mlt::Producer> producer, bool gene
}
m_duration = getStringDuration();
m_clipStatus = m_usesProxy ? FileStatus::StatusProxy : FileStatus::StatusReady;
QVector<int> updateRoles;
if (m_clipStatus != currentStatus) {
updateRoles = {AbstractProjectItem::ClipStatus, AbstractProjectItem::IconOverlay};
updateRoles << AbstractProjectItem::ClipStatus << AbstractProjectItem::IconOverlay;
updateTimelineClips({TimelineModel::StatusRole, TimelineModel::ClipThumbRole});
}
setTags(getProducerProperty(QStringLiteral("kdenlive:tags")));
......
......@@ -106,6 +106,46 @@ int ProjectItemModel::mapToColumn(int column) const
}
}
QList<int> ProjectItemModel::mapDataToColumn(AbstractProjectItem::DataType type) const
{
// Some data types are used in several columns, for example usage count has its
// own column for sorting but is also displayed in column 0
switch (type) {
case AbstractProjectItem::DataName:
case AbstractProjectItem::DataThumbnail:
case AbstractProjectItem::IconOverlay:
case AbstractProjectItem::JobProgress:
return {0};
break;
case AbstractProjectItem::DataDate:
return {1};
break;
case AbstractProjectItem::DataDescription:
return {2};
break;
case AbstractProjectItem::ClipType:
return {3};
break;
case AbstractProjectItem::DataTag:
return {0, 4};
break;
case AbstractProjectItem::DataDuration:
return {0, 5};
break;
case AbstractProjectItem::DataId:
return {6};
break;
case AbstractProjectItem::DataRating:
return {7};
break;
case AbstractProjectItem::UsageCount:
return {0, 8};
break;
default:
return {};
}
}
QVariant ProjectItemModel::data(const QModelIndex &index, int role) const
{
READ_LOCK();
......@@ -276,6 +316,9 @@ QVariant ProjectItemModel::headerData(int section, Qt::Orientation orientation,
case 7:
columnName = i18n("Rating");
break;
case 8:
columnName = i18n("Usage");
break;
default:
columnName = i18n("Unknown");
break;
......@@ -369,12 +412,33 @@ QMimeData *ProjectItemModel::mimeData(const QModelIndexList &indices) const
void ProjectItemModel::onItemUpdated(const std::shared_ptr<AbstractProjectItem> &item, const QVector<int> &roles)
{
int minColumn = -1;
int maxColumn = -1;
for (auto &r : roles) {
const QList<int> indexes = mapDataToColumn((AbstractProjectItem::DataType)r);
for (auto &ix : indexes) {
if (minColumn == -1 || ix < minColumn) {
minColumn = ix;
}
if (maxColumn == -1 || ix > maxColumn) {
maxColumn = ix;
}
}
}
if (minColumn == -1) {
return;
}
QWriteLocker locker(&m_lock);
auto tItem = std::static_pointer_cast<TreeItem>(item);
auto ptr = tItem->parentItem().lock();
if (ptr) {
auto index = getIndexFromItem(tItem);
emit dataChanged(index, index, roles);
auto index = getIndexFromItem(tItem, minColumn);
if (minColumn == maxColumn) {
emit dataChanged(index, index, roles);
} else {
auto index2 = getIndexFromItem(tItem, maxColumn);
emit dataChanged(index, index2, roles);
}
}
}
......
......@@ -10,6 +10,7 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#pragma once
#include "abstractmodel/abstracttreemodel.hpp"
#include "bin/abstractprojectitem.h"
#include "definitions.h"
#include "undohelper.hpp"
#include <QDomElement>
......@@ -19,7 +20,6 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include <QSize>
#include <QUuid>
class AbstractProjectItem;
class BinPlaylist;
class FileWatcher;
class MarkerListModel;
......@@ -242,6 +242,8 @@ public slots:
private:
/** @brief Return reference to column specific data */
int mapToColumn(int column) const;
/** @brief Return column number(s) responsible for a specific data type*/
QList<int> mapDataToColumn(AbstractProjectItem::DataType type) const;
mutable QReadWriteLock m_lock; // This is a lock that ensures safety in case of concurrent access
......
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