fix: made workspace undraggable and unreparentable
This commit is contained in:
parent
d49005295f
commit
8127d5b8f4
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
};
|
|
@ -18,5 +18,5 @@ DataModel::DataModel()
|
|||
|
||||
void DataModel::Init() {
|
||||
this->workspace = std::make_shared<Workspace>(shared<DataModel>());
|
||||
this->AddChild(this->workspace);
|
||||
this->workspace->InitService();
|
||||
}
|
|
@ -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) {
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue