various: implemented multiple project support

This required various changes to various parts of the infrastructure (mostly
using paths to finding the "root project" of any given object throughout).
Now theoretically infinite projects can be opened and accounted for at any
given time.
This commit is contained in:
itsmattkc
2020-04-18 01:50:47 +10:00
parent 77c0db55a5
commit f73c41d3fa
48 changed files with 824 additions and 224 deletions
+1 -1
View File
@@ -132,7 +132,7 @@ const Item *Item::root() const
{
const Item* item = this;
while (item->parent() != nullptr) {
while (item->parent()) {
item = item->parent();
}
+31 -1
View File
@@ -30,7 +30,9 @@
OLIVE_NAMESPACE_ENTER
Project::Project()
Project::Project() :
is_modified_(false),
autorecovery_saved_(true)
{
root_.set_project(this);
}
@@ -156,4 +158,32 @@ QList<ItemPtr> Project::get_items_of_type(Item::Type type) const
return root_.get_children_of_type(type, true);
}
bool Project::is_modified() const
{
return is_modified_;
}
void Project::set_modified(bool e)
{
is_modified_ = e;
autorecovery_saved_ = !e;
emit ModifiedChanged(is_modified_);
}
bool Project::has_autorecovery_been_saved() const
{
return autorecovery_saved_;
}
void Project::set_autorecovery_saved(bool e)
{
autorecovery_saved_ = e;
}
bool Project::is_new() const
{
return !is_modified_ && filename_.isEmpty();
}
OLIVE_NAMESPACE_EXIT
+14
View File
@@ -68,9 +68,19 @@ public:
QList<ItemPtr> get_items_of_type(Item::Type type) const;
bool is_modified() const;
void set_modified(bool e);
bool has_autorecovery_been_saved() const;
void set_autorecovery_saved(bool e);
bool is_new() const;
signals:
void NameChanged();
void ModifiedChanged(bool e);
private:
Folder root_;
@@ -80,6 +90,10 @@ private:
ColorManager color_manager_;
bool is_modified_;
bool autorecovery_saved_;
};
using ProjectPtr = std::shared_ptr<Project>;
+1
View File
@@ -55,6 +55,7 @@ void ProjectSaveManager::Action()
}
emit Succeeded();
emit ProjectSaveSucceeded(project_);
}
OLIVE_NAMESPACE_EXIT
+3
View File
@@ -32,6 +32,9 @@ class ProjectSaveManager : public Task
public:
ProjectSaveManager(Project* project);
signals:
void ProjectSaveSucceeded(Project* p);
protected:
virtual void Action() override;
+20
View File
@@ -511,6 +511,11 @@ ProjectViewModel::MoveItemCommand::MoveItemCommand(ProjectViewModel *model,
setText(tr("Move Item"));
}
Project *ProjectViewModel::MoveItemCommand::GetRelevantProject() const
{
return model_->project();
}
void ProjectViewModel::MoveItemCommand::redo_internal()
{
model_->MoveItemInternal(item_, destination_);
@@ -532,6 +537,11 @@ ProjectViewModel::RenameItemCommand::RenameItemCommand(ProjectViewModel* model,
setText(tr("Rename Item"));
}
Project *ProjectViewModel::RenameItemCommand::GetRelevantProject() const
{
return model_->project();
}
void ProjectViewModel::RenameItemCommand::redo_internal()
{
model_->RenameChild(item_, new_name_);
@@ -551,6 +561,11 @@ ProjectViewModel::AddItemCommand::AddItemCommand(ProjectViewModel* model, Item*
{
}
Project *ProjectViewModel::AddItemCommand::GetRelevantProject() const
{
return model_->project();
}
void ProjectViewModel::AddItemCommand::redo_internal()
{
model_->AddChild(parent_, child_);
@@ -572,6 +587,11 @@ ProjectViewModel::RemoveItemCommand::RemoveItemCommand(ProjectViewModel *model,
{
}
Project *ProjectViewModel::RemoveItemCommand::GetRelevantProject() const
{
return model_->project();
}
void ProjectViewModel::RemoveItemCommand::redo_internal()
{
parent_ = item_->parent();
+8
View File
@@ -114,6 +114,8 @@ public:
public:
MoveItemCommand(ProjectViewModel* model, Item* item, Folder* destination, QUndoCommand* parent = nullptr);
virtual Project* GetRelevantProject() const override;
protected:
virtual void redo_internal() override;
@@ -134,6 +136,8 @@ public:
public:
RenameItemCommand(ProjectViewModel* model, Item* item, const QString& name, QUndoCommand* parent = nullptr);
virtual Project* GetRelevantProject() const override;
protected:
virtual void redo_internal() override;
@@ -153,6 +157,8 @@ public:
public:
AddItemCommand(ProjectViewModel* model, Item* folder, ItemPtr child, QUndoCommand* parent = nullptr);
virtual Project* GetRelevantProject() const override;
protected:
virtual void redo_internal() override;
@@ -172,6 +178,8 @@ public:
public:
RemoveItemCommand(ProjectViewModel* model, ItemPtr item, QUndoCommand* parent = nullptr);
virtual Project* GetRelevantProject() const override;
protected:
virtual void redo_internal() override;