Choice model settings was added

This commit is contained in:
2023-04-10 19:24:25 +02:00
parent 25e8a3ea79
commit 4a52926be9
31 changed files with 938 additions and 227 deletions

View File

@@ -1,12 +1,63 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import ru.ded.beerlog 1.0
Page {
Label {
anchors.centerIn: parent
title: qsTr("Orders")
text: "Orders"
OrdersViewModel {
id: ordersModel
}
ListView {
id: ordersList
anchors.fill: parent
anchors.margins: 10
model: ordersModel
section.criteria: ViewSection.FullString
section.property: "date"
section.delegate: Label {
text: section
font.bold: true
}
delegate: Column {
width: ordersList.width
height: productsList.heigt
ListView {
id: productsList
width: ordersList.width
height: contentHeight
model: products
header: Label {
padding: 10
font.bold: true
text: "%1 (%2), %3".arg(userName).arg(storeName).arg(time.toLocaleTimeString(Qt.locale(), Locale.ShortFormat))
}
delegate: Label {
width: ordersList.width
leftPadding: 20
text: "%1 x%2, %3".arg(modelData.product).arg(modelData.quantity.toLocaleString(Qt.locale())).arg(modelData.price.toLocaleCurrencyString(Qt.locale()))
}
footer: Label {
padding: 10
font.bold: true
text: qsTr("Summary: %1").arg(amount.toLocaleCurrencyString(Qt.locale()))
}
}
}
}
}

106
qml/Views/ProductsView.qml Normal file
View File

@@ -0,0 +1,106 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import ru.ded.beerlog 1.0
Page {
ProductsViewModel {
id: productsModel
}
RowLayout {
anchors.fill: parent
ListView {
id: productsList
Layout.fillWidth: true
Layout.preferredHeight: parent.height
model: productsModel.products
delegate: ItemDelegate {
width: productsList.width
text: modelData.name
height: spinbox.height
SpinBox {
id: spinbox
width: 150
from: 0
to: 100 * 100
stepSize: 50
anchors.right: parent.right
editable: true
property int decimals: 1
property real realValue: value / 100
validator: DoubleValidator {
bottom: Math.min(spinbox.from, spinbox.to)
top: Math.max(spinbox.from, spinbox.to)
}
textFromValue: function(value, locale) {
return value === 0 ? "" : Number(value / 100).toLocaleString(locale, 'f', spinbox.decimals)
}
valueFromText: function(text, locale) {
return Number.fromLocaleString(locale, text) * 100
}
onRealValueChanged: productsModel.setOrderValue(modelData.id, realValue)
}
}
function reload() {
model = undefined
model = productsModel.products
}
}
ListView {
id: orderList
Layout.minimumWidth: parent.width * 0.3
Layout.preferredHeight: parent.height
model: productsModel.order
delegate: ItemDelegate {
width: orderList.width
text: "%1 x%2".arg(modelData.name).arg(modelData.count.toLocaleString(Qt.locale()))
}
footer: Column {
width: orderList.width
Label {
anchors.right: parent.right
anchors.margins: 10
text: qsTr("Summary: %1").arg(productsModel.orderSum.toLocaleCurrencyString(Qt.locale()))
}
Button {
anchors.right: parent.right
anchors.margins: 10
text: qsTr("Order")
enabled: productsModel.orderSum > 0
onClicked: {
productsModel.submitOrder()
productsList.reload()
}
}
}
}
}
}

View File

@@ -1,24 +1,20 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import Components 1.0
import ru.ded.beerlog 1.0
Page {
id: root
title: qsTr("Settings")
ListModel {
property var controls: {
"text": textComponent,
"choice": choiceComponent
}
SettingsViewModel {
id: settingsModel
ListElement {
title: qsTr("BeerLog service address")
name: "serverAddress"
}
ListElement {
title: qsTr("Selected user id")
name: "selectedUserId"
}
}
ListView {
@@ -35,6 +31,8 @@ Page {
onClicked: {
inputDialog.title = model.title
inputDialog.name = model.name
inputDialog.control = controls[model.control]
inputDialog.choiceModel = model.choiceModel
inputDialog.open()
}
}
@@ -44,6 +42,8 @@ Page {
id: inputDialog
property string name: ""
property var choiceModel: undefined
property alias control: editor.sourceComponent
width: root.width * 0.8
@@ -53,22 +53,54 @@ Page {
modal: true
standardButtons: Dialog.Ok | Dialog.Cancel
Column {
spacing: 20
Loader {
id: editor
property var value: item && item.value
anchors.fill: parent
TextField {
id: textField
width: parent.width
inputMethodHints: Qt.ImhNoAutoUppercase
placeholderText: inputDialog.title
text: settingsService[inputDialog.name] || ""
}
}
onAccepted: {
settingsService[inputDialog.name] = textField.text
settingsService[inputDialog.name] = editor.value
}
}
Component {
id: textComponent
TextField {
id: textField
property alias value: textField.text
inputMethodHints: Qt.ImhNoAutoUppercase
text: settingsService[inputDialog.name] || ""
}
}
ButtonGroup {
id: group
}
Component {
id: choiceComponent
Column {
property var value: group.checkedButton && group.checkedButton.valueId
Repeater {
model: inputDialog.choiceModel
delegate: RadioDelegate {
property var valueId: modelData.id
text: modelData.name
width: parent.width
checked: settingsService[inputDialog.name] === valueId
ButtonGroup.group: group
}
}
}
}
}

View File

@@ -26,6 +26,7 @@ ApplicationWindow {
Label {
text: stackView.currentItem.title || usersModel.selectedUserName
Layout.fillWidth: true
Layout.minimumWidth: 100
horizontalAlignment: Qt.AlignCenter
MouseArea {
@@ -55,24 +56,46 @@ ApplicationWindow {
}
}
}
Menu {
id: storesMenu
StoresViewModel {
id: storesModel
}
Repeater {
model: storesModel.stores
MenuItem {
text: modelData.name
onClicked: {
storesModel.selectedStore = modelData.id
}
}
}
}
}
MainMenu {
id: mainMenu
readonly property var actions: {
"orders": () => { stackView.openPage("Views/OrdersView.qml") },
"settings": () => { stackView.openPage("Views/SettingsView.qml") },
"quit": () => { Qt.quit() }
}
width: parent.width * 0.66
height: parent.height
logo: "qrc:/logo.png"
appName: qsTr("BeerLog v0.1")
connected: beerService.connected
model: ListModel {
ListElement {
title: qsTr("Orders")
action: "orders"
}
ListElement {
title: qsTr("Settings")
action: "settings"
@@ -88,7 +111,7 @@ ApplicationWindow {
StackView {
id: stackView
initialItem: "Views/OrdersView.qml"
initialItem: "Views/ProductsView.qml"
anchors.fill: parent
function openPage(page) {

View File

@@ -11,5 +11,6 @@
<file>Components/SubtitledItemDelegate.qml</file>
<file>Components/qmldir</file>
<file>qt_ru.qm</file>
<file>Views/ProductsView.qml</file>
</qresource>
</RCC>