schema_editor/comdel/display/schema_display.h

83 lines
2.1 KiB
C
Raw Permalink Normal View History

2022-04-07 22:21:23 +00:00
#ifndef DISPLAY_SCHEMA_H
#define DISPLAY_SCHEMA_H
#include <QGraphicsView>
#include <QWidget>
2022-06-09 18:24:27 +00:00
#include <QColor>
2022-05-25 05:39:45 +00:00
#include <QGraphicsLineItem>
2022-04-07 22:21:23 +00:00
#include <comdel/domain/schema.h>
#include <comdel/domain/library.h>
2022-05-25 05:39:45 +00:00
#include "component_display.h"
2022-04-07 22:21:23 +00:00
namespace display {
2022-05-17 22:14:33 +00:00
class BusConnection;
2022-05-27 06:18:17 +00:00
class Schema : public QGraphicsView {
Q_OBJECT
2022-05-27 06:18:17 +00:00
public:
2022-06-09 18:24:27 +00:00
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));
2022-05-25 05:39:45 +00:00
2022-05-27 06:18:17 +00:00
enum State {
DEFAULT,
CREATING_CONNECTION
};
2022-05-27 06:18:17 +00:00
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;
2022-05-27 06:18:17 +00:00
State state = DEFAULT;
Context context;
2022-05-25 05:39:45 +00:00
2022-05-27 06:18:17 +00:00
Schema();
2022-05-27 06:18:17 +00:00
std::vector<BusConnection *> busConnections;
std::vector<DirectConnection *> directConnections;
2022-04-07 22:21:23 +00:00
2022-05-27 06:18:17 +00:00
void updateConnections();
2022-04-07 22:21:23 +00:00
2022-05-27 06:18:17 +00:00
void removeConnectable(QPointF f);
2022-05-17 22:14:33 +00:00
2022-05-27 06:18:17 +00:00
void showConnectable(Pin *pin);
2022-05-25 05:39:45 +00:00
void refreshContent();
2022-05-27 06:18:17 +00:00
protected:
2022-05-25 05:39:45 +00:00
2022-05-27 06:18:17 +00:00
void dragEnterEvent(QDragEnterEvent *event) override;
2022-05-27 06:18:17 +00:00
void dropEvent(QDropEvent *event) override;
2022-05-27 06:18:17 +00:00
void dragMoveEvent(QDragMoveEvent *event) override;
2022-04-07 22:21:23 +00:00
2022-05-27 06:18:17 +00:00
private:
QGraphicsScene scene;
2022-05-25 05:39:45 +00:00
domain::Schema *schema{};
std::optional<domain::Library> library;
2022-05-25 05:39:45 +00:00
std::vector<domain::InstanceAttribute> populateAttributes(std::vector<domain::Attribute>& attributes);
std::vector<domain::InstanceAttribute> populateSingleAutomaticConnection(domain::Connection connection);
2022-06-09 18:24:27 +00:00
void clearSelectable();
2022-05-27 06:18:17 +00:00
};
2022-04-07 22:21:23 +00:00
} // namespace display
#endif // DISPLAY_SCHEMA_H