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

Force ProjectClips to be constructed using id

parent 1c660fe9
......@@ -46,13 +46,13 @@ AbstractProjectItem::AbstractProjectItem(PROJECTITEMTYPE type, const QString &id
{
}
AbstractProjectItem::AbstractProjectItem(PROJECTITEMTYPE type, const QDomElement &description, const std::shared_ptr<ProjectItemModel> &model)
AbstractProjectItem::AbstractProjectItem(PROJECTITEMTYPE type, const QString &id, const QDomElement &description, const std::shared_ptr<ProjectItemModel> &model)
: TreeItem(QList<QVariant>(), std::static_pointer_cast<AbstractTreeModel>(model), false)
, m_name()
, m_description()
, m_thumbnail(QIcon())
, m_date()
, m_binId(description.attribute(QStringLiteral("id")))
, m_binId(id)
, m_usage(0)
, m_clipStatus(StatusReady)
, m_jobType(AbstractClipJob::NOJOBTYPE)
......
......@@ -68,7 +68,7 @@ public:
*
* We try to read the attributes "name" and "description"
*/
AbstractProjectItem(PROJECTITEMTYPE type, const QDomElement &description, const std::shared_ptr<ProjectItemModel> &model);
AbstractProjectItem(PROJECTITEMTYPE type, const QString &id, const QDomElement &description, const std::shared_ptr<ProjectItemModel> &model);
bool operator==(const std::shared_ptr<AbstractProjectItem> &projectItem) const;
......
......@@ -50,6 +50,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "ui_qtextclip_ui.h"
#include "undohelper.hpp"
#include "utils/KoIconUtils.h"
#include "xml/xml.hpp"
#include <KColorScheme>
#include <KMessageBox>
......@@ -1282,7 +1283,11 @@ void Bin::createClip(const QDomElement &xml)
}
}
}
auto newClip = ProjectClip::construct(xml, m_blankThumb, m_itemModel);
QString id = Xml::getTagContentByAttribute(xml, QStringLiteral("property"), QStringLiteral("name"), QStringLiteral("kdenlive:id"));
if (id.isEmpty()) {
id = QString::number(m_itemModel->getFreeClipId());
}
auto newClip = ProjectClip::construct(id, xml, m_blankThumb, m_itemModel);
parentFolder->appendChild(newClip);
}
......
......@@ -41,6 +41,7 @@ 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 "xml/xml.hpp"
#include <kimagecache.h>
#include <QPainter>
......@@ -96,9 +97,9 @@ std::shared_ptr<ProjectClip> ProjectClip::construct(const QString &id, const QIc
return self;
}
ProjectClip::ProjectClip(const QDomElement &description, const QIcon &thumb, std::shared_ptr<ProjectItemModel> model)
: AbstractProjectItem(AbstractProjectItem::ClipItem, description, model)
, ClipController(description.attribute(QStringLiteral("id")), pCore->binController())
ProjectClip::ProjectClip(const QString &id, const QDomElement &description, const QIcon &thumb, std::shared_ptr<ProjectItemModel> model)
: AbstractProjectItem(AbstractProjectItem::ClipItem, id, description, model)
, ClipController(id, pCore->binController())
, m_abortAudioThumb(false)
, m_thumbsProducer(nullptr)
{
......@@ -127,9 +128,9 @@ ProjectClip::ProjectClip(const QDomElement &description, const QIcon &thumb, std
});
}
std::shared_ptr<ProjectClip> ProjectClip::construct(const QDomElement &description, const QIcon &thumb, std::shared_ptr<ProjectItemModel> model)
std::shared_ptr<ProjectClip> ProjectClip::construct(const QString &id, const QDomElement &description, const QIcon &thumb, std::shared_ptr<ProjectItemModel> model)
{
std::shared_ptr<ProjectClip> self(new ProjectClip(description, thumb, model));
std::shared_ptr<ProjectClip> self(new ProjectClip(id, description, thumb, model));
baseFinishConstruct(self);
pCore->binController()->addClipToBin(description.attribute(QStringLiteral("id")), self, true);
return self;
......
......@@ -64,13 +64,13 @@ public:
std::shared_ptr<Mlt::Producer> producer);
/**
* @brief Constructor.
* @param description element describing the clip; the "id" attribute and "resource" property are used
* @param description element describing the clip; the "kdenlive:id" attribute and "resource" property are used
*/
static std::shared_ptr<ProjectClip> construct(const QDomElement &description, const QIcon &thumb, std::shared_ptr<ProjectItemModel> model);
static std::shared_ptr<ProjectClip> construct(const QString &id, const QDomElement &description, const QIcon &thumb, std::shared_ptr<ProjectItemModel> model);
protected:
ProjectClip(const QString &id, const QIcon &thumb, std::shared_ptr<ProjectItemModel> model, std::shared_ptr<Mlt::Producer> producer);
ProjectClip(const QDomElement &description, const QIcon &thumb, std::shared_ptr<ProjectItemModel> model);
ProjectClip(const QString &id, const QDomElement &description, const QIcon &thumb, std::shared_ptr<ProjectItemModel> model);
public:
virtual ~ProjectClip();
......
......@@ -129,6 +129,11 @@ public:
/* @brief Request that the unused clips are deleted */
bool requestCleanup();
/* @brief Retrieves the next id available for attribution to a folder */
int getFreeFolderId();
/* @brief Retrieves the next id available for attribution to a clip */
int getFreeClipId();
protected:
/* @brief Register the existence of a new element
*/
......@@ -137,12 +142,6 @@ protected:
void deregisterItem(int id, TreeItem *item) override;
/* @brief Retrieves the next id available for attribution to a folder */
int getFreeFolderId();
/* @brief Retrieves the next id available for attribution to a clip */
int getFreeClipId();
/* @brief Helper function to generate a lambda that rename a folder */
Fun requestRenameFolder_lambda(std::shared_ptr<AbstractProjectItem> folder, const QString &newName);
......
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