Papierkorb / qt5.cr

Qt5 bindings for Crystal, based on Bindgen
Mozilla Public License 2.0
211 stars 20 forks source link

QStringList not mapped #39

Open byteit101 opened 4 years ago

byteit101 commented 4 years ago

This is making it much more difficult to do stuff, such as: Qt::Completer.new(["Option 1", "Option 2"], parent) must be replaced with a full blown model.

HertzDevil commented 4 years ago

QStringList is technically unsupported, because it inherits from QList<QString> which in turn inherits from QListSpecialMethods<QString>, where several methods are ultimately defined:

template <typename T> struct QListSpecialMethods { };
template <> struct QListSpecialMethods<QString>;

template <typename T>
class QList : public QListSpecialMethods<T> {
    // ...
};

template <> struct QListSpecialMethods<QString> {
public:
    inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive);
    inline int removeDuplicates();
    inline QString join(const QString &sep) const;
    inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
    inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
    // ...
};

Bindgen doesn't consider template specializations at the moment. That said, all these methods can be reimplemented on Crystal easily, since we have Enumerable.

If passing data to Qt is all that's needed, Bindgen master should be enough; wrapping QStringList normally gives a default constructor and #<<. This means you can do the following:

classes:
  QStringList: StringList
  # ...
Qt::Completer.new(Qt::StringList{"Option 1", "Option 2"}, parent)