implemented train list delete and train destroy
Dieser Commit ist enthalten in:
Ursprung
5278edb482
Commit
74e5222c08
@ -70,6 +70,13 @@ void Train::addToWorld()
|
||||
world->trains->addObject(shared_ptr<Train>());
|
||||
}
|
||||
|
||||
void Train::destroying()
|
||||
{
|
||||
if(auto world = m_world.lock())
|
||||
world->trains->removeObject(shared_ptr<Train>());
|
||||
IdObject::destroying();
|
||||
}
|
||||
|
||||
void Train::worldEvent(WorldState state, WorldEvent event)
|
||||
{
|
||||
IdObject::worldEvent(state, event);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2019-2020 Reinder Feenstra
|
||||
* Copyright (C) 2019-2021 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -34,6 +34,7 @@ class Train : public IdObject
|
||||
{
|
||||
protected:
|
||||
void addToWorld() override;
|
||||
void destroying() override;
|
||||
void worldEvent(WorldState state, WorldEvent event) override;
|
||||
|
||||
public:
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2019-2020 Reinder Feenstra
|
||||
* Copyright (C) 2019-2021 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -36,12 +36,21 @@ TrainList::TrainList(Object& _parent, const std::string& parentPropertyName) :
|
||||
return std::shared_ptr<Train>();
|
||||
return Train::create(world, world->getUniqueId("train"));
|
||||
}}
|
||||
, remove{*this, "remove",
|
||||
[this](const std::shared_ptr<Train>& train)
|
||||
{
|
||||
if(containsObject(train))
|
||||
train->destroy();
|
||||
assert(!containsObject(train));
|
||||
}}
|
||||
{
|
||||
auto world = getWorld(&_parent);
|
||||
const bool editable = world && contains(world->state.value(), WorldState::Edit);
|
||||
|
||||
Attributes::addEnabled(add, editable);
|
||||
m_interfaceItems.add(add);
|
||||
Attributes::addEnabled(remove, editable);
|
||||
m_interfaceItems.add(remove);
|
||||
}
|
||||
|
||||
TableModelPtr TrainList::getModel()
|
||||
@ -55,7 +64,8 @@ void TrainList::worldEvent(WorldState state, WorldEvent event)
|
||||
|
||||
const bool editable = contains(state, WorldState::Edit);
|
||||
|
||||
add.setAttributeEnabled(editable);
|
||||
Attributes::setEnabled(add, editable);
|
||||
Attributes::setEnabled(remove, editable);
|
||||
}
|
||||
|
||||
bool TrainList::isListedProperty(const std::string& name)
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2019-2020 Reinder Feenstra
|
||||
* Copyright (C) 2019-2021 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -37,6 +37,7 @@ class TrainList : public ObjectList<Train>
|
||||
CLASS_ID("list.train")
|
||||
|
||||
Method<std::shared_ptr<Train>()> add;
|
||||
Method<void(const std::shared_ptr<Train>&)> remove;
|
||||
|
||||
TrainList(Object& _parent, const std::string& parentPropertyName);
|
||||
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren