From 172d50360e17379338be4aedaf507be60176e5c0 Mon Sep 17 00:00:00 2001 From: Dmitri Rossev Date: Fri, 16 Oct 2020 14:51:23 +0300 Subject: [PATCH 1/2] Added FSharp examples --- src/.gitignore | 6 +- .../AsyncAwaitModel.cs | 0 .../CalculatorModel.cs | 158 ++++++------- .../CollectionsModel.cs | 0 .../DynamicModel.cs | 0 .../Features.CSharp.csproj} | 4 +- .../NetObjectsModel.cs | 0 .../NotifySignalsModel.cs | 0 src/{Features => Features.CSharp}/Program.cs | 4 +- .../Properties/Resources.Designer.cs | 63 +++++ src/Features.CSharp/Properties/Resources.resx | 101 ++++++++ .../SignalsModel.cs | 0 src/Features.Common/Features.Common.csproj | 13 ++ src/{Features => Features.Common}/Main.qml | 0 .../images/arrow.png | Bin .../images/back.png | Bin .../images/drawer.png | Bin .../images/menu.png | Bin .../images/qt-logo.png | Bin .../pages/AsyncAwait.qml | 0 .../pages/Calculator.qml | 218 +++++++++--------- .../pages/Collections.qml | 0 .../pages/Dynamics.qml | 0 .../pages/NetObjects.qml | 0 .../pages/NotifySignals.qml | 0 .../pages/ScrollablePage.qml | 0 .../pages/Signals.qml | 0 src/Features.FSharp/AsyncAwaitModel.fs | 11 + src/Features.FSharp/CalculatorModel.fs | 49 ++++ src/Features.FSharp/CollectionsModel.fs | 18 ++ src/Features.FSharp/DynamicModel.fs | 10 + src/Features.FSharp/Features.FSharp.fsproj | 26 +++ src/Features.FSharp/NetObjectsModel.fs | 8 + src/Features.FSharp/NotifySignalsModel.fs | 17 ++ src/Features.FSharp/Program.fs | 28 +++ src/Features.FSharp/SignalsModel.fs | 11 + src/Qml.Net.Examples.sln | 54 +++-- 37 files changed, 593 insertions(+), 206 deletions(-) rename src/{Features => Features.CSharp}/AsyncAwaitModel.cs (100%) rename src/{Features => Features.CSharp}/CalculatorModel.cs (96%) rename src/{Features => Features.CSharp}/CollectionsModel.cs (100%) rename src/{Features => Features.CSharp}/DynamicModel.cs (100%) rename src/{Features/Features.csproj => Features.CSharp/Features.CSharp.csproj} (76%) rename src/{Features => Features.CSharp}/NetObjectsModel.cs (100%) rename src/{Features => Features.CSharp}/NotifySignalsModel.cs (100%) rename src/{Features => Features.CSharp}/Program.cs (85%) create mode 100644 src/Features.CSharp/Properties/Resources.Designer.cs create mode 100644 src/Features.CSharp/Properties/Resources.resx rename src/{Features => Features.CSharp}/SignalsModel.cs (100%) create mode 100644 src/Features.Common/Features.Common.csproj rename src/{Features => Features.Common}/Main.qml (100%) rename src/{Features => Features.Common}/images/arrow.png (100%) rename src/{Features => Features.Common}/images/back.png (100%) rename src/{Features => Features.Common}/images/drawer.png (100%) rename src/{Features => Features.Common}/images/menu.png (100%) rename src/{Features => Features.Common}/images/qt-logo.png (100%) rename src/{Features => Features.Common}/pages/AsyncAwait.qml (100%) rename src/{Features => Features.Common}/pages/Calculator.qml (96%) rename src/{Features => Features.Common}/pages/Collections.qml (100%) rename src/{Features => Features.Common}/pages/Dynamics.qml (100%) rename src/{Features => Features.Common}/pages/NetObjects.qml (100%) rename src/{Features => Features.Common}/pages/NotifySignals.qml (100%) rename src/{Features => Features.Common}/pages/ScrollablePage.qml (100%) rename src/{Features => Features.Common}/pages/Signals.qml (100%) create mode 100644 src/Features.FSharp/AsyncAwaitModel.fs create mode 100644 src/Features.FSharp/CalculatorModel.fs create mode 100644 src/Features.FSharp/CollectionsModel.fs create mode 100644 src/Features.FSharp/DynamicModel.fs create mode 100644 src/Features.FSharp/Features.FSharp.fsproj create mode 100644 src/Features.FSharp/NetObjectsModel.fs create mode 100644 src/Features.FSharp/NotifySignalsModel.fs create mode 100644 src/Features.FSharp/Program.fs create mode 100644 src/Features.FSharp/SignalsModel.fs diff --git a/src/.gitignore b/src/.gitignore index 7446ab0..ea585ce 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -328,4 +328,8 @@ ASALocalRun/ # MFractors (Xamarin productivity tool) working folder .mfractor/ -**/*.qmlc \ No newline at end of file +**/*.qmlc + +# VS Code +.ionide +.vscode diff --git a/src/Features/AsyncAwaitModel.cs b/src/Features.CSharp/AsyncAwaitModel.cs similarity index 100% rename from src/Features/AsyncAwaitModel.cs rename to src/Features.CSharp/AsyncAwaitModel.cs diff --git a/src/Features/CalculatorModel.cs b/src/Features.CSharp/CalculatorModel.cs similarity index 96% rename from src/Features/CalculatorModel.cs rename to src/Features.CSharp/CalculatorModel.cs index d9e027e..cda39e9 100644 --- a/src/Features/CalculatorModel.cs +++ b/src/Features.CSharp/CalculatorModel.cs @@ -1,80 +1,80 @@ -using Qml.Net; -using System; - -namespace Features -{ - public class CalculatorModel - { - private bool _isValid = false; - private string _computedResult = ""; - - [NotifySignal] - public string ComputedResult - { - get - { - return _computedResult; - } - set - { - if (_computedResult == value) - { - // No signal is raised, Qml doesn't update any bound properties. - return; - } - - _computedResult = value; - this.ActivateSignal("computedResultChanged"); - } - } - - [NotifySignal] - public bool IsValid - { - get - { - return _isValid; - } - set - { - if (_isValid == value) - { - // No signal is raised, Qml doesn't update any bound properties. - return; - } - - _isValid = value; - this.ActivateSignal("isValidChanged"); - } - } - - public void Add(string inputValue1, string inputValue2) - { - ComputedResult = Convert.ToString(decimal.Parse(inputValue1) + decimal.Parse(inputValue2)); - } - - public void Subtract(string inputValue1, string inputValue2) - { - ComputedResult = Convert.ToString(decimal.Parse(inputValue1) - decimal.Parse(inputValue2)); - } - - public void Multiply(string inputValue1, string inputValue2) - { - ComputedResult = Convert.ToString(decimal.Parse(inputValue1) * decimal.Parse(inputValue2)); - } - - public void Divide(string inputValue1, string inputValue2) - { - var value1 = decimal.Parse(inputValue1); - var value2 = decimal.Parse(inputValue2); - - if (value2 == 0) - { - ComputedResult = $"Cannot devide by zero."; - return; - } - - ComputedResult = Convert.ToString(value1 / value2); - } - } +using Qml.Net; +using System; + +namespace Features +{ + public class CalculatorModel + { + private bool _isValid = false; + private string _computedResult = ""; + + [NotifySignal] + public string ComputedResult + { + get + { + return _computedResult; + } + set + { + if (_computedResult == value) + { + // No signal is raised, Qml doesn't update any bound properties. + return; + } + + _computedResult = value; + this.ActivateSignal("computedResultChanged"); + } + } + + [NotifySignal] + public bool IsValid + { + get + { + return _isValid; + } + set + { + if (_isValid == value) + { + // No signal is raised, Qml doesn't update any bound properties. + return; + } + + _isValid = value; + this.ActivateSignal("isValidChanged"); + } + } + + public void Add(string inputValue1, string inputValue2) + { + ComputedResult = Convert.ToString(decimal.Parse(inputValue1) + decimal.Parse(inputValue2)); + } + + public void Subtract(string inputValue1, string inputValue2) + { + ComputedResult = Convert.ToString(decimal.Parse(inputValue1) - decimal.Parse(inputValue2)); + } + + public void Multiply(string inputValue1, string inputValue2) + { + ComputedResult = Convert.ToString(decimal.Parse(inputValue1) * decimal.Parse(inputValue2)); + } + + public void Divide(string inputValue1, string inputValue2) + { + var value1 = decimal.Parse(inputValue1); + var value2 = decimal.Parse(inputValue2); + + if (value2 == 0) + { + ComputedResult = $"Cannot devide by zero."; + return; + } + + ComputedResult = Convert.ToString(value1 / value2); + } + } } \ No newline at end of file diff --git a/src/Features/CollectionsModel.cs b/src/Features.CSharp/CollectionsModel.cs similarity index 100% rename from src/Features/CollectionsModel.cs rename to src/Features.CSharp/CollectionsModel.cs diff --git a/src/Features/DynamicModel.cs b/src/Features.CSharp/DynamicModel.cs similarity index 100% rename from src/Features/DynamicModel.cs rename to src/Features.CSharp/DynamicModel.cs diff --git a/src/Features/Features.csproj b/src/Features.CSharp/Features.CSharp.csproj similarity index 76% rename from src/Features/Features.csproj rename to src/Features.CSharp/Features.CSharp.csproj index 5cde5d8..0c2a8a2 100644 --- a/src/Features/Features.csproj +++ b/src/Features.CSharp/Features.CSharp.csproj @@ -14,8 +14,6 @@ - - - + diff --git a/src/Features/NetObjectsModel.cs b/src/Features.CSharp/NetObjectsModel.cs similarity index 100% rename from src/Features/NetObjectsModel.cs rename to src/Features.CSharp/NetObjectsModel.cs diff --git a/src/Features/NotifySignalsModel.cs b/src/Features.CSharp/NotifySignalsModel.cs similarity index 100% rename from src/Features/NotifySignalsModel.cs rename to src/Features.CSharp/NotifySignalsModel.cs diff --git a/src/Features/Program.cs b/src/Features.CSharp/Program.cs similarity index 85% rename from src/Features/Program.cs rename to src/Features.CSharp/Program.cs index 485b14d..5fa6ed9 100644 --- a/src/Features/Program.cs +++ b/src/Features.CSharp/Program.cs @@ -10,7 +10,7 @@ class Program static int Main(string[] args) { RuntimeManager.DiscoverOrDownloadSuitableQtRuntime(); - + QQuickStyle.SetStyle("Material"); using (var application = new QGuiApplication(args)) @@ -25,6 +25,8 @@ static int Main(string[] args) Qml.Net.Qml.RegisterType("Features"); Qml.Net.Qml.RegisterType("Features"); + string binaryPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); + Directory.SetCurrentDirectory(binaryPath); qmlEngine.Load("Main.qml"); return application.Exec(); diff --git a/src/Features.CSharp/Properties/Resources.Designer.cs b/src/Features.CSharp/Properties/Resources.Designer.cs new file mode 100644 index 0000000..4c8893c --- /dev/null +++ b/src/Features.CSharp/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Features.CSharp.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Features.CSharp.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/src/Features.CSharp/Properties/Resources.resx b/src/Features.CSharp/Properties/Resources.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/src/Features.CSharp/Properties/Resources.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/Features/SignalsModel.cs b/src/Features.CSharp/SignalsModel.cs similarity index 100% rename from src/Features/SignalsModel.cs rename to src/Features.CSharp/SignalsModel.cs diff --git a/src/Features.Common/Features.Common.csproj b/src/Features.Common/Features.Common.csproj new file mode 100644 index 0000000..93dcdf5 --- /dev/null +++ b/src/Features.Common/Features.Common.csproj @@ -0,0 +1,13 @@ + + + + netstandard2.0 + + + + + + + + + diff --git a/src/Features/Main.qml b/src/Features.Common/Main.qml similarity index 100% rename from src/Features/Main.qml rename to src/Features.Common/Main.qml diff --git a/src/Features/images/arrow.png b/src/Features.Common/images/arrow.png similarity index 100% rename from src/Features/images/arrow.png rename to src/Features.Common/images/arrow.png diff --git a/src/Features/images/back.png b/src/Features.Common/images/back.png similarity index 100% rename from src/Features/images/back.png rename to src/Features.Common/images/back.png diff --git a/src/Features/images/drawer.png b/src/Features.Common/images/drawer.png similarity index 100% rename from src/Features/images/drawer.png rename to src/Features.Common/images/drawer.png diff --git a/src/Features/images/menu.png b/src/Features.Common/images/menu.png similarity index 100% rename from src/Features/images/menu.png rename to src/Features.Common/images/menu.png diff --git a/src/Features/images/qt-logo.png b/src/Features.Common/images/qt-logo.png similarity index 100% rename from src/Features/images/qt-logo.png rename to src/Features.Common/images/qt-logo.png diff --git a/src/Features/pages/AsyncAwait.qml b/src/Features.Common/pages/AsyncAwait.qml similarity index 100% rename from src/Features/pages/AsyncAwait.qml rename to src/Features.Common/pages/AsyncAwait.qml diff --git a/src/Features/pages/Calculator.qml b/src/Features.Common/pages/Calculator.qml similarity index 96% rename from src/Features/pages/Calculator.qml rename to src/Features.Common/pages/Calculator.qml index cbbb094..7ca4493 100644 --- a/src/Features/pages/Calculator.qml +++ b/src/Features.Common/pages/Calculator.qml @@ -1,109 +1,109 @@ -import QtQuick 2.6 -import QtQuick.Controls 2.1 -import Features 1.0 - -ScrollablePage { - Column { - Label { text: qsTr("Input") } - - Grid { - id: inputContainer - columns: 2 - spacing: 12 - width: parent.width - - TextField { - id: txtValue1 - placeholderText: qsTr("Value 1") - - onEditingFinished: { - inputContainer.validateInput() - } - } - TextField { - id: txtValue2 - placeholderText: qsTr("Value 2") - - onEditingFinished: { - inputContainer.validateInput() - } - } - - Label { - id: lblValidation - color: 'red' - } - - function validateInput() { - var fieldsFilled = txtValue1.text !== "" && txtValue2.text !== "" - if (!fieldsFilled) { - model.isValid = false - lblValidation.text = '' - return - } - - model.isValid = !isNaN(txtValue1.text) && !isNaN(txtValue2.text) - if (!model.isValid) { - lblValidation.text = qsTr("Input value(s) is/are invalid.") - } - else { - lblValidation.text = '' - } - } - } - - Label { text: qsTr("Operations") } - - Grid { - id: operationsContainer - columns: 4 - spacing: 12 - width: parent.width - - Button { - text: "+" - onClicked: { - if (model.isValid) { - model.add(txtValue1.text, txtValue2.text) - } - } - } - - Button { - text: "-" - onClicked: { - if (model.isValid) { - model.subtract(txtValue1.text, txtValue2.text) - } - } - } - - Button { - text: "x" - onClicked: { - if (model.isValid) { - model.multiply(txtValue1.text, txtValue2.text) - } - } - } - - Button { - text: ":" - onClicked: { - if (model.isValid) { - model.divide(txtValue1.text, txtValue2.text) - } - } - } - } - - Label { - text: model.computedResult - color: 'green' - } - - CalculatorModel { - id: model - } - } -} +import QtQuick 2.6 +import QtQuick.Controls 2.1 +import Features 1.0 + +ScrollablePage { + Column { + Label { text: qsTr("Input") } + + Grid { + id: inputContainer + columns: 2 + spacing: 12 + width: parent.width + + TextField { + id: txtValue1 + placeholderText: qsTr("Value 1") + + onEditingFinished: { + inputContainer.validateInput() + } + } + TextField { + id: txtValue2 + placeholderText: qsTr("Value 2") + + onEditingFinished: { + inputContainer.validateInput() + } + } + + Label { + id: lblValidation + color: 'red' + } + + function validateInput() { + var fieldsFilled = txtValue1.text !== "" && txtValue2.text !== "" + if (!fieldsFilled) { + model.isValid = false + lblValidation.text = '' + return + } + + model.isValid = !isNaN(txtValue1.text) && !isNaN(txtValue2.text) + if (!model.isValid) { + lblValidation.text = qsTr("Input value(s) is/are invalid.") + } + else { + lblValidation.text = '' + } + } + } + + Label { text: qsTr("Operations") } + + Grid { + id: operationsContainer + columns: 4 + spacing: 12 + width: parent.width + + Button { + text: "+" + onClicked: { + if (model.isValid) { + model.add(txtValue1.text, txtValue2.text) + } + } + } + + Button { + text: "-" + onClicked: { + if (model.isValid) { + model.subtract(txtValue1.text, txtValue2.text) + } + } + } + + Button { + text: "x" + onClicked: { + if (model.isValid) { + model.multiply(txtValue1.text, txtValue2.text) + } + } + } + + Button { + text: ":" + onClicked: { + if (model.isValid) { + model.divide(txtValue1.text, txtValue2.text) + } + } + } + } + + Label { + text: model.computedResult + color: 'green' + } + + CalculatorModel { + id: model + } + } +} diff --git a/src/Features/pages/Collections.qml b/src/Features.Common/pages/Collections.qml similarity index 100% rename from src/Features/pages/Collections.qml rename to src/Features.Common/pages/Collections.qml diff --git a/src/Features/pages/Dynamics.qml b/src/Features.Common/pages/Dynamics.qml similarity index 100% rename from src/Features/pages/Dynamics.qml rename to src/Features.Common/pages/Dynamics.qml diff --git a/src/Features/pages/NetObjects.qml b/src/Features.Common/pages/NetObjects.qml similarity index 100% rename from src/Features/pages/NetObjects.qml rename to src/Features.Common/pages/NetObjects.qml diff --git a/src/Features/pages/NotifySignals.qml b/src/Features.Common/pages/NotifySignals.qml similarity index 100% rename from src/Features/pages/NotifySignals.qml rename to src/Features.Common/pages/NotifySignals.qml diff --git a/src/Features/pages/ScrollablePage.qml b/src/Features.Common/pages/ScrollablePage.qml similarity index 100% rename from src/Features/pages/ScrollablePage.qml rename to src/Features.Common/pages/ScrollablePage.qml diff --git a/src/Features/pages/Signals.qml b/src/Features.Common/pages/Signals.qml similarity index 100% rename from src/Features/pages/Signals.qml rename to src/Features.Common/pages/Signals.qml diff --git a/src/Features.FSharp/AsyncAwaitModel.fs b/src/Features.FSharp/AsyncAwaitModel.fs new file mode 100644 index 0000000..ff411ab --- /dev/null +++ b/src/Features.FSharp/AsyncAwaitModel.fs @@ -0,0 +1,11 @@ +namespace Features + +open System +open System.Threading.Tasks + +type AsyncAwaitModel() = + member this.RunAsyncTask(message: string) = + async { + do! Async.Sleep 2000 + return message + } |> Async.StartAsTask diff --git a/src/Features.FSharp/CalculatorModel.fs b/src/Features.FSharp/CalculatorModel.fs new file mode 100644 index 0000000..767b42e --- /dev/null +++ b/src/Features.FSharp/CalculatorModel.fs @@ -0,0 +1,49 @@ +namespace Features + +open Qml.Net + +type CalculatorModel() = + let mutable isValid = false + let mutable computedResult = "" + + [] + member this.ComputedResult + with get() = computedResult + and set(value) = + if value <> computedResult then + computedResult <- value + this.ActivateSignal("computedResultChanged") |> ignore + + [] + member this.IsValid + with get() = isValid + and set(value) = + if value <> isValid then + isValid <- value + this.ActivateSignal("isValidChanged") |> ignore + + member this.Add(inputValue1: string, inputValue2: string) = + let a = decimal inputValue1 + let b = decimal inputValue2 + let result = a + b + this.ComputedResult <- string result + + member this.Subtract(inputValue1: string, inputValue2: string) = + let a = decimal inputValue1 + let b = decimal inputValue2 + let result = a - b + this.ComputedResult <- string result + + member this.Multiply(inputValue1: string, inputValue2: string) = + let a = decimal inputValue1 + let b = decimal inputValue2 + let result = a * b + this.ComputedResult <- string result + + member this.Divide(inputValue1: string, inputValue2: string) = + let a = decimal inputValue1 + let b = decimal inputValue2 + try + let result = a / b + this.ComputedResult <- string result + with | :? System.DivideByZeroException -> this.ComputedResult <- "Division by zero!" diff --git a/src/Features.FSharp/CollectionsModel.fs b/src/Features.FSharp/CollectionsModel.fs new file mode 100644 index 0000000..e280695 --- /dev/null +++ b/src/Features.FSharp/CollectionsModel.fs @@ -0,0 +1,18 @@ +namespace Features + +open System.Collections.Generic + +type Contact = { Name: string; PhoneNumber: string } + +type CollectionsModel() = + let mutable contacts = List [ {Name = "Paul Knopf"; PhoneNumber = "525-525-52555" } ] + + member this.AddContact(name: string, phoneNumber: string) = + if System.String.IsNullOrEmpty name || System.String.IsNullOrEmpty phoneNumber then false + else + contacts.Add {Name = name; PhoneNumber = phoneNumber} + true + + member this.RemoveContact(index: int) = contacts.RemoveAt(index) + + member this.Contacts with get() = contacts diff --git a/src/Features.FSharp/DynamicModel.fs b/src/Features.FSharp/DynamicModel.fs new file mode 100644 index 0000000..aff0864 --- /dev/null +++ b/src/Features.FSharp/DynamicModel.fs @@ -0,0 +1,10 @@ +namespace Features + +open FSharp.Interop.Dynamic + +type DynamicModel() = + member this.InvokeJavascriptFunction(funct: obj, message: string) = + !?funct message |> ignore + + member this.Add(source: obj, destination: obj) = + destination?computedResult <- source?value1 + source?value2 diff --git a/src/Features.FSharp/Features.FSharp.fsproj b/src/Features.FSharp/Features.FSharp.fsproj new file mode 100644 index 0000000..c569cd8 --- /dev/null +++ b/src/Features.FSharp/Features.FSharp.fsproj @@ -0,0 +1,26 @@ + + + Exe + netcoreapp3.1 + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Features.FSharp/NetObjectsModel.fs b/src/Features.FSharp/NetObjectsModel.fs new file mode 100644 index 0000000..5ef11a3 --- /dev/null +++ b/src/Features.FSharp/NetObjectsModel.fs @@ -0,0 +1,8 @@ +namespace Features + +type NetObject() = + member val Property = "" with get, set + member this.UpdateProperty(value: string) = this.Property <- value + +type NetObjectsModel() = + member this.GetNetObject() = NetObject() diff --git a/src/Features.FSharp/NotifySignalsModel.fs b/src/Features.FSharp/NotifySignalsModel.fs new file mode 100644 index 0000000..e13b598 --- /dev/null +++ b/src/Features.FSharp/NotifySignalsModel.fs @@ -0,0 +1,17 @@ +namespace Features + +open System +open Qml.Net + +type NotifySignalsModel() = + let mutable bindableProperty = "" + + [] + member this.BindableProperty + with get() = bindableProperty + and set(value) = + bindableProperty <- value + this.ActivateSignal("bindablePropertyChanged") |> ignore + + member this.ChangeBindableProperty() = + this.BindableProperty <- DateTime.Now.ToLongTimeString(); diff --git a/src/Features.FSharp/Program.fs b/src/Features.FSharp/Program.fs new file mode 100644 index 0000000..815079a --- /dev/null +++ b/src/Features.FSharp/Program.fs @@ -0,0 +1,28 @@ +open System +open System.IO +open System.Reflection +open Qml.Net +open Qml.Net.Runtimes + +open Features + +[] +let main argv = + RuntimeManager.DiscoverOrDownloadSuitableQtRuntime() + QQuickStyle.SetStyle("Material"); + use app = new QGuiApplication(argv) + use engine = new QQmlApplicationEngine() + let registeredTypes = [ + Qml.RegisterType("Features") + Qml.RegisterType("Features") + Qml.RegisterType("Features") + Qml.RegisterType("Features") + Qml.RegisterType("Features") + Qml.RegisterType("Features") + Qml.RegisterType("Features") + + ] + let binaryPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Directory.SetCurrentDirectory(binaryPath) + engine.Load("Main.qml") + app.Exec() diff --git a/src/Features.FSharp/SignalsModel.fs b/src/Features.FSharp/SignalsModel.fs new file mode 100644 index 0000000..ddde789 --- /dev/null +++ b/src/Features.FSharp/SignalsModel.fs @@ -0,0 +1,11 @@ +namespace Features + +open System +open Qml.Net + +[] +type SignalsModel() = + member this.RaiseSignal() = + let message = "Signal was raised from F# .NET at " + DateTime.Now.ToLongTimeString() + this.ActivateSignal("customSignal", message) + diff --git a/src/Qml.Net.Examples.sln b/src/Qml.Net.Examples.sln index b0d2c49..035bda1 100644 --- a/src/Qml.Net.Examples.sln +++ b/src/Qml.Net.Examples.sln @@ -3,7 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26124.0 MinimumVisualStudioVersion = 15.0.26124.0 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Features", "Features\Features.csproj", "{556C9821-F289-4B24-95B0-F5EDD1CDA832}" +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Features.FSharp", "Features.FSharp\Features.FSharp.fsproj", "{FBAAD685-EBB0-4166-920E-25F1612CFA6E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Features.CSharp", "Features.CSharp\Features.CSharp.csproj", "{1EB48836-4EE9-4D13-BF65-53A2DAEB0F2E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Features.Common", "Features.Common\Features.Common.csproj", "{3FFEA843-CB10-4465-B645-7FA9A86531C6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -18,17 +22,41 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {556C9821-F289-4B24-95B0-F5EDD1CDA832}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {556C9821-F289-4B24-95B0-F5EDD1CDA832}.Debug|Any CPU.Build.0 = Debug|Any CPU - {556C9821-F289-4B24-95B0-F5EDD1CDA832}.Debug|x64.ActiveCfg = Debug|Any CPU - {556C9821-F289-4B24-95B0-F5EDD1CDA832}.Debug|x64.Build.0 = Debug|Any CPU - {556C9821-F289-4B24-95B0-F5EDD1CDA832}.Debug|x86.ActiveCfg = Debug|Any CPU - {556C9821-F289-4B24-95B0-F5EDD1CDA832}.Debug|x86.Build.0 = Debug|Any CPU - {556C9821-F289-4B24-95B0-F5EDD1CDA832}.Release|Any CPU.ActiveCfg = Release|Any CPU - {556C9821-F289-4B24-95B0-F5EDD1CDA832}.Release|Any CPU.Build.0 = Release|Any CPU - {556C9821-F289-4B24-95B0-F5EDD1CDA832}.Release|x64.ActiveCfg = Release|Any CPU - {556C9821-F289-4B24-95B0-F5EDD1CDA832}.Release|x64.Build.0 = Release|Any CPU - {556C9821-F289-4B24-95B0-F5EDD1CDA832}.Release|x86.ActiveCfg = Release|Any CPU - {556C9821-F289-4B24-95B0-F5EDD1CDA832}.Release|x86.Build.0 = Release|Any CPU + {FBAAD685-EBB0-4166-920E-25F1612CFA6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBAAD685-EBB0-4166-920E-25F1612CFA6E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBAAD685-EBB0-4166-920E-25F1612CFA6E}.Debug|x64.ActiveCfg = Debug|Any CPU + {FBAAD685-EBB0-4166-920E-25F1612CFA6E}.Debug|x64.Build.0 = Debug|Any CPU + {FBAAD685-EBB0-4166-920E-25F1612CFA6E}.Debug|x86.ActiveCfg = Debug|Any CPU + {FBAAD685-EBB0-4166-920E-25F1612CFA6E}.Debug|x86.Build.0 = Debug|Any CPU + {FBAAD685-EBB0-4166-920E-25F1612CFA6E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBAAD685-EBB0-4166-920E-25F1612CFA6E}.Release|Any CPU.Build.0 = Release|Any CPU + {FBAAD685-EBB0-4166-920E-25F1612CFA6E}.Release|x64.ActiveCfg = Release|Any CPU + {FBAAD685-EBB0-4166-920E-25F1612CFA6E}.Release|x64.Build.0 = Release|Any CPU + {FBAAD685-EBB0-4166-920E-25F1612CFA6E}.Release|x86.ActiveCfg = Release|Any CPU + {FBAAD685-EBB0-4166-920E-25F1612CFA6E}.Release|x86.Build.0 = Release|Any CPU + {1EB48836-4EE9-4D13-BF65-53A2DAEB0F2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1EB48836-4EE9-4D13-BF65-53A2DAEB0F2E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1EB48836-4EE9-4D13-BF65-53A2DAEB0F2E}.Debug|x64.ActiveCfg = Debug|Any CPU + {1EB48836-4EE9-4D13-BF65-53A2DAEB0F2E}.Debug|x64.Build.0 = Debug|Any CPU + {1EB48836-4EE9-4D13-BF65-53A2DAEB0F2E}.Debug|x86.ActiveCfg = Debug|Any CPU + {1EB48836-4EE9-4D13-BF65-53A2DAEB0F2E}.Debug|x86.Build.0 = Debug|Any CPU + {1EB48836-4EE9-4D13-BF65-53A2DAEB0F2E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1EB48836-4EE9-4D13-BF65-53A2DAEB0F2E}.Release|Any CPU.Build.0 = Release|Any CPU + {1EB48836-4EE9-4D13-BF65-53A2DAEB0F2E}.Release|x64.ActiveCfg = Release|Any CPU + {1EB48836-4EE9-4D13-BF65-53A2DAEB0F2E}.Release|x64.Build.0 = Release|Any CPU + {1EB48836-4EE9-4D13-BF65-53A2DAEB0F2E}.Release|x86.ActiveCfg = Release|Any CPU + {1EB48836-4EE9-4D13-BF65-53A2DAEB0F2E}.Release|x86.Build.0 = Release|Any CPU + {3FFEA843-CB10-4465-B645-7FA9A86531C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3FFEA843-CB10-4465-B645-7FA9A86531C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3FFEA843-CB10-4465-B645-7FA9A86531C6}.Debug|x64.ActiveCfg = Debug|Any CPU + {3FFEA843-CB10-4465-B645-7FA9A86531C6}.Debug|x64.Build.0 = Debug|Any CPU + {3FFEA843-CB10-4465-B645-7FA9A86531C6}.Debug|x86.ActiveCfg = Debug|Any CPU + {3FFEA843-CB10-4465-B645-7FA9A86531C6}.Debug|x86.Build.0 = Debug|Any CPU + {3FFEA843-CB10-4465-B645-7FA9A86531C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3FFEA843-CB10-4465-B645-7FA9A86531C6}.Release|Any CPU.Build.0 = Release|Any CPU + {3FFEA843-CB10-4465-B645-7FA9A86531C6}.Release|x64.ActiveCfg = Release|Any CPU + {3FFEA843-CB10-4465-B645-7FA9A86531C6}.Release|x64.Build.0 = Release|Any CPU + {3FFEA843-CB10-4465-B645-7FA9A86531C6}.Release|x86.ActiveCfg = Release|Any CPU + {3FFEA843-CB10-4465-B645-7FA9A86531C6}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection EndGlobal From 17da1c183e06441ed45e7b939c334d59d464c174 Mon Sep 17 00:00:00 2001 From: Dmitri Rossev Date: Fri, 16 Oct 2020 14:55:15 +0300 Subject: [PATCH 2/2] Removed resources --- .../Properties/Resources.Designer.cs | 63 ----------- src/Features.CSharp/Properties/Resources.resx | 101 ------------------ 2 files changed, 164 deletions(-) delete mode 100644 src/Features.CSharp/Properties/Resources.Designer.cs delete mode 100644 src/Features.CSharp/Properties/Resources.resx diff --git a/src/Features.CSharp/Properties/Resources.Designer.cs b/src/Features.CSharp/Properties/Resources.Designer.cs deleted file mode 100644 index 4c8893c..0000000 --- a/src/Features.CSharp/Properties/Resources.Designer.cs +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Features.CSharp.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Features.CSharp.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - } -} diff --git a/src/Features.CSharp/Properties/Resources.resx b/src/Features.CSharp/Properties/Resources.resx deleted file mode 100644 index 4fdb1b6..0000000 --- a/src/Features.CSharp/Properties/Resources.resx +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file