@@ -41,6 +41,7 @@ ConfigurationSpaceScene::ConfigurationSpaceScene(QObject* parent) :
41
41
delta0(1 ),
42
42
delta1(1 ),
43
43
model(nullptr ),
44
+ collisions(nullptr ),
44
45
edges(nullptr ),
45
46
path(nullptr ),
46
47
scene(nullptr ),
@@ -73,19 +74,17 @@ ConfigurationSpaceScene::addCollision(const qreal& x, const qreal& y, const qrea
73
74
QBrush (QColor (rgb, rgb, rgb))
74
75
);
75
76
76
- rect->setParentItem (this ->scene );
77
- rect->setZValue (1 );
77
+ this ->collisions ->addToGroup (rect);
78
78
}
79
79
80
80
void
81
81
ConfigurationSpaceScene::clear ()
82
82
{
83
- QList<QGraphicsItem*> items = this ->items ();
84
-
85
- while (!items.isEmpty ())
86
- {
87
- delete items.takeFirst ();
88
- }
83
+ QGraphicsScene::clear ();
84
+ this ->collisions = nullptr ;
85
+ this ->edges = nullptr ;
86
+ this ->path = nullptr ;
87
+ this ->scene = nullptr ;
89
88
}
90
89
91
90
void
@@ -104,8 +103,6 @@ ConfigurationSpaceScene::drawConfigurationEdge(const rl::math::Vector& u, const
104
103
free ? QPen (QBrush (QColor (0 , 128 , 0 )), 0 ) : QPen (QBrush (QColor (128 , 0 , 0 )), 0 )
105
104
);
106
105
107
- line->setZValue (2 );
108
-
109
106
this ->edges ->addToGroup (line);
110
107
}
111
108
@@ -122,7 +119,7 @@ ConfigurationSpaceScene::drawConfigurationPath(const rl::plan::VectorList& path)
122
119
rl::plan::VectorList::const_iterator i = path.begin ();
123
120
rl::plan::VectorList::const_iterator j = ++path.begin ();
124
121
125
- while ( i != path.end () && j != path.end ())
122
+ for (; i != path.end () && j != path.end (); ++i, ++j )
126
123
{
127
124
QGraphicsLineItem* line = this ->addLine (
128
125
(*i)(this ->axis0 ),
@@ -132,12 +129,7 @@ ConfigurationSpaceScene::drawConfigurationPath(const rl::plan::VectorList& path)
132
129
QPen (QBrush (QColor (0 , 255 , 0 )), 0 )
133
130
);
134
131
135
- line->setZValue (3 );
136
-
137
132
this ->path ->addToGroup (line);
138
-
139
- ++i;
140
- ++j;
141
133
}
142
134
}
143
135
@@ -235,8 +227,14 @@ ConfigurationSpaceScene::init()
235
227
236
228
this ->setSceneRect (this ->scene ->boundingRect ());
237
229
238
- this ->edges = new QGraphicsItemGroup (this ->scene );
239
- this ->path = new QGraphicsItemGroup (this ->scene );
230
+ this ->collisions = this ->createItemGroup (QList<QGraphicsItem*>());
231
+ this ->collisions ->setZValue (1 );
232
+
233
+ this ->edges = this ->createItemGroup (QList<QGraphicsItem*>());
234
+ this ->edges ->setZValue (2 );
235
+
236
+ this ->path = this ->createItemGroup (QList<QGraphicsItem*>());
237
+ this ->path ->setZValue (3 );
240
238
}
241
239
242
240
void
@@ -295,6 +293,11 @@ ConfigurationSpaceScene::reset()
295
293
void
296
294
ConfigurationSpaceScene::resetEdges ()
297
295
{
296
+ if (nullptr == this ->edges )
297
+ {
298
+ return ;
299
+ }
300
+
298
301
QList<QGraphicsItem*> items = this ->edges ->childItems ();
299
302
300
303
while (!items.isEmpty ())
@@ -311,6 +314,11 @@ ConfigurationSpaceScene::resetLines()
311
314
void
312
315
ConfigurationSpaceScene::resetPath ()
313
316
{
317
+ if (nullptr == this ->path )
318
+ {
319
+ return ;
320
+ }
321
+
314
322
QList<QGraphicsItem*> items = this ->path ->childItems ();
315
323
316
324
while (!items.isEmpty ())
0 commit comments