aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiguel Costa <miguel.costa@qt.io>2025-11-12 20:16:18 +0100
committerMiguel Costa <miguel.costa@qt.io>2025-11-13 12:38:24 +0000
commit4737fbec6b821be7c4ee6d474ab35ce722698dc9 (patch)
treed568c57dfd227a9b4e113752f7a4dace252a5d42
parent895248821211d388586fca1a7559bd5620eb553d (diff)
Generate unique names for cast functions
Change-Id: I175385d20f7f37d3077faa021e29ea6db8d8bbf7 Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
-rw-r--r--examples/ColorPalette/ColorDialogDelete.qml2
-rw-r--r--examples/ColorPalette/ColorDialogEditor.qml2
-rw-r--r--src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/TypeCasting/GenerateTypeCast.cs8
3 files changed, 6 insertions, 6 deletions
diff --git a/examples/ColorPalette/ColorDialogDelete.qml b/examples/ColorPalette/ColorDialogDelete.qml
index e5bc3ea..611b842 100644
--- a/examples/ColorPalette/ColorDialogDelete.qml
+++ b/examples/ColorPalette/ColorDialogDelete.qml
@@ -21,7 +21,7 @@ Popup {
property string colorName: ""
function maybeDelete(resObj) {
- let resColor = TypeCast.asColorResource(resObj)
+ let resColor = TypeCast.as_ColorPalette_ColorResource(resObj)
if (resColor == null)
return;
colorName = resColor.name
diff --git a/examples/ColorPalette/ColorDialogEditor.qml b/examples/ColorPalette/ColorDialogEditor.qml
index 2c13e24..2a3cfc7 100644
--- a/examples/ColorPalette/ColorDialogEditor.qml
+++ b/examples/ColorPalette/ColorDialogEditor.qml
@@ -32,7 +32,7 @@ Popup {
}
function updateColor(resObj) {
- let resColor = TypeCast.asColorResource(resObj)
+ let resColor = TypeCast.as_ColorPalette_ColorResource(resObj)
if (resColor == null)
return;
newColor = false
diff --git a/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/TypeCasting/GenerateTypeCast.cs b/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/TypeCasting/GenerateTypeCast.cs
index af59fdd..55d600e 100644
--- a/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/TypeCasting/GenerateTypeCast.cs
+++ b/src/Qt.DotNet.GenerationRules/Qt/DotNet/CodeGeneration/Rules/TypeCasting/GenerateTypeCast.cs
@@ -7,6 +7,7 @@ using System.Reflection;
namespace Qt.DotNet.CodeGeneration.Rules.TypeCasting
{
+ using Extensions;
using static Placeholders;
using static Traits;
@@ -21,15 +22,14 @@ namespace Qt.DotNet.CodeGeneration.Rules.TypeCasting
return Error();
var typeCast = TypeOf<TypeCast>();
-
- // TO-DO: Generate unique names for cast functions
+ var castName = $"as_{type.FormatNamespace("_")}_{type.MFn(Name)}";
////////////////////////////////////////////////////////////////////////////////////////
//
if (typeCast.GetPlaceholder(MethodDeclarations) is not { } methods)
return Error();
methods += $@"
-Q_INVOKABLE {type.MFn(Ns | Name)} *as{type.MFn(Name)}(QObject *obj);
+Q_INVOKABLE {type.MFn(Ns | Name)} *{castName}(QObject *obj);
{Blank}";
////////////////////////////////////////////////////////////////////////////////////////
//
@@ -42,7 +42,7 @@ Q_INVOKABLE {type.MFn(Ns | Name)} *as{type.MFn(Name)}(QObject *obj);
if (typeCast.GetPlaceholder(MethodsImplementation) is not { } implementation)
return Error();
implementation += $@"
-{type.MFn(Ns | Name)} *{typeCast.MFn(Ns | Name)}::as{type.MFn(Name)}(QObject *qObj)
+{type.MFn(Ns | Name)} *{typeCast.MFn(Ns | Name)}::{castName}(QObject *qObj)
{{
return Convert::as<{type.MFn(Ns | Name)}>(qObj);
}}