In a Qt-related code I tried to reduce some duplicated lines by the following method:
QPainter createPainter(const QColor& color)
{
QPointer painter(&m_image);
painter.setBrush(color);
painter.setPen(color);
return painter;
}
But QPainter
's copy ctor is explicitly deleted. It should be not not problem in c++11, but sadly it is neither moveable. Is it any reason for this or just an API defect? Is it a good solution for createPainter
?
- It could accept a QPainter reference, but this would decrease the meaning of the method, and would add noise to the caller's code.
- It could return a
unique_ptr
to theQPainter
, but it would introduce overhead for heap-allocation. - ... Any other ideas?
Thanks for your responses!
Aucun commentaire:
Enregistrer un commentaire