diff options
| author | Miguel Costa <miguel.costa@qt.io> | 2025-11-04 14:17:39 +0100 |
|---|---|---|
| committer | Miguel Costa <miguel.costa@qt.io> | 2025-11-10 17:51:39 +0000 |
| commit | 2327ca438a80e825751c6432667aaa177b81be4b (patch) | |
| tree | 7d8b113a2571a79f209623c996d171e2ea87baa9 | |
| parent | 2289885d0f8fc81ce779c6d0335d1a1ebc5cdb7d (diff) | |
Extend dispatch to all object types
Mapping of object refs to an appropriate wrapper type will now use the
same mechanism that was already used for event type dispatch.
Change-Id: Ie82b6f32c2069f56048ced2788b1e1e9e5d87b96
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
| -rw-r--r-- | src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Placeholders.cs | 4 | ||||
| -rw-r--r-- | src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/Class/GenerateEvent.cs | 4 | ||||
| -rw-r--r-- | src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/GenerateObjectDispatch.cs (renamed from src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/GenerateEventDispatch.cs) | 30 |
3 files changed, 18 insertions, 20 deletions
diff --git a/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Placeholders.cs b/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Placeholders.cs index 0534307..27b4a8d 100644 --- a/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Placeholders.cs +++ b/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Placeholders.cs @@ -20,8 +20,8 @@ namespace Qt.DotNet.CodeGeneration ConvertHeader, ConvertSource , - EventDispatchHeader, - EventDispatchSource + ObjectDispatchHeader, + ObjectDispatchSource , MainCpp , MainIncludes diff --git a/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/Class/GenerateEvent.cs b/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/Class/GenerateEvent.cs index 11d021d..ff75b3c 100644 --- a/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/Class/GenerateEvent.cs +++ b/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/Class/GenerateEvent.cs @@ -48,7 +48,7 @@ EVENT_{ev.MFn(Src)} Q_SIGNAL void {ev.MFn(Signal)}(QObject *qEvArgs); privateIncludes += "#include <QMetaMethod>"; privateIncludes += "#include <QDotNetEventArgs>"; privateIncludes += "#include <QDotNetSignal>"; - privateIncludes += "#include <event_dispatch.h>"; + privateIncludes += "#include <object_dispatch.h>"; //////////////////////////////////////////////////////////////////////////////////////// // @@ -92,7 +92,7 @@ void {type.MFn(Ns | Name | Private)}::{ev.MFn(Handler)}::handleEvent( // * Event-to-signal mapping and property change notifications need to run on d->q's thread. QMetaObject::invokeMethod(d->q, [=]() mutable {{ - QObject *qEvArgs = QtDotNet::eventDispatch(args); + QObject *qEvArgs = QtDotNet::objectDispatch(args); if (!qEvArgs) return; {(!argsType.Is<PropertyChangedEventArgs>() ? Wrap : $@"{Wrap} diff --git a/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/GenerateEventDispatch.cs b/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/GenerateObjectDispatch.cs index 627fd23..49dac9c 100644 --- a/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/GenerateEventDispatch.cs +++ b/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/GenerateObjectDispatch.cs @@ -8,28 +8,26 @@ using System.Reflection; namespace Qt.DotNet.CodeGeneration.Rules { using MetaFunctions; - using Qt.DotNet.Extensions; + using Extensions; using static Placeholders; using static Traits; - public class GenerateEventDispatch : GenerateBuildSpec + public class GenerateObjectDispatch : GenerateBuildSpec { public override int Priority => base.Priority + 1; public override Result Execute(MemberInfo _) { - var dispatchHppPath = "hpp/event_dispatch.h"; - var dispatchCppPath = "cpp/event_dispatch.cpp"; + var dispatchHppPath = "hpp/object_dispatch.h"; + var dispatchCppPath = "cpp/object_dispatch.cpp"; if (Root.GetPlaceholder(SourceFiles) is not { } sourceFiles) return Error(); sourceFiles += dispatchHppPath; sourceFiles += dispatchCppPath; - var eventTypes = SourceGraph.NodeSet<EventInfo>() - .Select(e => e.EventHandlerType.DelegateSignature().ToArray()) - .Where(s => s.Length == 3 && s[0] == TypeOf(typeof(void)) - && s[1] == TypeOf<object>() && s[2].IsAssignableTo(TypeOf<EventArgs>())) - .Select(s => s[2]) + var allTypes = SourceGraph.NodeSet<Type>() + .Where(type => !type.IsEnum && !type.IsRootNode() + && !type.IsAssignableTo(TypeOf<Delegate>())) .Distinct() .OrderBy(t => t.AssemblyQualifiedName, StringComparer.Ordinal) .ToList(); @@ -37,25 +35,25 @@ namespace Qt.DotNet.CodeGeneration.Rules //////////////////////////////////////////////////////////////////////////////////////// // var dispatchHpp = new FilePlaceholder( - EventDispatchHeader, Root, $"{Root.MFn(Dir)}{dispatchHppPath}"); + ObjectDispatchHeader, Root, $"{Root.MFn(Dir)}{dispatchHppPath}"); dispatchHpp += $@" #pragma once #include <builtin_types.h> namespace QtDotNet {{ - QObject *eventDispatch(QDotNetObject &args); + QObject *objectDispatch(QDotNetObject &args); }} "; //////////////////////////////////////////////////////////////////////////////////////// // var dispatchCpp = new FilePlaceholder( - EventDispatchSource, Root, $"{Root.MFn(Dir)}{dispatchCppPath}"); + ObjectDispatchSource, Root, $"{Root.MFn(Dir)}{dispatchCppPath}"); dispatchCpp += $@" -#include <event_dispatch.h> +#include <object_dispatch.h> #include <QHash> -{dispatchCpp[new() { Distinct = true, Content = eventTypes.Select(t => $@" +{dispatchCpp[new() { Distinct = true, Content = allTypes.Select(t => $@" #include <{t.MFn(Ns | Dir)}{t.MFn(File)}.h>") }]} using Factory = QObject *(*)(QDotNetObject &); @@ -64,7 +62,7 @@ static const QHash<QString, Factory>& registry() {{ static const QHash<QString, Factory> reg = {{ {string.Join(@", - ", eventTypes.Select(t => $@"{{ + ", allTypes.Select(t => $@"{{ QStringLiteral(""{t.MFn(Src | Fqn)}""), [](QDotNetObject& obj) -> QObject * {{ @@ -75,7 +73,7 @@ static const QHash<QString, Factory>& registry() return reg; }} -QObject *QtDotNet::eventDispatch(QDotNetObject &args) +QObject *QtDotNet::objectDispatch(QDotNetObject &args) {{ const QString key = args.type().assemblyQualifiedName(); if (const auto it = registry().constFind(key); it != registry().cend()) |
