Remove items selected from scene in a dynamic array
-
@mrjj thanks a lot for answering.
i am gonna to try that.
And I am thinking about someting.
When I add line to the scene I do that in a for structure.
Is there any way to get the iterator of item selected ?
Because if i get that I can remove the line in the dimanyc array lines_vector if I now the iterator where I have to remove. -
@mrjj When I do for structure I save the line in the scene and in the lines_vector in the same iterator.
So the line in 4 position in scene is the same position than the line in 4 position in lines_vector.
So when I select for example one line in the scene, for example line 4, I have just to remove the line in position 4 in lines_vector.
So is ther any way to get the position vector of line that user selected in the scene -
-
in the same iterator.
Iterator is a helper class. Do you mean same index?
So first line and first struc_line but is at [0] in both lists? -
So is ther any way to get the position vector of line that user selected in the scene
The list contains one or more selected items.
Its not in the order it was inserted. Just the order selected.
So I dont think u can make a 1:1 map this way using selectedItems.
-
-
@mrjj Yes, index sorry.
Okey so I can not do like that.I have tried to use QMap like:
QMap<QGraphicsLineItem *, struc_line> LinesMap; //Adding lines to the scene and lines_vector for (int i=0; i<num_lines;i++) line = scene->addLine(...) LinesMap[line]=lines_vector[i]; //Button to remove lines selected QGraphicsLineItem *found= LinesMap.value(ui->scene->selectedItems(), NULL);
But it does not compile because there is a problem if users select more than one item because scene->selectedItems is a list
-
yes
you must loop over list and check eachQList<QGraphicsItem *> selList=ui->scene->selectedItems();
for (int c=0; c < selListt.size(); c++) {
QGraphicsLineItem *found= LinesMap.value(selList[c], NULL);
if (found) .....
} -
@mrjj I have tried to use QMap like you said but I get an error here:
error: no matching function for call to 'QMap<QGraphicsLineItem*, struc_line>::key(QGraphicsItem*&)'
QGraphicsLineItem *found=LinesMap.key(selList[c],NULL);
^You know why?
Thanks a lot again
-
yes,we store QGraphicsLineItem * in map and selectedItems is QGraphicsItem *
If you only do select "lines" then u can store it as QGraphicsItem * instead and
then no need for casting etc. -
super:)
good work.
please mark as solved.