This commit is contained in:
Michael Lamers 2018-08-04 09:28:33 +00:00 committed by GitHub
commit 38d1a55d45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 1 deletions

View file

@ -31,6 +31,20 @@ namespace Qml.Net.Tests.Qml
{
}
private string _somePropertyValue = "";
[NotifySignal]
public string SomeProperty
{
get => _somePropertyValue;
set {
if (_somePropertyValue == value)
return;
_somePropertyValue = value;
this.ActivatePropertyChangedSignal();
}
}
}
[Signal("testSignal")]
@ -153,6 +167,29 @@ namespace Qml.Net.Tests.Qml
Mock.VerifySet(x => x.SignalRaised = true, Times.Once);
}
[Fact]
public void Can_raise_changed_signal_from_net()
{
Mock.Setup(x => x.SignalRaised).Returns(false);
NetTestHelper.RunQml(qmlApplicationEngine,
@"
import QtQuick 2.0
import tests 1.0
ObjectTestsQml {
id: test
Component.onCompleted: function() {
test.somePropertyChanged.connect(function() {
test.signalRaised = true
})
test.someProperty = 'NewValue'
}
}
");
Mock.VerifySet(x => x.SignalRaised = true, Times.Once);
}
[Fact]
public void Can_raise_signal_from_net_with_args()
{

View file

@ -1,4 +1,5 @@
using Qml.Net.Internal;
using System.Runtime.CompilerServices;
using Qml.Net.Internal;
using Qml.Net.Internal.Types;
namespace Qml.Net
@ -34,6 +35,13 @@ namespace Qml.Net
return true;
}
public static bool ActivatePropertyChangedSignal(this object instance, [CallerMemberName] string propertyName = "")
{
var signalName = $"{propertyName}Changed";
signalName = char.ToLower(signalName[0]) + signalName.Substring(1);
return ActivateSignal(instance, signalName);
}
public static void AttachToSignal(this object instance, string signalName, System.Delegate del)
{
instance.AttachDelegateToSignal(signalName, del);