FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodeeditor/src/DataFlowGraphicsScene.cpp at bt3 · BehaviorTree/nodeeditor · GitHub
BehaviorTree
/
nodeeditor
Public
forked from
l3enQ/nodeeditor
Notifications
You must be signed in to change notification settings
Fork
0
Star
4
Code
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodeeditor
/
src
/
DataFlowGraphicsScene.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
171 lines (132 loc) · 5.08 KB
Breadcrumbs
nodeeditor
/
src
/
DataFlowGraphicsScene.cpp
Copy path
File metadata and controls
171 lines (132 loc) · 5.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#
include
"
DataFlowGraphicsScene.hpp
"
#
include
"
ConnectionGraphicsObject.hpp
"
#
include
"
GraphicsView.hpp
"
#
include
"
NodeDelegateModelRegistry.hpp
"
#
include
"
NodeGraphicsObject.hpp
"
#
include
"
UndoCommands.hpp
"
#
include
<
QtWidgets/QFileDialog
>
#
include
<
QtWidgets/QGraphicsSceneMoveEvent
>
#
include
<
QtWidgets/QHeaderView
>
#
include
<
QtWidgets/QLineEdit
>
#
include
<
QtWidgets/QTreeWidget
>
#
include
<
QtWidgets/QWidgetAction
>
#
include
<
QtCore/QBuffer
>
#
include
<
QtCore/QByteArray
>
#
include
<
QtCore/QDataStream
>
#
include
<
QtCore/QDebug
>
#
include
<
QtCore/QFile
>
#
include
<
QtCore/QJsonArray
>
#
include
<
QtCore/QJsonDocument
>
#
include
<
QtCore/QJsonObject
>
#
include
<
QtCore/QtGlobal
>
#
include
<
stdexcept
>
#
include
<
utility
>
namespace
QtNodes
{
DataFlowGraphicsScene::DataFlowGraphicsScene
(DataFlowGraphModel &graphModel, QObject *parent)
: BasicGraphicsScene(graphModel, parent)
, _graphModel(graphModel)
{
connect
(&_graphModel,
&DataFlowGraphModel::inPortDataWasSet,
[
this
](NodeId
const
nodeId, PortType
const
, PortIndex
const
) {
onNodeUpdated
(nodeId); });
}
//
TODO constructor for an empyt scene?
QMenu *
DataFlowGraphicsScene::createSceneMenu
(QPointF
const
scenePos)
{
QMenu *modelMenu =
new
QMenu
();
//
Add filterbox to the context menu
auto
*txtBox =
new
QLineEdit
(modelMenu);
txtBox->
setPlaceholderText
(
QStringLiteral
(
"
Filter
"
));
txtBox->
setClearButtonEnabled
(
true
);
auto
*txtBoxAction =
new
QWidgetAction
(modelMenu);
txtBoxAction->
setDefaultWidget
(txtBox);
//
1.
modelMenu->
addAction
(txtBoxAction);
//
Add result treeview to the context menu
QTreeWidget *treeView =
new
QTreeWidget
(modelMenu);
treeView->
header
()->
close
();
auto
*treeViewAction =
new
QWidgetAction
(modelMenu);
treeViewAction->
setDefaultWidget
(treeView);
//
2.
modelMenu->
addAction
(treeViewAction);
auto
registry = _graphModel.
dataModelRegistry
();
for
(
auto
const
&cat : registry->
categories
()) {
auto
item =
new
QTreeWidgetItem
(treeView);
item->
setText
(
0
, cat);
item->
setFlags
(item->
flags
() & ~Qt::ItemIsSelectable);
}
for
(
auto
const
&assoc : registry->
registeredModelsCategoryAssociation
()) {
QList<QTreeWidgetItem *> parent = treeView->
findItems
(assoc.
second
, Qt::MatchExactly);
if
(parent.
count
() <=
0
)
continue
;
auto
item =
new
QTreeWidgetItem
(parent.
first
());
item->
setText
(
0
, assoc.
first
);
}
treeView->
expandAll
();
connect
(treeView,
&QTreeWidget::itemClicked,
[
this
, modelMenu, scenePos](QTreeWidgetItem *item,
int
) {
if
(!(item->
flags
() & (Qt::ItemIsSelectable))) {
return
;
}
this
->
undoStack
().
push
(
new
CreateCommand
(
this
, item->
text
(
0
), scenePos));
modelMenu->
close
();
});
//
Setup filtering
connect
(txtBox, &QLineEdit::textChanged, [treeView](
const
QString &text) {
QTreeWidgetItemIterator
categoryIt
(treeView, QTreeWidgetItemIterator::HasChildren);
while
(*categoryIt)
(*categoryIt++)->
setHidden
(
true
);
QTreeWidgetItemIterator
it
(treeView, QTreeWidgetItemIterator::NoChildren);
while
(*it) {
auto
modelName = (*it)->
text
(
0
);
const
bool
match = (modelName.
contains
(text, Qt::CaseInsensitive));
(*it)->
setHidden
(!match);
if
(match) {
QTreeWidgetItem *parent = (*it)->
parent
();
while
(parent) {
parent->
setHidden
(
false
);
parent = parent->
parent
();
}
}
++it;
}
});
//
make sure the text box gets focus so the user doesn't have to click on it
txtBox->
setFocus
();
//
QMenu's instance auto-destruction
modelMenu->
setAttribute
(Qt::WA_DeleteOnClose);
return
modelMenu;
}
void
DataFlowGraphicsScene::save
()
const
{
QString fileName =
QFileDialog::getSaveFileName
(
nullptr
,
tr
(
"
Open Flow Scene
"
),
QDir::homePath
(),
tr
(
"
Flow Scene Files (*.flow)
"
));
if
(!fileName.
isEmpty
()) {
if
(!fileName.
endsWith
(
"
flow
"
, Qt::CaseInsensitive))
fileName +=
"
.flow
"
;
QFile
file
(fileName);
if
(file.
open
(QIODevice::WriteOnly)) {
file.
write
(
QJsonDocument
(_graphModel.
save
()).
toJson
());
}
}
}
void
DataFlowGraphicsScene::load
()
{
QString fileName =
QFileDialog::getOpenFileName
(
nullptr
,
tr
(
"
Open Flow Scene
"
),
QDir::homePath
(),
tr
(
"
Flow Scene Files (*.flow)
"
));
if
(!
QFileInfo::exists
(fileName))
return
;
QFile
file
(fileName);
if
(!file.
open
(QIODevice::ReadOnly))
return
;
clearScene
();
QByteArray
const
wholeFile = file.
readAll
();
_graphModel.
load
(
QJsonDocument::fromJson
(wholeFile).
object
());
Q_EMIT
sceneLoaded
();
}
}
//
namespace QtNodes
Back
|
FazBrowse Home
|
New Git URL