From 96d0a03ba863460a384110225deb53f14e3fc44a Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Mon, 23 Jul 2018 14:25:18 +0200 Subject: [PATCH] show article price as string --- src/core/article.cpp | 11 +++++++++++ src/core/article.h | 1 + src/gui/basketmodel.cpp | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/core/article.cpp b/src/core/article.cpp index ae34d46..fe75c19 100644 --- a/src/core/article.cpp +++ b/src/core/article.cpp @@ -1,5 +1,8 @@ #include "article.h" +#include +#include + // Article::Article() : Entity() {} Article::Article(int price) : price_(price) {} @@ -24,4 +27,12 @@ Seller* Article::getSeller() { return sellerPtr_; } 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 << " €"; + return sumStream.str(); +} + int Article::getArticleNo() { return articleNo_; } \ No newline at end of file diff --git a/src/core/article.h b/src/core/article.h index f2bfd15..27e858c 100644 --- a/src/core/article.h +++ b/src/core/article.h @@ -29,6 +29,7 @@ class Article : public Entity std::string getDescription(); Seller* getSeller(); int getPrice() const; + std::string getPriceAsString() const; private: Seller* sellerPtr_{}; diff --git a/src/gui/basketmodel.cpp b/src/gui/basketmodel.cpp index c14e4ff..243faf8 100644 --- a/src/gui/basketmodel.cpp +++ b/src/gui/basketmodel.cpp @@ -30,7 +30,8 @@ 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 "???"; }