Skip to content

Commit

Permalink
Fixed a regression - Qt events did not work at all. Also restored the…
Browse files Browse the repository at this point in the history
… ability to handle them.

Signed-off-by: Dimitar Dobrev <[email protected]>
  • Loading branch information
ddobrev committed Jun 12, 2016
1 parent 230685b commit 51bceda
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.5.1 - 12.6.2016
Fixed:
- Regression - Qt events did not work at all. Also restored the ability to handle them.

0.5.0 - 12.6.2016
Added:
- Wrapped the entire Qt.
Expand Down
20 changes: 8 additions & 12 deletions QtSharp/GenerateEventEventsPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,20 @@ where this.events.Contains(block.Declaration)
eventBlock.NewLine();
const string eventHandler = @"__eventHandler";
var raiseEvent = string.Format(
@" var {0} = {1};
@"var {0} = {1};
if ({0} != null)
{0}(this, {2});
", eventHandler, @event, method.Parameters[0].Name);
if ({2}.Handled)
return{3};
",
eventHandler, @event, method.Parameters[0].Name,
method.OriginalReturnType.Type.IsPrimitiveType(PrimitiveType.Void) ? string.Empty : " true");
if (block.Blocks.Count > 0 && block.Blocks[0].Kind == BlockKind.BlockComment)
{
eventBlock.Blocks.Add(block.Blocks[0]);
}
block.Parent.Blocks.Insert(blockIndex, eventBlock);
var stringBuilder = block.Text.StringBuilder;
if (method.OriginalReturnType.Type.IsPrimitiveType(PrimitiveType.Void))
{
stringBuilder.Insert(stringBuilder.Length - 1 - Environment.NewLine.Length, raiseEvent);
}
else
{
const string @return = " return ";
stringBuilder.Replace(@return, raiseEvent + @return);
}
block.Text.StringBuilder.Replace("var __slot", raiseEvent + " var __slot");
}
}

Expand All @@ -83,6 +78,7 @@ public override bool VisitMethodDecl(Method method)
baseMethod.IsPure)
{
this.events.Add(method);
this.Driver.Options.ExplicitlyPatchedVirtualFunctions.Add(method.QualifiedOriginalName);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions QtSharp/GenerateSignalEventsPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ public override bool VisitClassDecl(Class @class)
{
this.HandleQSignal(@class, method);
}
var qtMetaCall = @class.FindMethod("qt_metacall");
if (qtMetaCall != null)
{
this.Driver.Options.ExplicitlyPatchedVirtualFunctions.Add(qtMetaCall.QualifiedOriginalName);
}
return true;
}

Expand Down
15 changes: 15 additions & 0 deletions QtSharp/QEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace QtCore
{
public partial class QEvent
{
/// <summary>
/// Set to true in order to stop propagating the event to other widgets.
/// </summary>
/// <remarks>
/// It's different to <see cref="Accepted"/> because it's guaranteed to be false by default and
/// because setting it on ensures the base event handler is not called.
/// See https://doc.qt.io/qt-5.6/eventsandfilters.html#event-handlers and https://doc.qt.io/archives/qq/qq11-events.html#acceptorignore.
/// </remarks>
public bool Handled { get; set; }
}
}
2 changes: 1 addition & 1 deletion QtSharp/QtSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public void Setup(Driver driver)
{
module.CodeFiles.Add(Path.Combine(dir, "QObject.cs"));
module.CodeFiles.Add(Path.Combine(dir, "QChar.cs"));
module.CodeFiles.Add(Path.Combine(dir, "QEvent.cs"));
module.CodeFiles.Add(Path.Combine(dir, "_iobuf.cs"));
}

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

driver.Options.addLibraryDirs(Platform.IsWindows ? qtInfo.Bins : qtInfo.Libs);
driver.Options.ExplicitlyPatchedVirtualFunctions.Add("qt_metacall");
}

public static string GetModuleNameFromLibFile(string libFile)
Expand Down
3 changes: 3 additions & 0 deletions QtSharp/QtSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<Compile Include="DocGeneration\MemberDocumentationNode.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProcessHelper.cs" />
<None Include="QEvent.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Compile Include="RemoveQObjectMembersPass.cs" />
<None Include="packages.config" />
<None Include="_iobuf.cs">
Expand Down

0 comments on commit 51bceda

Please sign in to comment.