Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crystal 1.0.0-dev breaks several QGraphicsItem subclasses #35

Open
HertzDevil opened this issue Aug 8, 2020 · 0 comments
Open

Crystal 1.0.0-dev breaks several QGraphicsItem subclasses #35

HertzDevil opened this issue Aug 8, 2020 · 0 comments

Comments

@HertzDevil
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant