@@ -41,6 +41,7 @@ ConfigurationSpaceScene::ConfigurationSpaceScene(QObject* parent) :
4141 delta0(1 ),
4242 delta1(1 ),
4343 model(nullptr ),
44+ collisions(nullptr ),
4445 edges(nullptr ),
4546 path(nullptr ),
4647 scene(nullptr ),
@@ -73,19 +74,17 @@ ConfigurationSpaceScene::addCollision(const qreal& x, const qreal& y, const qrea
7374 QBrush (QColor (rgb, rgb, rgb))
7475 );
7576
76- rect->setParentItem (this ->scene );
77- rect->setZValue (1 );
77+ this ->collisions ->addToGroup (rect);
7878}
7979
8080void
8181ConfigurationSpaceScene::clear ()
8282{
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 ;
8988}
9089
9190void
@@ -104,8 +103,6 @@ ConfigurationSpaceScene::drawConfigurationEdge(const rl::math::Vector& u, const
104103 free ? QPen (QBrush (QColor (0 , 128 , 0 )), 0 ) : QPen (QBrush (QColor (128 , 0 , 0 )), 0 )
105104 );
106105
107- line->setZValue (2 );
108-
109106 this ->edges ->addToGroup (line);
110107}
111108
@@ -122,7 +119,7 @@ ConfigurationSpaceScene::drawConfigurationPath(const rl::plan::VectorList& path)
122119 rl::plan::VectorList::const_iterator i = path.begin ();
123120 rl::plan::VectorList::const_iterator j = ++path.begin ();
124121
125- while ( i != path.end () && j != path.end ())
122+ for (; i != path.end () && j != path.end (); ++i, ++j )
126123 {
127124 QGraphicsLineItem* line = this ->addLine (
128125 (*i)(this ->axis0 ),
@@ -132,12 +129,7 @@ ConfigurationSpaceScene::drawConfigurationPath(const rl::plan::VectorList& path)
132129 QPen (QBrush (QColor (0 , 255 , 0 )), 0 )
133130 );
134131
135- line->setZValue (3 );
136-
137132 this ->path ->addToGroup (line);
138-
139- ++i;
140- ++j;
141133 }
142134}
143135
@@ -235,8 +227,14 @@ ConfigurationSpaceScene::init()
235227
236228 this ->setSceneRect (this ->scene ->boundingRect ());
237229
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 );
240238}
241239
242240void
@@ -295,6 +293,11 @@ ConfigurationSpaceScene::reset()
295293void
296294ConfigurationSpaceScene::resetEdges ()
297295{
296+ if (nullptr == this ->edges )
297+ {
298+ return ;
299+ }
300+
298301 QList<QGraphicsItem*> items = this ->edges ->childItems ();
299302
300303 while (!items.isEmpty ())
@@ -311,6 +314,11 @@ ConfigurationSpaceScene::resetLines()
311314void
312315ConfigurationSpaceScene::resetPath ()
313316{
317+ if (nullptr == this ->path )
318+ {
319+ return ;
320+ }
321+
314322 QList<QGraphicsItem*> items = this ->path ->childItems ();
315323
316324 while (!items.isEmpty ())
0 commit comments