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