From fa7938ca200035b0acd6e8aaab7c5ba658c1d4da Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Mon, 23 Jul 2018 21:21:05 +0200 Subject: [PATCH] use C++ features to show price --- src/core/article.cpp | 4 ++-- src/gui/basketmodel.cpp | 20 +++++++++++++++++++- src/gui/pricedialog.ui | 17 ++++++++++++++++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/core/article.cpp b/src/core/article.cpp index fe75c19..ba4b5bf 100644 --- a/src/core/article.cpp +++ b/src/core/article.cpp @@ -29,9 +29,9 @@ int Article::getPrice() const { return price_; } std::string Article::getPriceAsString() const { - double sumInEuro = price_ / 100.0L; std::stringstream sumStream; - sumStream << std::fixed << std::setprecision(2) << sumInEuro << " €"; + sumStream.imbue(std::locale("de_DE.utf8")); + sumStream << std::right << std::setw(12) << std::showbase << std::put_money(price_, false); return sumStream.str(); } diff --git a/src/gui/basketmodel.cpp b/src/gui/basketmodel.cpp index 243faf8..cc2f1cb 100644 --- a/src/gui/basketmodel.cpp +++ b/src/gui/basketmodel.cpp @@ -1,5 +1,7 @@ #include "basketmodel.h" +#include + BasketModel::BasketModel(Marketplace* market, QObject* parent) : QAbstractTableModel(parent), marketplace_(market) { @@ -14,6 +16,22 @@ int BasketModel::columnCount([[maybe_unused]] const QModelIndex& parent) const { QVariant BasketModel::data(const QModelIndex& index, int role) const { + if (role == Qt::FontRole) { + QFont myFont; + + switch (index.column()) { + case 0: + [[fallthrough]]; + case 1: + [[fallthrough]]; + case 2: + return myFont; + case 3: + myFont.setFamily("monospace"); + return myFont; + } + } + if (role != Qt::DisplayRole) return QVariant(); @@ -30,7 +48,7 @@ QVariant BasketModel::data(const QModelIndex& index, int role) const case 2: return article->getSeller()->getSellerNo(); case 3: - //return article->getPrice(); + // return article->getPrice(); return article->getPriceAsString().c_str(); default: return "???"; diff --git a/src/gui/pricedialog.ui b/src/gui/pricedialog.ui index cf2062d..95d9dbd 100644 --- a/src/gui/pricedialog.ui +++ b/src/gui/pricedialog.ui @@ -2,6 +2,14 @@ PriceDialog + + + 0 + 0 + 171 + 71 + + Artikelpreis @@ -19,7 +27,14 @@ - + + + 999.990000000000009 + + + 0.500000000000000 + +