83 lines
2.1 KiB
C++
83 lines
2.1 KiB
C++
#ifndef DISPLAY_SCHEMA_H
|
|
#define DISPLAY_SCHEMA_H
|
|
|
|
|
|
#include <QGraphicsView>
|
|
#include <QWidget>
|
|
#include <QColor>
|
|
#include <QGraphicsLineItem>
|
|
|
|
#include <comdel/domain/schema.h>
|
|
#include <comdel/domain/library.h>
|
|
#include "component_display.h"
|
|
|
|
namespace display {
|
|
|
|
class BusConnection;
|
|
|
|
class Schema : public QGraphicsView {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
QBrush selectedBrush = QBrush(QColor::fromRgb(50, 50, 150, 100), Qt::BrushStyle::SolidPattern);
|
|
QPen selectedPen = QPen(QColor::fromRgb(50, 50, 150), 1, Qt::PenStyle::SolidLine);
|
|
QPen activeLinePen = QPen(QColor::fromRgb(250, 100, 100));
|
|
|
|
enum State {
|
|
DEFAULT,
|
|
CREATING_CONNECTION
|
|
};
|
|
|
|
struct Context {
|
|
display::Pin *pin = nullptr;
|
|
QPointF startingPoint;
|
|
QGraphicsLineItem *line = nullptr;
|
|
std::vector<QGraphicsRectItem *> selectable;
|
|
};
|
|
|
|
std::map<std::string, display::ComponentGroup *> components;
|
|
std::map<std::string, display::BusGroup *> buses;
|
|
std::map<domain::ConnectionComponent, display::Pin *> pins;
|
|
|
|
State state = DEFAULT;
|
|
Context context;
|
|
|
|
Schema();
|
|
|
|
std::vector<BusConnection *> busConnections;
|
|
std::vector<DirectConnection *> directConnections;
|
|
|
|
void updateConnections();
|
|
|
|
void removeConnectable(QPointF f);
|
|
|
|
void showConnectable(Pin *pin);
|
|
|
|
void refreshContent();
|
|
|
|
protected:
|
|
|
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
|
|
|
void dropEvent(QDropEvent *event) override;
|
|
|
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
|
|
|
private:
|
|
QGraphicsScene scene;
|
|
|
|
domain::Schema *schema{};
|
|
std::optional<domain::Library> library;
|
|
|
|
std::vector<domain::InstanceAttribute> populateAttributes(std::vector<domain::Attribute>& attributes);
|
|
|
|
std::vector<domain::InstanceAttribute> populateSingleAutomaticConnection(domain::Connection connection);
|
|
|
|
void clearSelectable();
|
|
};
|
|
|
|
} // namespace display
|
|
|
|
#endif // DISPLAY_SCHEMA_H
|