rename applicationLogic to applicationView to better reflect purpose

This commit is contained in:
Iuri Matias 2020-05-11 14:22:01 -04:00
parent b8563b25a3
commit 87c7abe687
2 changed files with 18 additions and 22 deletions

View File

@ -2,15 +2,14 @@ import NimQml
# Probably all QT classes will look like this: # Probably all QT classes will look like this:
QtObject: QtObject:
type ApplicationLogic* = ref object of QObject type ApplicationView* = ref object of QObject
app: QApplication app: QApplication
callResult: string callResult: string
accountResult: string accountResult: string
sendMessage: proc (msg: string): string sendMessage: proc (msg: string): string
# chats: seq[ChatView]
# Constructor # Constructor
proc newApplicationLogic*(app: QApplication, sendMessage: proc): ApplicationLogic = proc newApplicationView*(app: QApplication, sendMessage: proc): ApplicationView =
new(result) new(result)
result.app = app result.app = app
result.sendMessage = sendMessage result.sendMessage = sendMessage
@ -18,32 +17,31 @@ QtObject:
result.setup() result.setup()
# ¯\_(ツ)_/¯ dunno what is this # ¯\_(ツ)_/¯ dunno what is this
proc setup(self: ApplicationLogic) = proc setup(self: ApplicationView) =
# discard status.onMessage(self.onMessage)
self.QObject.setup self.QObject.setup
# ¯\_(ツ)_/¯ seems to be a method for garbage collection # ¯\_(ツ)_/¯ seems to be a method for garbage collection
proc delete*(self: ApplicationLogic) = proc delete*(self: ApplicationView) =
self.QObject.delete self.QObject.delete
# Read more about slots and signals here: https://doc.qt.io/qt-5/signalsandslots.html # Read more about slots and signals here: https://doc.qt.io/qt-5/signalsandslots.html
# This is an EventHandler # This is an EventHandler
proc onExitTriggered(self: ApplicationLogic) {.slot.} = proc onExitTriggered(self: ApplicationView) {.slot.} =
self.app.quit self.app.quit
# Accesors # Accesors
proc callResult*(self: ApplicationLogic): string {.slot.} = proc callResult*(self: ApplicationView): string {.slot.} =
result = self.callResult result = self.callResult
proc callResultChanged*(self: ApplicationLogic, callResult: string) {.signal.} proc callResultChanged*(self: ApplicationView, callResult: string) {.signal.}
proc setCallResult(self: ApplicationLogic, callResult: string) {.slot.} = proc setCallResult(self: ApplicationView, callResult: string) {.slot.} =
if self.callResult == callResult: return if self.callResult == callResult: return
self.callResult = callResult self.callResult = callResult
self.callResultChanged(callResult) self.callResultChanged(callResult)
proc `callResult=`*(self: ApplicationLogic, callResult: string) = self.setCallResult(callResult) proc `callResult=`*(self: ApplicationView, callResult: string) = self.setCallResult(callResult)
# Binding between a QML variable and accesors is done here # Binding between a QML variable and accesors is done here
QtProperty[string] callResult: QtProperty[string] callResult:
@ -51,20 +49,20 @@ QtObject:
write = setCallResult write = setCallResult
notify = callResultChanged notify = callResultChanged
proc onSend*(self: ApplicationLogic, inputJSON: string) {.slot.} = proc onSend*(self: ApplicationView, inputJSON: string) {.slot.} =
self.setCallResult(self.sendMessage(inputJSON)) self.setCallResult(self.sendMessage(inputJSON))
echo "Done!: ", self.callResult echo "Done!: ", self.callResult
# proc onMessage*(self: ApplicationLogic, message: string) {.slot.} = proc onMessage*(self: ApplicationView, message: string) {.slot.} =
# self.setCallResult(message) self.setCallResult(message)
# echo "Received message: ", message echo "Received message: ", message
proc accountResultChanged*(self: ApplicationLogic, callResult: string) {.signal.} proc accountResultChanged*(self: ApplicationView, callResult: string) {.signal.}
proc accountResult*(self: ApplicationLogic): string {.slot.} = proc accountResult*(self: ApplicationView): string {.slot.} =
result = self.accountResult result = self.accountResult
proc setAccountResult(self: ApplicationLogic, accountResult: string) {.slot.} = proc setAccountResult(self: ApplicationView, accountResult: string) {.slot.} =
if self.accountResult == accountResult: return if self.accountResult == accountResult: return
self.accountResult = accountResult self.accountResult = accountResult
self.accountResultChanged(accountResult) self.accountResultChanged(accountResult)

View File

@ -1,5 +1,5 @@
import NimQml import NimQml
import applicationLogic import applicationView
import chats import chats
import state import state
import status import status
@ -16,7 +16,6 @@ var signalHandler: SignalCallback = proc(p0: cstring): void =
tearDownForeignThreadGc() tearDownForeignThreadGc()
proc mainProc() = proc mainProc() =
# From QT docs: # From QT docs:
# For any GUI application using Qt, there is precisely one QApplication object, # For any GUI application using Qt, there is precisely one QApplication object,
# no matter whether the application has 0, 1, 2 or more windows at any given time. # no matter whether the application has 0, 1, 2 or more windows at any given time.
@ -31,7 +30,6 @@ proc mainProc() =
var engine = newQQmlApplicationEngine() var engine = newQQmlApplicationEngine()
defer: engine.delete() defer: engine.delete()
status.setSignalHandler(signalHandler) status.setSignalHandler(signalHandler)
status.setupNewAccount() status.setupNewAccount()
@ -41,7 +39,7 @@ proc mainProc() =
# result.accountResult = status.queryAccounts() # result.accountResult = status.queryAccounts()
status.subscribeToTest() status.subscribeToTest()
let logic = newApplicationLogic(app, status.callPrivateRPC) let logic = newApplicationView(app, status.callPrivateRPC)
defer: logic.delete defer: logic.delete
let logicVariant = newQVariant(logic) let logicVariant = newQVariant(logic)