qt5.cr
qt5.cr copied to clipboard
Crystal 1.0.0-dev breaks several QGraphicsItem subclasses
Crystal 1.0 strengthened checks on abstract def implementations, so the classes Qt::GraphicsSimpleTextItem
, Qt::GraphicsPixmapItem
, and Qt::GraphicsTextItem
will fail there. The reason is that the corresponding C++ method declarations have different default values for the widget
argument:
class QGraphicsItem
{
public:
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) = 0;
};
class QGraphicsPixmapItem : public QGraphicsItem
{
public:
// no default value for widget
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
};
// ditto for QGraphicsSimpleTextItem and QGraphicsTextItem
Other subclasses like Qt::GraphicsLineItem
work because the default values match:
class QGraphicsLineItem : public QGraphicsItem
{
public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
};
For now the workaround is to redefine the offending methods whenever the module is included:
module Qt
class GraphicsSimpleTextItem
def paint(painter : Painter, option : Binding::QStyleOptionGraphicsItem*, widget : Widget? = nil) : Void
Binding.bg_QGraphicsSimpleTextItem_paint_QPainter_X_const_QStyleOptionGraphicsItem_X_QWidget_X(self, painter, option, widget)
end
end
class GraphicsPixmapItem
def paint(painter : Painter, option : Binding::QStyleOptionGraphicsItem*, widget : Widget? = nil) : Void
Binding.bg_QGraphicsPixmapItem_paint_QPainter_X_const_QStyleOptionGraphicsItem_X_QWidget_X(self, painter, option, widget)
end
end
class GraphicsTextItem
def paint(painter : Painter, option : Binding::QStyleOptionGraphicsItem*, widget : Widget? = nil) : Void
Binding.bg_QGraphicsTextItem_paint_QPainter_X_const_QStyleOptionGraphicsItem_X_QWidget_X(self, painter, option, widget)
end
end
end
Without these redefinitions, those methods would take a plain widget : Widget
argument, and Crystal will complain about missing implementations, e.g. Error: abstract `def Qt::GraphicsItem#paint(painter : Painter, option : ::Pointer(Binding::QStyleOptionGraphicsItem), widget : Widget | ::Nil = nil)` must be implemented by Qt::GraphicsSimpleTextItem
.