fix: made workspace undraggable and unreparentable

This commit is contained in:
maelstrom 2025-02-04 21:53:47 +01:00
parent d49005295f
commit 8127d5b8f4
8 changed files with 19 additions and 7 deletions

View file

@ -144,7 +144,7 @@ Qt::ItemFlags ExplorerModel::flags(const QModelIndex &index) const
//return index.isValid()
// ? QAbstractItemModel::flags(index) : Qt::ItemFlags(Qt::NoItemFlags);
return index.isValid()
? QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled
? QAbstractItemModel::flags(index) | Qt::ItemIsEditable | (!fromIndex(index)->IsParentLocked() ? Qt::ItemIsDragEnabled : Qt::NoItemFlags) | Qt::ItemIsDropEnabled
: Qt::NoItemFlags | Qt::ItemIsDropEnabled;
}

View file

@ -75,6 +75,9 @@ std::optional<std::shared_ptr<Instance>> Instance::GetParent() {
return parent.value().lock();
}
bool Instance::IsParentLocked() {
return this->parentLocked;
}
void Instance::OnParentUpdated(std::optional<std::shared_ptr<Instance>> oldParent, std::optional<std::shared_ptr<Instance>> newParent) {
// Empty stub

View file

@ -55,6 +55,7 @@ public:
virtual const InstanceType* GetClass() = 0;
bool SetParent(std::optional<std::shared_ptr<Instance>> newParent);
std::optional<std::shared_ptr<Instance>> GetParent();
bool IsParentLocked();
inline const std::vector<std::shared_ptr<Instance>> GetChildren() { return children; }
// Utility functions

View file

@ -1,4 +1,9 @@
#include "service.h"
#include <memory>
Service::Service(std::weak_ptr<DataModel> root) : dataModel(root) {}
Service::Service(const InstanceType* type, std::weak_ptr<DataModel> root) : Instance(type), dataModel(root) {}
void Service::InitService() {
SetParent(dataModel.lock());
parentLocked = true;
}

View file

@ -4,9 +4,12 @@
// They serve one specific task and can be accessed using game:GetService
#include "objects/datamodel.h"
#include <memory>
class Service {
class Service : public Instance {
protected:
std::weak_ptr<DataModel> dataModel;
Service(std::weak_ptr<DataModel> root);
Service(const InstanceType* type, std::weak_ptr<DataModel> root);
virtual void InitService();
friend class DataModel;
};

View file

@ -18,5 +18,5 @@ DataModel::DataModel()
void DataModel::Init() {
this->workspace = std::make_shared<Workspace>(shared<DataModel>());
this->AddChild(this->workspace);
this->workspace->InitService();
}

View file

@ -11,5 +11,5 @@ const InstanceType* Workspace::GetClass() {
return &TYPE;
}
Workspace::Workspace(std::weak_ptr<DataModel> dataModel): Instance(&TYPE), Service(dataModel) {
Workspace::Workspace(std::weak_ptr<DataModel> dataModel): Service(&TYPE, dataModel) {
}

View file

@ -4,7 +4,7 @@
#include "objects/base/service.h"
#include <memory>
class Workspace : public Instance, Service {
class Workspace : public Service {
//private:
public:
const static InstanceType TYPE;