-
Notifications
You must be signed in to change notification settings - Fork 2
/
DocumentEntry.cpp
100 lines (78 loc) · 2.13 KB
/
DocumentEntry.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "DocumentEntry.h"
#include "Document.h"
#include "Enumerations.h"
#include "factories/ToolTipFactory.h"
#include "model/ModelElement.h"
#include <QtDebug>
using namespace q2d;
using namespace q2d::core;
using namespace q2d::gui;
using namespace q2d::model;
Identifiable*
DocumentEntry::chooseParentIdentifier(Identifiable* document, Identifiable* parentEntry){
if(parentEntry == nullptr){ return document; }
return parentEntry;
}
DocumentEntry::DocumentEntry(QString id,
enums::DocumentEntryType type, Document* document,
DocumentEntry* parent)
: QObject(document),
Identifiable(id, chooseParentIdentifier(document, parent)) {
Q_CHECK_PTR(document);
m_type = type;
m_modelElement = nullptr;
m_schematicElement = nullptr;
m_parent = parent;
m_document = document;
}
void
DocumentEntry::setModelElement(ModelElement* modelElement) {
Q_CHECK_PTR(modelElement);
m_modelElement = modelElement;
m_modelElement->setRelatedEntry(this);
this->slot_updateToolTip();
// connect signals and slots
connect(m_modelElement, &ModelElement::signal_changed,
this, &DocumentEntry::slot_updateToolTip);
}
void
DocumentEntry::setSchematicElement(SchematicElement* schematicElement) {
Q_CHECK_PTR(schematicElement);
m_schematicElement = schematicElement;
this->slot_updateToolTip();
}
q2d::enums::DocumentEntryType
DocumentEntry::type() const {
return m_type;
}
ModelElement*
DocumentEntry::modelElement() const {
return m_modelElement;
}
SchematicElement*
DocumentEntry::schematicElement() const {
return m_schematicElement;
}
DocumentEntry*
DocumentEntry::parent() const {
return m_parent;
}
Document*
DocumentEntry::document() const {
return m_document;
}
Model*
DocumentEntry::model() const {
return m_document->model();
}
Schematic*
DocumentEntry::scene() const {
return m_document->schematic();
}
void
DocumentEntry::slot_updateToolTip() {
if (m_schematicElement == nullptr) {
return;
}
m_schematicElement->setToolTip(factories::ToolTipFactory::generateToolTip(this));
}