change: change code style to Linux style except indent.
This commit is contained in:
@@ -26,7 +26,8 @@
|
||||
#include "node/project/sequence/sequence.h"
|
||||
#include "ui/icons/icons.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super Node
|
||||
|
||||
@@ -34,143 +35,152 @@ const QString Folder::kChildInput = QStringLiteral("child_in");
|
||||
|
||||
Folder::Folder()
|
||||
{
|
||||
SetFlag(kIsItem);
|
||||
SetFlag(kIsItem);
|
||||
|
||||
AddInput(kChildInput, NodeValue::kNone, InputFlags(kInputFlagArray | kInputFlagNotKeyframable));
|
||||
AddInput(kChildInput, NodeValue::kNone,
|
||||
InputFlags(kInputFlagArray | kInputFlagNotKeyframable));
|
||||
}
|
||||
|
||||
QVariant Folder::data(const DataType &d) const
|
||||
{
|
||||
if (d == ICON) {
|
||||
return icon::Folder;
|
||||
}
|
||||
if (d == ICON) {
|
||||
return icon::Folder;
|
||||
}
|
||||
|
||||
return super::data(d);
|
||||
return super::data(d);
|
||||
}
|
||||
|
||||
void Folder::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kChildInput, tr("Children"));
|
||||
SetInputName(kChildInput, tr("Children"));
|
||||
}
|
||||
|
||||
Node *GetChildWithNameInternal(const Folder* n, const QString& s)
|
||||
Node *GetChildWithNameInternal(const Folder *n, const QString &s)
|
||||
{
|
||||
for (int i=0; i<n->item_child_count(); i++) {
|
||||
Node* child = n->item_child(i);
|
||||
for (int i = 0; i < n->item_child_count(); i++) {
|
||||
Node *child = n->item_child(i);
|
||||
|
||||
if (child->GetLabel() == s) {
|
||||
return child;
|
||||
} else if (Folder* subfolder = dynamic_cast<Folder*>(child)) {
|
||||
if (Node *n2 = GetChildWithNameInternal(subfolder, s)) {
|
||||
return n2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (child->GetLabel() == s) {
|
||||
return child;
|
||||
} else if (Folder *subfolder = dynamic_cast<Folder *>(child)) {
|
||||
if (Node *n2 = GetChildWithNameInternal(subfolder, s)) {
|
||||
return n2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Node *Folder::GetChildWithName(const QString &s) const
|
||||
{
|
||||
return GetChildWithNameInternal(this, s);
|
||||
return GetChildWithNameInternal(this, s);
|
||||
}
|
||||
|
||||
bool Folder::HasChildRecursive(Node *child) const
|
||||
{
|
||||
for (Node *i : item_children_) {
|
||||
if (i == child) {
|
||||
return true;
|
||||
} else if (Folder *f = dynamic_cast<Folder*>(i)) {
|
||||
if (f->HasChildRecursive(child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Node *i : item_children_) {
|
||||
if (i == child) {
|
||||
return true;
|
||||
} else if (Folder *f = dynamic_cast<Folder *>(i)) {
|
||||
if (f->HasChildRecursive(child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
int Folder::index_of_child_in_array(Node *item) const
|
||||
{
|
||||
int index_of_item = item_children_.indexOf(item);
|
||||
int index_of_item = item_children_.indexOf(item);
|
||||
|
||||
if (index_of_item == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (index_of_item == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return item_element_index_.at(index_of_item);
|
||||
return item_element_index_.at(index_of_item);
|
||||
}
|
||||
|
||||
void Folder::InputConnectedEvent(const QString &input, int element, Node *output)
|
||||
void Folder::InputConnectedEvent(const QString &input, int element,
|
||||
Node *output)
|
||||
{
|
||||
if (input == kChildInput && element != -1) {
|
||||
Node* item = output;
|
||||
if (input == kChildInput && element != -1) {
|
||||
Node *item = output;
|
||||
|
||||
// The insert index is always our "count" because we only support appending in our internal
|
||||
// model. For sorting/organizing, a QSortFilterProxyModel is used instead.
|
||||
emit BeginInsertItem(item, item_child_count());
|
||||
item_children_.append(item);
|
||||
item_element_index_.append(element);
|
||||
item->SetFolder(this);
|
||||
emit EndInsertItem();
|
||||
}
|
||||
// The insert index is always our "count" because we only support appending in our internal
|
||||
// model. For sorting/organizing, a QSortFilterProxyModel is used instead.
|
||||
emit BeginInsertItem(item, item_child_count());
|
||||
item_children_.append(item);
|
||||
item_element_index_.append(element);
|
||||
item->SetFolder(this);
|
||||
emit EndInsertItem();
|
||||
}
|
||||
}
|
||||
|
||||
void Folder::InputDisconnectedEvent(const QString &input, int element, Node *output)
|
||||
void Folder::InputDisconnectedEvent(const QString &input, int element,
|
||||
Node *output)
|
||||
{
|
||||
if (input == kChildInput && element != -1) {
|
||||
Node* item = output;
|
||||
if (input == kChildInput && element != -1) {
|
||||
Node *item = output;
|
||||
|
||||
int child_index = item_children_.indexOf(item);
|
||||
emit BeginRemoveItem(item, child_index);
|
||||
item_children_.removeAt(child_index);
|
||||
item_element_index_.removeAt(child_index);
|
||||
item->SetFolder(nullptr);
|
||||
emit EndRemoveItem();
|
||||
}
|
||||
int child_index = item_children_.indexOf(item);
|
||||
emit BeginRemoveItem(item, child_index);
|
||||
item_children_.removeAt(child_index);
|
||||
item_element_index_.removeAt(child_index);
|
||||
item->SetFolder(nullptr);
|
||||
emit EndRemoveItem();
|
||||
}
|
||||
}
|
||||
|
||||
FolderAddChild::FolderAddChild(Folder *folder, Node *child) :
|
||||
folder_(folder),
|
||||
child_(child)
|
||||
FolderAddChild::FolderAddChild(Folder *folder, Node *child)
|
||||
: folder_(folder)
|
||||
, child_(child)
|
||||
{
|
||||
}
|
||||
|
||||
Project *FolderAddChild::GetRelevantProject() const
|
||||
{
|
||||
return folder_->project();
|
||||
return folder_->project();
|
||||
}
|
||||
|
||||
void FolderAddChild::redo()
|
||||
{
|
||||
int array_index = folder_->InputArraySize(Folder::kChildInput);
|
||||
folder_->InputArrayAppend(Folder::kChildInput);
|
||||
Node::ConnectEdge(child_, NodeInput(folder_, Folder::kChildInput, array_index));
|
||||
int array_index = folder_->InputArraySize(Folder::kChildInput);
|
||||
folder_->InputArrayAppend(Folder::kChildInput);
|
||||
Node::ConnectEdge(child_,
|
||||
NodeInput(folder_, Folder::kChildInput, array_index));
|
||||
}
|
||||
|
||||
void FolderAddChild::undo()
|
||||
{
|
||||
Node::DisconnectEdge(child_, NodeInput(folder_, Folder::kChildInput, folder_->InputArraySize(Folder::kChildInput)-1));
|
||||
folder_->InputArrayRemoveLast(Folder::kChildInput);
|
||||
Node::DisconnectEdge(
|
||||
child_, NodeInput(folder_, Folder::kChildInput,
|
||||
folder_->InputArraySize(Folder::kChildInput) - 1));
|
||||
folder_->InputArrayRemoveLast(Folder::kChildInput);
|
||||
}
|
||||
|
||||
void Folder::RemoveElementCommand::redo()
|
||||
{
|
||||
if (!subcommand_) {
|
||||
remove_index_ = folder_->index_of_child_in_array(child_);
|
||||
if (remove_index_ != -1) {
|
||||
NodeInput connected_input(folder_, Folder::kChildInput, remove_index_);
|
||||
subcommand_ = new MultiUndoCommand();
|
||||
subcommand_->add_child(new NodeEdgeRemoveCommand(folder_->GetConnectedOutput(connected_input), connected_input));
|
||||
subcommand_->add_child(new NodeArrayRemoveCommand(folder_, Folder::kChildInput, remove_index_));
|
||||
}
|
||||
}
|
||||
if (!subcommand_) {
|
||||
remove_index_ = folder_->index_of_child_in_array(child_);
|
||||
if (remove_index_ != -1) {
|
||||
NodeInput connected_input(folder_, Folder::kChildInput,
|
||||
remove_index_);
|
||||
subcommand_ = new MultiUndoCommand();
|
||||
subcommand_->add_child(new NodeEdgeRemoveCommand(
|
||||
folder_->GetConnectedOutput(connected_input), connected_input));
|
||||
subcommand_->add_child(new NodeArrayRemoveCommand(
|
||||
folder_, Folder::kChildInput, remove_index_));
|
||||
}
|
||||
}
|
||||
|
||||
if (subcommand_) {
|
||||
subcommand_->redo_now();
|
||||
}
|
||||
if (subcommand_) {
|
||||
subcommand_->redo_now();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+131
-134
@@ -23,7 +23,8 @@
|
||||
|
||||
#include "node/node.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The Folder class representing a directory in a project structure
|
||||
@@ -31,193 +32,189 @@ namespace olive {
|
||||
* The Item base class already has support for children, but this functionality is disabled by default
|
||||
* (see CanHaveChildren() override). The Folder is a specific type that enables this functionality.
|
||||
*/
|
||||
class Folder : public Node
|
||||
{
|
||||
Q_OBJECT
|
||||
class Folder : public Node {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Folder();
|
||||
Folder();
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(Folder)
|
||||
NODE_DEFAULT_FUNCTIONS(Folder)
|
||||
|
||||
virtual QString Name() const override
|
||||
{
|
||||
return tr("Folder");
|
||||
}
|
||||
virtual QString Name() const override
|
||||
{
|
||||
return tr("Folder");
|
||||
}
|
||||
|
||||
virtual QString id() const override
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.folder");
|
||||
}
|
||||
virtual QString id() const override
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.folder");
|
||||
}
|
||||
|
||||
virtual QVector<CategoryID> Category() const override
|
||||
{
|
||||
return {kCategoryProject};
|
||||
}
|
||||
virtual QVector<CategoryID> Category() const override
|
||||
{
|
||||
return { kCategoryProject };
|
||||
}
|
||||
|
||||
virtual QString Description() const override
|
||||
{
|
||||
return tr("Organize several items into a single collection.");
|
||||
}
|
||||
virtual QString Description() const override
|
||||
{
|
||||
return tr("Organize several items into a single collection.");
|
||||
}
|
||||
|
||||
virtual QVariant data(const DataType &d) const override;
|
||||
virtual QVariant data(const DataType &d) const override;
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
Node *GetChildWithName(const QString& s) const;
|
||||
bool ChildExistsWithName(const QString& s) const
|
||||
{
|
||||
return GetChildWithName(s);
|
||||
}
|
||||
Node *GetChildWithName(const QString &s) const;
|
||||
bool ChildExistsWithName(const QString &s) const
|
||||
{
|
||||
return GetChildWithName(s);
|
||||
}
|
||||
|
||||
bool HasChildRecursive(Node *child) const;
|
||||
bool HasChildRecursive(Node *child) const;
|
||||
|
||||
int item_child_count() const
|
||||
{
|
||||
return item_children_.size();
|
||||
}
|
||||
int item_child_count() const
|
||||
{
|
||||
return item_children_.size();
|
||||
}
|
||||
|
||||
Node* item_child(int i) const
|
||||
{
|
||||
return item_children_.at(i);
|
||||
}
|
||||
Node *item_child(int i) const
|
||||
{
|
||||
return item_children_.at(i);
|
||||
}
|
||||
|
||||
const QVector<Node*>& children() const
|
||||
{
|
||||
return item_children_;
|
||||
}
|
||||
const QVector<Node *> &children() const
|
||||
{
|
||||
return item_children_;
|
||||
}
|
||||
|
||||
int index_of_child(Node* item) const
|
||||
{
|
||||
return item_children_.indexOf(item);
|
||||
}
|
||||
int index_of_child(Node *item) const
|
||||
{
|
||||
return item_children_.indexOf(item);
|
||||
}
|
||||
|
||||
int index_of_child_in_array(Node* item) const;
|
||||
int index_of_child_in_array(Node *item) const;
|
||||
|
||||
template <typename T>
|
||||
QVector<T*> ListChildrenOfType() const
|
||||
{
|
||||
QVector<T*> list;
|
||||
template <typename T> QVector<T *> ListChildrenOfType() const
|
||||
{
|
||||
QVector<T *> list;
|
||||
|
||||
foreach (Node* node, item_children_) {
|
||||
T* cast_test = dynamic_cast<T*>(node);
|
||||
if (cast_test) {
|
||||
list.append(cast_test);
|
||||
}
|
||||
foreach (Node *node, item_children_) {
|
||||
T *cast_test = dynamic_cast<T *>(node);
|
||||
if (cast_test) {
|
||||
list.append(cast_test);
|
||||
}
|
||||
|
||||
Folder *folder_test = dynamic_cast<Folder*>(node);
|
||||
if (folder_test) {
|
||||
list.append(folder_test->ListChildrenOfType<T>());
|
||||
}
|
||||
}
|
||||
Folder *folder_test = dynamic_cast<Folder *>(node);
|
||||
if (folder_test) {
|
||||
list.append(folder_test->ListChildrenOfType<T>());
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static const QString kChildInput;
|
||||
static const QString kChildInput;
|
||||
|
||||
class RemoveElementCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
RemoveElementCommand(Folder *folder, Node *child) :
|
||||
folder_(folder),
|
||||
child_(child),
|
||||
subcommand_(nullptr)
|
||||
{
|
||||
}
|
||||
class RemoveElementCommand : public UndoCommand {
|
||||
public:
|
||||
RemoveElementCommand(Folder *folder, Node *child)
|
||||
: folder_(folder)
|
||||
, child_(child)
|
||||
, subcommand_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~RemoveElementCommand() override
|
||||
{
|
||||
delete subcommand_;
|
||||
}
|
||||
virtual ~RemoveElementCommand() override
|
||||
{
|
||||
delete subcommand_;
|
||||
}
|
||||
|
||||
virtual Project *GetRelevantProject() const override
|
||||
{
|
||||
return folder_->project();
|
||||
}
|
||||
virtual Project *GetRelevantProject() const override
|
||||
{
|
||||
return folder_->project();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void redo() override;
|
||||
protected:
|
||||
virtual void redo() override;
|
||||
|
||||
virtual void undo() override
|
||||
{
|
||||
if (subcommand_) {
|
||||
subcommand_->undo_now();
|
||||
}
|
||||
}
|
||||
virtual void undo() override
|
||||
{
|
||||
if (subcommand_) {
|
||||
subcommand_->undo_now();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Folder *folder_;
|
||||
private:
|
||||
Folder *folder_;
|
||||
|
||||
Node *child_;
|
||||
Node *child_;
|
||||
|
||||
int remove_index_;
|
||||
int remove_index_;
|
||||
|
||||
MultiUndoCommand *subcommand_;
|
||||
|
||||
};
|
||||
MultiUndoCommand *subcommand_;
|
||||
};
|
||||
|
||||
signals:
|
||||
void BeginInsertItem(Node* n, int index);
|
||||
void BeginInsertItem(Node *n, int index);
|
||||
|
||||
void EndInsertItem();
|
||||
void EndInsertItem();
|
||||
|
||||
void BeginRemoveItem(Node* n, int index);
|
||||
void BeginRemoveItem(Node *n, int index);
|
||||
|
||||
void EndRemoveItem();
|
||||
void EndRemoveItem();
|
||||
|
||||
protected:
|
||||
virtual void InputConnectedEvent(const QString& input, int element, Node *output) override;
|
||||
virtual void InputConnectedEvent(const QString &input, int element,
|
||||
Node *output) override;
|
||||
|
||||
virtual void InputDisconnectedEvent(const QString& input, int element, Node *output) override;
|
||||
virtual void InputDisconnectedEvent(const QString &input, int element,
|
||||
Node *output) override;
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
static void ListOutputsOfTypeInternal(const Folder* n, QVector<T*>& list, bool recursive)
|
||||
{
|
||||
foreach (const Node::OutputConnection& c, n->output_connections()) {
|
||||
Node* connected = c.second.node();
|
||||
template <typename T>
|
||||
static void ListOutputsOfTypeInternal(const Folder *n, QVector<T *> &list,
|
||||
bool recursive)
|
||||
{
|
||||
foreach (const Node::OutputConnection &c, n->output_connections()) {
|
||||
Node *connected = c.second.node();
|
||||
|
||||
T* cast_test = dynamic_cast<T*>(connected);
|
||||
T *cast_test = dynamic_cast<T *>(connected);
|
||||
|
||||
if (cast_test) {
|
||||
// Avoid duplicates
|
||||
if (!list.contains(cast_test)) {
|
||||
list.append(cast_test);
|
||||
}
|
||||
}
|
||||
if (cast_test) {
|
||||
// Avoid duplicates
|
||||
if (!list.contains(cast_test)) {
|
||||
list.append(cast_test);
|
||||
}
|
||||
}
|
||||
|
||||
if (recursive) {
|
||||
Folder* subfolder = dynamic_cast<Folder*>(connected);
|
||||
if (recursive) {
|
||||
Folder *subfolder = dynamic_cast<Folder *>(connected);
|
||||
|
||||
if (subfolder) {
|
||||
ListOutputsOfTypeInternal(subfolder, list, recursive);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVector<Node*> item_children_;
|
||||
QVector<int> item_element_index_;
|
||||
if (subfolder) {
|
||||
ListOutputsOfTypeInternal(subfolder, list, recursive);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVector<Node *> item_children_;
|
||||
QVector<int> item_element_index_;
|
||||
};
|
||||
|
||||
class FolderAddChild : public UndoCommand
|
||||
{
|
||||
class FolderAddChild : public UndoCommand {
|
||||
public:
|
||||
FolderAddChild(Folder* folder, Node* child);
|
||||
FolderAddChild(Folder *folder, Node *child);
|
||||
|
||||
virtual Project * GetRelevantProject() const override;
|
||||
virtual Project *GetRelevantProject() const override;
|
||||
|
||||
protected:
|
||||
virtual void redo() override;
|
||||
virtual void redo() override;
|
||||
|
||||
virtual void undo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
Folder* folder_;
|
||||
|
||||
Node* child_;
|
||||
Folder *folder_;
|
||||
|
||||
Node *child_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user