diff --git a/io/loadthread.cpp b/io/loadthread.cpp index b8dbf9534..0e3582830 100644 --- a/io/loadthread.cpp +++ b/io/loadthread.cpp @@ -263,7 +263,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { switch (type) { case MEDIA_TYPE_FOLDER: { - Media* folder = panel_project->create_folder_internal(nullptr); + MediaPtr folder = panel_project->create_folder_internal(nullptr); folder->temp_id2 = 0; for (int j=0;j(); FootagePtr f(new Footage()); f->using_inout = false; @@ -381,7 +381,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { olive::project_model.appendChild(find_loaded_folder_by_id(folder), item); // analyze media to see if it's the same - loaded_media_items.append(item); + loaded_media_items.append(item.get()); } break; case MEDIA_TYPE_SEQUENCE: @@ -581,9 +581,9 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { } } - Media* m = panel_project->create_sequence_internal(nullptr, s, false, parent); + MediaPtr m = panel_project->create_sequence_internal(nullptr, s, false, parent); - loaded_sequences.append(m); + loaded_sequences.append(m.get()); } break; } @@ -600,7 +600,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { Media* LoadThread::find_loaded_folder_by_id(int id) { if (id == 0) return nullptr; for (int j=0;jtemp_id == id) { return parent_item; } @@ -632,12 +632,7 @@ void LoadThread::run() { error_str.clear(); show_err = true; - // temp variables for loading (unnecessary?) open_seq = nullptr; - loaded_folders.clear(); - loaded_media_items.clear(); - loaded_clips.clear(); - loaded_sequences.clear(); // get "element" count current_element_count = 0; @@ -669,7 +664,7 @@ void LoadThread::run() { if (cont) { // since folders loaded correctly, organize them appropriately for (int i=0;itemp_id2; olive::project_model.appendChild(find_loaded_folder_by_id(parent), folder); } diff --git a/io/loadthread.h b/io/loadthread.h index 22da99ded..5888bb99f 100644 --- a/io/loadthread.h +++ b/io/loadthread.h @@ -70,7 +70,7 @@ private: bool is_element(QXmlStreamReader& stream); - QVector loaded_folders; + QVector loaded_folders; QVector loaded_clips; QVector loaded_sequences; Media* find_loaded_folder_by_id(int id); diff --git a/panels/project.cpp b/panels/project.cpp index 0966c4ce7..86fe5dbf6 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -333,14 +333,14 @@ void Project::duplicate_selected() { void Project::replace_selected_file() { QModelIndexList selected_items = get_current_selected(); if (selected_items.size() == 1) { - Media* item = item_to_media(selected_items.at(0)); + MediaPtr item = item_to_media_ptr(selected_items.at(0)); if (item->get_type() == MEDIA_TYPE_FOOTAGE) { replace_media(item, nullptr); } } } -void Project::replace_media(Media* item, QString filename) { +void Project::replace_media(MediaPtr item, QString filename) { if (filename.isEmpty()) { filename = QFileDialog::getOpenFileName( this, @@ -412,10 +412,10 @@ void Project::open_properties() { } void Project::new_folder() { - Media* m = create_folder_internal(nullptr); + MediaPtr m = create_folder_internal(nullptr); olive::UndoStack.push(new AddMediaCommand(m, get_selected_folder())); - QModelIndex index = olive::project_model.create_index(m->row(), 0, m); + QModelIndex index = olive::project_model.create_index(m->row(), 0, m.get()); switch (olive::CurrentConfig.project_view_type) { case olive::PROJECT_VIEW_TREE: tree_view->edit(sorter->mapFromSource(index)); @@ -432,16 +432,16 @@ void Project::new_sequence() { nsd.exec(); } -Media* Project::create_sequence_internal(ComboAction *ca, SequencePtr s, bool open, Media* parent) { +MediaPtr Project::create_sequence_internal(ComboAction *ca, SequencePtr s, bool open, Media* parent) { if (parent == nullptr) { parent = olive::project_model.get_root(); } - Media* item = new Media(parent); + MediaPtr item = std::make_shared(parent); item->set_sequence(s); if (ca != nullptr) { - ca->append(new NewSequenceCommand(item, parent)); + ca->append(new AddMediaCommand(item, parent)); if (open) { ca->append(new ChangeSequenceAction(s)); @@ -460,26 +460,25 @@ QString Project::get_file_name_from_path(const QString& path) { return path.mid(path.lastIndexOf('/')+1); } -/*Media* Project::new_item() { - Media* item = new Media(0); - //item->setFlags(item->flags() | Qt::ItemIsEditable); - return item; -}*/ - bool Project::is_focused() { return tree_view->hasFocus() || icon_view->hasFocus(); } -Media* Project::create_folder_internal(QString name) { - Media* item = new Media(nullptr); +MediaPtr Project::create_folder_internal(QString name) { + MediaPtr item = std::make_shared(); item->set_folder(); item->set_name(name); return item; } -Media *Project::item_to_media(const QModelIndex &index) { +Media* Project::item_to_media(const QModelIndex &index) { return static_cast(sorter->mapToSource(index).internalPointer()); - // return static_cast(index.internalPointer()); +} + +MediaPtr Project::item_to_media_ptr(const QModelIndex &index) { + Media* raw_ptr = item_to_media(index); + + return raw_ptr->parentItem()->get_shared_ptr(raw_ptr); } void Project::get_all_media_from_table(QList& items, QList& list, int search_type) { @@ -514,10 +513,12 @@ bool delete_clips_in_clipboard_with_media(ComboAction* ca, Media* m) { void Project::delete_selected_media() { ComboAction* ca = new ComboAction(); QModelIndexList selected_items = get_current_selected(); + QList items; for (int i=0;i 0) { + QList media_items; get_all_media_from_table(items, media_items, MEDIA_TYPE_FOOTAGE); + for (int i=0;ito_footage(); @@ -618,7 +621,8 @@ void Project::delete_selected_media() { } for (int i=0;iappend(new DeleteMediaCommand(items.at(i))); + + ca->append(new DeleteMediaCommand(items.at(i)->parentItem()->get_shared_ptr(items.at(i)))); if (items.at(i)->get_type() == MEDIA_TYPE_SEQUENCE) { redraw = true; @@ -655,7 +659,7 @@ void Project::delete_selected_media() { } } -void Project::process_file_list(QStringList& files, bool recursive, Media* replace, Media* parent) { +void Project::process_file_list(QStringList& files, bool recursive, MediaPtr replace, Media* parent) { bool imported = false; // retrieve the array of image formats from the user's configuration @@ -678,7 +682,7 @@ void Project::process_file_list(QStringList& files, bool recursive, Media* repla if (QFileInfo(files.at(i)).isDir()) { QString folder_name = get_file_name_from_path(files.at(i)); - Media* folder = create_folder_internal(folder_name); + MediaPtr folder = create_folder_internal(folder_name); QDir directory(files.at(i)); directory.setFilter(QDir::NoDotAndDotDot | QDir::AllEntries); @@ -690,7 +694,7 @@ void Project::process_file_list(QStringList& files, bool recursive, Media* repla subdir_filenames.append(subdir_files.at(j).filePath()); } - process_file_list(subdir_filenames, true, nullptr, folder); + process_file_list(subdir_filenames, true, nullptr, folder.get()); if (create_undo_action) { ca->append(new AddMediaCommand(folder, parent)); @@ -852,13 +856,13 @@ void Project::process_file_list(QStringList& files, bool recursive, Media* repla // If we're not skipping this file, let's import it if (!skip) { - Media* item; + MediaPtr item; FootagePtr m; if (replace != nullptr) { item = replace; } else { - item = new Media(parent); + item = std::make_shared(parent); } m = FootagePtr(new Footage()); @@ -870,7 +874,7 @@ void Project::process_file_list(QStringList& files, bool recursive, Media* repla item->set_footage(m); - last_imported_media.append(item); + last_imported_media.append(item.get()); if (replace == nullptr) { if (create_undo_action) { diff --git a/panels/project.h b/panels/project.h index 4b1414f76..6c12294e3 100644 --- a/panels/project.h +++ b/panels/project.h @@ -58,10 +58,10 @@ public: bool is_focused(); void clear(); - Media* create_sequence_internal(ComboAction *ca, SequencePtr s, bool open, Media* parent); + MediaPtr create_sequence_internal(ComboAction *ca, SequencePtr s, bool open, Media* parent); QString get_next_sequence_name(QString start = nullptr); - void process_file_list(QStringList& files, bool recursive = false, Media* replace = nullptr, Media *parent = nullptr); - void replace_media(Media* item, QString filename); + void process_file_list(QStringList& files, bool recursive = false, MediaPtr replace = nullptr, Media *parent = nullptr); + void replace_media(MediaPtr item, QString filename); Media* get_selected_folder(); bool reveal_media(Media *media, QModelIndex parent = QModelIndex()); void add_recent_project(QString url); @@ -70,8 +70,10 @@ public: void load_project(const QString &filename, bool autorecovery, bool clear); void save_project(bool autorecovery); - Media* create_folder_internal(QString name); + MediaPtr create_folder_internal(QString name); + Media* item_to_media(const QModelIndex& index); + MediaPtr item_to_media_ptr(const QModelIndex &index); void save_recent_projects(); diff --git a/panels/timeline.cpp b/panels/timeline.cpp index 4170246e8..48db4b0df 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -444,11 +444,11 @@ void Timeline::nest() { relink_clips_using_ids(selected_clips, s->clips); // add sequence to project - Media* m = panel_project->create_sequence_internal(ca, s, false, nullptr); + MediaPtr m = panel_project->create_sequence_internal(ca, s, false, nullptr); // add nested sequence to active sequence QVector media_list; - media_list.append(m); + media_list.append(m.get()); create_ghosts_from_media(olive::ActiveSequence.get(), earliest_point, media_list); add_clips_from_ghosts(ca, olive::ActiveSequence.get()); diff --git a/project/media.cpp b/project/media.cpp index b9d4508a2..bc0afa64b 100644 --- a/project/media.cpp +++ b/project/media.cpp @@ -67,12 +67,6 @@ Media::Media(Media* iparent) { type = -1; } -Media::~Media() { - for (int i=0;i(object.get()); } @@ -262,7 +256,7 @@ int Media::get_sampling_rate(int stream) { return 0; } -void Media::appendChild(Media *child) { +void Media::appendChild(MediaPtr child) { child->set_parent(this); children.append(child); } @@ -279,7 +273,7 @@ bool Media::setData(int col, const QVariant &value) { } Media *Media::child(int row) { - return children.value(row); + return children.value(row).get(); } int Media::childCount() const { @@ -348,7 +342,11 @@ QVariant Media::data(int column, int role) { int Media::row() const { if (parent) { - return parent->children.indexOf(const_cast(this)); + for (int i=0;ichildren.size();i++) { + if (parent->children.at(i).get() == this) { + return i; + } + } } return 0; } @@ -361,6 +359,16 @@ void Media::removeChild(int i) { children.removeAt(i); } +MediaPtr Media::get_shared_ptr(Media *m) +{ + for (int i=0;i &Media::get_markers() { // returns the marker array from the internal object // diff --git a/project/media.h b/project/media.h index b4f6c628d..3dd26f044 100644 --- a/project/media.h +++ b/project/media.h @@ -39,11 +39,14 @@ using SequencePtr = std::shared_ptr; using VoidPtr = std::shared_ptr; +class Media; +using MediaPtr = std::shared_ptr; + class Media { public: - Media(Media* iparent); - ~Media(); + Media(Media* iparent = nullptr); + Footage *to_footage(); SequencePtr to_sequence(); void set_icon(const QString& str); @@ -62,7 +65,7 @@ public: int get_sampling_rate(int stream = -1); // item functions - void appendChild(Media *child); + void appendChild(MediaPtr child); bool setData(int col, const QVariant &value); Media *child(int row); int childCount() const; @@ -71,6 +74,7 @@ public: int row() const; Media *parentItem(); void removeChild(int i); + MediaPtr get_shared_ptr(Media* m); // get markers from internal object QVector& get_markers(); @@ -84,7 +88,7 @@ private: VoidPtr object; // item functions - QList children; + QList children; Media* parent; QString folder_name; QString tooltip; diff --git a/project/projectmodel.cpp b/project/projectmodel.cpp index 268d7f01e..b1b5022c4 100644 --- a/project/projectmodel.cpp +++ b/project/projectmodel.cpp @@ -28,77 +28,77 @@ ProjectModel olive::project_model; -ProjectModel::ProjectModel(QObject *parent) : QAbstractItemModel(parent), root_item(nullptr) { - make_root(); +ProjectModel::ProjectModel(QObject *parent) : QAbstractItemModel(parent), root_item_(nullptr) { + make_root(); } ProjectModel::~ProjectModel() { - destroy_root(); + destroy_root(); } void ProjectModel::make_root() { - root_item = new Media(nullptr); - root_item->temp_id = 0; - root_item->root = true; + root_item_ = std::make_shared(); + root_item_->temp_id = 0; + root_item_->root = true; } void ProjectModel::destroy_root() { - if (panel_sequence_viewer != nullptr) panel_sequence_viewer->viewer_widget->delete_function(); - if (panel_footage_viewer != nullptr) panel_footage_viewer->viewer_widget->delete_function(); + if (panel_sequence_viewer != nullptr) panel_sequence_viewer->viewer_widget->delete_function(); + if (panel_footage_viewer != nullptr) panel_footage_viewer->viewer_widget->delete_function(); - if (root_item != nullptr) { - delete root_item; - } + root_item_ = std::make_shared(); } void ProjectModel::clear() { - beginResetModel(); - destroy_root(); - make_root(); - endResetModel(); + beginResetModel(); + destroy_root(); + make_root(); + endResetModel(); } -Media *ProjectModel::get_root() { - return root_item; +Media *ProjectModel::get_root() const { + return root_item_.get(); } QVariant ProjectModel::data(const QModelIndex &index, int role) const { - if (!index.isValid()) - return QVariant(); + if (!index.isValid()) + return QVariant(); - return static_cast(index.internalPointer())->data(index.column(), role); + return static_cast(index.internalPointer())->data(index.column(), role); } Qt::ItemFlags ProjectModel::flags(const QModelIndex &index) const { - if (!index.isValid()) - return Qt::ItemIsDropEnabled; + if (!index.isValid()) + return Qt::ItemIsDropEnabled; - return QAbstractItemModel::flags(index) | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEditable; + return QAbstractItemModel::flags(index) | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEditable; } QVariant ProjectModel::headerData(int section, Qt::Orientation orientation, int role) const { - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) - return root_item->data(section, role); + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + return root_item_->data(section, role); - return QVariant(); + return QVariant(); } QModelIndex ProjectModel::index(int row, int column, const QModelIndex &parent) const { - if (!hasIndex(row, column, parent)) - return QModelIndex(); + if (!hasIndex(row, column, parent)) + return QModelIndex(); - Media *parentItem; + Media *parentItem; - if (!parent.isValid()) - parentItem = root_item; - else - parentItem = static_cast(parent.internalPointer()); + if (!parent.isValid()) { + parentItem = get_root(); + } else { + parentItem = static_cast(parent.internalPointer()); + } - Media *childItem = parentItem->child(row); - if (childItem) - return createIndex(row, column, childItem); - else - return QModelIndex(); + Media *childItem = parentItem->child(row); + if (childItem) { + return createIndex(row, column, childItem); + } else { + return QModelIndex(); + } } QModelIndex ProjectModel::create_index(int arow, int acolumn, void* adata) { @@ -106,14 +106,14 @@ QModelIndex ProjectModel::create_index(int arow, int acolumn, void* adata) { } QModelIndex ProjectModel::parent(const QModelIndex &index) const { - if (!index.isValid()) - return QModelIndex(); + if (!index.isValid()) + return QModelIndex(); - Media *childItem = static_cast(index.internalPointer()); - Media *parentItem = childItem->parentItem(); + Media *childItem = static_cast(index.internalPointer()); + Media *parentItem = childItem->parentItem(); - if (parentItem == root_item) - return QModelIndex(); + if (parentItem == get_root()) + return QModelIndex(); return createIndex(parentItem->row(), 0, parentItem); } @@ -142,89 +142,104 @@ bool ProjectModel::hasChildren(const QModelIndex &parent) const } bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if (role != Qt::EditRole) - return false; + if (role != Qt::EditRole) + return false; - Media *item = static_cast(index.internalPointer()); - bool result = item->setData(index.column(), value); + Media *item = static_cast(index.internalPointer()); + bool result = item->setData(index.column(), value); - if (result) - emit dataChanged(index, index); + if (result) + emit dataChanged(index, index); - return result; + return result; } int ProjectModel::rowCount(const QModelIndex &parent) const { Media *parentItem; - if (parent.column() > 0) - return 0; + if (parent.column() > 0) + return 0; - if (!parent.isValid()) { - parentItem = root_item; - } else { - parentItem = static_cast(parent.internalPointer()); - } + if (!parent.isValid()) { + parentItem = get_root(); + } else { + parentItem = static_cast(parent.internalPointer()); + } - return parentItem->childCount(); + return parentItem->childCount(); } int ProjectModel::columnCount(const QModelIndex &parent) const { - if (parent.isValid()) - return static_cast(parent.internalPointer())->columnCount(); - else - return root_item->columnCount(); + if (parent.isValid()) + return static_cast(parent.internalPointer())->columnCount(); + else + return root_item_->columnCount(); } Media *ProjectModel::getItem(const QModelIndex &index) const { - if (index.isValid()) { - Media *item = static_cast(index.internalPointer()); - if (item) - return item; - } - return root_item; + if (index.isValid()) { + Media *item = static_cast(index.internalPointer()); + if (item) + return item; + } + return get_root(); } void ProjectModel::set_icon(Media* m, const QIcon &ico) { - QModelIndex index = createIndex(m->row(), 0, m); - m->set_icon(ico); - emit dataChanged(index, index); + QModelIndex index = createIndex(m->row(), 0, m); + m->set_icon(ico); + emit dataChanged(index, index); } -void ProjectModel::appendChild(Media *parent, Media *child) { - if (parent == nullptr) parent = root_item; - beginInsertRows(parent == root_item ? QModelIndex() : createIndex(parent->row(), 0, parent), parent->childCount(), parent->childCount()); - parent->appendChild(child); - endInsertRows(); +void ProjectModel::appendChild(Media* parent, MediaPtr child) { + if (parent == nullptr) { + parent = get_root(); + } + beginInsertRows(parent == get_root() ? + QModelIndex() : createIndex(parent->row(), 0, parent), parent->childCount(), parent->childCount()); + parent->appendChild(child); + endInsertRows(); } -void ProjectModel::moveChild(Media *child, Media *to) { - if (to == nullptr) to = root_item; - Media* from = child->parentItem(); - beginMoveRows( - from == root_item ? QModelIndex() : createIndex(from->row(), 0, from), - child->row(), - child->row(), - to == root_item ? QModelIndex() : createIndex(to->row(), 0, to), - to->childCount() - ); - from->removeChild(child->row()); - to->appendChild(child); - endMoveRows(); +void ProjectModel::moveChild(MediaPtr child, Media *to) { + if (to == nullptr) { + to = get_root(); + } + + Media* from = child->parentItem(); + + beginMoveRows( + from == get_root() ? QModelIndex() : createIndex(from->row(), 0, from), + child->row(), + child->row(), + to == get_root() ? QModelIndex() : createIndex(to->row(), 0, to), + to->childCount() + ); + + from->removeChild(child->row()); + to->appendChild(child); + endMoveRows(); } void ProjectModel::removeChild(Media* parent, Media* m) { - if (parent == nullptr) parent = root_item; - beginRemoveRows(parent == root_item ? QModelIndex() : createIndex(parent->row(), 0, parent), m->row(), m->row()); - parent->removeChild(m->row()); - endRemoveRows(); + if (parent == nullptr) { + parent = get_root(); + } + beginRemoveRows(parent == get_root() ? + QModelIndex() : createIndex(parent->row(), 0, parent), m->row(), m->row()); + parent->removeChild(m->row()); + endRemoveRows(); } Media* ProjectModel::child(int i, Media* parent) { - if (parent == nullptr) parent = root_item; - return parent->child(i); + if (parent == nullptr) { + parent = get_root(); + } + return parent->child(i); } int ProjectModel::childCount(Media *parent) { - if (parent == nullptr) parent = root_item; - return parent->childCount(); + if (parent == nullptr) { + parent = get_root(); + } + return parent->childCount(); } diff --git a/project/projectmodel.h b/project/projectmodel.h index b2ccc7c3a..17edade63 100644 --- a/project/projectmodel.h +++ b/project/projectmodel.h @@ -35,7 +35,7 @@ public: void make_root(); void destroy_root(); void clear(); - Media* get_root(); + Media* get_root() const; QVariant data(const QModelIndex &index, int role) const override; Qt::ItemFlags flags(const QModelIndex &index) const override; QVariant headerData(int section, Qt::Orientation orientation, @@ -51,15 +51,15 @@ public: int columnCount(const QModelIndex &parent = QModelIndex()) const override; Media* getItem(const QModelIndex &index) const; - void appendChild(Media* parent, Media* child); - void moveChild(Media* child, Media* to); + void appendChild(Media *parent, MediaPtr child); + void moveChild(MediaPtr child, Media* to); void removeChild(Media* parent, Media* m); Media* child(int i, Media* parent = nullptr); int childCount(Media* parent = nullptr); void set_icon(Media* m, const QIcon &ico); private: - Media* root_item; + MediaPtr root_item_; }; namespace olive { diff --git a/project/sourcescommon.cpp b/project/sourcescommon.cpp index c52f85f50..0156520e0 100644 --- a/project/sourcescommon.cpp +++ b/project/sourcescommon.cpp @@ -261,9 +261,12 @@ void SourcesCommon::mouseDoubleClickEvent(const QModelIndexList& selected_items) } } -void SourcesCommon::dropEvent(QWidget* parent, QDropEvent *event, const QModelIndex& drop_item, const QModelIndexList& items) { +void SourcesCommon::dropEvent(QWidget* parent, + QDropEvent *event, + const QModelIndex& drop_item, + const QModelIndexList& items) { const QMimeData* mimeData = event->mimeData(); - Media* m = project_parent->item_to_media(drop_item); + MediaPtr m = project_parent->item_to_media_ptr(drop_item); if (mimeData->hasUrls()) { // drag files in from outside QList urls = mimeData->urls(); @@ -305,11 +308,11 @@ void SourcesCommon::dropEvent(QWidget* parent, QDropEvent *event, const QModelIn // dragging files within project // if we dragged to the root OR dragged to a folder if (!drop_item.isValid() || m->get_type() == MEDIA_TYPE_FOLDER) { - QVector move_items; + QVector move_items; for (int i=0;iitem_to_media(item); + MediaPtr s = project_parent->item_to_media_ptr(item); if (parent != drop_item && item != drop_item) { bool ignore = false; if (parent.isValid()) { @@ -332,7 +335,7 @@ void SourcesCommon::dropEvent(QWidget* parent, QDropEvent *event, const QModelIn } if (move_items.size() > 0) { MediaMove* mm = new MediaMove(); - mm->to = m; + mm->to = m.get(); mm->items = move_items; olive::UndoStack.push(mm); } diff --git a/project/undo.cpp b/project/undo.cpp index fd022f15c..977494e79 100644 --- a/project/undo.cpp +++ b/project/undo.cpp @@ -322,76 +322,32 @@ void DeleteTransitionCommand::doRedo() { } } -NewSequenceCommand::NewSequenceCommand(Media *s, Media* iparent) { - seq = s; - parent = iparent; - done = false; - - if (parent == nullptr) parent = olive::project_model.get_root(); -} - -NewSequenceCommand::~NewSequenceCommand() { - if (!done) delete seq; -} - -void NewSequenceCommand::doUndo() { - olive::project_model.removeChild(parent, seq); - - done = false; -} - -void NewSequenceCommand::doRedo() { - olive::project_model.appendChild(parent, seq); - - done = true; -} - -AddMediaCommand::AddMediaCommand(Media* iitem, Media *iparent) { - item = iitem; - parent = iparent; - done = false; -} - -AddMediaCommand::~AddMediaCommand() { - if (!done) { - delete item; - } +AddMediaCommand::AddMediaCommand(MediaPtr iitem, Media *iparent) : + item(iitem), + parent(iparent) +{ } void AddMediaCommand::doUndo() { - olive::project_model.removeChild(parent, item); - done = false; - + olive::project_model.removeChild(parent, item.get()); } void AddMediaCommand::doRedo() { olive::project_model.appendChild(parent, item); - - done = true; } -DeleteMediaCommand::DeleteMediaCommand(Media* i) { - item = i; - parent = i->parentItem(); -} - -DeleteMediaCommand::~DeleteMediaCommand() { - if (done) { - delete item; - } +DeleteMediaCommand::DeleteMediaCommand(MediaPtr i) : + item(i), + parent(i->parentItem()) +{ } void DeleteMediaCommand::doUndo() { olive::project_model.appendChild(parent, item); - - - done = false; } void DeleteMediaCommand::doRedo() { - olive::project_model.removeChild(parent, item); - - done = true; + olive::project_model.removeChild(parent, item.get()); } AddClipCommand::AddClipCommand(Sequence *s, QVector& add) { @@ -501,7 +457,7 @@ void CheckboxCommand::doRedo() { } } -ReplaceMediaCommand::ReplaceMediaCommand(Media* i, QString s) { +ReplaceMediaCommand::ReplaceMediaCommand(MediaPtr i, QString s) { item = i; new_filename = s; old_filename = item->to_footage()->url; @@ -514,7 +470,7 @@ void ReplaceMediaCommand::replace(QString& filename) { Sequence* s = all_sequences.at(i)->to_sequence().get(); for (int j=0;jclips.size();j++) { ClipPtr c = s->clips.at(j); - if (c != nullptr && c->media() == item && c->IsOpen()) { + if (c != nullptr && c->media() == item.get() && c->IsOpen()) { c->Close(true); c->replaced = true; } @@ -525,7 +481,7 @@ void ReplaceMediaCommand::replace(QString& filename) { QStringList files; files.append(filename); panel_project->process_file_list(files, false, item, nullptr); - PreviewGenerator::AnalyzeMedia(item); + PreviewGenerator::AnalyzeMedia(item.get()); } void ReplaceMediaCommand::doUndo() { @@ -615,7 +571,6 @@ void MediaMove::doUndo() { for (int i=0;i items; + QVector items; Media* to; virtual void doUndo() override; virtual void doRedo() override;