SILICON
Toggle main menu visibility
Loading...
Searching...
No Matches
gui_component_factory.hpp
Go to the documentation of this file.
1
/*
2
Copyright (c) 2026. Giulio Cocconi
3
4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#pragma once
19
20
#include <QGraphicsItem>
21
22
#include <
core/serialization/component_registry.hpp
>
23
24
#include <memory>
25
#include <
ui/circuit/diagram/graphicalComponent.hpp
>
26
27
#include <functional>
28
#include <map>
29
#include <optional>
30
#include <stdexcept>
31
#include <string>
32
#include <string_view>
33
#include <vector>
34
35
36
namespace
SILICON::ui
{
37
class
GraphicalComponent
;
38
55
class
GUIComponentFactory
{
56
public
:
63
using
Factory
= std::function<std::unique_ptr<GraphicalComponent>(QGraphicsItem*)>;
64
65
struct
EntryMetadata
{
66
std::string
coreType
;
67
std::optional<SILICON::core::ComponentMetadata>
graphicalMetadata
= std::nullopt;
68
};
69
70
GUIComponentFactory
();
71
76
static
GUIComponentFactory
empty
();
77
82
static
GUIComponentFactory
&
instance
();
83
91
void
registerType
(std::string type,
Factory
factory);
92
void
registerType
(std::string type,
Factory
factory,
EntryMetadata
metadata
);
93
102
std::unique_ptr<GraphicalComponent>
create
(std::string_view type,
103
QGraphicsItem* parent =
nullptr
)
const
;
104
114
std::unique_ptr<GraphicalComponent>
115
createForCoreType
(std::string_view coreType, QGraphicsItem* parent =
nullptr
)
const
;
116
121
std::vector<std::string>
availableTypes
()
const
;
122
123
const
EntryMetadata
&
metadata
(std::string_view type)
const
;
124
130
bool
hasType
(std::string_view type)
const
;
131
132
private
:
134
struct
Entry
{
135
Factory
factory
;
136
EntryMetadata
metadata
;
137
};
138
139
std::map<std::string, Entry, std::less<>>
factories
;
140
};
141
142
}
// namespace SILICON::ui
SILICON::ui::GUIComponentFactory::instance
static GUIComponentFactory & instance()
Gets the global singleton factory instance.
Definition
gui_component_factory.cpp:31
SILICON::ui::GUIComponentFactory::metadata
const EntryMetadata & metadata(std::string_view type) const
Definition
gui_component_factory.cpp:117
SILICON::ui::GUIComponentFactory::factories
std::map< std::string, Entry, std::less<> > factories
Definition
gui_component_factory.hpp:139
SILICON::ui::GUIComponentFactory::empty
static GUIComponentFactory empty()
Creates an empty factory without registered types.
Definition
gui_component_factory.cpp:26
SILICON::ui::GUIComponentFactory::Factory
std::function< std::unique_ptr< GraphicalComponent >(QGraphicsItem *)> Factory
Factory function type for creating components.
Definition
gui_component_factory.hpp:63
SILICON::ui::GUIComponentFactory::createForCoreType
std::unique_ptr< GraphicalComponent > createForCoreType(std::string_view coreType, QGraphicsItem *parent=nullptr) const
Creates the graphical component registered for a core component type.
Definition
gui_component_factory.cpp:72
SILICON::ui::GUIComponentFactory::GUIComponentFactory
GUIComponentFactory()
SILICON::ui::GUIComponentFactory::availableTypes
std::vector< std::string > availableTypes() const
Gets all available component types.
Definition
gui_component_factory.cpp:101
SILICON::ui::GUIComponentFactory::registerType
void registerType(std::string type, Factory factory)
Registers a component type.
Definition
gui_component_factory.cpp:37
SILICON::ui::GUIComponentFactory::hasType
bool hasType(std::string_view type) const
Checks if a type is registered.
Definition
gui_component_factory.cpp:111
SILICON::ui::GUIComponentFactory::create
std::unique_ptr< GraphicalComponent > create(std::string_view type, QGraphicsItem *parent=nullptr) const
Creates a component by type name.
Definition
gui_component_factory.cpp:61
SILICON::ui::GraphicalComponent
Base class for graphical circuit components.
Definition
graphicalComponent.hpp:154
component_registry.hpp
graphicalComponent.hpp
SILICON::ui
Definition
actionGroups.hpp:14
SILICON::ui::GUIComponentFactory::EntryMetadata
Definition
gui_component_factory.hpp:65
SILICON::ui::GUIComponentFactory::EntryMetadata::coreType
std::string coreType
Definition
gui_component_factory.hpp:66
SILICON::ui::GUIComponentFactory::EntryMetadata::graphicalMetadata
std::optional< SILICON::core::ComponentMetadata > graphicalMetadata
Definition
gui_component_factory.hpp:67
SILICON::ui::GUIComponentFactory::Entry
Map of type names to factory functions.
Definition
gui_component_factory.hpp:134
SILICON::ui::GUIComponentFactory::Entry::factory
Factory factory
Definition
gui_component_factory.hpp:135
SILICON::ui::GUIComponentFactory::Entry::metadata
EntryMetadata metadata
Definition
gui_component_factory.hpp:136
src
ui
serialization
gui_component_factory.hpp
Generated by
1.17.0