mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-21 06:45:32 -06:00
Merge feb329bf53 into d7570ee166
This commit is contained in:
commit
38d1a55d45
2 changed files with 46 additions and 1 deletions
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue