Commit dbf31ec1 authored by Nicolas Carion's avatar Nicolas Carion
Browse files

ProjectItemModel no longer depends on Bin

parent fddab565
......@@ -593,6 +593,14 @@ Bin::Bin(QWidget *parent)
connect(m_itemModel.get(), &ProjectItemModel::reloadProducer, this, &Bin::reloadProducer);
connect(m_itemModel.get(), &ProjectItemModel::refreshPanel, this, &Bin::refreshPanel);
connect(m_itemModel.get(), &ProjectItemModel::requestAudioThumbs, this, &Bin::requestAudioThumbs);
connect(m_itemModel.get(), &ProjectItemModel::discardJobs, [&](const QString &id, AbstractClipJob::JOBTYPE type){
if (hasPendingJob(id, type))
discardJobs(id, type);
});
connect(m_itemModel.get(), &ProjectItemModel::startJob, this, &Bin::startJob);
connect(m_itemModel.get(), &ProjectItemModel::refreshClip, this, &Bin::refreshClip);
connect(m_itemModel.get(), &ProjectItemModel::updateTimelineProducers, this, &Bin::updateTimelineProducers);
connect(m_itemModel.get(), &ProjectItemModel::emitMessage, this, &Bin::emitMessage);
// Connect models
m_proxyModel->setSourceModel(m_itemModel.get());
......@@ -3455,19 +3463,6 @@ void Bin::getBinStats(uint *used, uint *unused, qint64 *usedSize, qint64 *unused
}
}
QImage Bin::findCachedPixmap(const QString &path)
{
QImage img;
m_doc->clipManager()->pixmapCache->findImage(path, &img);
return img;
}
void Bin::cachePixmap(const QString &path, const QImage &img)
{
if (!m_doc->clipManager()->pixmapCache->contains(path)) {
m_doc->clipManager()->pixmapCache->insertImage(path, img);
}
}
QDir Bin::getCacheDir(CacheType type, bool *ok) const
{
......
......@@ -300,9 +300,6 @@ public:
void getBinStats(uint *used, uint *unused, qint64 *usedSize, qint64 *unusedSize);
/** @brief Returns the clip properties dockwidget. */
QDockWidget *clipPropertiesDock();
/** @brief Returns a cached thumbnail. */
QImage findCachedPixmap(const QString &path);
void cachePixmap(const QString &path, const QImage &img);
/** @brief Returns a document's cache dir. ok is set to false if folder does not exist */
QDir getCacheDir(CacheType type, bool *ok) const;
/** @brief Command adding a bin clip */
......
......@@ -21,7 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "projectclip.h"
#include "bin.h"
#include "core.h"
#include "doc/docundostack.hpp"
#include "doc/kdenlivedoc.h"
......@@ -42,6 +41,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "timeline/clip.h"
#include "timeline2/model/snapmodel.hpp"
#include "utils/KoIconUtils.h"
#include <kimagecache.h>
#include <QPainter>
#include "kdenlive_debug.h"
#include <KLocalizedString>
......@@ -513,16 +514,15 @@ void ProjectClip::setProperties(const QMap<QString, QString> &properties, bool r
if (value.isEmpty() || value == QLatin1String("-")) {
// reset proxy
if (auto ptr = m_model.lock()) {
if (std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->hasPendingJob(m_binId, AbstractClipJob::PROXYJOB)) {
std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->discardJobs(m_binId, AbstractClipJob::PROXYJOB);
} else {
reloadProducer();
}
emit std::static_pointer_cast<ProjectItemModel>(ptr)->discardJobs(m_binId, AbstractClipJob::PROXYJOB);
reloadProducer();
}
} else {
// A proxy was requested, make sure to keep original url
setProducerProperty(QStringLiteral("kdenlive:originalurl"), url());
if (auto ptr = m_model.lock()) std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->startJob(m_binId, AbstractClipJob::PROXYJOB);
if (auto ptr = m_model.lock()) {
emit std::static_pointer_cast<ProjectItemModel>(ptr)->startJob(m_binId, AbstractClipJob::PROXYJOB);
}
}
} else if (properties.contains(QStringLiteral("resource")) || properties.contains(QStringLiteral("templatetext")) ||
properties.contains(QStringLiteral("autorotate"))) {
......@@ -560,10 +560,10 @@ void ProjectClip::setProperties(const QMap<QString, QString> &properties, bool r
if (reload) {
// producer has changed, refresh monitor and thumbnail
reloadProducer(refreshOnly);
if (auto ptr = m_model.lock()) std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->refreshClip(m_binId);
if (auto ptr = m_model.lock()) emit std::static_pointer_cast<ProjectItemModel>(ptr)->refreshClip(m_binId);
}
if (!passProperties.isEmpty()) {
if (auto ptr = m_model.lock()) std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->updateTimelineProducers(m_binId, passProperties);
if (auto ptr = m_model.lock()) emit std::static_pointer_cast<ProjectItemModel>(ptr)->updateTimelineProducers(m_binId, passProperties);
}
}
......@@ -582,7 +582,7 @@ void ProjectClip::setJobStatus(int jobType, int status, int progress, const QStr
}
if ((status == JobAborted || status == JobCrashed || status == JobDone) && !statusMessage.isEmpty()) {
m_jobMessage = statusMessage;
if (auto ptr = m_model.lock()) std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->emitMessage(statusMessage, 100, OperationCompletedMessage);
if (auto ptr = m_model.lock()) emit std::static_pointer_cast<ProjectItemModel>(ptr)->emitMessage(statusMessage, 100, OperationCompletedMessage);
}
}
if (auto ptr = m_model.lock()) std::static_pointer_cast<ProjectItemModel>(ptr)->onItemUpdated(std::static_pointer_cast<ProjectClip>(shared_from_this()));
......@@ -593,7 +593,7 @@ ClipPropertiesController *ProjectClip::buildProperties(QWidget *parent)
auto ptr = m_model.lock();
Q_ASSERT(ptr);
ClipPropertiesController *panel =
new ClipPropertiesController(std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->projectTimecode(), static_cast<ClipController *>(this), parent);
new ClipPropertiesController(static_cast<ClipController *>(this), parent);
connect(this, &ProjectClip::refreshPropertiesPanel, panel, &ClipPropertiesController::slotReloadProperties);
connect(this, &ProjectClip::refreshAnalysisPanel, panel, &ClipPropertiesController::slotFillAnalysisData);
return panel;
......@@ -645,7 +645,8 @@ bool ProjectClip::rename(const QString &name, int column)
break;
}
if (edited) {
if (auto ptr = m_model.lock()) std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->slotEditClipCommand(m_binId, oldProperites, newProperites);
// TODO refac
//if (auto ptr = m_model.lock()) std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->slotEditClipCommand(m_binId, oldProperites, newProperites);
}
return edited;
}
......@@ -680,6 +681,7 @@ bool ProjectClip::deleteClipMarkers(QUndoCommand *command)
void ProjectClip::addMarkers(QList<CommentedTime> &markers)
{
// TODO refac : this must be cleaned
for (int i = 0; i < markers.count(); ++i) {
if (markers.at(i).markerType() < 0) {
m_markerModel->removeMarker(markers.at(i).time());
......@@ -688,7 +690,7 @@ void ProjectClip::addMarkers(QList<CommentedTime> &markers)
}
}
// refresh markers in clip monitor
if (auto ptr = m_model.lock()) std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->refreshClipMarkers(m_binId);
//if (auto ptr = m_model.lock()) std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->refreshClipMarkers(m_binId);
// refresh markers in timeline clips
emit refreshClipDisplay();
}
......@@ -743,7 +745,8 @@ void ProjectClip::doExtractIntra()
const QString path = url() + QLatin1Char('_') + QString::number(pos);
auto ptr = m_model.lock();
Q_ASSERT(ptr);
QImage img = std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->findCachedPixmap(path);
QImage img;
std::static_pointer_cast<ProjectItemModel>(ptr)->m_pixmapCache->findImage(path, &img);
if (!img.isNull()) {
// Cache already contains image
continue;
......@@ -754,7 +757,7 @@ void ProjectClip::doExtractIntra()
frame->set("top_field_first", -1);
if (frame->is_valid()) {
img = KThumb::getFrame(frame, fullWidth, 150);
std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->cachePixmap(path, img);
std::static_pointer_cast<ProjectItemModel>(ptr)->m_pixmapCache->insertImage(path, img);
emit thumbReady(pos, img);
}
delete frame;
......@@ -785,7 +788,7 @@ void ProjectClip::doExtractImage()
bool ok = false;
auto ptr = m_model.lock();
Q_ASSERT(ptr);
QDir thumbFolder = std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->getCacheDir(CacheThumbs, &ok);
QDir thumbFolder = pCore->currentDoc()->getCacheDir(CacheThumbs, &ok);
int max = prod->get_length();
while (!m_requestedThumbs.isEmpty()) {
m_thumbMutex.lock();
......@@ -799,7 +802,8 @@ void ProjectClip::doExtractImage()
pos = max - 1;
}
const QString path = url() + QLatin1Char('_') + QString::number(pos);
QImage img = std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->findCachedPixmap(path);
QImage img;
std::static_pointer_cast<ProjectItemModel>(ptr)->m_pixmapCache->findImage(path, &img);
if (!img.isNull()) {
emit thumbReady(pos, img);
continue;
......@@ -810,7 +814,7 @@ void ProjectClip::doExtractImage()
frame->set("top_field_first", -1);
if (frame->is_valid()) {
img = KThumb::getFrame(frame, frameWidth, 150, prod->profile()->sar() != 1);
std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->cachePixmap(path, img);
std::static_pointer_cast<ProjectItemModel>(ptr)->m_pixmapCache->insertImage(path, img);
emit thumbReady(pos, img);
}
delete frame;
......@@ -851,7 +855,7 @@ const QString ProjectClip::getAudioThumbPath(AudioStreamInfo *audioInfo)
bool ok = false;
auto ptr = m_model.lock();
Q_ASSERT(ptr);
QDir thumbFolder = std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->getCacheDir(CacheAudio, &ok);
QDir thumbFolder = pCore->currentDoc()->getCacheDir(CacheAudio, &ok);
QString audioPath = thumbFolder.absoluteFilePath(clipHash);
if (audioStream > 0) {
audioPath.append(QLatin1Char('_') + QString::number(audioInfo->audio_index()));
......@@ -909,7 +913,7 @@ void ProjectClip::slotCreateAudioThumbs()
if (!channelTmpfile->open()) {
delete channelTmpfile;
if (auto ptr = m_model.lock())
std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->emitMessage(i18n("Cannot create temporary file, check disk space and permissions"),
emit std::static_pointer_cast<ProjectItemModel>(ptr)->emitMessage(i18n("Cannot create temporary file, check disk space and permissions"),
100, ErrorMessage);
return;
}
......@@ -1008,7 +1012,7 @@ void ProjectClip::slotCreateAudioThumbs()
}
emit updateJobStatus(AbstractClipJob::THUMBJOB, JobDone, 0);
if (auto ptr = m_model.lock())
std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->emitMessage(i18n("Error reading audio thumbnail"), 100, ErrorMessage);
emit std::static_pointer_cast<ProjectItemModel>(ptr)->emitMessage(i18n("Error reading audio thumbnail"), 100, ErrorMessage);
return;
}
rawChannels << (const qint16 *)res.constData();
......@@ -1056,7 +1060,7 @@ void ProjectClip::slotCreateAudioThumbs()
jobFinished = true;
} else {
if (auto ptr = m_model.lock())
std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->emitMessage(i18n("Failed to create FFmpeg audio thumbnails, using MLT"), 100,
emit std::static_pointer_cast<ProjectItemModel>(ptr)->emitMessage(i18n("Failed to create FFmpeg audio thumbnails, using MLT"), 100,
ErrorMessage);
}
// Cleanup temporary ffmpeg audio thumb file
......@@ -1246,7 +1250,9 @@ QImage ProjectClip::findCachedThumb(int pos)
const QString path = url() + QLatin1Char('_') + QString::number(pos);
auto ptr = m_model.lock();
Q_ASSERT(ptr);
return std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->findCachedPixmap(path);
QImage img;
std::static_pointer_cast<ProjectItemModel>(ptr)->m_pixmapCache->findImage(path, &img);
return img;
}
bool ProjectClip::isSplittable() const
......
......@@ -41,10 +41,12 @@ ProjectItemModel::ProjectItemModel(Bin *bin, QObject *parent)
: AbstractTreeModel(parent)
, m_lock(QReadWriteLock::Recursive)
, m_binPlaylist(new Mlt::Playlist(pCore->getCurrentProfile()->profile()))
, m_bin(bin)
, m_clipCounter(1)
, m_folderCounter(1)
{
KImageCache::deleteCache(QStringLiteral("kdenlive-thumbs"));
m_pixmapCache.reset(new KImageCache(QStringLiteral("kdenlive-thumbs"), 10000000));
m_pixmapCache->setEvictionPolicy(KSharedDataCache::EvictOldest);
}
std::shared_ptr<ProjectItemModel> ProjectItemModel::construct(Bin *bin, QObject *parent)
......@@ -339,6 +341,7 @@ void ProjectItemModel::clean()
Q_ASSERT(rootItem->childCount() == 0);
m_clipCounter = 1;
m_folderCounter = 1;
m_pixmapCache->clear();
}
std::shared_ptr<ProjectFolder> ProjectItemModel::getRootFolder() const
......@@ -378,11 +381,6 @@ void ProjectItemModel::loadSubClips(const QString &id, const QMap<QString, QStri
}
}
Bin *ProjectItemModel::bin() const
{
return m_bin;
}
std::shared_ptr<AbstractProjectItem> ProjectItemModel::getBinItemByIndex(const QModelIndex &index) const
{
return std::static_pointer_cast<AbstractProjectItem>(getItemById((int)index.internalId()));
......
......@@ -25,15 +25,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "abstractmodel/abstracttreemodel.hpp"
#include "mltcontroller/bincontroller.h"
#include "project/jobs/abstractclipjob.h"
#include "undohelper.hpp"
#include <QReadWriteLock>
#include <QSize>
#include <kimagecache.h>
class AbstractProjectItem;
class ProjectClip;
class ProjectFolder;
class Bin;
class Bin;
/**
* @class ProjectItemModel
* @brief Acts as an adaptor to be able to use BinModel with item views.
......@@ -50,6 +52,8 @@ public:
static std::shared_ptr<ProjectItemModel> construct(Bin *bin, QObject *parent);
~ProjectItemModel();
friend class ProjectClip;
/** @brief Returns a clip from the hierarchy, given its id
*/
std::shared_ptr<ProjectClip> getClipByBinID(const QString &binId);
......@@ -71,11 +75,6 @@ public:
/** @brief Convenience method to access root folder */
std::shared_ptr<ProjectFolder> getRootFolder() const;
/** @brief Convenience method to access the bin associated with this model
TODO remove that.
*/
Bin *bin() const;
/** @brief Create the subclips defined in the parent clip.
@param id is the id of the parent clip
@param data is a definition of the subclips (keys are subclips' names, value are "in:out")*/
......@@ -155,6 +154,7 @@ protected:
/* @brief Helper function to generate a lambda that rename a folder */
Fun requestRenameFolder_lambda(std::shared_ptr<AbstractProjectItem> folder, const QString &newName);
std::unique_ptr<KImageCache> m_pixmapCache;
public slots:
/** @brief An item in the list was modified, notify */
void onItemUpdated(std::shared_ptr<AbstractProjectItem> item);
......@@ -168,11 +168,14 @@ private:
/** @brief The MLT playlist holding our Producers */
std::unique_ptr<Mlt::Playlist> m_binPlaylist;
Bin *m_bin;
int m_clipCounter;
int m_folderCounter;
signals:
void discardJobs(const QString &id, AbstractClipJob::JOBTYPE type);
void startJob(const QString &id, AbstractClipJob::JOBTYPE type);
void refreshClip(const QString &id);
void emitMessage(const QString &, int, MessageType);
void updateTimelineProducers(const QString &id, const QMap<QString, QString> &passProperties);
void updateThumbProgress(long ms);
void abortAudioThumb(const QString &id, long duration);
void refreshAudioThumbs(const QString &id);
......
......@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "projectsubclip.h"
#include "bin.h"
#include "projectclip.h"
#include "projectitemmodel.h"
......@@ -142,17 +141,18 @@ void ProjectSubClip::setThumbnail(const QImage &img)
QPixmap thumb = roundedPixmap(QPixmap::fromImage(img));
m_thumbnail = QIcon(thumb);
if (auto ptr = m_model.lock())
std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->emitItemUpdated(std::static_pointer_cast<ProjectSubClip>(shared_from_this()));
std::static_pointer_cast<ProjectItemModel>(ptr)->onItemUpdated(std::static_pointer_cast<ProjectSubClip>(shared_from_this()));
}
bool ProjectSubClip::rename(const QString &name, int column)
{
// TODO refac: rework this
Q_UNUSED(column)
if (m_name == name) {
return false;
}
// Rename folder
if (auto ptr = m_model.lock()) std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->renameSubClipCommand(m_binId, name, m_name, m_in, m_out);
//if (auto ptr = m_model.lock()) std::static_pointer_cast<ProjectItemModel>(ptr)->bin()->renameSubClipCommand(m_binId, name, m_name, m_in, m_out);
return true;
}
......
......@@ -155,10 +155,10 @@ private:
};
#endif
ClipPropertiesController::ClipPropertiesController(const Timecode &tc, ClipController *controller, QWidget *parent)
ClipPropertiesController::ClipPropertiesController(ClipController *controller, QWidget *parent)
: QWidget(parent)
, m_controller(controller)
, m_tc(tc)
, m_tc(Timecode(Timecode::HH_MM_SS_HH, pCore->getCurrentFps()))
, m_id(controller->clipId())
, m_type(controller->clipType())
, m_properties(controller->properties())
......@@ -256,7 +256,7 @@ ClipPropertiesController::ClipPropertiesController(const Timecode &tc, ClipContr
QCheckBox *box = new QCheckBox(i18n("Duration"), this);
box->setObjectName(QStringLiteral("force_duration"));
hlay->addWidget(box);
auto *timePos = new TimecodeDisplay(tc, this);
auto *timePos = new TimecodeDisplay(m_tc, this);
timePos->setObjectName(QStringLiteral("force_duration_value"));
timePos->setValue(kdenlive_length > 0 ? kdenlive_length : m_properties.get_int("length"));
int original_length = m_properties.get_int("kdenlive:original_length");
......
......@@ -57,7 +57,7 @@ public:
* @param properties The clip's properties
* @param parent The widget where our infos will be displayed
*/
explicit ClipPropertiesController(const Timecode &tc, ClipController *controller, QWidget *parent);
explicit ClipPropertiesController(ClipController *controller, QWidget *parent);
virtual ~ClipPropertiesController();
public slots:
......
......@@ -58,9 +58,6 @@ ClipManager::ClipManager(KdenliveDoc *doc)
, m_closing(false)
, m_abortAudioThumb(false)
{
KImageCache::deleteCache(QStringLiteral("kdenlive-thumbs"));
pixmapCache = new KImageCache(QStringLiteral("kdenlive-thumbs"), 10000000);
pixmapCache->setEvictionPolicy(KSharedDataCache::EvictOldest);
}
ClipManager::~ClipManager()
......@@ -74,8 +71,6 @@ ClipManager::~ClipManager()
m_requestedThumbs.clear();
m_audioThumbsQueue.clear();
m_thumbsMutex.unlock();
delete pixmapCache;
}
void ClipManager::clear()
......@@ -92,13 +87,8 @@ void ClipManager::clear()
m_abortAudioThumb = false;
m_folderList.clear();
m_modifiedClips.clear();
pixmapCache->clear();
}
void ClipManager::clearCache()
{
pixmapCache->clear();
}
void ClipManager::slotRequestThumbs(const QString &id, const QList<int> &frames)
{
......
......@@ -27,7 +27,6 @@
#include <KIO/CopyJob>
#include <QUrl>
#include <kimagecache.h>
#include "definitions.h"
#include "gentime.h"
......@@ -68,7 +67,6 @@ class ClipManager : public QObject
int lastClipId() const;
/** @brief Prepare deletion of clips and folders from the Bin. */
void clear();
void clearCache();
AbstractGroupItem *createGroup();
void removeGroup(AbstractGroupItem *group);
/** @brief Delete groups list, prepare for a reload. */
......@@ -77,7 +75,6 @@ class ClipManager : public QObject
/** @brief remove a clip id from the queue list. */
void stopThumbs(const QString &id);
void projectTreeThumbReady(const QString &id, int frame, const QImage &img, int type);
KImageCache *pixmapCache;
public slots:
/** @brief Request creation of a clip thumbnail for specified frames. */
......
......@@ -1408,7 +1408,7 @@ void Timeline::updateProfile(double fpsChanged)
void Timeline::checkTrackHeight(bool force)
{
if (m_trackview->checkTrackHeight(force)) {
m_doc->clipManager()->clearCache();
//m_doc->clipManager()->clearCache();
m_ruler->updateFrameSize();
slotChangeZoom(m_doc->zoom().x(), m_doc->zoom().y());
slotSetZone(m_doc->zone(), false);
......
Markdown is supported
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