1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Qt.DotNet;
using Qt.MetaObject;
namespace FooLib
{
public interface IBarTransformation
{
string Transform(string bar);
Uri GetUri(int n);
void SetUri(Uri uri);
int GetNumber();
}
public class BarIdentity : IBarTransformation
{
public string Transform(string bar) => bar;
public Uri GetUri(int n) => null;
public void SetUri(Uri uri) { }
public int GetNumber() => 0;
}
public class Foo : INotifyPropertyChanged
{
public const int FooNumber = 42;
public const string FooString = "FOO";
public int FooField = FooNumber;
public static int FooStaticField = -FooNumber;
public Foo(IBarTransformation barTransformation)
{
BarTransformation = barTransformation;
}
public Foo() : this(null)
{ }
private IBarTransformation BarTransformation { get; }
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string bar;
public string Bar
{
get => bar;
set
{
bar = value;
if (BarTransformation is IBarTransformation) {
bar = BarTransformation.Transform(value) ?? bar;
BarTransformation.SetUri(new("https://qt.io/developers"));
var n = BarTransformation.GetNumber();
if (BarTransformation.GetUri(n) is { } uri)
bar += $" ({uri})";
}
NotifyPropertyChanged();
}
}
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public delegate string FormatNumberDelegate(
[In, MarshalAs(UnmanagedType.LPWStr)] string format, int number);
public static string FormatNumber(string format, int number)
{
return string.Format(format, number);
}
public static int EntryPoint(IntPtr arg, int argLength)
{
return Convert.ToInt32(Marshal.PtrToStringUni(arg, argLength));
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class Date
{
[MarshalAs(UnmanagedType.LPWStr)]
public string Year = "";
[MarshalAs(UnmanagedType.LPWStr)]
public string Month = "";
[MarshalAs(UnmanagedType.LPWStr)]
public string Day = "";
}
[return: MarshalAs(UnmanagedType.LPWStr)]
public delegate string FormatDateDelegate(
[In, MarshalAs(UnmanagedType.LPWStr)] string format, [In] Date date);
public static string FormatDate(string format, Date date)
{
return string.Format(format, date.Year, date.Month, date.Day);
}
public delegate int FooFunc(int x);
public static FooFunc Plus42 { get; } = new FooFunc(x => x + 42);
public static ModelIndex FindIndex()
{
return new(42, 24, 0x12345678);
}
public static string DataAt(ModelIndex idx)
{
return $"{idx.Row}, {idx.Column}, 0x{idx.Id:X}";
}
public static DateTime GetDateTime()
{
return new DateTime(1912, 6, 23, 11, 22, 33, 444);
}
public static string PrintDateTime(DateTime t)
{
return $"{t.Year:0000}-{t.Month:00}-{t.Day:00} {t.Hour:00}:{t.Minute:00}:{t.Second:00}.{t.Millisecond:000}";
}
public static Uri GetUri()
{
return new Uri("https://www.qt.io/developers#wiki");
}
public static string PrintUri(Uri uri)
{
return uri.ToString();
}
}
public class Coord2DEventArgs : EventArgs
{
public double X { get; set; }
public double Y { get; set; }
}
public class Coord3DEventArgs : Coord2DEventArgs
{
public double Z { get; set; }
}
[QObject(Name = "ApolloXI")]
public class Apollo11
{
[QSlot(Name = "GoForEagleLanding")]
public void Land(double x, double y, double z)
{
EagleLanded?.Invoke(this, new Coord3DEventArgs() { X = x, Y = y, Z = z });
}
[QSignal]
[QSignal(Name = "TheEagleHasLanded")]
[QSignal<Coord3DEventArgs, string, string>(Name = "TheEagleHasLanded_WRONG_PARAMS")]
[QSignal<Coord2DEventArgs, string, string>(Name = "TheEagleHasLanded_WRONG_ORDER")]
[QSignal<UnhandledExceptionEventArgs, string, bool>(Name = "TheEagleHasLanded_WRONG_EVENT")]
[QSignal<EagleLandedSignal>(Name = "TheEagleHasLanded_OK")]
public event EventHandler<EventArgs> EagleLanded;
}
public class EagleLandedSignal : Signal<Coord3DEventArgs, string, string>
{
public override bool Convert(object sender, Coord3DEventArgs args)
{
var lat = TimeSpan.FromHours(Math.Abs(args.Y));
char latNS = args.Y >= 0 ? 'N' : 'S';
Param1 = $"{lat.Hours}\u00B0 {lat.Minutes}' {lat.Seconds}'' {latNS}";
var lon = TimeSpan.FromHours(Math.Abs(args.X));
char lonEW = args.X >= 0 ? 'E' : 'W';
Param2 = $"{lon.Hours}\u00B0 {lon.Minutes}' {lon.Seconds}'' {lonEW}";
return true;
}
}
}
|