schema_editor/comdel/display/component_display.h

123 lines
3.7 KiB
C++

#ifndef DISPLAY_COMPONENT_H
#define DISPLAY_COMPONENT_H
#include <comdel/domain/instance.h>
#include <QGraphicsItemGroup>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneMouseEvent>
#include <utility>
#include "comdel/domain/connection_instance.h"
namespace display {
class Pin : public QGraphicsItemGroup {
private:
domain::Pin pin;
std::shared_ptr<domain::ComponentInstance> componentInstance;
public:
Pin(domain::Pin pin, std::shared_ptr<domain::ComponentInstance> componentInstance) : pin(pin),
componentInstance(std::move(
componentInstance)) {
pin.getDisplayPin().render(this);
this->setToolTip(QString::fromStdString(pin.getTooltip()));
}
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
domain::Pin &getPin();
domain::ComponentInstance *getComponentInstance();
};
class Component : public QGraphicsItemGroup {
private:
std::shared_ptr<domain::ComponentInstance> instance;
public:
explicit Component(const std::shared_ptr<domain::ComponentInstance> &instance);
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
};
class Bus : public QGraphicsItemGroup {
std::shared_ptr<domain::BusInstance> busInstance;
public:
explicit Bus(const std::shared_ptr<domain::BusInstance> &instance);
domain::BusInstance *getBusInstance();
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
};
class ComponentGroup : public QGraphicsItemGroup {
private:
std::shared_ptr<domain::ComponentInstance> componentInstance;
std::vector<display::Pin *> pins;
public:
std::shared_ptr<domain::ComponentInstance> getComponentInstance();
std::vector<display::Pin *> &getPins();
explicit ComponentGroup(const std::shared_ptr<domain::ComponentInstance> &instance);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
};
class BusGroup : public QGraphicsItemGroup {
private:
std::shared_ptr<domain::BusInstance> busInstance;
display::Bus *bus;
public:
explicit BusGroup(const std::shared_ptr<domain::BusInstance> &instance);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
};
class BusConnection : public QGraphicsLineItem {
private:
domain::BusConnectionInstance *connection;
ComponentGroup *component;
BusGroup *bus;
public:
BusConnection(domain::BusConnectionInstance *connection, ComponentGroup *component, BusGroup *bus);
void updateConnection();
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
};
class DirectConnection : public QGraphicsLineItem {
private:
domain::DirectConnectionInstance *connection;
ComponentGroup *first;
ComponentGroup *second;
public:
DirectConnection(domain::DirectConnectionInstance *connection, ComponentGroup *first, ComponentGroup *second);
void updateConnection();
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
};
} // namespace display
#endif // DISPLAY_COMPONENT_H