R8: finish app/ pure C ABI migration (P3-P9) and make OTIO required

- app/ no longer includes engine C++ headers nor holds engine C++ types:
  engine access goes through the oakengine C ABI plus C++ wrappers
  (oakutil/oaknode.h, oakutil/oakvideo.h) and app-local mirror types
  (tooltypes, trackreferencehandle, timelinecommonapp, keyframetypes,
  subtitleapp, serializedlayoutinfoapp, nodevaluehandle, sliderdisplaytypeapp)
- engine: new C ABI functions for block/track/clip/transition navigation
  and predicates, links, caches, waveform/playback, disk folder,
  sequence_track_list, node_free, footage_is_valid, block_get_track,
  get_brush; loadotio/saveotio ported to the current engine API
- OTIO is now a required dependency: CI and CD build it on every
  platform, FindOpenTimelineIO fixed for OTIO 0.16/0.19 (the old deps
  include requirement silently disabled OTIO everywhere), runtime
  libraries are bundled into packages and copied next to macOS binaries
  (oak_copy_otio_runtime)
- fix ProjectViewModel drag&drop mime read/write size mismatch (segfault)
- unify color label naming (k_olive -> "Oak") in the app-side mirror
- docs: OTIO required, FFmpeg minimum corrected to 6.0 (en/zh)
- gtest suite: 1925 passed, 0 failed
This commit is contained in:
2026-07-31 22:46:52 +08:00
parent 18aed979a2
commit 66d761b4b7
285 changed files with 13261 additions and 5895 deletions
+145 -147
View File
@@ -53,20 +53,19 @@ namespace olive
namespace
{
QVector<Footage *> get_selected_proxy_footage(const QVector<Node *> &items)
QVector<oak::Node> get_selected_proxy_footage(const QVector<oak::Node> &items)
{
QVector<Footage *> footage;
for (Node *node : items) {
Footage *candidate = dynamic_cast<Footage *>(node);
QVector<oak::Node> footage;
for (const oak::Node &node : items) {
oak_video_params _vp;
if (!candidate ||
if (!node.is_footage() ||
oakengine_viewer_get_first_enabled_video_stream(
reinterpret_cast<OakEngineNode *>(candidate), &_vp) < 0 ||
node.handle(), &_vp) < 0 ||
!oakengine_video_params_is_valid(&_vp) ||
footage.contains(candidate)) {
footage.contains(node)) {
continue;
}
footage.append(candidate);
footage.append(node);
}
return footage;
}
@@ -161,7 +160,7 @@ void ProjectExplorer::set_view_type(ProjectToolbar::ViewType type)
void ProjectExplorer::edit(OakEngineNode *item)
{
current_view()->edit(
sort_model_.mapFromSource(model_.create_index_from_item(reinterpret_cast<Node *>(item))));
sort_model_.mapFromSource(model_.create_index_from_item(oak::Node(item))));
}
void ProjectExplorer::add_view(QAbstractItemView *view)
@@ -190,18 +189,18 @@ void ProjectExplorer::browse_to_folder(const QModelIndex &index)
nav_bar_->set_dir_up_enabled(index.isValid());
}
int ProjectExplorer::confirm_item_deletion(Node *item)
int ProjectExplorer::confirm_item_deletion(oak::Node item)
{
QMessageBox msgbox(this);
msgbox.setWindowTitle(tr("Confirm Item Deletion"));
msgbox.setIcon(QMessageBox::Warning);
QStringList connected_nodes_names;
foreach (const Node::OutputConnection &connected,
item->output_connections()) {
if (!dynamic_cast<Folder *>(connected.second.node())) {
for (int i = 0; i < item.output_connection_count(); i++) {
oak::Node connected_node = item.output_connection_node(i);
if (!connected_node.is_folder()) {
connected_nodes_names.append(
get_human_readable_node_name(connected.second.node()));
get_human_readable_node_name(connected_node));
}
}
@@ -222,21 +221,20 @@ int ProjectExplorer::confirm_item_deletion(Node *item)
return msgbox.exec();
}
bool ProjectExplorer::delete_items_internal(const QVector<Node *> &selected,
bool ProjectExplorer::delete_items_internal(const QVector<oak::Node> &selected,
bool &check_if_item_is_in_use,
void *command)
{
for (int i = 0; i < selected.size(); i++) {
// Delete sequences first
Node *node = selected.at(i);
oak::Node node = selected.at(i);
bool can_delete_item = true;
if (check_if_item_is_in_use) {
foreach (const Node::OutputConnection &oc,
node->output_connections()) {
Folder *folder_test = dynamic_cast<Folder *>(oc.second.node());
if (!folder_test) {
for (int j = 0; j < node.output_connection_count(); j++) {
oak::Node oc_node = node.output_connection_node(j);
if (!oc_node.is_folder()) {
// This sequence outputs to SOMETHING, confirm the user if they want to delete this
int r = confirm_item_deletion(node);
@@ -255,30 +253,31 @@ bool ProjectExplorer::delete_items_internal(const QVector<Node *> &selected,
}
if (can_delete_item) {
Sequence *sequence = dynamic_cast<Sequence *>(node);
if (sequence &&
Core::instance()->main_window()->is_sequence_open(sequence)) {
oakengine_undo_command_multi_add_child(command, make_close_sequence_command(sequence));
if (node.is_sequence() &&
Core::instance()->main_window()->is_sequence_open(node.handle())) {
oakengine_undo_command_multi_add_child(command, make_close_sequence_command(node.handle()));
}
if (node->folder()) {
oak::Node parent_folder = node.folder();
if (parent_folder) {
oakengine_undo_command_multi_add_child(
command,
oakengine_folder_remove_element_command(
reinterpret_cast<OakEngineNode *>(node->folder()),
reinterpret_cast<OakEngineNode *>(node)));
parent_folder.handle(),
node.handle()));
}
void *remove_cmd = oakengine_undo_command_create_multi();
oakengine_undo_command_multi_add_child(
remove_cmd,
oakengine_node_remove_and_disconnect_command(
reinterpret_cast<void *>(node)));
for (Node *dep : node->get_exclusive_dependencies()) {
node.handle()));
for (int d = 0; d < node.exclusive_dependency_count(); d++) {
oak::Node dep = node.exclusive_dependency_at(d);
oakengine_undo_command_multi_add_child(
remove_cmd,
oakengine_node_remove_and_disconnect_command(
reinterpret_cast<void *>(dep)));
dep.handle()));
}
oakengine_undo_command_multi_add_child(command, remove_cmd);
}
@@ -287,12 +286,12 @@ bool ProjectExplorer::delete_items_internal(const QVector<Node *> &selected,
return true;
}
QString ProjectExplorer::get_human_readable_node_name(Node *node)
QString ProjectExplorer::get_human_readable_node_name(const oak::Node &node)
{
if (node->get_label().isEmpty()) {
return node->name();
if (node.get_label().isEmpty()) {
return node.name();
} else {
return tr("%1 (%2)").arg(node->get_label(), node->name());
return tr("%1 (%2)").arg(node.get_label(), node.name());
}
}
@@ -300,11 +299,11 @@ void ProjectExplorer::update_nav_bar_text()
{
QString absolute;
Folder *f = static_cast<Folder *>(
sort_model_.mapToSource(list_view_->rootIndex()).internalPointer());
while (f && f != project()->root()) {
absolute.prepend(QStringLiteral("%1 / ").arg(f->get_label()));
f = f->folder();
oak::Node f(static_cast<OakEngineNode *>(
sort_model_.mapToSource(list_view_->rootIndex()).internalPointer()));
while (f && f != project().root()) {
absolute.prepend(QStringLiteral("%1 / ").arg(f.get_label()));
f = f.folder();
}
absolute.prepend(QStringLiteral("/ "));
@@ -325,18 +324,18 @@ void ProjectExplorer::view_empty_area_double_clicked_slot()
void ProjectExplorer::item_double_clicked_slot(const QModelIndex &index)
{
// Retrieve source item from index
Node *i =
static_cast<Node *>(sort_model_.mapToSource(index).internalPointer());
oak::Node i(
static_cast<OakEngineNode *>(sort_model_.mapToSource(index).internalPointer()));
// If the item is a folder, browse to it
if (dynamic_cast<Folder *>(i) &&
if (i.is_folder() &&
(view_type() == ProjectToolbar::list_view ||
view_type() == ProjectToolbar::icon_view)) {
browse_to_folder(index);
}
// Emit a signal
emit double_clicked_item(reinterpret_cast<OakEngineNode *>(i));
emit double_clicked_item(i.handle());
}
void ProjectExplorer::size_changed_slot(int s)
@@ -392,9 +391,9 @@ void ProjectExplorer::show_context_menu()
} else {
// Actions to add when only one item is selected
if (context_menu_items_.size() == 1) {
Node *context_menu_item = context_menu_items_.first();
oak::Node context_menu_item = context_menu_items_.first();
if (dynamic_cast<Folder *>(context_menu_item)) {
if (context_menu_item.is_folder()) {
QAction *open_in_new_tab =
menu.addAction(tr("Open in New Tab"));
connect(open_in_new_tab, &QAction::triggered, this,
@@ -405,7 +404,7 @@ void ProjectExplorer::show_context_menu()
connect(open_in_new_window, &QAction::triggered, this,
&ProjectExplorer::open_context_menu_item_in_new_window);
} else if (dynamic_cast<Footage *>(context_menu_item)) {
} else if (context_menu_item.is_footage()) {
QString reveal_text;
#if defined(Q_OS_WINDOWS)
@@ -432,28 +431,28 @@ void ProjectExplorer::show_context_menu()
bool all_items_have_video_streams = true;
bool all_items_are_footage_or_sequence = true;
foreach (Node *i, context_menu_items_) {
Footage *footage_cast_test = dynamic_cast<Footage *>(i);
Sequence *sequence_cast_test = dynamic_cast<Sequence *>(i);
foreach (const oak::Node &i, context_menu_items_) {
bool is_footage = i.is_footage();
bool is_sequence = i.is_sequence();
if (footage_cast_test &&
if (is_footage &&
!oakengine_viewer_has_enabled_streams(
reinterpret_cast<OakEngineNode *>(footage_cast_test),
i.handle(),
OAKENGINE_TRACK_TYPE_VIDEO)) {
all_items_have_video_streams = false;
}
if (!footage_cast_test) {
if (!is_footage) {
all_items_are_footage = false;
}
if (!footage_cast_test && !sequence_cast_test) {
if (!is_footage && !is_sequence) {
all_items_are_footage_or_sequence = false;
}
}
if (all_items_are_footage && all_items_have_video_streams) {
const QVector<Footage *> proxy_footage =
const QVector<oak::Node> proxy_footage =
get_selected_proxy_footage(context_menu_items_);
Menu *proxy_menu = new Menu(tr("Proxy"), &menu);
@@ -471,8 +470,9 @@ void ProjectExplorer::show_context_menu()
use_proxy->setChecked(
!proxy_footage.isEmpty() &&
std::all_of(proxy_footage.cbegin(), proxy_footage.cend(),
[](const Footage *footage) {
return footage->proxy_enabled();
[](const oak::Node &node) {
oak::Footage f = node.as_footage();
return f && f.proxy_enabled();
}));
connect(use_proxy, &QAction::triggered, this,
&ProjectExplorer::set_selected_footage_proxy_enabled);
@@ -480,8 +480,9 @@ void ProjectExplorer::show_context_menu()
QAction *reveal_proxy = proxy_menu->addAction(tr("Reveal Proxy"));
reveal_proxy->setEnabled(
std::any_of(proxy_footage.cbegin(), proxy_footage.cend(),
[](const Footage *footage) {
return !footage->proxy_path().isEmpty();
[](const oak::Node &node) {
oak::Footage f = node.as_footage();
return f && !f.proxy_path().isEmpty();
}));
connect(reveal_proxy, &QAction::triggered, this,
&ProjectExplorer::reveal_proxy_for_selected_footage);
@@ -489,8 +490,9 @@ void ProjectExplorer::show_context_menu()
QAction *delete_proxy = proxy_menu->addAction(tr("Delete Proxy"));
delete_proxy->setEnabled(
std::any_of(proxy_footage.cbegin(), proxy_footage.cend(),
[](const Footage *footage) {
return !footage->proxy_path().isEmpty();
[](const oak::Node &node) {
oak::Footage f = node.as_footage();
return f && !f.proxy_path().isEmpty();
}));
connect(delete_proxy, &QAction::triggered, this,
&ProjectExplorer::delete_proxies_for_selected_footage);
@@ -529,19 +531,23 @@ void ProjectExplorer::show_context_menu()
void ProjectExplorer::show_item_properties_dialog()
{
Node *sel = context_menu_items_.first();
oak::Node sel = context_menu_items_.first();
// FIXME: Support for multiple items
if (dynamic_cast<Footage *>(sel)) {
FootagePropertiesDialog fpd(this, static_cast<Footage *>(sel));
if (sel.is_footage()) {
FootagePropertiesDialog fpd(this, sel.handle());
fpd.exec();
} else if (dynamic_cast<Folder *>(sel)) {
Core::instance()->label_nodes(
reinterpret_cast<const QVector<OakEngineNode *> &>(context_menu_items_));
} else if (sel.is_folder()) {
QVector<OakEngineNode *> handles;
handles.reserve(context_menu_items_.size());
for (const oak::Node &n : context_menu_items_) {
handles.append(n.handle());
}
Core::instance()->label_nodes(handles);
} else if (dynamic_cast<Sequence *>(sel)) {
SequenceDialog sd(static_cast<Sequence *>(sel),
} else if (sel.is_sequence()) {
SequenceDialog sd(sel.handle(),
SequenceDialog::k_existing, this);
sd.exec();
}
@@ -549,12 +555,12 @@ void ProjectExplorer::show_item_properties_dialog()
void ProjectExplorer::reveal_selected_footage()
{
Footage *footage = static_cast<Footage *>(context_menu_items_.first());
oak::Footage footage = context_menu_items_.first().as_footage();
#if defined(Q_OS_WINDOWS)
// Explorer
QStringList args;
args << "/select," << QDir::toNativeSeparators(footage->filename());
args << "/select," << QDir::toNativeSeparators(footage.filename());
QProcess::startDetached("explorer", args);
#elif defined(Q_OS_MAC)
QStringList args;
@@ -563,19 +569,20 @@ void ProjectExplorer::reveal_selected_footage()
args << "-e";
args << "activate";
args << "-e";
args << "select POSIX file \"" + footage->filename() + "\"";
args << "select POSIX file \"" + footage.filename() + "\"";
args << "-e";
args << "end tell";
QProcess::startDetached("osascript", args);
#else
QDesktopServices::openUrl(QUrl::fromLocalFile(
QFileInfo(footage->filename()).dir().absolutePath()));
QFileInfo(footage.filename()).dir().absolutePath()));
#endif
}
void ProjectExplorer::replace_selected_footage()
{
Footage *footage = static_cast<Footage *>(context_menu_items_.first());
oak::Node node = context_menu_items_.first();
oak::Footage footage = node.as_footage();
QString file =
QFileDialog::getOpenFileName(this, tr("Replace Footage"), QString(),
@@ -591,28 +598,20 @@ void ProjectExplorer::replace_selected_footage()
// Change the filename through the facade relink (reprobes the new
// file and resets proxy/stream state); the label policy stays here.
OakEngineFootage *facade_handle = oakengine_footage_borrow(
reinterpret_cast<OakEngineNode *>(footage));
const int relink_rc = oakengine_footage_relink(
facade_handle, file.toUtf8().constData());
oakengine_footage_free(facade_handle);
const int relink_rc = footage.relink(file);
if (relink_rc != OAKENGINE_OK) {
char err[512];
err[0] = '\0';
oakengine_footage_last_error(err, sizeof(err));
const QString err = oak::Footage::last_error();
QMessageBox::warning(
this, tr("Cannot replace footage"),
err[0] ? QString::fromUtf8(err) :
tr("The file could not be used as media."));
!err.isEmpty() ? err :
tr("The file could not be used as media."));
return;
}
if (QFileInfo(footage->filename()).fileName() ==
footage->get_label()) {
if (QFileInfo(footage.filename()).fileName() ==
node.get_label()) {
// Footage label == filename, change label too
oakengine_node_set_label(
reinterpret_cast<OakEngineNode *>(footage),
QFileInfo(file).fileName().toUtf8().constData());
node.set_label(QFileInfo(file).fileName());
}
}
}
@@ -620,13 +619,13 @@ void ProjectExplorer::replace_selected_footage()
void ProjectExplorer::open_context_menu_item_in_new_tab()
{
Core::instance()->main_window()->open_folder(
static_cast<Folder *>(context_menu_items_.first()), false);
context_menu_items_.first().handle(), false);
}
void ProjectExplorer::open_context_menu_item_in_new_window()
{
Core::instance()->main_window()->open_folder(
static_cast<Folder *>(context_menu_items_.first()), true);
context_menu_items_.first().handle(), true);
}
void ProjectExplorer::generate_proxies_for_selected_footage()
@@ -636,69 +635,65 @@ void ProjectExplorer::generate_proxies_for_selected_footage()
return;
}
const QVector<Footage *> footage =
const QVector<oak::Node> footage =
get_selected_proxy_footage(context_menu_items_);
qDebug()
<< "GenerateProxiesForSelectedFootage: starting proxy generation for"
<< footage.size() << "footage item(s)";
for (Footage *item : footage) {
for (const oak::Node &item : footage) {
oak_video_params _vp;
if (oakengine_viewer_get_first_enabled_video_stream(
reinterpret_cast<OakEngineNode *>(item), &_vp) < 0 ||
item.handle(), &_vp) < 0 ||
!oakengine_video_params_is_valid(&_vp)) {
oak::Footage f = item.as_footage();
qWarning()
<< "GenerateProxiesForSelectedFootage: skipping item with no valid video stream"
<< item->filename();
<< (f ? f.filename() : QString());
continue;
}
// Queue one facade-backed task per footage item (same queueing
// semantics as the old per-footage proxy tasks).
OakEngineTask *proxy_task = oakengine_task_create_proxy(
reinterpret_cast<OakEngineNode *>(item));
item.handle());
oakengine_task_manager_add(proxy_task);
}
}
void ProjectExplorer::set_selected_footage_proxy_enabled(bool enabled)
{
const QVector<Footage *> footage =
const QVector<oak::Node> footage =
get_selected_proxy_footage(context_menu_items_);
qDebug() << "ProjectExplorer::SetSelectedFootageProxyEnabled:" << enabled
<< "footage count=" << footage.size();
for (Footage *item : footage) {
if (item->proxy_path().isEmpty()) {
for (const oak::Node &item : footage) {
oak::Footage f = item.as_footage();
if (!f || f.proxy_path().isEmpty()) {
qDebug()
<< " skipping item with empty proxy path" << item->filename();
<< " skipping item with empty proxy path" << (f ? f.filename() : QString());
continue;
}
OakEngineFootage *handle = oakengine_footage_borrow(
reinterpret_cast<OakEngineNode *>(item));
oakengine_footage_proxy_set_enabled(handle, enabled ? 1 : 0);
f.set_proxy_enabled(enabled);
// The facade call toggles the flag; cache invalidation for the UI
// stays here.
oakengine_footage_invalidate(handle);
oakengine_footage_free(handle);
f.invalidate();
}
}
void ProjectExplorer::reveal_proxy_for_selected_footage()
{
const QVector<Footage *> footage =
const QVector<oak::Node> footage =
get_selected_proxy_footage(context_menu_items_);
for (Footage *item : footage) {
char proxy_path[4096];
proxy_path[0] = '\0';
OakEngineFootage *handle = oakengine_footage_borrow(
reinterpret_cast<OakEngineNode *>(item));
oakengine_footage_proxy_get_path(handle, proxy_path,
sizeof(proxy_path));
oakengine_footage_free(handle);
if (proxy_path[0] == '\0') {
for (const oak::Node &item : footage) {
oak::Footage f = item.as_footage();
if (!f) {
continue;
}
const QString path = f.proxy_path();
if (path.isEmpty()) {
continue;
}
const QString path = QString::fromUtf8(proxy_path);
#if defined(Q_OS_WINDOWS)
QStringList args;
@@ -724,25 +719,29 @@ void ProjectExplorer::reveal_proxy_for_selected_footage()
void ProjectExplorer::delete_proxies_for_selected_footage()
{
const QVector<Footage *> footage =
const QVector<oak::Node> footage =
get_selected_proxy_footage(context_menu_items_);
for (Footage *item : footage) {
if (item->proxy_path().isEmpty()) {
for (const oak::Node &item : footage) {
oak::Footage f = item.as_footage();
if (!f || f.proxy_path().isEmpty()) {
continue;
}
// Facade delete: removes the file, clears the proxy state and
// invalidates the footage.
OakEngineFootage *handle = oakengine_footage_borrow(
reinterpret_cast<OakEngineNode *>(item));
oakengine_footage_proxy_delete(handle);
oakengine_footage_free(handle);
f.proxy_delete();
}
}
void ProjectExplorer::show_proxy_dialog_for_selected_footage()
{
ProxyDialog d(this, get_selected_proxy_footage(context_menu_items_));
QVector<OakEngineNode *> handles;
const QVector<oak::Node> footage = get_selected_proxy_footage(context_menu_items_);
handles.reserve(footage.size());
for (const oak::Node &n : footage) {
handles.append(n.handle());
}
ProxyDialog d(this, handles);
d.exec();
}
@@ -755,43 +754,42 @@ void ProjectExplorer::view_selection_changed()
QVector<OakEngineNode *> nodes;
foreach (const QModelIndex &index, selection) {
Node *sel = static_cast<Node *>(
auto handle = static_cast<OakEngineNode *>(
sort_model_.mapToSource(index).internalPointer());
auto handle = reinterpret_cast<OakEngineNode *>(sel);
if (!nodes.contains(handle)) {
nodes.append(handle);
}
}
if (nodes.isEmpty()) {
nodes.append(reinterpret_cast<OakEngineNode *>(get_root()));
nodes.append(get_root().handle());
}
emit selection_changed(nodes);
}
Project *ProjectExplorer::project() const
oak::Project ProjectExplorer::project() const
{
return model_.project();
}
void ProjectExplorer::set_project(Project *p)
void ProjectExplorer::set_project(oak::Project p)
{
model_.set_project(p);
}
Folder *ProjectExplorer::get_root() const
oak::Node ProjectExplorer::get_root() const
{
QModelIndex root_index = sort_model_.mapToSource(tree_view_->rootIndex());
if (!root_index.isValid()) {
return project()->root();
return project().root();
}
return static_cast<Folder *>(root_index.internalPointer());
return oak::Node(static_cast<OakEngineNode *>(root_index.internalPointer()));
}
void ProjectExplorer::set_root(Folder *item)
void ProjectExplorer::set_root(oak::Node item)
{
QModelIndex index =
sort_model_.mapFromSource(model_.create_index_from_item(item));
@@ -800,19 +798,19 @@ void ProjectExplorer::set_root(Folder *item)
tree_view_->setRootIndex(index);
}
QVector<Node *> ProjectExplorer::selected_items() const
QVector<oak::Node> ProjectExplorer::selected_items() const
{
// Determine which view is active and get its selected indexes
QModelIndexList index_list =
current_view()->selectionModel()->selectedRows();
// Convert indexes to item objects
QVector<Node *> selected_items;
QVector<oak::Node> selected_items;
for (int i = 0; i < index_list.size(); i++) {
QModelIndex index = sort_model_.mapToSource(index_list.at(i));
Node *item = static_cast<Node *>(index.internalPointer());
oak::Node item(static_cast<OakEngineNode *>(index.internalPointer()));
selected_items.append(item);
}
@@ -820,16 +818,16 @@ QVector<Node *> ProjectExplorer::selected_items() const
return selected_items;
}
Folder *ProjectExplorer::get_selected_folder() const
oak::Node ProjectExplorer::get_selected_folder() const
{
if (project() == nullptr) {
return nullptr;
return oak::Node();
}
Folder *folder = nullptr;
oak::Node folder;
// Get the selected items from the panel
QVector<Node *> selected_nodes = selected_items();
QVector<oak::Node> selected_nodes = selected_items();
// Heuristic for finding the selected folder:
//
@@ -839,27 +837,27 @@ Folder *ProjectExplorer::get_selected_folder() const
// - If more than one folder is found, we play it safe and import into the root folder
for (int i = 0; i < selected_nodes.size(); i++) {
Node *sel_item = selected_nodes.at(i);
oak::Node sel_item = selected_nodes.at(i);
// If this item is not a folder, presumably it's parent is
if (!dynamic_cast<Folder *>(sel_item)) {
sel_item = sel_item->folder();
if (!sel_item.is_folder()) {
sel_item = sel_item.folder();
}
if (folder == nullptr) {
// If the folder is nullptr, cache it as this folder
folder = static_cast<Folder *>(sel_item);
folder = sel_item;
} else if (folder != sel_item) {
// If not, we've already cached a folder so we check if it's the same
// If it isn't, we "play it safe" and use the root folder
folder = nullptr;
folder = oak::Node();
break;
}
}
// If we didn't pick up a folder from the heuristic above for whatever reason, use root
if (folder == nullptr) {
folder = project()->root();
folder = project().root();
}
return folder;
@@ -882,7 +880,7 @@ void ProjectExplorer::deselect_all()
void ProjectExplorer::delete_selected()
{
QVector<Node *> selected = selected_items();
QVector<oak::Node> selected = selected_items();
if (selected.isEmpty()) {
return;
@@ -900,7 +898,7 @@ void ProjectExplorer::delete_selected()
}
}
bool ProjectExplorer::select_item(Node *n, bool deselect_all_first)
bool ProjectExplorer::select_item(oak::Node n, bool deselect_all_first)
{
if (deselect_all_first) {
deselect_all();
+11 -19
View File
@@ -27,7 +27,6 @@
#include <QTimer>
#include <QTreeView>
#include "node/project.h"
#include "projectviewmodel.h"
#include "widget/projectexplorer/projectexplorericonview.h"
#include "widget/projectexplorer/projectexplorerlistview.h"
@@ -55,13 +54,13 @@ public:
const ProjectToolbar::ViewType &view_type() const;
Project *project() const;
void set_project(Project *p);
oak::Project project() const;
void set_project(oak::Project p);
Folder *get_root() const;
void set_root(Folder *item);
oak::Node get_root() const;
void set_root(oak::Node item);
QVector<Node *> selected_items() const;
QVector<oak::Node> selected_items() const;
/**
* @brief Use a heuristic to determine which (if any) folder is selected
@@ -75,7 +74,7 @@ public:
* A folder that's heuristically been determined as "selected", or the root directory if none, or nullptr if no
* project is open.
*/
Folder *get_selected_folder() const;
oak::Node get_selected_folder() const;
/**
* @brief Access the ViewModel model of the project
@@ -88,7 +87,7 @@ public:
void delete_selected();
bool select_item(Node *n, bool deselect_all_first = true);
bool select_item(oak::Node n, bool deselect_all_first = true);
public slots:
void set_view_type(ProjectToolbar::ViewType type);
@@ -112,13 +111,6 @@ signals:
void selection_changed(const QVector<OakEngineNode *> &selected);
private:
/**
* @brief Get all the blocks that solely rely on an input node
*
* Ignores blocks that depend on multiple inputs
*/
QList<Block *> get_footage_blocks(QList<Node *> nodes);
/**
* @brief Simple convenience function for adding a view to this stacked widget
*
@@ -141,13 +133,13 @@ private:
*/
void browse_to_folder(const QModelIndex &index);
int confirm_item_deletion(Node *item);
int confirm_item_deletion(oak::Node item);
bool delete_items_internal(const QVector<Node *> &selected,
bool delete_items_internal(const QVector<oak::Node> &selected,
bool &check_if_item_is_in_use,
void *command);
static QString get_human_readable_node_name(Node *node);
static QString get_human_readable_node_name(const oak::Node &node);
void update_nav_bar_text();
@@ -169,7 +161,7 @@ private:
QSortFilterProxyModel sort_model_;
ProjectViewModel model_;
QVector<Node *> context_menu_items_;
QVector<oak::Node> context_menu_items_;
private slots:
void view_empty_area_double_clicked_slot();
+92 -101
View File
@@ -28,9 +28,6 @@
#include "oakutil/qtutils.h"
#include "core.h"
#include "oakengine/project.h"
#include "oakengine/node.h"
#include "oakengine/undo.h"
namespace olive
{
@@ -47,9 +44,7 @@ void ProjectViewModel::connect_bridge_signals()
{
connect(bridge_, &EngineEventBridge::folder_begin_insert_item, this,
[this](OakEngineNode *folder, OakEngineNode *child, int index) {
this->folder_begin_insert_item(
reinterpret_cast<Folder *>(folder),
reinterpret_cast<Node *>(child), index);
this->folder_begin_insert_item(folder, child, index);
});
connect(bridge_, &EngineEventBridge::folder_end_insert_item, this,
[this](OakEngineNode *) {
@@ -57,9 +52,7 @@ void ProjectViewModel::connect_bridge_signals()
});
connect(bridge_, &EngineEventBridge::folder_begin_remove_item, this,
[this](OakEngineNode *folder, OakEngineNode *child, int index) {
this->folder_begin_remove_item(
reinterpret_cast<Folder *>(folder),
reinterpret_cast<Node *>(child), index);
this->folder_begin_remove_item(folder, child, index);
});
connect(bridge_, &EngineEventBridge::folder_end_remove_item, this,
[this](OakEngineNode *) {
@@ -69,17 +62,17 @@ void ProjectViewModel::connect_bridge_signals()
&ProjectViewModel::item_renamed);
}
Project *ProjectViewModel::project() const
oak::Project ProjectViewModel::project() const
{
return project_;
}
void ProjectViewModel::set_project(Project *p)
void ProjectViewModel::set_project(oak::Project p)
{
beginResetModel();
if (project_) {
disconnect_item(project_->root());
disconnect_item(project_.root());
// Recreate bridge to clear all folder subscriptions
delete bridge_;
bridge_ = new EngineEventBridge(this);
@@ -89,7 +82,7 @@ void ProjectViewModel::set_project(Project *p)
project_ = p;
if (project_) {
connect_item(project_->root());
connect_item(project_.root());
}
endResetModel();
@@ -104,22 +97,22 @@ QModelIndex ProjectViewModel::index(int row, int column,
}
// Get the parent object, we assume it's a folder since only folders can have children
Folder *item_parent = static_cast<Folder *>(get_item_object_from_index(parent));
oak::Node item_parent = get_item_object_from_index(parent);
// Return an index to this object
return createIndex(row, column, item_parent->item_child(row));
return createIndex(row, column, item_parent.item_child(row).handle());
}
QModelIndex ProjectViewModel::parent(const QModelIndex &child) const
{
// Get the Item object from the index
Node *item = get_item_object_from_index(child);
oak::Node item = get_item_object_from_index(child);
// Get Item's parent object
Folder *par = item->folder();
oak::Node par = item.folder();
// If the parent is the root, return an empty index
if (par == project_->root()) {
if (par == project_.root()) {
return QModelIndex();
}
@@ -130,7 +123,7 @@ QModelIndex ProjectViewModel::parent(const QModelIndex &child) const
Q_ASSERT(parent_index > -1);
// Return an index to the parent
return createIndex(parent_index, 0, par);
return createIndex(parent_index, 0, par.handle());
}
int ProjectViewModel::rowCount(const QModelIndex &parent) const
@@ -142,12 +135,11 @@ int ProjectViewModel::rowCount(const QModelIndex &parent) const
// If the index is the root, return the root child count
if (parent == QModelIndex()) {
return project_->root()->item_child_count();
return project_.root().item_child_count();
}
// Otherwise, the index must contain a valid pointer, so we just return its child count
return static_cast<Folder *>(get_item_object_from_index(parent))
->item_child_count();
return get_item_object_from_index(parent).item_child_count();
}
int ProjectViewModel::columnCount(const QModelIndex &parent) const
@@ -164,7 +156,7 @@ int ProjectViewModel::columnCount(const QModelIndex &parent) const
QVariant ProjectViewModel::data(const QModelIndex &index, int role) const
{
Node *internal_item = get_item_object_from_index(index);
oak::Node internal_item = get_item_object_from_index(index);
ColumnType column_type = static_cast<ColumnType>(index.column());
@@ -175,17 +167,15 @@ QVariant ProjectViewModel::data(const QModelIndex &index, int role) const
switch (column_type) {
case k_name:
return internal_item->get_label();
return internal_item.get_label();
case k_duration:
return internal_item->data(Node::duration);
return internal_item.data(1);
case k_rate:
return internal_item->data(Node::frequency_rate);
return internal_item.data(4);
case k_last_modified:
case k_created_time: {
qint64 using_time =
(column_type == k_last_modified) ?
internal_item->data(Node::modified_time).toLongLong() :
internal_item->data(Node::created_time).toLongLong();
const int data_role = (column_type == k_last_modified) ? 3 : 2;
qint64 using_time = internal_item.data(data_role).toLongLong();
if (using_time == 0) {
// 0 is the null value, return nothing
@@ -211,17 +201,17 @@ QVariant ProjectViewModel::data(const QModelIndex &index, int role) const
} break;
case Qt::EditRole:
if (column_type == k_name) {
return internal_item->get_label();
return internal_item.get_label();
}
break;
case Qt::DecorationRole:
// If this is the first column, return the Item's icon
if (column_type == k_name) {
return icon::from_name(internal_item->data(Node::icon).toString());
return icon::from_name(internal_item.data(0).toString());
}
break;
case Qt::ToolTipRole:
return internal_item->data(Node::tooltip);
return internal_item.data(5);
}
return QVariant();
@@ -259,9 +249,7 @@ bool ProjectViewModel::hasChildren(const QModelIndex &parent) const
{
// If it's a folder, we always return TRUE in order to always show the "expand triangle" icon,
// even when there are no "physical" children
Node *item = get_item_object_from_index(parent);
return dynamic_cast<Folder *>(item);
return get_item_object_from_index(parent).is_folder();
}
bool ProjectViewModel::setData(const QModelIndex &index, const QVariant &value,
@@ -269,18 +257,17 @@ bool ProjectViewModel::setData(const QModelIndex &index, const QVariant &value,
{
// The name is editable
if (index.isValid() && index.column() == k_name && role == Qt::EditRole) {
Node *item = get_item_object_from_index(index);
oak::Node item = get_item_object_from_index(index);
QString new_name = value.toString();
if (!new_name.isEmpty()) {
void *nrc = oakengine_node_rename_command(
reinterpret_cast<OakEngineNode *>(item),
new_name.toUtf8().constData());
item.handle(), new_name.toUtf8().constData());
oakengine_undo_push(
nrc,
tr("Renamed Item \"%1\" to \"%2\"").arg(item->get_label(), new_name).toUtf8().constData());
tr("Renamed Item \"%1\" to \"%2\"").arg(item.get_label(), new_name).toUtf8().constData());
return true;
}
@@ -304,7 +291,7 @@ Qt::ItemFlags ProjectViewModel::flags(const QModelIndex &index) const
Qt::ItemFlags f = Qt::ItemIsDragEnabled | QAbstractItemModel::flags(index);
if (dynamic_cast<Folder *>(get_item_object_from_index(index))) {
if (get_item_object_from_index(index).is_folder()) {
f |= Qt::ItemIsDropEnabled;
}
@@ -345,17 +332,20 @@ QMimeData *ProjectViewModel::mimeData(const QModelIndexList &indexes) const
// Check if we've dragged this item before
if (!dragged_items.contains(index.internalPointer())) {
// If not, add it to the stream (and also keep track of it in the vector)
Node *item = static_cast<Node *>(index.internalPointer());
QVector<Track::Reference> streams;
oak::Node item(static_cast<OakEngineNode *>(index.internalPointer()));
if (ViewerOutput *footage =
dynamic_cast<ViewerOutput *>(item)) {
streams = footage->get_enabled_streams_as_references();
// Serialize the enabled streams (type/index pairs) for viewer items
const QVector<QPair<int, int>> streams =
item.is_viewer_output() ? item.enabled_streams()
: QVector<QPair<int, int>>();
stream << streams.size();
for (const QPair<int, int> &s : streams) {
stream << s.first << s.second;
}
stream << reinterpret_cast<quintptr>(item.handle());
stream << streams << reinterpret_cast<quintptr>(item);
dragged_items.append(item);
dragged_items.append(item.handle());
}
}
}
@@ -390,34 +380,38 @@ bool ProjectViewModel::dropMimeData(const QMimeData *data,
QDataStream stream(&model_data, QIODevice::ReadOnly);
// Get the Item object that the items were dropped on
Folder *drop_location =
dynamic_cast<Folder *>(get_item_object_from_index(drop));
oak::Node drop_location = get_item_object_from_index(drop);
// If this is not a folder, we cannot drop these items here
if (!drop_location) {
if (!drop_location.is_folder()) {
return false;
}
// Variables to deserialize into
quintptr item_ptr;
QList<Track::Reference> streams;
// Loop through all data, collecting the items to move
QVector<OakEngineNode *> items_to_move;
while (!stream.atEnd()) {
stream >> streams >> item_ptr;
// Written as qsizetype (8 bytes) by mimeData(); must match
qint64 stream_count = 0;
stream >> stream_count;
for (qint64 si = 0; si < stream_count; si++) {
int st = 0, sidx = 0;
stream >> st >> sidx;
}
Node *item = reinterpret_cast<Node *>(item_ptr);
quintptr item_ptr;
stream >> item_ptr;
oak::Node item(reinterpret_cast<OakEngineNode *>(item_ptr));
// Check if Item is already the drop location or if its parent is the drop location, in which case this is a
// no-op
if (item != drop_location && item->folder() != drop_location &&
(!dynamic_cast<Folder *>(item) ||
!item_is_parent_of_child(static_cast<Folder *>(item),
drop_location))) {
items_to_move.append(reinterpret_cast<OakEngineNode *>(item));
if (item != drop_location &&
item.folder() != drop_location &&
(!item.is_folder() ||
!item_is_parent_of_child(item, drop_location))) {
items_to_move.append(item.handle());
}
}
@@ -426,7 +420,7 @@ bool ProjectViewModel::dropMimeData(const QMimeData *data,
// item from its old folder, then adds it to the drop location)
oakengine_folder_move_children(
items_to_move.constData(), items_to_move.size(),
reinterpret_cast<OakEngineNode *>(drop_location),
drop_location.handle(),
tr("Move %1 Item(s)").arg(items_to_move.size()).toUtf8().constData());
}
@@ -450,11 +444,11 @@ bool ProjectViewModel::dropMimeData(const QMimeData *data,
}
// Get folder dropped onto
Node *drop_item = get_item_object_from_index(drop);
oak::Node drop_item = get_item_object_from_index(drop);
// If we didn't drop onto an item, find the nearest parent folder (should eventually terminate at root either way)
if (!dynamic_cast<Folder *>(drop_item)) {
drop_item = drop_item->folder();
if (!drop_item.is_folder()) {
drop_item = drop_item.folder();
if (!drop_item) {
// Failed to find folder to place this in
@@ -463,7 +457,7 @@ bool ProjectViewModel::dropMimeData(const QMimeData *data,
}
// Trigger an import
Core::instance()->import_files(urls, reinterpret_cast<OakEngineNode *>(drop_item));
Core::instance()->import_files(urls, drop_item.handle());
return true;
}
@@ -471,32 +465,32 @@ bool ProjectViewModel::dropMimeData(const QMimeData *data,
return false;
}
int ProjectViewModel::index_of_child(Node *item) const
int ProjectViewModel::index_of_child(oak::Node item) const
{
// Find parent's index within its own parent
Folder *parent = item->folder();
oak::Node parent = item.folder();
if (parent) {
return parent->index_of_child(item);
return parent.index_of_child(item);
}
return -1;
}
Node *ProjectViewModel::get_item_object_from_index(const QModelIndex &index) const
oak::Node ProjectViewModel::get_item_object_from_index(const QModelIndex &index) const
{
if (index.isValid()) {
return static_cast<Node *>(index.internalPointer());
return oak::Node(static_cast<OakEngineNode *>(index.internalPointer()));
}
return project_ ? project_->root() : nullptr;
return project_ ? project_.root() : oak::Node();
}
bool ProjectViewModel::item_is_parent_of_child(Folder *parent, Node *child) const
bool ProjectViewModel::item_is_parent_of_child(oak::Node parent, oak::Node child) const
{
// Loop through parent hierarchy checking if `parent` is one of its parents
do {
child = child->folder();
child = child.folder();
if (parent == child) {
return true;
@@ -506,49 +500,48 @@ bool ProjectViewModel::item_is_parent_of_child(Folder *parent, Node *child) cons
return false;
}
void ProjectViewModel::connect_item(Node *n)
void ProjectViewModel::connect_item(oak::Node n)
{
label_changed_subs_[n] = bridge_->subscribe(
reinterpret_cast<void *>(n), OAKENGINE_EVENT_NODE_LABEL_CHANGED);
n.handle(), OAKENGINE_EVENT_NODE_LABEL_CHANGED);
Folder *f = dynamic_cast<Folder *>(n);
if (f) {
OakEngineNode *handle = reinterpret_cast<OakEngineNode *>(f);
bridge_->subscribe(handle, OAKENGINE_EVENT_FOLDER_BEGIN_INSERT_ITEM);
bridge_->subscribe(handle, OAKENGINE_EVENT_FOLDER_END_INSERT_ITEM);
bridge_->subscribe(handle, OAKENGINE_EVENT_FOLDER_BEGIN_REMOVE_ITEM);
bridge_->subscribe(handle, OAKENGINE_EVENT_FOLDER_END_REMOVE_ITEM);
if (n.is_folder()) {
bridge_->subscribe(n.handle(), OAKENGINE_EVENT_FOLDER_BEGIN_INSERT_ITEM);
bridge_->subscribe(n.handle(), OAKENGINE_EVENT_FOLDER_END_INSERT_ITEM);
bridge_->subscribe(n.handle(), OAKENGINE_EVENT_FOLDER_BEGIN_REMOVE_ITEM);
bridge_->subscribe(n.handle(), OAKENGINE_EVENT_FOLDER_END_REMOVE_ITEM);
foreach (Node *c, f->children()) {
connect_item(c);
const int count = n.item_child_count();
for (int i = 0; i < count; i++) {
connect_item(n.item_child(i));
}
}
}
void ProjectViewModel::disconnect_item(Node *n)
void ProjectViewModel::disconnect_item(oak::Node n)
{
int64_t sub = label_changed_subs_.take(n);
if (sub > 0) {
bridge_->unsubscribe(sub);
}
Folder *f = dynamic_cast<Folder *>(n);
if (f) {
if (n.is_folder()) {
// Bridge subscriptions are cleaned up by recreating the bridge in set_project
foreach (Node *c, f->children()) {
disconnect_item(c);
const int count = n.item_child_count();
for (int i = 0; i < count; i++) {
disconnect_item(n.item_child(i));
}
}
}
void ProjectViewModel::folder_begin_insert_item(Folder *folder, Node *n,
void ProjectViewModel::folder_begin_insert_item(oak::Node folder, oak::Node n,
int insert_index)
{
connect_item(n);
QModelIndex index;
if (folder != project_->root()) {
if (folder != project_.root()) {
index = create_index_from_item(folder);
}
@@ -560,14 +553,14 @@ void ProjectViewModel::folder_end_insert_item()
endInsertRows();
}
void ProjectViewModel::folder_begin_remove_item(Folder *folder, Node *n,
void ProjectViewModel::folder_begin_remove_item(oak::Node folder, oak::Node n,
int child_index)
{
disconnect_item(n);
QModelIndex index;
if (folder != project_->root()) {
if (folder != project_.root()) {
index = create_index_from_item(folder);
}
@@ -581,16 +574,14 @@ void ProjectViewModel::folder_end_remove_item()
void ProjectViewModel::item_renamed(OakEngineNode *source)
{
Node *item = reinterpret_cast<Node *>(source);
QModelIndex index = create_index_from_item(item);
QModelIndex index = create_index_from_item(oak::Node(source));
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
}
QModelIndex ProjectViewModel::create_index_from_item(Node *item, int column)
QModelIndex ProjectViewModel::create_index_from_item(oak::Node item, int column)
{
return createIndex(index_of_child(item), column, item);
return createIndex(index_of_child(item), column, item.handle());
}
}
+18 -16
View File
@@ -26,8 +26,7 @@
#include <QHash>
#include "engineeventbridge.h"
#include "node/block/block.h"
#include "node/project.h"
#include "oakutil/oaknode.h"
namespace olive
{
@@ -39,6 +38,9 @@ namespace olive
* a ProjectViewModel), it may be better to make modifications (e.g. additions/removals/renames) through the
* ProjectViewModel so that the views can be efficiently and correctly updated. ProjectViewModel contains several
* "wrapper" functions for Project and Item functions that also signal any connected views to update accordingly.
*
* Engine access goes through the oak:: C++ wrapper layer (oakutil/oaknode.h),
* which re-wraps the engine's pure C ABI into object form.
*/
class ProjectViewModel : public QAbstractItemModel {
Q_OBJECT
@@ -78,9 +80,9 @@ public:
*
* @return
*
* Currently active project or nullptr if there is none
* Currently active project or a null handle if there is none
*/
Project *project() const;
oak::Project project() const;
/**
* @brief Set the project to adapt
@@ -89,9 +91,9 @@ public:
*
* @param p
*
* Project to adapt, can be set to nullptr to "close" the project (will show an empty model that cannot be modified)
* Project to adapt, can be set to null to "close" the project (will show an empty model that cannot be modified)
*/
void set_project(Project *p);
void set_project(oak::Project p);
/** Compulsory Qt QAbstractItemModel overrides */
virtual QModelIndex
@@ -125,7 +127,7 @@ public:
/**
* @brief Convenience function for creating QModelIndexes from an Item object
*/
QModelIndex create_index_from_item(Node *item, int column = 0);
QModelIndex create_index_from_item(oak::Node item, int column = 0);
private:
/**
@@ -138,25 +140,25 @@ private:
*
* Index of the specified item, or -1 if the item is root (in which case it has no parent).
*/
int index_of_child(Node *item) const;
int index_of_child(oak::Node item) const;
/**
* @brief Retrieves the Item object from a given index
*
* A convenience function for retrieving Item objects. If the index is not valid, this returns the root Item.
*/
Node *get_item_object_from_index(const QModelIndex &index) const;
oak::Node get_item_object_from_index(const QModelIndex &index) const;
/**
* @brief Check if an Item is a parent of a Child
*
* Checks entire "parent hierarchy" of `child` to see if `parent` is one of its parents.
*/
bool item_is_parent_of_child(Folder *parent, Node *child) const;
bool item_is_parent_of_child(oak::Node parent, oak::Node child) const;
void connect_item(Node *n);
void connect_item(oak::Node n);
void disconnect_item(Node *n);
void disconnect_item(oak::Node n);
/**
* @brief Wire the bridge's folder signals to our handlers.
@@ -166,19 +168,19 @@ private:
*/
void connect_bridge_signals();
void folder_begin_insert_item(Folder *folder, Node *n, int insert_index);
void folder_begin_insert_item(oak::Node folder, oak::Node n, int insert_index);
void folder_end_insert_item();
void folder_begin_remove_item(Folder *folder, Node *n, int child_index);
void folder_begin_remove_item(oak::Node folder, oak::Node n, int child_index);
void folder_end_remove_item();
Project *project_;
oak::Project project_;
EngineEventBridge *bridge_;
QHash<Node *, int64_t> label_changed_subs_;
QHash<oak::Node, int64_t> label_changed_subs_;
private slots:
void item_renamed(OakEngineNode *source);