Skip to content

Commit 51bceda

Browse files
committed
Fixed a regression - Qt events did not work at all. Also restored the ability to handle them.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 230685b commit 51bceda

6 files changed

+36
-13
lines changed

CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
0.5.1 - 12.6.2016
2+
Fixed:
3+
- Regression - Qt events did not work at all. Also restored the ability to handle them.
4+
15
0.5.0 - 12.6.2016
26
Added:
37
- Wrapped the entire Qt.

QtSharp/GenerateEventEventsPass.cs

+8-12
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,20 @@ where this.events.Contains(block.Declaration)
3838
eventBlock.NewLine();
3939
const string eventHandler = @"__eventHandler";
4040
var raiseEvent = string.Format(
41-
@" var {0} = {1};
41+
@"var {0} = {1};
4242
if ({0} != null)
4343
{0}(this, {2});
44-
", eventHandler, @event, method.Parameters[0].Name);
44+
if ({2}.Handled)
45+
return{3};
46+
",
47+
eventHandler, @event, method.Parameters[0].Name,
48+
method.OriginalReturnType.Type.IsPrimitiveType(PrimitiveType.Void) ? string.Empty : " true");
4549
if (block.Blocks.Count > 0 && block.Blocks[0].Kind == BlockKind.BlockComment)
4650
{
4751
eventBlock.Blocks.Add(block.Blocks[0]);
4852
}
4953
block.Parent.Blocks.Insert(blockIndex, eventBlock);
50-
var stringBuilder = block.Text.StringBuilder;
51-
if (method.OriginalReturnType.Type.IsPrimitiveType(PrimitiveType.Void))
52-
{
53-
stringBuilder.Insert(stringBuilder.Length - 1 - Environment.NewLine.Length, raiseEvent);
54-
}
55-
else
56-
{
57-
const string @return = " return ";
58-
stringBuilder.Replace(@return, raiseEvent + @return);
59-
}
54+
block.Text.StringBuilder.Replace("var __slot", raiseEvent + " var __slot");
6055
}
6156
}
6257

@@ -83,6 +78,7 @@ public override bool VisitMethodDecl(Method method)
8378
baseMethod.IsPure)
8479
{
8580
this.events.Add(method);
81+
this.Driver.Options.ExplicitlyPatchedVirtualFunctions.Add(method.QualifiedOriginalName);
8682
}
8783
}
8884
}

QtSharp/GenerateSignalEventsPass.cs

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ public override bool VisitClassDecl(Class @class)
144144
{
145145
this.HandleQSignal(@class, method);
146146
}
147+
var qtMetaCall = @class.FindMethod("qt_metacall");
148+
if (qtMetaCall != null)
149+
{
150+
this.Driver.Options.ExplicitlyPatchedVirtualFunctions.Add(qtMetaCall.QualifiedOriginalName);
151+
}
147152
return true;
148153
}
149154

QtSharp/QEvent.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace QtCore
2+
{
3+
public partial class QEvent
4+
{
5+
/// <summary>
6+
/// Set to true in order to stop propagating the event to other widgets.
7+
/// </summary>
8+
/// <remarks>
9+
/// It's different to <see cref="Accepted"/> because it's guaranteed to be false by default and
10+
/// because setting it on ensures the base event handler is not called.
11+
/// See https://doc.qt.io/qt-5.6/eventsandfilters.html#event-handlers and https://doc.qt.io/archives/qq/qq11-events.html#acceptorignore.
12+
/// </remarks>
13+
public bool Handled { get; set; }
14+
}
15+
}

QtSharp/QtSharp.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ public void Setup(Driver driver)
265265
{
266266
module.CodeFiles.Add(Path.Combine(dir, "QObject.cs"));
267267
module.CodeFiles.Add(Path.Combine(dir, "QChar.cs"));
268+
module.CodeFiles.Add(Path.Combine(dir, "QEvent.cs"));
268269
module.CodeFiles.Add(Path.Combine(dir, "_iobuf.cs"));
269270
}
270271

@@ -284,7 +285,6 @@ public void Setup(Driver driver)
284285
driver.Options.addIncludeDirs(qtInfo.Headers);
285286

286287
driver.Options.addLibraryDirs(Platform.IsWindows ? qtInfo.Bins : qtInfo.Libs);
287-
driver.Options.ExplicitlyPatchedVirtualFunctions.Add("qt_metacall");
288288
}
289289

290290
public static string GetModuleNameFromLibFile(string libFile)

QtSharp/QtSharp.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
<Compile Include="DocGeneration\MemberDocumentationNode.cs" />
7777
<Compile Include="Properties\AssemblyInfo.cs" />
7878
<Compile Include="ProcessHelper.cs" />
79+
<None Include="QEvent.cs">
80+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
81+
</None>
7982
<Compile Include="RemoveQObjectMembersPass.cs" />
8083
<None Include="packages.config" />
8184
<None Include="_iobuf.cs">

0 commit comments

Comments
 (0)