wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
ElementFactory.h
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
7
8#pragma once
9
10#include <functional>
11
12#include <QHash>
13
14#include "App/Core/Enums.h"
15
16class GraphicElement;
17
26class ElementFactory : public QObject
27{
28 Q_OBJECT
29
30public:
33 {
35 return instance;
36 }
37
38 // --- Element creation ---
39
41 static GraphicElement *buildElement(const ElementType type);
42
44 static bool hasCreator(ElementType type);
45
47 static void registerCreator(ElementType type, std::function<GraphicElement *()> creator);
48
49 // --- Type name conversion ---
50
52 static ElementType textToType(const QString &text);
53
55 static QString typeToText(const ElementType type);
56
58 static QString typeToTitleText(const ElementType type);
59
61 static QString translatedName(const ElementType type);
62
65 static QString description(const ElementType type);
66
68 static QPixmap pixmap(const ElementType type);
69
70private:
71 QHash<ElementType, std::function<GraphicElement *()>> m_creatorMap;
72};
Central enumeration types for element types, groups, and signal status.
Enums::ElementType ElementType
Definition Enums.h:107
Factory for circuit elements.
static QString translatedName(const ElementType type)
Returns the translated human-readable name for type.
static bool hasCreator(ElementType type)
Returns true if a creator function is registered for type.
static QPixmap pixmap(const ElementType type)
Returns the pixmap icon for the given element type.
static void registerCreator(ElementType type, std::function< GraphicElement *()> creator)
Registers a creator lambda for type, used by buildElement().
static QString typeToText(const ElementType type)
Converts type to its internal name string.
static QString description(const ElementType type)
static QString typeToTitleText(const ElementType type)
Returns the display title string for type.
static ElementFactory & instance()
Returns the singleton ElementFactory instance.
static ElementType textToType(const QString &text)
Converts an element type name string to its ElementType enum value.
static GraphicElement * buildElement(const ElementType type)
Constructs and returns a new graphic element of the given type.
Abstract base class for all graphical circuit elements in wiRedPanda.