moved media to smart pointers
This commit is contained in:
+7
-12
@@ -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<stream.attributes().size();j++) {
|
||||
const QXmlStreamAttribute& attr = stream.attributes().at(j);
|
||||
@@ -282,7 +282,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
|
||||
{
|
||||
int folder = 0;
|
||||
|
||||
Media* item = new Media(nullptr);
|
||||
MediaPtr item = std::make_shared<Media>();
|
||||
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;j<loaded_folders.size();j++) {
|
||||
Media* parent_item = loaded_folders.at(j);
|
||||
Media* parent_item = loaded_folders.at(j).get();
|
||||
if (parent_item->temp_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;i<loaded_folders.size();i++) {
|
||||
Media* folder = loaded_folders.at(i);
|
||||
MediaPtr folder = loaded_folders.at(i);
|
||||
int parent = folder->temp_id2;
|
||||
olive::project_model.appendChild(find_loaded_folder_by_id(parent), folder);
|
||||
}
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ private:
|
||||
|
||||
bool is_element(QXmlStreamReader& stream);
|
||||
|
||||
QVector<Media*> loaded_folders;
|
||||
QVector<MediaPtr> loaded_folders;
|
||||
QVector<ClipPtr> loaded_clips;
|
||||
QVector<Media*> loaded_sequences;
|
||||
Media* find_loaded_folder_by_id(int id);
|
||||
|
||||
+28
-24
@@ -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<Media>(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<Media>();
|
||||
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<Media*>(sorter->mapToSource(index).internalPointer());
|
||||
// return static_cast<Media*>(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<Media*>& items, QList<Media*>& 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<Media*> items;
|
||||
for (int i=0;i<selected_items.size();i++) {
|
||||
items.append(item_to_media(selected_items.at(i)));
|
||||
}
|
||||
|
||||
bool remove = true;
|
||||
bool redraw = false;
|
||||
|
||||
@@ -530,8 +531,10 @@ void Project::delete_selected_media() {
|
||||
}
|
||||
get_all_media_from_table(all_top_level_items, sequence_items, MEDIA_TYPE_SEQUENCE); // find all sequences in project
|
||||
if (sequence_items.size() > 0) {
|
||||
|
||||
QList<Media*> media_items;
|
||||
get_all_media_from_table(items, media_items, MEDIA_TYPE_FOOTAGE);
|
||||
|
||||
for (int i=0;i<media_items.size();i++) {
|
||||
Media* item = media_items.at(i);
|
||||
Footage* media = item->to_footage();
|
||||
@@ -618,7 +621,8 @@ void Project::delete_selected_media() {
|
||||
}
|
||||
|
||||
for (int i=0;i<items.size();i++) {
|
||||
ca->append(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<Media>(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) {
|
||||
|
||||
+6
-4
@@ -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();
|
||||
|
||||
|
||||
+2
-2
@@ -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*> 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());
|
||||
|
||||
|
||||
+17
-9
@@ -67,12 +67,6 @@ Media::Media(Media* iparent) {
|
||||
type = -1;
|
||||
}
|
||||
|
||||
Media::~Media() {
|
||||
for (int i=0;i<children.size();i++) {
|
||||
delete children.at(i);
|
||||
}
|
||||
}
|
||||
|
||||
Footage* Media::to_footage() {
|
||||
return static_cast<Footage*>(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<Media*>(this));
|
||||
for (int i=0;i<parent->children.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<children.size();i++) {
|
||||
if (children.at(i).get() == m) {
|
||||
return children.at(i);
|
||||
}
|
||||
}
|
||||
return MediaPtr();
|
||||
}
|
||||
|
||||
QVector<Marker> &Media::get_markers() {
|
||||
// returns the marker array from the internal object
|
||||
//
|
||||
|
||||
+8
-4
@@ -39,11 +39,14 @@ using SequencePtr = std::shared_ptr<Sequence>;
|
||||
|
||||
using VoidPtr = std::shared_ptr<void>;
|
||||
|
||||
class Media;
|
||||
using MediaPtr = std::shared_ptr<Media>;
|
||||
|
||||
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<Marker>& get_markers();
|
||||
@@ -84,7 +88,7 @@ private:
|
||||
VoidPtr object;
|
||||
|
||||
// item functions
|
||||
QList<Media*> children;
|
||||
QList<MediaPtr> children;
|
||||
Media* parent;
|
||||
QString folder_name;
|
||||
QString tooltip;
|
||||
|
||||
+113
-98
@@ -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<Media>();
|
||||
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<Media>();
|
||||
}
|
||||
|
||||
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<Media*>(index.internalPointer())->data(index.column(), role);
|
||||
return static_cast<Media*>(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<Media*>(parent.internalPointer());
|
||||
if (!parent.isValid()) {
|
||||
parentItem = get_root();
|
||||
} else {
|
||||
parentItem = static_cast<Media*>(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<Media*>(index.internalPointer());
|
||||
Media *parentItem = childItem->parentItem();
|
||||
Media *childItem = static_cast<Media*>(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<Media*>(index.internalPointer());
|
||||
bool result = item->setData(index.column(), value);
|
||||
Media *item = static_cast<Media*>(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<Media*>(parent.internalPointer());
|
||||
}
|
||||
if (!parent.isValid()) {
|
||||
parentItem = get_root();
|
||||
} else {
|
||||
parentItem = static_cast<Media*>(parent.internalPointer());
|
||||
}
|
||||
|
||||
return parentItem->childCount();
|
||||
return parentItem->childCount();
|
||||
}
|
||||
|
||||
int ProjectModel::columnCount(const QModelIndex &parent) const {
|
||||
if (parent.isValid())
|
||||
return static_cast<Media*>(parent.internalPointer())->columnCount();
|
||||
else
|
||||
return root_item->columnCount();
|
||||
if (parent.isValid())
|
||||
return static_cast<Media*>(parent.internalPointer())->columnCount();
|
||||
else
|
||||
return root_item_->columnCount();
|
||||
}
|
||||
|
||||
Media *ProjectModel::getItem(const QModelIndex &index) const {
|
||||
if (index.isValid()) {
|
||||
Media *item = static_cast<Media*>(index.internalPointer());
|
||||
if (item)
|
||||
return item;
|
||||
}
|
||||
return root_item;
|
||||
if (index.isValid()) {
|
||||
Media *item = static_cast<Media*>(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();
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<QUrl> 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<Media*> move_items;
|
||||
QVector<MediaPtr> move_items;
|
||||
for (int i=0;i<items.size();i++) {
|
||||
const QModelIndex& item = items.at(i);
|
||||
const QModelIndex& parent = item.parent();
|
||||
Media* s = project_parent->item_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);
|
||||
}
|
||||
|
||||
+13
-58
@@ -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<ClipPtr>& 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;j<s->clips.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.size();i++) {
|
||||
olive::project_model.moveChild(items.at(i), froms.at(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MediaMove::doRedo() {
|
||||
|
||||
+7
-23
@@ -191,40 +191,24 @@ private:
|
||||
long new_out;
|
||||
};
|
||||
|
||||
class NewSequenceCommand : public OliveAction {
|
||||
public:
|
||||
NewSequenceCommand(Media* s, Media* iparent);
|
||||
virtual ~NewSequenceCommand() override;
|
||||
virtual void doUndo() override;
|
||||
virtual void doRedo() override;
|
||||
private:
|
||||
Media* seq;
|
||||
Media* parent;
|
||||
bool done;
|
||||
};
|
||||
|
||||
class AddMediaCommand : public OliveAction {
|
||||
public:
|
||||
AddMediaCommand(Media* iitem, Media* iparent);
|
||||
virtual ~AddMediaCommand() override;
|
||||
AddMediaCommand(MediaPtr iitem, Media* iparent);
|
||||
virtual void doUndo() override;
|
||||
virtual void doRedo() override;
|
||||
private:
|
||||
Media* item;
|
||||
MediaPtr item;
|
||||
Media* parent;
|
||||
bool done;
|
||||
};
|
||||
|
||||
class DeleteMediaCommand : public OliveAction {
|
||||
public:
|
||||
DeleteMediaCommand(Media *i);
|
||||
virtual ~DeleteMediaCommand() override;
|
||||
DeleteMediaCommand(MediaPtr i);
|
||||
virtual void doUndo() override;
|
||||
virtual void doRedo() override;
|
||||
private:
|
||||
Media* item;
|
||||
MediaPtr item;
|
||||
Media* parent;
|
||||
bool done;
|
||||
};
|
||||
|
||||
class AddClipCommand : public OliveAction {
|
||||
@@ -265,11 +249,11 @@ private:
|
||||
|
||||
class ReplaceMediaCommand : public OliveAction {
|
||||
public:
|
||||
ReplaceMediaCommand(Media*, QString);
|
||||
ReplaceMediaCommand(MediaPtr, QString);
|
||||
virtual void doUndo() override;
|
||||
virtual void doRedo() override;
|
||||
private:
|
||||
Media *item;
|
||||
MediaPtr item;
|
||||
QString old_filename;
|
||||
QString new_filename;
|
||||
void replace(QString& filename);
|
||||
@@ -304,7 +288,7 @@ private:
|
||||
class MediaMove : public OliveAction {
|
||||
public:
|
||||
MediaMove();
|
||||
QVector<Media*> items;
|
||||
QVector<MediaPtr> items;
|
||||
Media* to;
|
||||
virtual void doUndo() override;
|
||||
virtual void doRedo() override;
|
||||
|
||||
Reference in New Issue
Block a user