project: remove constant root node
This commit is contained in:
+3
-1
@@ -293,7 +293,9 @@ void Core::CreateNewProject()
|
||||
{
|
||||
// If we already have an empty/new project, switch to it
|
||||
if (CloseProject(false)) {
|
||||
AddOpenProject(new Project());
|
||||
Project *p = new Project();
|
||||
p->Initialize();
|
||||
AddOpenProject(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+25
-20
@@ -42,22 +42,19 @@ const QString Project::kCachePathKey = QStringLiteral("customcachepath");
|
||||
const QString Project::kColorConfigFilename = QStringLiteral("colorconfigfilename");
|
||||
const QString Project::kDefaultInputColorSpaceKey = QStringLiteral("defaultinputcolorspace");
|
||||
const QString Project::kColorReferenceSpace = QStringLiteral("colorreferencespace");
|
||||
const QString Project::kRootKey = QStringLiteral("root");
|
||||
|
||||
const QString Project::kItemMimeType = QStringLiteral("application/x-oliveprojectitemdata");
|
||||
|
||||
Project::Project() :
|
||||
root_(nullptr),
|
||||
is_modified_(false),
|
||||
autorecovery_saved_(true)
|
||||
{
|
||||
// Generate UUID for this project
|
||||
RegenerateUuid();
|
||||
|
||||
// Folder root for project
|
||||
root_ = new Folder();
|
||||
root_->setParent(this);
|
||||
root_->SetLabel(tr("Root"));
|
||||
AddDefaultNode(root_);
|
||||
|
||||
// Initialize color manager
|
||||
color_manager_ = new ColorManager(this);
|
||||
color_manager_->Init();
|
||||
}
|
||||
@@ -67,6 +64,16 @@ Project::~Project()
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Project::Initialize()
|
||||
{
|
||||
if (!root_) {
|
||||
root_ = new Folder();
|
||||
root_->setParent(this);
|
||||
root_->SetLabel(tr("Root"));
|
||||
settings_.insert(kRootKey, QString::number(reinterpret_cast<quintptr>(root_)));
|
||||
}
|
||||
}
|
||||
|
||||
void Project::Clear()
|
||||
{
|
||||
// By deleting the last nodes first, we assume that nodes that are most important are deleted last
|
||||
@@ -93,15 +100,12 @@ SerializedData Project::Load(QXmlStreamReader *reader)
|
||||
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (reader->name() == QStringLiteral("node")) {
|
||||
bool is_root = false;
|
||||
QString id;
|
||||
|
||||
{
|
||||
XMLAttributeLoop(reader, attr) {
|
||||
if (attr.name() == QStringLiteral("id")) {
|
||||
id = attr.value().toString();
|
||||
} else if (attr.name() == QStringLiteral("root") && attr.value() == QStringLiteral("1")) {
|
||||
is_root = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,13 +114,7 @@ SerializedData Project::Load(QXmlStreamReader *reader)
|
||||
qWarning() << "Failed to load node with empty ID";
|
||||
reader->skipCurrentElement();
|
||||
} else {
|
||||
Node* node;
|
||||
|
||||
if (is_root) {
|
||||
node = this->root();
|
||||
} else {
|
||||
node = NodeFactory::CreateFromID(id);
|
||||
}
|
||||
Node* node = NodeFactory::CreateFromID(id);
|
||||
|
||||
if (!node) {
|
||||
qWarning() << "Failed to find node with ID" << id;
|
||||
@@ -149,6 +147,17 @@ SerializedData Project::Load(QXmlStreamReader *reader)
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve root if applicable
|
||||
QString root = GetSetting(kRootKey);
|
||||
if (!root.isEmpty()) {
|
||||
quintptr r = root.toULongLong();
|
||||
if (Node *n = data.node_ptrs.value(r)) {
|
||||
Q_ASSERT(!root_);
|
||||
root_ = dynamic_cast<Folder*>(n);
|
||||
SetSetting(kRootKey, QString::number(reinterpret_cast<quintptr>(root_)));
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -164,10 +173,6 @@ void Project::Save(QXmlStreamWriter *writer) const
|
||||
foreach (Node* node, this->nodes()) {
|
||||
writer->writeStartElement(QStringLiteral("node"));
|
||||
|
||||
if (node == this->root()) {
|
||||
writer->writeAttribute(QStringLiteral("root"), QStringLiteral("1"));
|
||||
}
|
||||
|
||||
node->Save(writer);
|
||||
|
||||
writer->writeEndElement(); // node
|
||||
|
||||
+2
-11
@@ -70,10 +70,7 @@ public:
|
||||
return node_children_;
|
||||
}
|
||||
|
||||
const QVector<Node*>& default_nodes() const
|
||||
{
|
||||
return default_nodes_;
|
||||
}
|
||||
void Initialize();
|
||||
|
||||
SerializedData Load(QXmlStreamReader *reader);
|
||||
void Save(QXmlStreamWriter *writer) const;
|
||||
@@ -144,6 +141,7 @@ public:
|
||||
static const QString kColorConfigFilename;
|
||||
static const QString kColorReferenceSpace;
|
||||
static const QString kDefaultInputColorSpaceKey;
|
||||
static const QString kRootKey;
|
||||
|
||||
QString GetSetting(const QString &key) const { return settings_.value(key); }
|
||||
void SetSetting(const QString &key, const QString &value);
|
||||
@@ -195,11 +193,6 @@ signals:
|
||||
void SettingChanged(const QString &key, const QString &value);
|
||||
|
||||
protected:
|
||||
void AddDefaultNode(Node* n)
|
||||
{
|
||||
default_nodes_.append(n);
|
||||
}
|
||||
|
||||
virtual void childEvent(QChildEvent* event) override;
|
||||
|
||||
private:
|
||||
@@ -219,8 +212,6 @@ private:
|
||||
|
||||
QVector<Node*> node_children_;
|
||||
|
||||
QVector<Node*> default_nodes_;
|
||||
|
||||
QMap<QString, QString> settings_;
|
||||
|
||||
};
|
||||
|
||||
@@ -66,6 +66,7 @@ ProjectSerializer210528::LoadData ProjectSerializer210528::Load(Project *project
|
||||
bool handled_elsewhere = false;
|
||||
|
||||
if (is_root) {
|
||||
project->Initialize();
|
||||
node = project->root();
|
||||
} else if (is_cm) {
|
||||
LoadColorManager(reader, project);
|
||||
|
||||
@@ -66,6 +66,7 @@ ProjectSerializer210907::LoadData ProjectSerializer210907::Load(Project *project
|
||||
bool handled_elsewhere = false;
|
||||
|
||||
if (is_root) {
|
||||
project->Initialize();
|
||||
node = project->root();
|
||||
} else if (is_cm) {
|
||||
LoadColorManager(reader, project);
|
||||
|
||||
@@ -68,6 +68,7 @@ ProjectSerializer211228::LoadData ProjectSerializer211228::Load(Project *project
|
||||
bool handled_elsewhere = false;
|
||||
|
||||
if (is_root) {
|
||||
project->Initialize();
|
||||
node = project->root();
|
||||
} else if (is_cm) {
|
||||
LoadColorManager(reader, project);
|
||||
|
||||
@@ -87,6 +87,7 @@ ProjectSerializer220403::LoadData ProjectSerializer220403::Load(Project *project
|
||||
bool handled_elsewhere = false;
|
||||
|
||||
if (is_root) {
|
||||
project->Initialize();
|
||||
node = project->root();
|
||||
} else if (is_cm) {
|
||||
LoadColorManager(reader, project);
|
||||
|
||||
@@ -67,6 +67,7 @@ bool LoadOTIOTask::Run()
|
||||
}
|
||||
|
||||
project_ = new Project();
|
||||
project_->Initialize();
|
||||
project_->set_modified(true);
|
||||
|
||||
std::vector<OTIO::Timeline*> timelines;
|
||||
|
||||
Reference in New Issue
Block a user