From 3e302a02bc3d6145969c0326a9748dda420cf899 Mon Sep 17 00:00:00 2001 From: Chris Brandhorst Date: Mon, 31 Jan 2022 18:35:51 +0100 Subject: [PATCH] Added price per kilo column --- src/bricklink/lot.h | 1 + src/common/document.cpp | 2 ++ src/common/documentmodel.cpp | 10 ++++++++++ src/common/documentmodel.h | 1 + src/desktop/documentdelegate.cpp | 1 + src/mobile/View.qml | 1 + 6 files changed, 16 insertions(+) diff --git a/src/bricklink/lot.h b/src/bricklink/lot.h index 5c977ce7..fac2f614 100755 --- a/src/bricklink/lot.h +++ b/src/bricklink/lot.h @@ -86,6 +86,7 @@ class Lot int tierQuantity(int i) const { return m_tier_quantity [qBound(0, i, 2)]; } void setTierQuantity(int i, int q) { m_tier_quantity [qBound(0, i, 2)] = q; } double price() const { return m_price; } + double priceKilo() const { return price() > 0 && weight() > 0 ? price() / weight() * 1000 : 0; } void setPrice(double p) { m_price = p; } double tierPrice(int i) const { return m_tier_price[qBound(0, i, 2)]; } void setTierPrice(int i, double p) { m_tier_price[qBound(0, i, 2)] = p; } diff --git a/src/common/document.cpp b/src/common/document.cpp index c69f5a93..cba028f9 100755 --- a/src/common/document.cpp +++ b/src/common/document.cpp @@ -1863,6 +1863,7 @@ QVector Document::defaultColumnLayout(bool simpleMode) DocumentModel::PriceDiff, DocumentModel::Price, DocumentModel::Total, + DocumentModel::PriceKilo, DocumentModel::Cost, DocumentModel::Bulk, DocumentModel::Sale, @@ -1904,6 +1905,7 @@ QVector Document::defaultColumnLayout(bool simpleMode) DocumentModel::DateLastSold, DocumentModel::PriceOrig, DocumentModel::PriceDiff, + DocumentModel::PriceKilo, DocumentModel::QuantityOrig, DocumentModel::QuantityDiff, }; diff --git a/src/common/documentmodel.cpp b/src/common/documentmodel.cpp index bdfb2ce4..adecb6e6 100755 --- a/src/common/documentmodel.cpp +++ b/src/common/documentmodel.cpp @@ -1634,6 +1634,16 @@ void DocumentModel::initializeColumns() return doubleCompare(l1->total(), l2->total()); }, }); + C(PriceKilo, Column { + .defaultWidth = 15, + .alignment = Qt::AlignRight, + .editable = false, + .title = QT_TR_NOOP("Price / kg"), + .displayFn = [&](const Lot *lot) { return lot->priceKilo(); }, + .compareFn = [&](const Lot *l1, const Lot *l2) { + return doubleCompare(l1->priceKilo(), l2->priceKilo()); + }, + }); C(Sale, Column { .defaultWidth = 5, .alignment = Qt::AlignRight, diff --git a/src/common/documentmodel.h b/src/common/documentmodel.h index ea828404..02309490 100644 --- a/src/common/documentmodel.h +++ b/src/common/documentmodel.h @@ -61,6 +61,7 @@ class DocumentModel : public QAbstractTableModel PriceDiff, Price, Total, + PriceKilo, Cost, Bulk, Sale, diff --git a/src/desktop/documentdelegate.cpp b/src/desktop/documentdelegate.cpp index fdadd2e8..93da6c12 100755 --- a/src/desktop/documentdelegate.cpp +++ b/src/desktop/documentdelegate.cpp @@ -1108,6 +1108,7 @@ QString DocumentDelegate::displayData(const QModelIndex &idx, const QVariant &di case DocumentModel::PriceDiff: case DocumentModel::Price: case DocumentModel::Total: + case DocumentModel::PriceKilo: case DocumentModel::Cost: case DocumentModel::TierP1: case DocumentModel::TierP2: diff --git a/src/mobile/View.qml b/src/mobile/View.qml index ac9e946f..eb3527ce 100755 --- a/src/mobile/View.qml +++ b/src/mobile/View.qml @@ -235,6 +235,7 @@ Page { tint: Qt.rgba(1, 1, 0, .1) } } + DelegateChoice { roleValue: Document.PriceKilo; delegate: currencyDelegate } DelegateChoice { roleValue: Document.Cost; delegate: currencyDelegate } DelegateChoice { roleValue: Document.TierP1 GridCell {