schema_editor/comdel/display/component_display.h

117 lines
3.4 KiB
C
Raw Permalink Normal View History

2022-04-07 22:21:23 +00:00
#ifndef DISPLAY_COMPONENT_H
#define DISPLAY_COMPONENT_H
#include <comdel/domain/instance.h>
#include <QGraphicsItemGroup>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneMouseEvent>
2022-05-27 06:18:17 +00:00
#include <utility>
#include "comdel/domain/connection_instance.h"
2022-04-07 22:21:23 +00:00
namespace display {
2022-05-27 06:18:17 +00:00
class Pin : public QGraphicsItemGroup {
private:
domain::Pin pin;
std::shared_ptr<domain::ComponentInstance> componentInstance;
public:
2022-06-09 21:42:45 +00:00
Pin(domain::Pin pin, std::shared_ptr<domain::ComponentInstance> componentInstance) : pin(pin), componentInstance(std::move(componentInstance)) {
2022-05-27 06:18:17 +00:00
pin.getDisplayPin().render(this);
this->setToolTip(QString::fromStdString(pin.getTooltip()));
}
2022-05-27 06:18:17 +00:00
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
domain::Pin &getPin();
2022-05-17 19:31:32 +00:00
2022-05-27 06:18:17 +00:00
domain::ComponentInstance *getComponentInstance();
2022-06-09 21:42:45 +00:00
bool isSingleAutomatic(std::vector<domain::ConnectionInstance *> pinConnections);
2022-05-27 06:18:17 +00:00
};
class Component : public QGraphicsItemGroup {
private:
std::shared_ptr<domain::ComponentInstance> instance;
public:
explicit Component(const std::shared_ptr<domain::ComponentInstance> &instance);
2022-05-17 19:31:32 +00:00
2022-05-27 06:18:17 +00:00
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
};
2022-05-27 06:18:17 +00:00
class Bus : public QGraphicsItemGroup {
std::shared_ptr<domain::BusInstance> busInstance;
public:
explicit Bus(const std::shared_ptr<domain::BusInstance> &instance);
2022-05-27 06:18:17 +00:00
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
};
2022-05-17 19:31:32 +00:00
2022-05-27 06:18:17 +00:00
class ComponentGroup : public QGraphicsItemGroup {
private:
std::shared_ptr<domain::ComponentInstance> componentInstance;
std::vector<display::Pin *> pins;
2022-04-07 22:21:23 +00:00
2022-05-27 06:18:17 +00:00
public:
2022-05-17 22:14:33 +00:00
2022-05-27 06:18:17 +00:00
std::shared_ptr<domain::ComponentInstance> getComponentInstance();
2022-05-17 22:14:33 +00:00
2022-05-27 06:18:17 +00:00
std::vector<display::Pin *> &getPins();
2022-05-17 22:14:33 +00:00
2022-05-27 06:18:17 +00:00
explicit ComponentGroup(const std::shared_ptr<domain::ComponentInstance> &instance);
2022-05-17 22:14:33 +00:00
2022-05-27 06:18:17 +00:00
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
2022-05-25 05:39:45 +00:00
2022-05-27 06:18:17 +00:00
};
2022-05-25 05:39:45 +00:00
2022-05-27 06:18:17 +00:00
class BusGroup : public QGraphicsItemGroup {
private:
std::shared_ptr<domain::BusInstance> busInstance;
display::Bus *bus;
2022-05-17 22:14:33 +00:00
2022-05-27 06:18:17 +00:00
public:
explicit BusGroup(const std::shared_ptr<domain::BusInstance> &instance);
2022-05-17 19:31:32 +00:00
2022-05-27 06:18:17 +00:00
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
};
2022-05-17 19:31:32 +00:00
2022-05-27 06:18:17 +00:00
class BusConnection : public QGraphicsLineItem {
2022-05-19 19:08:00 +00:00
private:
2022-05-27 06:18:17 +00:00
domain::BusConnectionInstance *connection;
ComponentGroup *component;
BusGroup *bus;
2022-05-19 19:08:00 +00:00
public:
2022-05-27 06:18:17 +00:00
BusConnection(domain::BusConnectionInstance *connection, ComponentGroup *component, BusGroup *bus);
2022-05-19 19:08:00 +00:00
2022-05-27 06:18:17 +00:00
void updateConnection();
};
2022-05-25 05:39:45 +00:00
2022-05-27 06:18:17 +00:00
class DirectConnection : public QGraphicsLineItem {
private:
domain::DirectConnectionInstance *connection;
ComponentGroup *first;
ComponentGroup *second;
public:
DirectConnection(domain::DirectConnectionInstance *connection, ComponentGroup *first, ComponentGroup *second);
void updateConnection();
2022-05-19 19:08:00 +00:00
};
2022-04-07 22:21:23 +00:00
} // namespace display
#endif // DISPLAY_COMPONENT_H