LCOV - code coverage report
Current view: top level - dbe/apps/SchemaEditor - SchemaGraphicsScene.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 473 0
Test Date: 2026-10-11 15:05:20 Functions: 0.0 % 42 0

            Line data    Source code
       1              : /// Including QT Headers
       2              : #include <QEvent>
       3              : #include <QGraphicsSceneDragDropEvent>
       4              : #include <QMimeData>
       5              : #include <QSettings>
       6              : 
       7              : #include <QWidget>
       8              : 
       9              : #include <QApplication>
      10              : #include <QMenu>
      11              : /// Including Schema Editor
      12              : #include "dbe/SchemaClassEditor.hpp"
      13              : #include "dbe/SchemaGraphicNote.hpp"
      14              : #include "dbe/SchemaGraphicObject.hpp"
      15              : #include "dbe/SchemaGraphicSegmentedArrow.hpp"
      16              : #include "dbe/SchemaGraphicsScene.hpp"
      17              : #include "dbe/SchemaKernelWrapper.hpp"
      18              : #include "dbe/SchemaNoteEditor.hpp"
      19              : #include "dbe/SchemaRelationshipEditor.hpp"
      20              : 
      21              : using namespace dunedaq::oks;
      22              : 
      23            0 : dbse::SchemaGraphicsScene::SchemaGraphicsScene(QObject* parent)
      24              :   : QGraphicsScene(parent)
      25            0 :   , m_line(nullptr)
      26            0 :   , m_context_menu(nullptr)
      27            0 :   , CurrentObject(nullptr)
      28            0 :   , m_current_arrow(nullptr)
      29            0 :   , m_modified(false)
      30              : {
      31            0 :   setSceneRect(QRectF(0, 0, 10000, 10000));
      32              : 
      33            0 :   QSettings settings;
      34            0 :   settings.beginGroup("view defaults");
      35              : 
      36            0 :   m_inherited_properties_visible = settings.value("show_inherited", false).toBool();
      37            0 :   m_highlight_abstract = settings.value("highlight_abstract", false).toBool();
      38            0 :   m_highlight_active = settings.value("highlight_active", false).toBool();
      39            0 :   m_show_defaults = settings.value("show_default", false).toBool();
      40              : 
      41            0 :   CreateActions();
      42            0 : }
      43              : 
      44            0 : dbse::SchemaGraphicsScene::~SchemaGraphicsScene() {}
      45              : 
      46              : void
      47            0 : dbse::SchemaGraphicsScene::CreateActions()
      48              : {
      49              :   // Add new class
      50            0 :   m_add_class = new QAction("&Add new class", this);
      51            0 :   connect(m_add_class, SIGNAL(triggered()), this, SLOT(new_class_slot()));
      52              : 
      53              :   // Edit current class
      54            0 :   m_edit_class = new QAction("&Edit class", this);
      55            0 :   connect(m_edit_class, SIGNAL(triggered()), this, SLOT(EditClassSlot()));
      56              : 
      57              :   // Toggle inherited properties of all classes in view
      58            0 :   m_toggle_indirect_infos = new QAction("Show &inherited properties", this);
      59            0 :   m_toggle_indirect_infos->setCheckable(true);
      60            0 :   m_toggle_indirect_infos->setChecked(m_inherited_properties_visible);
      61            0 :   connect(m_toggle_indirect_infos, SIGNAL(triggered()), this, SLOT(ToggleIndirectInfos()));
      62              : 
      63              :   // Toggle highlighting of all classes in active schema
      64            0 :   m_toggle_highlight_active = new QAction("&Highlight classes in active schema", this);
      65            0 :   m_toggle_highlight_active->setCheckable(true);
      66            0 :   m_toggle_highlight_active->setChecked(m_highlight_active);
      67            0 :   connect(m_toggle_highlight_active, SIGNAL(triggered()), this, SLOT(ToggleHighlightActive()));
      68              : 
      69              :   // Toggle highlighting of all abstract classes in view
      70            0 :   m_toggle_highlight_abstract = new QAction("&Highlight abstract classes in view", this);
      71            0 :   m_toggle_highlight_abstract->setCheckable(true);
      72            0 :   m_toggle_highlight_abstract->setChecked(m_highlight_abstract);
      73            0 :   connect(m_toggle_highlight_abstract, SIGNAL(triggered()), this, SLOT(ToggleHighlightAbstract()));
      74              : 
      75              :   // Toggle displaying default values of attributes
      76            0 :   m_toggle_default = new QAction("Show &default values of attributes", this);
      77            0 :   m_toggle_default->setCheckable(true);
      78            0 :   m_toggle_default->setChecked(m_show_defaults);
      79            0 :   connect(m_toggle_default, SIGNAL(triggered()), this, SLOT(ToggleDefault()));
      80              : 
      81              :   // Toggle highlighting of current class
      82            0 :   m_toggle_highlight_class = new QAction("&Highlight this class", this);
      83            0 :   m_toggle_highlight_class->setCheckable(true);
      84            0 :   connect(m_toggle_highlight_class, SIGNAL(triggered()), this, SLOT(ToggleHighlightClass()));
      85              : 
      86            0 :   m_add_note = new QAction("&Add note to view", this);
      87            0 :   connect(m_add_note, SIGNAL(triggered()), this, SLOT(new_note_slot()));
      88              : 
      89            0 :   m_edit_note = new QAction("&Edit note", this);
      90            0 :   connect(m_edit_note, SIGNAL(triggered()), this, SLOT(edit_note_slot()));
      91              : 
      92            0 :   m_remove_note = new QAction("&Remove note", this);
      93            0 :   connect(m_remove_note, SIGNAL(triggered()), this, SLOT(remove_note_slot()));
      94              : 
      95              :   // Show superclasses of the current class
      96            0 :   m_add_direct_super_classes = new QAction("Add direct &superclasses to view", this);
      97            0 :   connect(m_add_direct_super_classes, SIGNAL(triggered()), this, SLOT(AddDirectSuperClassesSlot()));
      98              : 
      99              :   // Show relationship classes of the current clas
     100            0 :   m_add_direct_relationship_classes = new QAction("Add direct &relationship classes to view", this);
     101            0 :   connect(m_add_direct_relationship_classes, SIGNAL(triggered()), this, SLOT(AddDirectRelationshipClassesSlot()));
     102              : 
     103              :   // Show superclasses of the current class
     104            0 :   m_add_all_super_classes = new QAction("Add all &superclasses to view", this);
     105            0 :   connect(m_add_all_super_classes, SIGNAL(triggered()), this, SLOT(AddAllSuperClassesSlot()));
     106              : 
     107              :   // Show subclasses of the current clas
     108            0 :   m_add_all_sub_classes = new QAction("Add all s&ubclasses to view", this);
     109            0 :   connect(m_add_all_sub_classes, SIGNAL(triggered()), this, SLOT(AddAllSubClassesSlot()));
     110              : 
     111              :   // Show indirect relationship classes of the current class
     112            0 :   m_add_all_relationship_classes = new QAction("Add all &relationship classes to view", this);
     113            0 :   connect(m_add_all_relationship_classes, SIGNAL(triggered()), this, SLOT(AddAllRelationshipClassesSlot()));
     114              : 
     115              :   // Remove class
     116            0 :   m_remove_class = new QAction("&Remove Class from view", this);
     117            0 :   connect(m_remove_class, SIGNAL(triggered()), this, SLOT(RemoveClassSlot()));
     118              : 
     119              :   // Remove arrow
     120            0 :   m_remove_arrow = new QAction("&Remove Arrow", this);
     121            0 :   connect(m_remove_arrow, SIGNAL(triggered()), this, SLOT(RemoveArrowSlot()));
     122              : 
     123            0 :   m_save = new QAction("&Save view", this);
     124            0 :   connect(m_save, SIGNAL(triggered()), this, SLOT(requestSave()));
     125              : 
     126            0 :   m_move = new QAction("&Move scene", this);
     127            0 :   connect(m_move, SIGNAL(triggered()), this, SLOT(moveScene()));
     128            0 : }
     129              : 
     130              : void
     131            0 : dbse::SchemaGraphicsScene::dragEnterEvent(QGraphicsSceneDragDropEvent* event)
     132              : {
     133            0 :   if (event->mimeData()->hasFormat("application/vnd.text.list")) {
     134            0 :     event->accept();
     135              :   }
     136            0 : }
     137              : 
     138              : void
     139            0 : dbse::SchemaGraphicsScene::dragMoveEvent(QGraphicsSceneDragDropEvent* event)
     140              : {
     141            0 :   if (event->mimeData()->hasFormat("application/vnd.text.list")) {
     142            0 :     event->accept();
     143              :   }
     144            0 : }
     145              : 
     146              : void
     147            0 : dbse::SchemaGraphicsScene::dropEvent(QGraphicsSceneDragDropEvent* event)
     148              : {
     149            0 :   QByteArray encodedData = event->mimeData()->data("application/vnd.text.list");
     150            0 :   QDataStream stream(&encodedData, QIODevice::ReadOnly);
     151              : 
     152            0 :   if (stream.atEnd()) {
     153            0 :     return;
     154              :   }
     155              : 
     156            0 :   QStringList schema_classes;
     157            0 :   while (!stream.atEnd()) {
     158            0 :     QString class_name;
     159            0 :     stream >> class_name;
     160            0 :     schema_classes.append(class_name);
     161            0 :   }
     162              : 
     163            0 :   QList<QPointF> positions;
     164            0 :   for (int i = 0; i < schema_classes.size(); ++i) {
     165            0 :     positions.push_back(event->scenePos());
     166              :   }
     167              : 
     168            0 :   AddItemsToScene(schema_classes, positions);
     169            0 : }
     170              : 
     171              : void
     172            0 : dbse::SchemaGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
     173              : {
     174            0 :   if (m_context_menu == nullptr) {
     175            0 :     m_context_menu = new QMenu();
     176            0 :     m_context_menu->addAction(m_add_class);
     177            0 :     m_context_menu->addAction(m_add_note);
     178            0 :     m_context_menu->addAction(m_toggle_indirect_infos);
     179            0 :     m_context_menu->addAction(m_toggle_highlight_abstract);
     180            0 :     m_context_menu->addAction(m_toggle_highlight_active);
     181            0 :     m_context_menu->addAction(m_toggle_default);
     182              : 
     183            0 :     m_seperator_pos = m_context_menu->actions().size();
     184            0 :     m_context_menu->addSeparator();
     185              : 
     186            0 :     m_class_pos = m_context_menu->actions().size();
     187            0 :     m_context_menu->addAction(m_edit_class);
     188            0 :     m_context_menu->addAction(m_remove_class);
     189            0 :     m_context_menu->addAction(m_toggle_highlight_class);
     190            0 :     m_context_menu->addSeparator();
     191              : 
     192            0 :     m_context_menu->addAction(m_add_direct_super_classes);
     193            0 :     m_context_menu->addAction(m_add_direct_relationship_classes);
     194            0 :     m_context_menu->addAction(m_add_all_super_classes);
     195            0 :     m_context_menu->addAction(m_add_all_sub_classes);
     196            0 :     m_context_menu->addAction(m_add_all_sub_classes);
     197            0 :     m_context_menu->addAction(m_add_all_relationship_classes);
     198              : 
     199            0 :     m_arrow_pos = m_context_menu->actions().size();
     200            0 :     m_context_menu->addAction(m_remove_arrow);
     201              : 
     202            0 :     m_note_pos = m_context_menu->actions().size();
     203            0 :     m_context_menu->addAction(m_edit_note);
     204            0 :     m_context_menu->addAction(m_remove_note);
     205              : 
     206            0 :     m_context_menu->addSeparator();
     207            0 :     m_save_pos = m_context_menu->actions().size();
     208            0 :     m_context_menu->addAction(m_save);
     209            0 :     m_context_menu->addAction(m_move);
     210              :   }
     211              : 
     212            0 :   bool active = KernelWrapper::GetInstance().IsActive();
     213            0 :   m_context_menu->actions().at(0)->setVisible(active);
     214              : 
     215            0 :   for (int item = 1; item < m_seperator_pos; item++) {
     216            0 :     m_context_menu->actions().at(item)->setVisible(true);
     217              :   }
     218              : 
     219              :   // Set all other items invisible
     220            0 :   const auto nitems = m_context_menu->actions().size();
     221            0 :   for (int item = m_seperator_pos; item < nitems; item++) {
     222            0 :     m_context_menu->actions().at(item)->setVisible(false);
     223              :   }
     224              : 
     225            0 :   if (ItemMap.size() > 0) {
     226            0 :     m_context_menu->actions().at(m_save_pos - 1)->setVisible(true);
     227            0 :     m_context_menu->actions().at(m_save_pos + 1)->setVisible(true);
     228              :   }
     229            0 :   if (m_modified && ItemMap.size() > 0) {
     230            0 :     m_context_menu->actions().at(m_save_pos)->setVisible(true);
     231              :   }
     232              : 
     233            0 :   if (itemAt(event->scenePos(), QTransform())) {
     234              :     // Something under mouse pointer, set additional items visible
     235              :     // depending on what it is
     236            0 :     m_context_menu->actions().at(m_seperator_pos)->setVisible(true);
     237              : 
     238            0 :     auto object = dynamic_cast<SchemaGraphicObject*>(itemAt(event->scenePos(), QTransform()));
     239            0 :     auto arrow = dynamic_cast<SchemaGraphicSegmentedArrow*>(itemAt(event->scenePos(), QTransform()));
     240            0 :     auto note = dynamic_cast<SchemaGraphicNote*>(itemAt(event->scenePos(), QTransform()));
     241              : 
     242            0 :     if (object != nullptr) {
     243            0 :       CurrentObject = object;
     244            0 :       m_toggle_highlight_class->setChecked(CurrentObject->highlighted());
     245              : 
     246            0 :       auto filename = CurrentObject->GetClass()->get_file()->get_full_file_name();
     247            0 :       bool writable = KernelWrapper::GetInstance().IsFileWritable(filename);
     248            0 :       m_context_menu->actions().at(m_class_pos)->setVisible(writable);
     249              : 
     250            0 :       for (int item = m_class_pos + 1; item < m_arrow_pos; item++) {
     251            0 :         m_context_menu->actions().at(item)->setVisible(true);
     252              :       }
     253            0 :     } else if (arrow != nullptr) {
     254            0 :       m_context_menu->actions().at(m_arrow_pos)->setVisible(true);
     255            0 :       m_current_arrow = arrow;
     256            0 :     } else if (note != nullptr) {
     257            0 :       for (int item = m_note_pos; item < nitems; item++) {
     258            0 :         m_context_menu->actions().at(item)->setVisible(true);
     259              :       }
     260            0 :       m_current_note = note;
     261              :     }
     262              :   }
     263            0 :   m_current_pos = event->scenePos();
     264            0 :   m_context_menu->exec(event->screenPos());
     265            0 : }
     266              : 
     267              : QStringList
     268            0 : dbse::SchemaGraphicsScene::AddItemsToScene(QStringList SchemaClasses, QList<QPointF> Positions)
     269              : {
     270            0 :   QStringList missingItems{};
     271              : 
     272            0 :   for (QString& ClassName : SchemaClasses) {
     273            0 :     if (!ItemMap.contains(ClassName)) {
     274              : 
     275            0 :       if (!KernelWrapper::GetInstance().FindClass(ClassName.toStdString())) {
     276            0 :         std::cout << "ERROR: class " << ClassName.toStdString() << " not found" << std::endl;
     277            0 :         missingItems.append(ClassName);
     278            0 :         continue;
     279              :       }
     280              : 
     281            0 :       SchemaGraphicObject* Object = new SchemaGraphicObject(ClassName, this);
     282            0 :       Object->setPos(Positions.at(SchemaClasses.indexOf(ClassName)));
     283            0 :       addItem(Object);
     284              :       /// Updating item list
     285            0 :       ItemMap.insert(ClassName, Object);
     286              :     }
     287              :   }
     288              : 
     289            0 :   for (QString& ClassName : ItemMap.keys()) {
     290            0 :     OksClass* ClassInfo = KernelWrapper::GetInstance().FindClass(ClassName.toStdString());
     291              : 
     292            0 :     const std::list<OksRelationship*>* DirectRelationshipList = ClassInfo->direct_relationships();
     293            0 :     const std::list<std::string*>* DirectSuperClassesList = ClassInfo->direct_super_classes();
     294              : 
     295            0 :     std::map<std::string, unsigned int> arrow_count;
     296              : 
     297              :     //// PLotting relationships
     298            0 :     if (DirectRelationshipList != nullptr) {
     299            0 :       for (OksRelationship* ClassRelationship : *(DirectRelationshipList)) {
     300            0 :         auto rct = ClassRelationship->get_class_type()->get_name();
     301            0 :         QString RelationshipClassType = QString::fromStdString(rct);
     302              : 
     303            0 :         if (ItemMap.contains(RelationshipClassType)) //&& !ItemMap[ClassName]->HasArrow (
     304              :                                                      // ItemMap[RelationshipClassType] ) )
     305              :         {
     306            0 :           QString SchemaCardinality =
     307            0 :             KernelWrapper::GetInstance().GetCardinalityStringRelationship(ClassRelationship) + " ";
     308            0 :           SchemaGraphicSegmentedArrow* NewArrow =
     309            0 :             new SchemaGraphicSegmentedArrow(ItemMap[ClassName],
     310            0 :                                             ItemMap[RelationshipClassType],
     311            0 :                                             arrow_count[rct],
     312              :                                             false,
     313            0 :                                             ClassRelationship->get_is_composite(),
     314            0 :                                             QString::fromStdString(ClassRelationship->get_name()),
     315            0 :                                             SchemaCardinality);
     316            0 :           ItemMap[ClassName]->AddArrow(NewArrow);
     317            0 :           ItemMap[RelationshipClassType]->AddArrow(NewArrow);
     318            0 :           addItem(NewArrow);
     319              :           // NewArrow->SetLabelScene(this);
     320            0 :           NewArrow->setZValue(-1000.0);
     321            0 :           NewArrow->UpdatePosition();
     322            0 :           arrow_count[rct]++;
     323            0 :         }
     324            0 :       }
     325              :     }
     326              : 
     327              :     /// Plotting the superclasses
     328            0 :     if (DirectSuperClassesList != nullptr) {
     329            0 :       for (std::string* SuperClassNameStd : *(DirectSuperClassesList)) {
     330            0 :         QString SuperClassName = QString::fromStdString(*SuperClassNameStd);
     331              : 
     332            0 :         if (ItemMap.contains(SuperClassName)) // && !ItemMap[ClassName]->HasArrow (
     333              :                                               // ItemMap[SuperClassName] ) )
     334              :         {
     335            0 :           SchemaGraphicSegmentedArrow* NewArrow = new SchemaGraphicSegmentedArrow(
     336            0 :             ItemMap[ClassName], ItemMap[SuperClassName], arrow_count[*SuperClassNameStd], true, false, "", "");
     337            0 :           ItemMap[ClassName]->AddArrow(NewArrow);
     338            0 :           ItemMap[SuperClassName]->AddArrow(NewArrow);
     339            0 :           addItem(NewArrow);
     340              :           // NewArrow->SetLabelScene(this);
     341            0 :           NewArrow->setZValue(-1000.0);
     342            0 :           NewArrow->UpdatePosition();
     343            0 :           arrow_count[*SuperClassNameStd]++;
     344              :         }
     345            0 :       }
     346              :     }
     347            0 :   }
     348            0 :   modified(true);
     349            0 :   return missingItems;
     350            0 : }
     351              : 
     352              : void
     353            0 : dbse::SchemaGraphicsScene::RemoveItemFromScene(QGraphicsItem* item)
     354              : {
     355            0 :   removeItem(item);
     356            0 :   modified(true);
     357            0 : }
     358              : 
     359              : void
     360            0 : dbse::SchemaGraphicsScene::add_notes(QStringList notes, QList<QPointF> positions)
     361              : {
     362            0 :   for (int index = 0; index < notes.size(); index++) {
     363            0 :     auto note = new SchemaGraphicNote(QString("#" + QString::number(m_next_note++)), notes.at(index));
     364            0 :     note->setPos(positions.at(index));
     365            0 :     m_notes.insert(note);
     366            0 :     addItem(note);
     367              :   }
     368            0 : }
     369              : void
     370            0 : dbse::SchemaGraphicsScene::remove_note_object(SchemaGraphicNote* note)
     371              : {
     372            0 :   if (note == nullptr) {
     373              :     return;
     374              :   }
     375            0 :   RemoveItemFromScene(note);
     376              : }
     377              : 
     378              : void
     379            0 : dbse::SchemaGraphicsScene::RemoveClassObject(SchemaGraphicObject* Object)
     380              : {
     381            0 :   if (Object == nullptr) {
     382              :     return;
     383              :   }
     384              : 
     385            0 :   Object->RemoveArrows();
     386            0 :   RemoveItemFromScene(Object);
     387            0 :   ItemMap.remove(Object->GetClassName());
     388              : }
     389              : 
     390              : void
     391            0 : dbse::SchemaGraphicsScene::CleanItemMap()
     392              : {
     393            0 :   ItemMap.clear();
     394            0 : }
     395              : 
     396              : void
     397            0 : dbse::SchemaGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent)
     398              : {
     399            0 :   if (itemAt(mouseEvent->scenePos(), QTransform())) {
     400              :     // Save position of item under mouse so we can see if it has been
     401              :     // moved in mouseReleaseEvent
     402            0 :     m_mouse_item_pos = itemAt(mouseEvent->scenePos(), QTransform())->pos();
     403              :   }
     404            0 :   if (mouseEvent->button() != Qt::LeftButton) {
     405              :     return;
     406              :   }
     407              : 
     408            0 :   if (mouseEvent->widget()->cursor().shape() == Qt::CrossCursor) {
     409            0 :     m_line = new QGraphicsLineItem(QLineF(mouseEvent->scenePos(), mouseEvent->scenePos()));
     410            0 :     m_line->setPen(QPen(Qt::black, 2));
     411            0 :     addItem(m_line);
     412            0 :     modified(true);
     413            0 :     return;
     414              :   }
     415              : 
     416            0 :   QGraphicsScene::mousePressEvent(mouseEvent);
     417              : }
     418              : 
     419              : void
     420            0 : dbse::SchemaGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent)
     421              : {
     422            0 :   if (m_line != nullptr) {
     423            0 :     QLineF newLine(m_line->line().p1(), mouseEvent->scenePos());
     424            0 :     m_line->setLine(newLine);
     425              :   } else {
     426            0 :     QGraphicsScene::mouseMoveEvent(mouseEvent);
     427              :   }
     428            0 : }
     429              : 
     430              : void
     431            0 : dbse::SchemaGraphicsScene::ClearModified()
     432              : {
     433            0 :   modified(false);
     434            0 : }
     435              : 
     436              : void
     437            0 : dbse::SchemaGraphicsScene::modified(bool state)
     438              : {
     439            0 :   m_modified = state;
     440            0 :   emit sceneModified(state);
     441            0 : }
     442              : 
     443              : void
     444            0 : dbse::SchemaGraphicsScene::moveScene()
     445              : {
     446            0 :   qreal minx = 1e6;
     447            0 :   qreal miny = 1e6;
     448            0 :   for (auto obj : ItemMap) {
     449            0 :     auto pos = obj->pos();
     450            0 :     if (pos.x() < minx) {
     451              :       minx = pos.x();
     452              :     }
     453            0 :     if (pos.y() < miny) {
     454              :       miny = pos.y();
     455              :     }
     456              :   }
     457            0 :   qreal xoffset = m_current_pos.x() - minx;
     458            0 :   qreal yoffset = m_current_pos.y() - miny;
     459            0 :   for (auto obj : ItemMap) {
     460            0 :     obj->setX(obj->x() + xoffset);
     461            0 :     obj->setY(obj->y() + yoffset);
     462            0 :     obj->update_arrows();
     463              :   }
     464            0 :   for (auto obj : m_notes) {
     465            0 :     obj->setX(obj->x() + xoffset);
     466            0 :     obj->setY(obj->y() + yoffset);
     467              :   }
     468            0 :   update();
     469            0 :   modified(true);
     470            0 : }
     471              : 
     472              : void
     473            0 : dbse::SchemaGraphicsScene::requestSave()
     474              : {
     475            0 :   emit saveRequested();
     476            0 : }
     477              : void
     478            0 : dbse::SchemaGraphicsScene::modified_slot()
     479              : {
     480            0 :   modified(true);
     481            0 : }
     482              : void
     483            0 : dbse::SchemaGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent)
     484              : {
     485            0 :   if (itemAt(mouseEvent->scenePos(), QTransform())) {
     486            0 :     auto item = itemAt(mouseEvent->scenePos(), QTransform());
     487            0 :     if (!m_mouse_item_pos.isNull()) {
     488            0 :       if (m_mouse_item_pos != item->pos()) {
     489            0 :         modified(true);
     490              :       }
     491            0 :       m_mouse_item_pos = QPointF();
     492              :     }
     493              :   }
     494            0 :   if (m_line != nullptr) {
     495            0 :     QList<QGraphicsItem*> startItems = items(m_line->line().p1());
     496              : 
     497            0 :     if (startItems.count() && startItems.first() == m_line) {
     498            0 :       startItems.removeFirst();
     499              :     }
     500              : 
     501            0 :     QList<QGraphicsItem*> endItems = items(m_line->line().p2());
     502              : 
     503            0 :     if (endItems.count() && endItems.first() == m_line) {
     504            0 :       endItems.removeFirst();
     505              :     }
     506              : 
     507            0 :     RemoveItemFromScene(m_line);
     508            0 :     delete m_line;
     509              : 
     510            0 :     if (startItems.count() > 0 && endItems.count() > 0 && startItems.first() != endItems.first()) {
     511              : 
     512            0 :       bool Inheritance = KernelWrapper::GetInstance().GetInheritanceMode();
     513            0 :       SchemaGraphicObject* startItem = qgraphicsitem_cast<SchemaGraphicObject*>(startItems.first());
     514            0 :       SchemaGraphicObject* endItem = qgraphicsitem_cast<SchemaGraphicObject*>(endItems.first());
     515              : 
     516            0 :       if (Inheritance) {
     517            0 :         startItem->GetClass()->add_super_class(endItem->GetClassName().toStdString());
     518              :         /// Create arrow
     519            0 :         SchemaGraphicSegmentedArrow* newArrow =
     520            0 :           new SchemaGraphicSegmentedArrow(startItem, endItem, 0, Inheritance, true, "", "");
     521            0 :         startItem->AddArrow(newArrow);
     522            0 :         endItem->AddArrow(newArrow);
     523            0 :         newArrow->setZValue(-1000.0);
     524            0 :         addItem(newArrow);
     525              :         // newArrow->SetLabelScene(this);
     526            0 :         newArrow->UpdatePosition();
     527              :       } else {
     528            0 :         SchemaRelationshipEditor* Editor = new SchemaRelationshipEditor(startItem->GetClass(), endItem->GetClassName());
     529            0 :         connect(Editor,
     530              :                 SIGNAL(MakeGraphConnection(QString, QString, QString)),
     531              :                 this,
     532              :                 SLOT(DrawArrow(QString, QString, QString)));
     533            0 :         Editor->show();
     534              :       }
     535              :     }
     536            0 :   }
     537              : 
     538            0 :   m_line = nullptr;
     539            0 :   QGraphicsScene::mouseReleaseEvent(mouseEvent);
     540            0 : }
     541              : 
     542              : void
     543            0 : dbse::SchemaGraphicsScene::edit_note_slot()
     544              : {
     545            0 :   m_current_note->open_editor();
     546            0 : }
     547              : 
     548              : void
     549            0 : dbse::SchemaGraphicsScene::remove_note_slot()
     550              : {
     551            0 :   remove_note_object(m_current_note);
     552            0 : }
     553              : 
     554              : void
     555            0 : dbse::SchemaGraphicsScene::add_note_slot(SchemaGraphicNote* note)
     556              : {
     557            0 :   m_notes.insert(note);
     558            0 :   addItem(note);
     559            0 :   modified(true);
     560            0 : }
     561              : void
     562            0 : dbse::SchemaGraphicsScene::cancel_note_slot(SchemaGraphicNote* note)
     563              : {
     564            0 :   m_notes.erase(note);
     565            0 :   delete note;
     566            0 : }
     567              : 
     568              : void
     569            0 : dbse::SchemaGraphicsScene::new_note_slot()
     570              : {
     571            0 :   auto note = new SchemaGraphicNote(QString("#") + QString::number(m_next_note++), QString());
     572            0 :   note->setPos(m_current_pos);
     573            0 :   auto editor = new SchemaNoteEditor(note);
     574            0 :   connect(editor, SIGNAL(note_accepted(SchemaGraphicNote*)), this, SLOT(add_note_slot(SchemaGraphicNote*)));
     575            0 :   connect(editor, SIGNAL(cancelled(SchemaGraphicNote*)), this, SLOT(cancel_note_slot(SchemaGraphicNote*)));
     576            0 :   editor->show();
     577            0 : }
     578              : 
     579              : void
     580            0 : dbse::SchemaGraphicsScene::add_class_slot(QString class_name)
     581              : {
     582            0 :   disconnect(m_addclass_connection);
     583              : 
     584            0 :   auto object = new SchemaGraphicObject(class_name, this);
     585            0 :   object->setPos(m_current_pos);
     586            0 :   addItem(object);
     587              :   /// Updating item list
     588            0 :   ItemMap.insert(class_name, object);
     589            0 : }
     590              : void
     591            0 : dbse::SchemaGraphicsScene::new_class_slot()
     592              : {
     593            0 :   m_addclass_connection =
     594            0 :     connect(&KernelWrapper::GetInstance(), SIGNAL(ClassCreated(QString)), this, SLOT(add_class_slot(QString)));
     595            0 :   SchemaClassEditor::createNewClass();
     596            0 : }
     597              : 
     598              : void
     599            0 : dbse::SchemaGraphicsScene::EditClassSlot()
     600              : {
     601            0 :   QString class_name = QString::fromStdString(CurrentObject->GetClass()->get_name());
     602            0 :   SchemaClassEditor::launch(class_name);
     603            0 : }
     604              : 
     605              : void
     606            0 : dbse::SchemaGraphicsScene::ToggleHighlightClass()
     607              : {
     608            0 :   CurrentObject->toggle_highlight_class();
     609            0 :   this->update();
     610            0 : }
     611              : 
     612              : void
     613            0 : dbse::SchemaGraphicsScene::ToggleHighlightActive()
     614              : {
     615            0 :   m_highlight_active = !m_highlight_active;
     616            0 :   this->update();
     617            0 : }
     618              : 
     619              : void
     620            0 : dbse::SchemaGraphicsScene::ToggleHighlightAbstract()
     621              : {
     622            0 :   m_highlight_abstract = !m_highlight_abstract;
     623            0 :   this->update();
     624            0 : }
     625              : 
     626              : void
     627            0 : dbse::SchemaGraphicsScene::ToggleDefault()
     628              : {
     629            0 :   m_show_defaults = !m_show_defaults;
     630            0 :   for (SchemaGraphicObject* item : ItemMap.values()) {
     631            0 :     item->update_arrows();
     632            0 :   }
     633            0 :   this->update();
     634            0 : }
     635              : 
     636              : void
     637            0 : dbse::SchemaGraphicsScene::ToggleIndirectInfos()
     638              : {
     639            0 :   m_inherited_properties_visible = !m_inherited_properties_visible;
     640              : 
     641            0 :   for (SchemaGraphicObject* item : ItemMap.values()) {
     642            0 :     item->update_arrows();
     643            0 :   }
     644            0 :   this->update();
     645            0 : }
     646              : 
     647              : void
     648            0 : dbse::SchemaGraphicsScene::AddDirectSuperClassesSlot()
     649              : {
     650              : 
     651            0 :   QString class_name = QString::fromStdString(CurrentObject->GetClass()->get_name());
     652            0 :   OksClass* class_info = KernelWrapper::GetInstance().FindClass(class_name.toStdString());
     653              : 
     654            0 :   QStringList super_class_list;
     655            0 :   QList<QPointF> positions;
     656              : 
     657            0 :   const std::list<std::string*>* direct_classes = class_info->direct_super_classes();
     658            0 :   if (direct_classes != nullptr) {
     659            0 :     for (std::string* cl_name : *direct_classes) {
     660            0 :       super_class_list.push_back(QString::fromStdString(*cl_name));
     661            0 :       positions.push_back({ 0, 0 });
     662              :     }
     663              :   }
     664              : 
     665            0 :   this->AddItemsToScene(super_class_list, positions);
     666            0 : }
     667              : 
     668              : void
     669            0 : dbse::SchemaGraphicsScene::AddAllSuperClassesSlot()
     670              : {
     671              : 
     672            0 :   QString class_name = QString::fromStdString(CurrentObject->GetClass()->get_name());
     673            0 :   OksClass* class_info = KernelWrapper::GetInstance().FindClass(class_name.toStdString());
     674              : 
     675            0 :   QStringList super_class_list;
     676            0 :   QList<QPointF> positions;
     677              : 
     678            0 :   const OksClass::FList* all_classes = class_info->all_super_classes();
     679            0 :   if (all_classes != nullptr) {
     680            0 :     for (const OksClass* cl : *all_classes) {
     681            0 :       super_class_list.push_back(QString::fromStdString(cl->get_name()));
     682            0 :       positions.push_back({ 0, 0 });
     683              :     }
     684              :   }
     685              : 
     686            0 :   this->AddItemsToScene(super_class_list, positions);
     687            0 : }
     688              : 
     689              : void
     690            0 : dbse::SchemaGraphicsScene::AddAllSubClassesSlot()
     691              : {
     692              : 
     693            0 :   QString class_name = QString::fromStdString(CurrentObject->GetClass()->get_name());
     694            0 :   OksClass* class_info = KernelWrapper::GetInstance().FindClass(class_name.toStdString());
     695              : 
     696            0 :   QStringList sub_class_list;
     697            0 :   QList<QPointF> positions;
     698              : 
     699            0 :   const OksClass::FList* all_classes = class_info->all_sub_classes();
     700            0 :   if (all_classes != nullptr) {
     701            0 :     for (const OksClass* cl : *all_classes) {
     702            0 :       sub_class_list.push_back(QString::fromStdString(cl->get_name()));
     703            0 :       positions.push_back({ 0, 0 });
     704              :     }
     705              :   }
     706              : 
     707            0 :   this->AddItemsToScene(sub_class_list, positions);
     708            0 : }
     709              : 
     710              : void
     711            0 : dbse::SchemaGraphicsScene::AddDirectRelationshipClassesSlot()
     712              : {
     713              : 
     714            0 :   QString class_name = QString::fromStdString(CurrentObject->GetClass()->get_name());
     715            0 :   OksClass* class_info = KernelWrapper::GetInstance().FindClass(class_name.toStdString());
     716              : 
     717            0 :   QStringList relationship_classes;
     718            0 :   QList<QPointF> positions;
     719              : 
     720            0 :   const std::list<OksRelationship*>* direct_relationship_list = class_info->direct_relationships();
     721            0 :   if (direct_relationship_list != nullptr) {
     722            0 :     for (const OksRelationship* rl : *direct_relationship_list) {
     723            0 :       relationship_classes.push_back(QString::fromStdString(rl->get_type()));
     724            0 :       positions.push_back({ 0, 0 });
     725              :     }
     726              :   }
     727              : 
     728            0 :   this->AddItemsToScene(relationship_classes, positions);
     729            0 : }
     730              : 
     731              : void
     732            0 : dbse::SchemaGraphicsScene::AddAllRelationshipClassesSlot()
     733              : {
     734              : 
     735            0 :   QString class_name = QString::fromStdString(CurrentObject->GetClass()->get_name());
     736            0 :   OksClass* class_info = KernelWrapper::GetInstance().FindClass(class_name.toStdString());
     737              : 
     738            0 :   QStringList relationship_classes;
     739            0 :   QList<QPointF> positions;
     740              : 
     741            0 :   const std::list<OksRelationship*>* all_relationship_list = class_info->all_relationships();
     742            0 :   if (all_relationship_list != nullptr) {
     743            0 :     for (const OksRelationship* rl : *all_relationship_list) {
     744            0 :       relationship_classes.push_back(QString::fromStdString(rl->get_type()));
     745            0 :       positions.push_back({ 0, 0 });
     746              :     }
     747              :   }
     748              : 
     749            0 :   this->AddItemsToScene(relationship_classes, positions);
     750            0 : }
     751              : 
     752              : void
     753            0 : dbse::SchemaGraphicsScene::RemoveClassSlot()
     754              : {
     755            0 :   if (CurrentObject == nullptr) {
     756              :     return;
     757              :   }
     758              : 
     759            0 :   CurrentObject->RemoveArrows();
     760            0 :   RemoveItemFromScene(CurrentObject);
     761            0 :   ItemMap.remove(CurrentObject->GetClassName());
     762              : }
     763              : 
     764              : void
     765            0 : dbse::SchemaGraphicsScene::RemoveArrowSlot()
     766              : {
     767            0 :   RemoveItemFromScene(m_current_arrow);
     768            0 :   m_current_arrow->GetStartItem()->RemoveArrow(m_current_arrow);
     769            0 :   m_current_arrow->GetEndItem()->RemoveArrow(m_current_arrow);
     770            0 :   m_current_arrow->RemoveArrow();
     771            0 : }
     772              : 
     773              : void
     774            0 : dbse::SchemaGraphicsScene::DrawArrow(QString ClassName, QString RelationshipType, QString RelationshipName)
     775              : {
     776            0 :   if (!ItemMap.contains(ClassName) || !ItemMap.contains(RelationshipType)) {
     777            0 :     return;
     778              :   }
     779              : 
     780            0 :   SchemaGraphicObject* startItem = ItemMap[ClassName];
     781            0 :   SchemaGraphicObject* endItem = ItemMap[RelationshipType];
     782              : 
     783            0 :   OksClass* SchemaClass = KernelWrapper::GetInstance().FindClass(ClassName.toStdString());
     784            0 :   OksRelationship* SchemaRelationship = SchemaClass->find_direct_relationship(RelationshipName.toStdString());
     785              : 
     786            0 :   if (SchemaRelationship != nullptr) {
     787            0 :     QString RelationshipCardinality = KernelWrapper::GetInstance().GetCardinalityStringRelationship(SchemaRelationship);
     788            0 :     SchemaGraphicSegmentedArrow* newArrow =
     789              :       new SchemaGraphicSegmentedArrow(startItem,
     790              :                                       endItem,
     791              :                                       0,
     792              :                                       false,
     793            0 :                                       SchemaRelationship->get_is_composite(),
     794            0 :                                       QString::fromStdString(SchemaRelationship->get_name()),
     795            0 :                                       RelationshipCardinality);
     796            0 :     startItem->AddArrow(newArrow);
     797            0 :     endItem->AddArrow(newArrow);
     798            0 :     newArrow->setZValue(-1000.0);
     799            0 :     addItem(newArrow);
     800              :     // newArrow->SetLabelScene(this);
     801            0 :     newArrow->UpdatePosition();
     802            0 :   }
     803              : }
        

Generated by: LCOV version 2.0-1