From 5694305ab843ee3e8358f8ae6ab39dda566a5420 Mon Sep 17 00:00:00 2001 From: Reinder Feenstra Date: Tue, 29 Jun 2021 21:04:52 +0200 Subject: [PATCH] use DisplayName namespace everywhere for setting displayname attribute --- server/src/board/board.cpp | 3 ++- server/src/board/tile/rail/blockrailtile.cpp | 3 ++- server/src/board/tile/rail/sensorrailtile.cpp | 3 ++- server/src/board/tile/rail/signal/signalrailtile.cpp | 3 ++- server/src/board/tile/rail/turnout/turnoutrailtile.cpp | 3 ++- server/src/core/idobject.cpp | 3 ++- server/src/hardware/commandstation/commandstation.cpp | 5 +++-- server/src/hardware/controller/controller.cpp | 5 +++-- server/src/hardware/decoder/decoder.cpp | 7 ++++--- server/src/hardware/decoder/decoderfunction.cpp | 3 ++- server/src/hardware/input/input.cpp | 3 ++- server/src/hardware/output/output.cpp | 3 ++- server/src/lua/script.cpp | 2 ++ server/src/train/train.cpp | 7 ++++--- server/src/utils/displayname.hpp | 1 + server/src/vehicle/vehicle.cpp | 7 ++++--- server/src/world/world.cpp | 3 ++- 17 files changed, 41 insertions(+), 23 deletions(-) diff --git a/server/src/board/board.cpp b/server/src/board/board.cpp index f98cbb3b..a08a2a79 100644 --- a/server/src/board/board.cpp +++ b/server/src/board/board.cpp @@ -26,6 +26,7 @@ #include "../world/world.hpp" #include "../world/worldloader.hpp" #include "../core/attributes.hpp" +#include "../utils/displayname.hpp" Board::Board(const std::weak_ptr& world, std::string_view _id) : IdObject(world, _id), @@ -98,7 +99,7 @@ Board::Board(const std::weak_ptr& world, std::string_view _id) : const bool editable = w && contains(w->state.value(), WorldState::Edit); const bool stopped = w && !contains(w->state.value(), WorldState::Run); - Attributes::addDisplayName(name, "object:name"); + Attributes::addDisplayName(name, DisplayName::Object::name); Attributes::addEnabled(name, editable); m_interfaceItems.add(name); m_interfaceItems.add(left); diff --git a/server/src/board/tile/rail/blockrailtile.cpp b/server/src/board/tile/rail/blockrailtile.cpp index b8ad5d54..e392aca9 100644 --- a/server/src/board/tile/rail/blockrailtile.cpp +++ b/server/src/board/tile/rail/blockrailtile.cpp @@ -23,6 +23,7 @@ #include "blockrailtile.hpp" #include "../../../world/world.hpp" #include "../../../core/attributes.hpp" +#include "../../../utils/displayname.hpp" BlockRailTile::BlockRailTile(const std::weak_ptr& world, std::string_view _id) : RailTile(world, _id, TileId::RailBlock), @@ -39,7 +40,7 @@ BlockRailTile::BlockRailTile(const std::weak_ptr& world, std::string_view const bool editable = w && contains(w->state.value(), WorldState::Edit); Attributes::addEnabled(name, editable); - Attributes::addDisplayName(name, "object:name"); + Attributes::addDisplayName(name, DisplayName::Object::name); m_interfaceItems.add(name); m_interfaceItems.add(inputMap); Attributes::addValues(state, blockStateValues); diff --git a/server/src/board/tile/rail/sensorrailtile.cpp b/server/src/board/tile/rail/sensorrailtile.cpp index 88d91eb7..a90382e7 100644 --- a/server/src/board/tile/rail/sensorrailtile.cpp +++ b/server/src/board/tile/rail/sensorrailtile.cpp @@ -24,6 +24,7 @@ #include "../../../world/world.hpp" #include "../../../core/attributes.hpp" #include "../../../utils/sensor.hpp" +#include "../../../utils/displayname.hpp" SensorRailTile::SensorRailTile(const std::weak_ptr& world, std::string_view _id) : StraightRailTile(world, _id, TileId::RailSensor), @@ -64,7 +65,7 @@ SensorRailTile::SensorRailTile(const std::weak_ptr& world, std::string_vi const bool editable = w && contains(w->state.value(), WorldState::Edit); Attributes::addEnabled(name, editable); - Attributes::addDisplayName(name, "object:name"); + Attributes::addDisplayName(name, DisplayName::Object::name); m_interfaceItems.add(name); Attributes::addEnabled(input, editable); Attributes::addObjectList(input, w->inputs); diff --git a/server/src/board/tile/rail/signal/signalrailtile.cpp b/server/src/board/tile/rail/signal/signalrailtile.cpp index ac32bd4d..57341a26 100644 --- a/server/src/board/tile/rail/signal/signalrailtile.cpp +++ b/server/src/board/tile/rail/signal/signalrailtile.cpp @@ -23,6 +23,7 @@ #include "signalrailtile.hpp" #include "../../../../core/attributes.hpp" #include "../../../../world/getworld.hpp" +#include "../../../../utils/displayname.hpp" SignalRailTile::SignalRailTile(const std::weak_ptr& world, std::string_view _id, TileId tileId) : StraightRailTile(world, _id, tileId), @@ -38,7 +39,7 @@ SignalRailTile::SignalRailTile(const std::weak_ptr& world, std::string_vi auto w = world.lock(); const bool editable = w && contains(w->state.value(), WorldState::Edit); - Attributes::addDisplayName(name, "object:name"); + Attributes::addDisplayName(name, DisplayName::Object::name); Attributes::addEnabled(name, editable); m_interfaceItems.add(name); Attributes::addObjectEditor(aspect, false); diff --git a/server/src/board/tile/rail/turnout/turnoutrailtile.cpp b/server/src/board/tile/rail/turnout/turnoutrailtile.cpp index 08eaef78..3e846ce7 100644 --- a/server/src/board/tile/rail/turnout/turnoutrailtile.cpp +++ b/server/src/board/tile/rail/turnout/turnoutrailtile.cpp @@ -23,6 +23,7 @@ #include "turnoutrailtile.hpp" #include "../../../../core/attributes.hpp" #include "../../../../world/world.hpp" +#include "../../../../utils/displayname.hpp" TurnoutRailTile::TurnoutRailTile(const std::weak_ptr& world, std::string_view _id, TileId tileId) : RailTile(world, _id, tileId), @@ -38,7 +39,7 @@ TurnoutRailTile::TurnoutRailTile(const std::weak_ptr& world, std::string_ auto w = world.lock(); const bool editable = w && contains(w->state.value(), WorldState::Edit); - Attributes::addDisplayName(name, "object:name"); + Attributes::addDisplayName(name, DisplayName::Object::name); Attributes::addEnabled(name, editable); m_interfaceItems.add(name); Attributes::addObjectEditor(position, false); diff --git a/server/src/core/idobject.cpp b/server/src/core/idobject.cpp index 543717c8..291f90ab 100644 --- a/server/src/core/idobject.cpp +++ b/server/src/core/idobject.cpp @@ -23,6 +23,7 @@ #include "console.hpp" #include "../world/getworld.hpp" #include "attributes.hpp" +#include "../utils/displayname.hpp" IdObject::IdObject(const std::weak_ptr& world, std::string_view _id) : Object{}, @@ -49,7 +50,7 @@ IdObject::IdObject(const std::weak_ptr& world, std::string_view _id) : auto w = world.lock(); const bool editable = w && contains(w->state.value(), WorldState::Edit); - Attributes::addDisplayName(id, "object:id"); + Attributes::addDisplayName(id, DisplayName::Object::id); Attributes::addEnabled(id, editable); m_interfaceItems.add(id); } diff --git a/server/src/hardware/commandstation/commandstation.cpp b/server/src/hardware/commandstation/commandstation.cpp index d4d329b3..cc0cde39 100644 --- a/server/src/hardware/commandstation/commandstation.cpp +++ b/server/src/hardware/commandstation/commandstation.cpp @@ -28,6 +28,7 @@ #include "../decoder/decoder.hpp" #include "../decoder/decoderlist.hpp" #include "../../core/attributes.hpp" +#include "../../utils/displayname.hpp" CommandStation::CommandStation(const std::weak_ptr& world, std::string_view _id) : IdObject(world, _id), @@ -60,7 +61,7 @@ CommandStation::CommandStation(const std::weak_ptr& world, std::string_vi auto w = world.lock(); const bool editable = w && contains(w->state.value(), WorldState::Edit); - Attributes::addDisplayName(name, "object:name"); + Attributes::addDisplayName(name, DisplayName::Object::name); Attributes::addEnabled(name, editable); m_interfaceItems.add(name); @@ -78,7 +79,7 @@ CommandStation::CommandStation(const std::weak_ptr& world, std::string_vi m_interfaceItems.add(controllers); - Attributes::addDisplayName(notes, "object:notes"); + Attributes::addDisplayName(notes, DisplayName::Object::notes); m_interfaceItems.add(notes); } diff --git a/server/src/hardware/controller/controller.cpp b/server/src/hardware/controller/controller.cpp index 3c736b31..250c15da 100644 --- a/server/src/hardware/controller/controller.cpp +++ b/server/src/hardware/controller/controller.cpp @@ -26,6 +26,7 @@ #include "../commandstation/commandstation.hpp" #include "../../world/getworld.hpp" #include "../../core/attributes.hpp" +#include "../../utils/displayname.hpp" Controller::Controller(const std::weak_ptr& _world, std::string_view _id) : IdObject(_world, _id), @@ -51,13 +52,13 @@ Controller::Controller(const std::weak_ptr& _world, std::string_view _id) auto world = _world.lock(); const bool editable = world && contains(world->state.value(), WorldState::Edit); - Attributes::addDisplayName(name, "object:name"); + Attributes::addDisplayName(name, DisplayName::Object::name); m_interfaceItems.add(name); Attributes::addEnabled(commandStation, editable); Attributes::addObjectList(commandStation, world->commandStations); m_interfaceItems.add(commandStation); m_interfaceItems.add(active); - Attributes::addDisplayName(notes, "object:notes"); + Attributes::addDisplayName(notes, DisplayName::Object::notes); m_interfaceItems.add(notes); } diff --git a/server/src/hardware/decoder/decoder.cpp b/server/src/hardware/decoder/decoder.cpp index ecc67322..8f37fd11 100644 --- a/server/src/hardware/decoder/decoder.cpp +++ b/server/src/hardware/decoder/decoder.cpp @@ -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 @@ -29,6 +29,7 @@ #include "../../world/world.hpp" #include "../commandstation/commandstation.hpp" #include "../../core/attributes.hpp" +#include "../../utils/displayname.hpp" //constexpr uint16_t addressDCCMin = 1; constexpr uint16_t addressDCCShortMax = 127; @@ -111,7 +112,7 @@ Decoder::Decoder(const std::weak_ptr& world, std::string_view _id) : // const bool editable = w && contains(w->state.value(), WorldState::Edit) && speedStep == 0; - Attributes::addDisplayName(name, "object:name"); + Attributes::addDisplayName(name, DisplayName::Object::name); Attributes::addEnabled(name, false); m_interfaceItems.add(name); Attributes::addEnabled(commandStation, false); @@ -131,7 +132,7 @@ Decoder::Decoder(const std::weak_ptr& world, std::string_view _id) : m_interfaceItems.add(speedSteps); m_interfaceItems.add(speedStep); m_interfaceItems.add(functions); - Attributes::addDisplayName(notes, "object:notes"); + Attributes::addDisplayName(notes, DisplayName::Object::notes); m_interfaceItems.add(notes); updateEditable(); diff --git a/server/src/hardware/decoder/decoderfunction.cpp b/server/src/hardware/decoder/decoderfunction.cpp index 72a1d01d..601a89bf 100644 --- a/server/src/hardware/decoder/decoderfunction.cpp +++ b/server/src/hardware/decoder/decoderfunction.cpp @@ -23,6 +23,7 @@ #include "decoderchangeflags.hpp" #include "../../world/world.hpp" #include "../../core/attributes.hpp" +#include "../../utils/displayname.hpp" const std::shared_ptr DecoderFunction::null; @@ -54,7 +55,7 @@ DecoderFunction::DecoderFunction(Decoder& decoder, std::string_view _id) : Attributes::addEnabled(number, editable); m_interfaceItems.add(number); - Attributes::addDisplayName(name, "object:name"); + Attributes::addDisplayName(name, DisplayName::Object::name); Attributes::addEnabled(name, editable); m_interfaceItems.add(name); Attributes::addEnabled(type, editable); diff --git a/server/src/hardware/input/input.cpp b/server/src/hardware/input/input.cpp index 65591baf..3241bd49 100644 --- a/server/src/hardware/input/input.cpp +++ b/server/src/hardware/input/input.cpp @@ -24,6 +24,7 @@ #include "../../world/world.hpp" #include "list/inputlisttablemodel.hpp" #include "../../core/attributes.hpp" +#include "../../utils/displayname.hpp" Input::Input(const std::weak_ptr world, std::string_view _id) : IdObject(world, _id), @@ -33,7 +34,7 @@ Input::Input(const std::weak_ptr world, std::string_view _id) : auto w = world.lock(); const bool editable = w && contains(w->state.value(), WorldState::Edit); - Attributes::addDisplayName(name, "object:name"); + Attributes::addDisplayName(name, DisplayName::Object::name); Attributes::addEnabled(name, editable); m_interfaceItems.add(name); Attributes::addObjectEditor(value, false); diff --git a/server/src/hardware/output/output.cpp b/server/src/hardware/output/output.cpp index 76de500c..e97acbb9 100644 --- a/server/src/hardware/output/output.cpp +++ b/server/src/hardware/output/output.cpp @@ -24,6 +24,7 @@ #include "../../world/world.hpp" #include "list/outputlisttablemodel.hpp" #include "../../core/attributes.hpp" +#include "../../utils/displayname.hpp" Output::Output(const std::weak_ptr world, std::string_view _id) : IdObject(world, _id), @@ -41,7 +42,7 @@ Output::Output(const std::weak_ptr world, std::string_view _id) : auto w = world.lock(); const bool editable = w && contains(w->state.value(), WorldState::Edit); - Attributes::addDisplayName(name, "object:name"); + Attributes::addDisplayName(name, DisplayName::Object::name); Attributes::addEnabled(name, editable); m_interfaceItems.add(name); Attributes::addObjectEditor(value, false); diff --git a/server/src/lua/script.cpp b/server/src/lua/script.cpp index 004f8855..1e4e463a 100644 --- a/server/src/lua/script.cpp +++ b/server/src/lua/script.cpp @@ -30,6 +30,7 @@ #include "../core/attributes.hpp" #include "../world/worldloader.hpp" #include "../world/worldsaver.hpp" +#include "../utils/displayname.hpp" namespace Lua { @@ -64,6 +65,7 @@ Script::Script(const std::weak_ptr& world, std::string_view _id) : stopSandbox(); }} { + Attributes::addDisplayName(name, DisplayName::Object::name); Attributes::addEnabled(name, false); m_interfaceItems.add(name); Attributes::addValues(state, LuaScriptStateValues); diff --git a/server/src/train/train.cpp b/server/src/train/train.cpp index cacde2cd..b2591906 100644 --- a/server/src/train/train.cpp +++ b/server/src/train/train.cpp @@ -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 @@ -24,6 +24,7 @@ #include "../world/world.hpp" #include "trainlisttablemodel.hpp" #include "../core/attributes.hpp" +#include "../utils/displayname.hpp" Train::Train(const std::weak_ptr& world, std::string_view _id) : IdObject(world, _id), @@ -42,7 +43,7 @@ Train::Train(const std::weak_ptr& world, std::string_view _id) : auto w = world.lock(); const bool editable = w && contains(w->state.value(), WorldState::Edit); - Attributes::addDisplayName(name, "object:name"); + Attributes::addDisplayName(name, DisplayName::Object::name); Attributes::addEnabled(name, editable); m_interfaceItems.add(name); m_interfaceItems.add(lob); @@ -57,7 +58,7 @@ Train::Train(const std::weak_ptr& world, std::string_view _id) : m_interfaceItems.add(throttleSpeed); m_interfaceItems.add(weight); m_interfaceItems.add(vehicles); - Attributes::addDisplayName(notes, "object:notes"); + Attributes::addDisplayName(notes, DisplayName::Object::notes); m_interfaceItems.add(notes); } diff --git a/server/src/utils/displayname.hpp b/server/src/utils/displayname.hpp index 38eaddff..a4ad8cff 100644 --- a/server/src/utils/displayname.hpp +++ b/server/src/utils/displayname.hpp @@ -31,6 +31,7 @@ namespace DisplayName { constexpr std::string_view id = "object:id"; constexpr std::string_view name = "object:name"; + constexpr std::string_view notes = "object:notes"; } } diff --git a/server/src/vehicle/vehicle.cpp b/server/src/vehicle/vehicle.cpp index e40bb575..397a45eb 100644 --- a/server/src/vehicle/vehicle.cpp +++ b/server/src/vehicle/vehicle.cpp @@ -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 @@ -23,6 +23,7 @@ #include "vehicle.hpp" #include "../world/world.hpp" #include "../core/attributes.hpp" +#include "../utils/displayname.hpp" Vehicle::Vehicle(const std::weak_ptr& world, std::string_view _id) : IdObject(world, _id), @@ -32,10 +33,10 @@ Vehicle::Vehicle(const std::weak_ptr& world, std::string_view _id) : auto w = world.lock(); const bool editable = w && contains(w->state.value(), WorldState::Edit); - Attributes::addDisplayName(name, "object:name"); + Attributes::addDisplayName(name, DisplayName::Object::name); Attributes::addEnabled(name, editable); m_interfaceItems.add(name); - Attributes::addDisplayName(notes, "object:notes"); + Attributes::addDisplayName(notes, DisplayName::Object::notes); m_interfaceItems.add(notes); } diff --git a/server/src/world/world.cpp b/server/src/world/world.cpp index 6fc53545..139ded31 100644 --- a/server/src/world/world.cpp +++ b/server/src/world/world.cpp @@ -31,6 +31,7 @@ #include "../core/objectlisttablemodel.hpp" #include "../core/attributes.hpp" #include "../core/abstractvectorproperty.hpp" +#include "../utils/displayname.hpp" using nlohmann::json; @@ -187,7 +188,7 @@ World::World(Private) : m_filename = Traintastic::instance->worldDir() / to_string(m_uuid) / filename; m_filenameState = Traintastic::instance->worldDir() / to_string(m_uuid) / filenameState; - Attributes::addDisplayName(name, "object:name"); + Attributes::addDisplayName(name, DisplayName::Object::name); m_interfaceItems.add(name); Attributes::addEnabled(scale, false); Attributes::addValues(scale, WorldScaleValues);