I have a QgraphicsScene which contains many QGraphicsItem. I am reading line, arc and circle's co-ordinates from a file and storing them in a map and when time comes to draw them, I iterate over that map and give those co-ordinates to respective Qt's Api.
But the problem is that, the symbol which is getting generated is not fully selectable.
Means if a symbol is created by let's say 4 lines, 1 arc and 1 circle. Then if I click on a particular line, then only that line gets selected. Or that particular arc gets selected.
But I am expecting, on clicking, the full symbol should be selected.
For that I was suggested to use
wrapper class. But not understanding how to use that ?
Here is my structure:
class mySymbol
{
struct Line {
std::tuple<int, int, int, int> line;
};
struct Arc {
std::tuple<int, int, int, int, int, int> arc;
};
struct Circle {
std::tuple<int, int, int> circle;
};
struct Rect
{
std::vector<Line> allLines;
std::vector<Arc> allArcs;
std::vector<Circle> allCircles;
}
std::map<std::string, Rect> allShapes;
}
DrawShapes.h
class DrawShapes
{
void createSymbol(map<std::string, Rect>);
}
DrawShapes.cpp
void DrawShapes :: createSymbol(map<std::string, Rect> allShapes)
{
QGraphicsItemGroup * parentGroup = new QGraphicsItemGroup;
for (auto iter = allShapes.begin(); iter != allShapes.end(); ++iter)
{
if (iter->second.allLines.size() > 0)
{
for (unsigned int i = 0; i < iter->second.allLines.size(); i++)
{
// getting 4 co-ordinates of line as first,second,third and fourth
myLine* line = new myLine(first,second,third,fourth);
line->DrawLine();
parentGroup->addToGroup(line);
scene->addItem(static_cast<QGraphicsLineItem*>(line));
}
}
// same logic for arc and circle
}
myLine.h
class myLine: public QGraphicsLineItem
{
public:
myLine();
myLine(int x1,int y1,int x2 ,int y2,QGraphicsItem *parent = nullptr)
: QGraphicsLineItem(x1,y1,x2,y2,parent)
{}
void DrawLine();
};
myLine.cpp
void myLine::DrawLine()
{
this->setPen(QPen(QColor("blue"), 1));
this->setFlag(QGraphicsItem::ItemIsSelectable);
}