Add employee in GUI and set up a dictionary for it

This commit is contained in:
2025-01-15 09:35:54 +01:00
parent 80a269a729
commit 3eadad5d5b
3 changed files with 87 additions and 18 deletions

View File

@@ -3,7 +3,7 @@ import QtQuick.Layouts
import QtQuick.Controls import QtQuick.Controls
ApplicationWindow ApplicationWindow
{ {
id: addmitarbeiter id: addMitarbeiter
title: qsTr("Objekt - Neuer Mitarbeiter") title: qsTr("Objekt - Neuer Mitarbeiter")
ColumnLayout ColumnLayout
@@ -31,6 +31,7 @@ ApplicationWindow
} }
TextField TextField
{ {
id: assignee
Layout.fillWidth: true Layout.fillWidth: true
} }
Label Label
@@ -40,6 +41,7 @@ ApplicationWindow
} }
TextField TextField
{ {
id: wage
Layout.fillWidth: true Layout.fillWidth: true
} }
Label Label
@@ -49,6 +51,7 @@ ApplicationWindow
} }
TextField TextField
{ {
id: duration
Layout.fillWidth: true Layout.fillWidth: true
} }
Label Label
@@ -58,6 +61,7 @@ ApplicationWindow
} }
TextField TextField
{ {
id: cleanDays
Layout.fillWidth: true Layout.fillWidth: true
} }
Label Label
@@ -67,6 +71,7 @@ ApplicationWindow
} }
TextField TextField
{ {
id: tasks
Layout.fillWidth: true Layout.fillWidth: true
} }
Label Label
@@ -76,6 +81,7 @@ ApplicationWindow
} }
TextField TextField
{ {
id: output
Layout.fillWidth: true Layout.fillWidth: true
} }
} }
@@ -90,11 +96,30 @@ ApplicationWindow
Button Button
{ {
text: qsTr("Abbrechen") text: qsTr("Abbrechen")
onClicked: addMitarbeiter.close()
} }
Button Button
{ {
text: qsTr("Hinzufügen") text: qsTr("Hinzufügen")
onClicked:
{
if (assignee.text.trim() !== "" && duration.text.trim() !== "" && wage.text.trim() !== "" && cleanDays.text.trim() !== "" && tasks.text.trim() !== "" && output.text.trim() !== "")
{
var ne = {
"assignee": assignee.text.trim(),
"duration": duration.text.trim(),
"wage": wage.text.trim(),
"cleandays": cleanDays.text.trim(),
"tasks": tasks.text.trim(),
"output": output.text.trim(),
};
addMitarbeiter.addNewEmployee(ne)
addMitarbeiter.close()
} }
} }
} }
}
}
signal addNewEmployee(var new_employee)
} }

View File

@@ -182,7 +182,6 @@ GridLayout
ListView ListView
{ {
id: contactView id: contactView
//Layout.fillWidth: true
implicitHeight: parent.height implicitHeight: parent.height
model: contactModel model: contactModel
@@ -191,8 +190,6 @@ GridLayout
delegate: Item delegate: Item
{ {
width: parent.width width: parent.width
//color: firstname.palette.base
//border.color: firstname.activeFocus? firstname.palette.highlight: firstname.palette.base
height: 15 height: 15
Row Row

View File

@@ -4,7 +4,8 @@ import QtQuick.Controls
GridLayout GridLayout
{ {
property var employeens: null property var employeeForm: null
property var employees: null
id: oaoemployee id: oaoemployee
columns: 2 columns: 2
rows: 4 rows: 4
@@ -19,6 +20,23 @@ GridLayout
id: employeeModel id: employeeModel
} }
Component
{
id: employeesHeader
Row
{
Text
{
id: empName
text: qsTr("Mitarbeiter")
width: 175
font.bold: true
horizontalAlignment: Text.AlignHCenter
color: "yellow"
}
}
}
Rectangle Rectangle
{ {
Layout.fillWidth: true Layout.fillWidth: true
@@ -28,21 +46,26 @@ GridLayout
border.color: mitarbeiterhin.activeFocus? mitarbeiterhin.palette.highlight: mitarbeiterhin.palette.base border.color: mitarbeiterhin.activeFocus? mitarbeiterhin.palette.highlight: mitarbeiterhin.palette.base
ListView ListView
{ {
id: mitarbeitertext id: employeesList
model: ListModel{ListElement {name: "Mitarbeiter1"} ListElement{name: "Mitarbeiter2"}} //anchors.fill: parent
delegate: Item implicitHeight: parent.height
model: employeeModel
header: employeesHeader
delegate: Row
{ {
width: 200
height: 15
padding: 7
Text Text
{ {
text: model.name text: model.namens
color: "yellow"
} }
} }
// wrapMode: TextEdit.Wrap
// background: Rectangle
// {
// color: mitarbeiterhin.palette.base
// border.color: mitarbeiterhin.activeFocus? mitarbeiterhin.palette.highlight: mitarbeiterhin.palette.base
// }
} }
} }
RowLayout RowLayout
@@ -63,18 +86,42 @@ GridLayout
Button Button
{ {
id: mitarbeiterhin id: mitarbeiterhin
property var neuermitarbeiter: undefined
text: qsTr("Mitarbeiter hinzufügen") text: qsTr("Mitarbeiter hinzufügen")
onClicked: onClicked:
{ {
var nm = Qt.createComponent("AddObjectEmployee.qml") var nm = Qt.createComponent("AddObjectEmployee.qml")
if (nm.status === Component.Ready) if (nm.status === Component.Ready)
{ {
neuermitarbeiter = nm.createObject (appWindow, {width: 600, height: 400}) employeeForm = nm.createObject (appWindow, {width: 600, height: 400})
neuermitarbeiter.show() employeeForm.addNewEmployee.connect(onAddEmployee)
employeeForm.show()
}
else console.log(nm.errorString())
} }
} }
} }
function onAddEmployee(new_employee)
{
var num_employees = 0
if (employees === null || employees === undefined) employees = {}
else num_employees = Object.keys(employees).length;
employees[num_employees] = {}
employees[num_employees]["assignee"] = new_employee["assignee"];
employees[num_employees]["duration"] = new_employee["duration"];
employees[num_employees]["wage"] = new_employee["wage"];
employees[num_employees]["cleandays"] = new_employee["cleandays"];
employees[num_employees]["tasks"] = new_employee["tasks"];
employees[num_employees]["output"] = new_employee["output"];
employeeModel.append({namens: new_employee["assignee"]});
console.log(employeeModel.get(num_employees).namens)
console.log(new_employee["assignee"])
console.log(JSON.stringify(new_employee))
} }
} }