Commit 723ee972 authored by Nicolas Carion's avatar Nicolas Carion
Browse files

Add safeguard when requesting creation of clip with invalid id

parent 61fc54ff
...@@ -321,6 +321,11 @@ std::shared_ptr<ProjectClip> ProjectItemModel::getClipByBinID(const QString &bin ...@@ -321,6 +321,11 @@ std::shared_ptr<ProjectClip> ProjectItemModel::getClipByBinID(const QString &bin
return nullptr; return nullptr;
} }
bool ProjectItemModel::hasClip(const QString &binId)
{
return getClipByBinID(binId) != nullptr;
}
std::shared_ptr<ProjectFolder> ProjectItemModel::getFolderByBinId(const QString &binId) std::shared_ptr<ProjectFolder> ProjectItemModel::getFolderByBinId(const QString &binId)
{ {
for (const auto &clip : m_allItems) { for (const auto &clip : m_allItems) {
......
...@@ -66,6 +66,10 @@ public: ...@@ -66,6 +66,10 @@ public:
*/ */
std::shared_ptr<ProjectClip> getClipByBinID(const QString &binId); std::shared_ptr<ProjectClip> getClipByBinID(const QString &binId);
/** @brief Helper to check whether a clip with a given id exists
*/
bool hasClip(const QString &binId);
/** @brief Gets a folder by its id. If none is found, the root is returned /** @brief Gets a folder by its id. If none is found, the root is returned
*/ */
std::shared_ptr<ProjectFolder> getFolderByBinId(const QString &binId); std::shared_ptr<ProjectFolder> getFolderByBinId(const QString &binId);
......
...@@ -575,6 +575,9 @@ bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, Playl ...@@ -575,6 +575,9 @@ bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, Playl
if (binClipId.contains(QLatin1Char('/'))) { if (binClipId.contains(QLatin1Char('/'))) {
bid = binClipId.section(QLatin1Char('/'), 0, 0); bid = binClipId.section(QLatin1Char('/'), 0, 0);
} }
if (!pCore->projectItemModel()->hasClip(bid)) {
return false;
}
ClipModel::construct(shared_from_this(), bid, clipId, state); ClipModel::construct(shared_from_this(), bid, clipId, state);
auto clip = m_allClips[clipId]; auto clip = m_allClips[clipId];
Fun local_redo = [clip, this, state]() { Fun local_redo = [clip, this, state]() {
......
...@@ -895,6 +895,14 @@ TEST_CASE("Undo and Redo", "[ClipModel]") ...@@ -895,6 +895,14 @@ TEST_CASE("Undo and Redo", "[ClipModel]")
SECTION("requestCreateClip") SECTION("requestCreateClip")
{ {
// an invalid clip id shouln't get created
{
int temp;
Fun undo = []() { return true; };
Fun redo = []() { return true; };
REQUIRE_FALSE(timeline->requestClipCreation("impossible bin id", temp, PlaylistState::Original, undo, redo));
}
auto state0 = [&]() { auto state0 = [&]() {
REQUIRE(timeline->checkConsistency()); REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->m_allClips.size() == nclips); REQUIRE(timeline->m_allClips.size() == nclips);
......
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