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

Add bindings for Qt5Svg, Qt6Svg, Qt5Script, Qt5Webkit #95

Merged
merged 12 commits into from
Nov 26, 2024
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ examples/libraries/extras-scintillaedit/extras-scintillaedit
examples/libraries/qt-multimedia/qt-multimedia
examples/libraries/qt-network/qt-network
examples/libraries/qt-printsupport/qt-printsupport
examples/libraries/qt-script/qt-script
examples/libraries/qt-svg/qt-svg
examples/libraries/qt-webkit/qt-webkit
examples/libraries/qt6-multimedia/qt6-multimedia
examples/libraries/restricted-extras-qscintilla/restricted-extras-qscintilla

Expand Down
18 changes: 18 additions & 0 deletions cmd/genbindings/config-allowlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ func InsertTypedefs(qt6 bool) {
KnownTypedefs["QFileDevice::Permissions"] = lookupResultTypedef{pp, CppTypedef{"QFile::Permissions", parseSingleTypeString("QFlags<QFileDevice::Permission>")}}
KnownTypedefs["QIODevice::OpenMode"] = lookupResultTypedef{pp, CppTypedef{"QIODevice::OpenMode", parseSingleTypeString("QIODeviceBase::OpenMode")}}

// Qt 5 WebKit - use of an empty enum (should be possible to support?)
KnownEnums["QWebPluginFactory::Extension"] = lookupResultEnum{"qt/webkit", CppEnum{
EnumName: "QWebPluginFactory::Extension",
UnderlyingType: CppParameter{
ParameterType: "int",
},
}}

if qt6 {
// Qt 6 QVariant helper types - needs investigation
KnownTypedefs["QVariantHash"] = lookupResultTypedef{"qt6", CppTypedef{"QVariantHash", parseSingleTypeString("QHash<QString,QVariant>")}}
Expand Down Expand Up @@ -231,6 +239,14 @@ func AllowVirtualForClass(className string) bool {
return false
}

// Qt 5 QWebkit: undefined reference to typeinfo
if className == "QWebNotificationPresenter" {
return false
}
if className == "QWebHapticFeedbackPlayer" {
return false
}

return true
}

Expand Down Expand Up @@ -492,6 +508,8 @@ func AllowType(p CppParameter, isReturnType bool) error {
"QPostEventList", // Qt QCoreApplication: private headers required
"QMetaCallEvent", // ..
"QPostEvent", // ..
"QWebFrameAdapter", // Qt 5 Webkit: Used by e.g. qwebframe.h but never defined anywhere
"QWebPageAdapter", // ...
"____last____":
return ErrTooComplex
}
Expand Down
53 changes: 53 additions & 0 deletions cmd/genbindings/config-libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ func ProcessLibraries(clangBin, outDir, extraLibsDir string) {
ClangMatchSameHeaderDefinitionOnly,
)

generate(
"qt/svg",
[]string{
"/usr/include/x86_64-linux-gnu/qt5/QtSvg",
},
AllowAllHeaders,
clangBin,
pkgConfigCflags("Qt5Svg"),
outDir,
ClangMatchSameHeaderDefinitionOnly,
)

generate(
"qt/network",
[]string{
Expand Down Expand Up @@ -90,6 +102,33 @@ func ProcessLibraries(clangBin, outDir, extraLibsDir string) {
ClangMatchSameHeaderDefinitionOnly,
)

generate(
"qt/script",
[]string{
"/usr/include/x86_64-linux-gnu/qt5/QtScript",
},
AllowAllHeaders,
clangBin,
pkgConfigCflags("Qt5Script"),
outDir,
ClangMatchSameHeaderDefinitionOnly,
)

// Qt 5 QWebkit: depends on Qt5PrintSupport but only at runtime, not at
// codegen time
generate(
"qt/webkit",
[]string{
"/usr/include/x86_64-linux-gnu/qt5/QtWebKit",
"/usr/include/x86_64-linux-gnu/qt5/QtWebKitWidgets",
},
AllowAllHeaders,
clangBin,
pkgConfigCflags("Qt5WebKitWidgets"),
outDir,
ClangMatchSameHeaderDefinitionOnly,
)

// Depends on QtCore/Gui/Widgets, QPrintSupport
generate(
"qt-restricted-extras/qscintilla",
Expand Down Expand Up @@ -173,6 +212,20 @@ func ProcessLibraries(clangBin, outDir, extraLibsDir string) {
ClangMatchSameHeaderDefinitionOnly,
)

// Qt 6 SVG
generate(
"qt6/svg",
[]string{
"/usr/include/x86_64-linux-gnu/qt6/QtSvg",
"/usr/include/x86_64-linux-gnu/qt6/QtSvgWidgets",
},
AllowAllHeaders,
clangBin,
"--std=c++17 "+pkgConfigCflags("Qt6SvgWidgets"),
outDir,
ClangMatchSameHeaderDefinitionOnly,
)

// Qt 6 QtNetwork
generate(
"qt6/network",
Expand Down
29 changes: 17 additions & 12 deletions cmd/genbindings/emitcabi.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ func emitCABI2CppForwarding(p CppParameter, indent string) (preamble string, for
p.ParameterType == "qulonglong" ||
p.GetQtCppType().ParameterType == "qintptr" ||
p.GetQtCppType().ParameterType == "qsizetype" || // Qt 6 qversionnumber.h: invalid ‘static_cast’ from type ‘ptrdiff_t*’ {aka ‘long int*’} to type ‘qsizetype*’ {aka ‘long long int*’}
p.ParameterType == "qint8" {
p.ParameterType == "qint8" ||
(p.IsFlagType() && p.ByRef) {
// QDataStream::operator>>() by reference (qint64)
// QLockFile::getLockInfo() by pointer
// QTextStream::operator>>() by reference (qlonglong + qulonglong)
Expand Down Expand Up @@ -556,24 +557,28 @@ func getReferencedTypes(src *CppParsedHeader) []string {

foundTypes := map[string]struct{}{}

maybeAddType := func(p CppParameter) {
var maybeAddType func(p CppParameter)
maybeAddType = func(p CppParameter) {
if p.QtClassType() {
foundTypes[p.ParameterType] = struct{}{}
}
if t, ok := p.QListOf(); ok {
foundTypes["QList"] = struct{}{} // FIXME or QVector?
if t.QtClassType() {
foundTypes[t.ParameterType] = struct{}{}
}
maybeAddType(t)
}
if kType, vType, ok := p.QMapOf(); ok {
foundTypes["QMap"] = struct{}{} // FIXME or QHash?
if kType.QtClassType() {
foundTypes[kType.ParameterType] = struct{}{}
}
if vType.QtClassType() {
foundTypes[vType.ParameterType] = struct{}{}
}
maybeAddType(kType)
maybeAddType(vType)
}
if kType, vType, ok := p.QPairOf(); ok {
foundTypes["QPair"] = struct{}{}
maybeAddType(kType)
maybeAddType(vType)
}
if t, ok := p.QSetOf(); ok {
foundTypes["QSet"] = struct{}{}
maybeAddType(t)
}
}

Expand Down Expand Up @@ -639,7 +644,7 @@ func cabiClassName(className string) string {

func cabiPreventStructDeclaration(className string) bool {
switch className {
case "QList", "QString", "QSet", "QMap", "QHash":
case "QList", "QString", "QSet", "QMap", "QHash", "QPair", "QVector", "QByteArray":
return true // These types are reprojected
default:
return false
Expand Down
4 changes: 4 additions & 0 deletions docker/genbindings.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
golang-go \
qtbase5-dev \
qtmultimedia5-dev \
qtscript5-dev \
libqt5svg5-dev \
libqt5webkit5-dev \
qt6-base-dev \
qt6-multimedia-dev \
qt6-svg-dev \
libqscintilla2-qt5-dev \
libqscintilla2-qt6-dev \
clang \
Expand Down
23 changes: 23 additions & 0 deletions examples/libraries/qt-script/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"fmt"
"os"

"github.com/mappu/miqt/qt"
"github.com/mappu/miqt/qt/script"
)

func main() {

qt.NewQApplication(os.Args)

inputProgram := "1 + 2"

eng := script.NewQScriptEngine()
result := eng.Evaluate(inputProgram)

fmt.Printf("%s = %1.f\n", inputProgram, result.ToNumber())

// qt.QApplication_Exec()
}
18 changes: 18 additions & 0 deletions examples/libraries/qt-svg/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"os"

"github.com/mappu/miqt/qt"
"github.com/mappu/miqt/qt/svg"
)

func main() {

qt.NewQApplication(os.Args)

w := svg.NewQSvgWidget3("../../../doc/logo.svg")
w.Show()

qt.QApplication_Exec()
}
Binary file added examples/libraries/qt-svg/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions examples/libraries/qt-webkit/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"os"

"github.com/mappu/miqt/qt"
"github.com/mappu/miqt/qt/webkit"
)

func main() {

qt.NewQApplication(os.Args)

w := webkit.NewQWebView2()
w.Load(qt.NewQUrl3("https://www.github.com/mappu/miqt"))
w.Show()

qt.QApplication_Exec()
}
Binary file added examples/libraries/qt-webkit/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions qt-extras/scintillaedit/gen_ScintillaEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QObject>
#include <QPaintDevice>
#include <QPaintEvent>
#include <QPair>
#include <QRect>
#include <QResizeEvent>
#include <QSize>
Expand Down
2 changes: 0 additions & 2 deletions qt-extras/scintillaedit/gen_ScintillaEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ extern "C" {

#ifdef __cplusplus
class QAbstractScrollArea;
class QByteArray;
class QChildEvent;
class QContextMenuEvent;
class QDragEnterEvent;
Expand Down Expand Up @@ -213,7 +212,6 @@ class ScintillaEdit;
class ScintillaEditBase;
#else
typedef struct QAbstractScrollArea QAbstractScrollArea;
typedef struct QByteArray QByteArray;
typedef struct QChildEvent QChildEvent;
typedef struct QContextMenuEvent QContextMenuEvent;
typedef struct QDragEnterEvent QDragEnterEvent;
Expand Down
2 changes: 0 additions & 2 deletions qt-restricted-extras/qscintilla/gen_qsciscintilla.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ extern "C" {

#ifdef __cplusplus
class QAbstractScrollArea;
class QByteArray;
class QColor;
class QContextMenuEvent;
class QDragEnterEvent;
Expand Down Expand Up @@ -53,7 +52,6 @@ class QsciStyle;
class QsciStyledText;
#else
typedef struct QAbstractScrollArea QAbstractScrollArea;
typedef struct QByteArray QByteArray;
typedef struct QColor QColor;
typedef struct QContextMenuEvent QContextMenuEvent;
typedef struct QDragEnterEvent QDragEnterEvent;
Expand Down
2 changes: 0 additions & 2 deletions qt-restricted-extras/qscintilla/gen_qsciscintillabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ extern "C" {

#ifdef __cplusplus
class QAbstractScrollArea;
class QByteArray;
class QColor;
class QContextMenuEvent;
class QDragEnterEvent;
Expand Down Expand Up @@ -48,7 +47,6 @@ class QWidget;
class QsciScintillaBase;
#else
typedef struct QAbstractScrollArea QAbstractScrollArea;
typedef struct QByteArray QByteArray;
typedef struct QColor QColor;
typedef struct QContextMenuEvent QContextMenuEvent;
typedef struct QDragEnterEvent QDragEnterEvent;
Expand Down
2 changes: 0 additions & 2 deletions qt-restricted-extras/qscintilla6/gen_qsciscintilla.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ extern "C" {

#ifdef __cplusplus
class QAbstractScrollArea;
class QByteArray;
class QColor;
class QContextMenuEvent;
class QDragEnterEvent;
Expand Down Expand Up @@ -53,7 +52,6 @@ class QsciStyle;
class QsciStyledText;
#else
typedef struct QAbstractScrollArea QAbstractScrollArea;
typedef struct QByteArray QByteArray;
typedef struct QColor QColor;
typedef struct QContextMenuEvent QContextMenuEvent;
typedef struct QDragEnterEvent QDragEnterEvent;
Expand Down
2 changes: 0 additions & 2 deletions qt-restricted-extras/qscintilla6/gen_qsciscintillabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ extern "C" {

#ifdef __cplusplus
class QAbstractScrollArea;
class QByteArray;
class QColor;
class QContextMenuEvent;
class QDragEnterEvent;
Expand Down Expand Up @@ -48,7 +47,6 @@ class QWidget;
class QsciScintillaBase;
#else
typedef struct QAbstractScrollArea QAbstractScrollArea;
typedef struct QByteArray QByteArray;
typedef struct QColor QColor;
typedef struct QContextMenuEvent QContextMenuEvent;
typedef struct QDragEnterEvent QDragEnterEvent;
Expand Down
1 change: 1 addition & 0 deletions qt/cbor/gen_qcbormap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QJsonObject>
#include <QList>
#include <QMap>
#include <QPair>
#include <QString>
#include <QByteArray>
#include <cstring>
Expand Down
2 changes: 0 additions & 2 deletions qt/cbor/gen_qcborstreamreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ extern "C" {
#endif

#ifdef __cplusplus
class QByteArray;
class QCborError;
class QCborStreamReader;
class QIODevice;
#else
typedef struct QByteArray QByteArray;
typedef struct QCborError QCborError;
typedef struct QCborStreamReader QCborStreamReader;
typedef struct QIODevice QIODevice;
Expand Down
2 changes: 0 additions & 2 deletions qt/cbor/gen_qcborstreamwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ extern "C" {
#endif

#ifdef __cplusplus
class QByteArray;
class QCborStreamWriter;
class QIODevice;
#else
typedef struct QByteArray QByteArray;
typedef struct QCborStreamWriter QCborStreamWriter;
typedef struct QIODevice QIODevice;
#endif
Expand Down
2 changes: 0 additions & 2 deletions qt/cbor/gen_qcborvalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ extern "C" {
#endif

#ifdef __cplusplus
class QByteArray;
class QCborArray;
class QCborMap;
class QCborParserError;
Expand All @@ -30,7 +29,6 @@ class QUrl;
class QUuid;
class QVariant;
#else
typedef struct QByteArray QByteArray;
typedef struct QCborArray QCborArray;
typedef struct QCborMap QCborMap;
typedef struct QCborParserError QCborParserError;
Expand Down
Loading