3#include <QGraphicsSceneDragDropEvent>
24 : QGraphicsScene(parent)
31 setSceneRect(QRectF(0, 0, 10000, 10000));
34 settings.beginGroup(
"view defaults");
86 m_add_note =
new QAction(
"&Add note to view",
this);
123 m_save =
new QAction(
"&Save view",
this);
126 m_move =
new QAction(
"&Move scene",
this);
133 if (event->mimeData()->hasFormat(
"application/vnd.text.list")) {
141 if (event->mimeData()->hasFormat(
"application/vnd.text.list")) {
149 QByteArray encodedData =
event->mimeData()->data(
"application/vnd.text.list");
150 QDataStream stream(&encodedData, QIODevice::ReadOnly);
152 if (stream.atEnd()) {
156 QStringList schema_classes;
157 while (!stream.atEnd()) {
159 stream >> class_name;
160 schema_classes.append(class_name);
163 QList<QPointF> positions;
164 for (
int i = 0; i < schema_classes.size(); ++i) {
165 positions.push_back(event->scenePos());
233 if (itemAt(event->scenePos(), QTransform())) {
240 auto note =
dynamic_cast<SchemaGraphicNote*
>(itemAt(event->scenePos(), QTransform()));
242 if (
object !=
nullptr) {
253 }
else if (arrow !=
nullptr) {
256 }
else if (note !=
nullptr) {
257 for (
int item =
m_note_pos; item < nitems; item++) {
270 QStringList missingItems{};
272 for (QString& ClassName : SchemaClasses) {
273 if (!
ItemMap.contains(ClassName)) {
276 std::cout <<
"ERROR: class " << ClassName.toStdString() <<
" not found" << std::endl;
277 missingItems.append(ClassName);
282 Object->setPos(Positions.at(SchemaClasses.indexOf(ClassName)));
285 ItemMap.insert(ClassName, Object);
289 for (QString& ClassName :
ItemMap.keys()) {
295 std::map<std::string, unsigned int> arrow_count;
298 if (DirectRelationshipList !=
nullptr) {
300 auto rct = ClassRelationship->get_class_type()->get_name();
301 QString RelationshipClassType = QString::fromStdString(rct);
303 if (
ItemMap.contains(RelationshipClassType))
306 QString SchemaCardinality =
310 ItemMap[RelationshipClassType],
313 ClassRelationship->get_is_composite(),
314 QString::fromStdString(ClassRelationship->get_name()),
316 ItemMap[ClassName]->AddArrow(NewArrow);
317 ItemMap[RelationshipClassType]->AddArrow(NewArrow);
320 NewArrow->setZValue(-1000.0);
328 if (DirectSuperClassesList !=
nullptr) {
329 for (std::string* SuperClassNameStd : *(DirectSuperClassesList)) {
330 QString SuperClassName = QString::fromStdString(*SuperClassNameStd);
332 if (
ItemMap.contains(SuperClassName))
336 ItemMap[ClassName],
ItemMap[SuperClassName], arrow_count[*SuperClassNameStd],
true,
false,
"",
"");
337 ItemMap[ClassName]->AddArrow(NewArrow);
338 ItemMap[SuperClassName]->AddArrow(NewArrow);
341 NewArrow->setZValue(-1000.0);
343 arrow_count[*SuperClassNameStd]++;
362 for (
int index = 0; index < notes.size(); index++) {
364 note->setPos(positions.at(index));
372 if (note ==
nullptr) {
381 if (Object ==
nullptr) {
399 if (itemAt(mouseEvent->scenePos(), QTransform())) {
404 if (mouseEvent->button() != Qt::LeftButton) {
408 if (mouseEvent->widget()->cursor().shape() == Qt::CrossCursor) {
409 m_line =
new QGraphicsLineItem(QLineF(mouseEvent->scenePos(), mouseEvent->scenePos()));
410 m_line->setPen(QPen(Qt::black, 2));
416 QGraphicsScene::mousePressEvent(mouseEvent);
423 QLineF newLine(
m_line->line().p1(), mouseEvent->scenePos());
426 QGraphicsScene::mouseMoveEvent(mouseEvent);
449 auto pos =
obj->pos();
450 if (pos.x() < minx) {
453 if (pos.y() < miny) {
460 obj->setX(
obj->x() + xoffset);
461 obj->setY(
obj->y() + yoffset);
462 obj->update_arrows();
465 obj->setX(
obj->x() + xoffset);
466 obj->setY(
obj->y() + yoffset);
485 if (itemAt(mouseEvent->scenePos(), QTransform())) {
486 auto item = itemAt(mouseEvent->scenePos(), QTransform());
495 QList<QGraphicsItem*> startItems = items(
m_line->line().p1());
497 if (startItems.count() && startItems.first() ==
m_line) {
498 startItems.removeFirst();
501 QList<QGraphicsItem*> endItems = items(
m_line->line().p2());
503 if (endItems.count() && endItems.first() ==
m_line) {
504 endItems.removeFirst();
510 if (startItems.count() > 0 && endItems.count() > 0 && startItems.first() != endItems.first()) {
513 SchemaGraphicObject* startItem = qgraphicsitem_cast<SchemaGraphicObject*>(startItems.first());
523 newArrow->setZValue(-1000.0);
530 SIGNAL(MakeGraphConnection(QString, QString, QString)),
532 SLOT(
DrawArrow(QString, QString, QString)));
539 QGraphicsScene::mouseReleaseEvent(mouseEvent);
588 ItemMap.insert(class_name,
object);
601 QString class_name = QString::fromStdString(
CurrentObject->GetClass()->get_name());
631 item->update_arrows();
642 item->update_arrows();
651 QString class_name = QString::fromStdString(
CurrentObject->GetClass()->get_name());
654 QStringList super_class_list;
655 QList<QPointF> positions;
658 if (direct_classes !=
nullptr) {
659 for (std::string* cl_name : *direct_classes) {
660 super_class_list.push_back(QString::fromStdString(*cl_name));
661 positions.push_back({ 0, 0 });
672 QString class_name = QString::fromStdString(
CurrentObject->GetClass()->get_name());
675 QStringList super_class_list;
676 QList<QPointF> positions;
679 if (all_classes !=
nullptr) {
680 for (
const OksClass* cl : *all_classes) {
681 super_class_list.push_back(QString::fromStdString(cl->get_name()));
682 positions.push_back({ 0, 0 });
693 QString class_name = QString::fromStdString(
CurrentObject->GetClass()->get_name());
696 QStringList sub_class_list;
697 QList<QPointF> positions;
700 if (all_classes !=
nullptr) {
701 for (
const OksClass* cl : *all_classes) {
702 sub_class_list.push_back(QString::fromStdString(cl->get_name()));
703 positions.push_back({ 0, 0 });
714 QString class_name = QString::fromStdString(
CurrentObject->GetClass()->get_name());
717 QStringList relationship_classes;
718 QList<QPointF> positions;
720 const std::list<OksRelationship*>* direct_relationship_list = class_info->
direct_relationships();
721 if (direct_relationship_list !=
nullptr) {
723 relationship_classes.push_back(QString::fromStdString(rl->get_type()));
724 positions.push_back({ 0, 0 });
735 QString class_name = QString::fromStdString(
CurrentObject->GetClass()->get_name());
738 QStringList relationship_classes;
739 QList<QPointF> positions;
741 const std::list<OksRelationship*>* all_relationship_list = class_info->
all_relationships();
742 if (all_relationship_list !=
nullptr) {
744 relationship_classes.push_back(QString::fromStdString(rl->get_type()));
745 positions.push_back({ 0, 0 });
776 if (!
ItemMap.contains(ClassName) || !
ItemMap.contains(RelationshipType)) {
786 if (SchemaRelationship !=
nullptr) {
794 QString::fromStdString(SchemaRelationship->
get_name()),
795 RelationshipCardinality);
798 newArrow->setZValue(-1000.0);
static KernelWrapper & GetInstance()
QString GetCardinalityStringRelationship(dunedaq::oks::OksRelationship *SchemaRelationship) const
dunedaq::oks::OksClass * FindClass(std::string ClassName) const
bool GetInheritanceMode() const
bool IsFileWritable(const std::string &FileName) const
static void launch(QString class_name)
static QString createNewClass()
SchemaGraphicNote(const QString &name, const QString &text, QGraphicsObject *parent=nullptr)
void AddArrow(SchemaGraphicSegmentedArrow *Arrow)
Arrow API.
SchemaGraphicObject(QString &ClassName, SchemaGraphicsScene *scene, QGraphicsObject *parent=nullptr)
QString GetClassName() const
dunedaq::oks::OksClass * GetClass() const
SchemaGraphicSegmentedArrow(SchemaGraphicObject *StartItem, SchemaGraphicObject *EndItem, int connection_count, bool IsInheritance, bool IsComposite, QString ArrowName, QString ArrowCardinality, QGraphicsItem *parent=nullptr)
QStringList AddItemsToScene(QStringList SchemaClasses, QList< QPointF > Positions)
bool m_inherited_properties_visible
SchemaGraphicsScene(QObject *parent=nullptr)
QAction * m_add_direct_super_classes
void AddAllSubClassesSlot()
QAction * m_toggle_highlight_active
QAction * m_toggle_highlight_abstract
void ToggleHighlightActive()
void AddDirectRelationshipClassesSlot()
void ToggleHighlightClass()
void AddAllRelationshipClassesSlot()
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
bool m_highlight_abstract
QAction * m_add_direct_relationship_classes
void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
Drag & Drop.
void modified(bool state)
void ToggleHighlightAbstract()
QAction * m_toggle_indirect_infos
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
std::set< SchemaGraphicNote * > m_notes
void add_note_slot(SchemaGraphicNote *)
QAction * m_toggle_default
SchemaGraphicSegmentedArrow * m_current_arrow
void dropEvent(QGraphicsSceneDragDropEvent *event)
QAction * m_toggle_highlight_class
void add_notes(QStringList notes, QList< QPointF > positions)
QGraphicsLineItem * m_line
void ToggleIndirectInfos()
QAction * m_add_all_sub_classes
QMap< QString, SchemaGraphicObject * > ItemMap
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
void AddDirectSuperClassesSlot()
void add_class_slot(QString)
void DrawArrow(QString ClassName, QString RelationshipType, QString RelationshipName)
void remove_note_object(SchemaGraphicNote *obj)
QAction * m_add_all_super_classes
QMetaObject::Connection m_addclass_connection
SchemaGraphicObject * CurrentObject
SchemaGraphicNote * m_current_note
void AddAllSuperClassesSlot()
void RemoveItemFromScene(QGraphicsItem *item)
void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
void RemoveClassObject(SchemaGraphicObject *Object)
void cancel_note_slot(SchemaGraphicNote *)
QAction * m_add_all_relationship_classes
SchemaNoteEditor(SchemaGraphicNote *note, QWidget *parent=0)
SchemaRelationshipEditor(dunedaq::oks::OksClass *Class, dunedaq::oks::OksRelationship *Relationship, QWidget *parent=nullptr)
const FList * all_sub_classes() const noexcept
OksRelationship * find_direct_relationship(const std::string &name) const noexcept
Find direct relationship.
std::list< OksClass *, boost::fast_pool_allocator< OksClass * > > FList
void add_super_class(const std::string &name)
const FList * all_super_classes() const noexcept
const std::list< OksRelationship * > * direct_relationships() const noexcept
const std::list< std::string * > * direct_super_classes() const noexcept
const std::list< OksRelationship * > * all_relationships() const noexcept
bool get_is_composite() const noexcept
const std::string & get_name() const noexcept