nimqml/examples/contactapp/contact.nim

52 lines
1.2 KiB
Nim
Raw Normal View History

2015-09-14 21:38:02 +00:00
import NimQml
QtObject:
type Contact* = ref object of QObject
name: string
surname: string
proc delete*(self: Contact) =
self.QObject.delete
proc setup(self: Contact) =
self.QObject.setup
2015-09-14 21:38:02 +00:00
proc newContact*(): Contact =
new(result)
result.name = ""
result.setup
2015-09-14 21:38:02 +00:00
proc firstName*(self: Contact): string {.slot.} =
2015-09-14 21:38:02 +00:00
result = self.name
2017-03-12 16:01:54 +00:00
proc firstNameChanged*(self: Contact, firstName: string) {.signal.}
2015-09-14 21:38:02 +00:00
proc setFirstName(self: Contact, name: string) {.slot.} =
if self.name == name: return
self.name = name
2017-03-12 16:01:54 +00:00
self.firstNameChanged(name)
2015-09-14 21:38:02 +00:00
proc `firstName=`*(self: Contact, name: string) = self.setFirstName(name)
QtProperty[string] firstName:
read = firstName
write = setFirstName
notify = firstNameChanged
proc surname*(self: Contact): string {.slot.} =
2015-09-14 21:38:02 +00:00
result = self.surname
2017-03-12 16:01:54 +00:00
proc surnameChanged*(self: Contact, surname: string) {.signal.}
2015-09-14 21:38:02 +00:00
proc setSurname(self: Contact, surname: string) {.slot.} =
if self.surname == surname: return
self.surname = surname
2017-03-12 16:01:54 +00:00
self.surnameChanged(surname)
2015-09-14 21:38:02 +00:00
proc `surname=`*(self: Contact, surname: string) = self.setSurname(surname)
QtProperty[string] surname:
read = surname
write = setSurname
notify = surnameChanged