FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodeeditor/src/GraphicsViewStyle.cpp at bt · 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
/
GraphicsViewStyle.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
94 lines (75 loc) · 2.51 KB
Breadcrumbs
nodeeditor
/
src
/
GraphicsViewStyle.cpp
Copy path
File metadata and controls
94 lines (75 loc) · 2.51 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
#
include
"
GraphicsViewStyle.hpp
"
#
include
<
QtCore/QFile
>
#
include
<
QtCore/QJsonArray
>
#
include
<
QtCore/QJsonObject
>
#
include
<
QtCore/QJsonValueRef
>
#
include
"
StyleCollection.hpp
"
using
QtNodes::GraphicsViewStyle;
inline
void
initResources
()
{
Q_INIT_RESOURCE
(resources);
}
GraphicsViewStyle::GraphicsViewStyle
()
{
//
Explicit resources inialization for preventing the static initialization
//
order fiasco: https://isocpp.org/wiki/faq/ctors#static-init-order
initResources
();
//
This configuration is stored inside the compiled unit and is loaded statically
loadJsonFile
(
"
:DefaultStyle.json
"
);
}
GraphicsViewStyle::GraphicsViewStyle
(QString jsonText)
{
loadJsonText
(jsonText);
}
void
GraphicsViewStyle::setStyle
(QString jsonText)
{
GraphicsViewStyle
style
(jsonText);
StyleCollection::setGraphicsViewStyle
(style);
}
#
ifdef
STYLE_DEBUG
#
define
FLOW_VIEW_STYLE_CHECK_UNDEFINED_VALUE
(
v, variable
) \
{ \
if
(v.
type
() == QJsonValue::Undefined || v.
type
() == QJsonValue::Null) \
qWarning
() <<
"
Undefined value for parameter:
"
<< #variable; \
}
#
else
#
define
FLOW_VIEW_STYLE_CHECK_UNDEFINED_VALUE
(
v, variable
)
#
endif
#
define
FLOW_VIEW_STYLE_READ_COLOR
(
values, variable
) \
{ \
auto
valueRef = values[#variable]; \
FLOW_VIEW_STYLE_CHECK_UNDEFINED_VALUE
(valueRef, variable) \
if
(valueRef.
isArray
()) { \
auto
colorArray = valueRef.
toArray
(); \
std::vector<
int
> rgb; \
rgb.
reserve
(
3
); \
for
(
auto
it = colorArray.
begin
(); it != colorArray.
end
(); ++it) { \
rgb.
push_back
((*it).
toInt
()); \
} \
variable =
QColor
(rgb[
0
], rgb[
1
], rgb[
2
]); \
}
else
{ \
variable =
QColor
(valueRef.
toString
()); \
} \
}
#
define
FLOW_VIEW_STYLE_WRITE_COLOR
(
values, variable
) \
{ \
values[#variable] = variable.
name
(); \
}
void
GraphicsViewStyle::loadJson
(QJsonObject
const
&json)
{
QJsonValue nodeStyleValues = json[
"
GraphicsViewStyle
"
];
QJsonObject obj = nodeStyleValues.
toObject
();
FLOW_VIEW_STYLE_READ_COLOR
(obj, BackgroundColor);
FLOW_VIEW_STYLE_READ_COLOR
(obj, FineGridColor);
FLOW_VIEW_STYLE_READ_COLOR
(obj, CoarseGridColor);
}
QJsonObject
GraphicsViewStyle::toJson
()
const
{
QJsonObject obj;
FLOW_VIEW_STYLE_WRITE_COLOR
(obj, BackgroundColor);
FLOW_VIEW_STYLE_WRITE_COLOR
(obj, FineGridColor);
FLOW_VIEW_STYLE_WRITE_COLOR
(obj, CoarseGridColor);
QJsonObject root;
root[
"
GraphicsViewStyle
"
] = obj;
return
root;
}
Back
|
FazBrowse Home
|
New Git URL