show article price as string
This commit is contained in:
parent
10d3a681b1
commit
96d0a03ba8
3 changed files with 14 additions and 1 deletions
|
@ -1,5 +1,8 @@
|
||||||
#include "article.h"
|
#include "article.h"
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
// Article::Article() : Entity() {}
|
// Article::Article() : Entity() {}
|
||||||
|
|
||||||
Article::Article(int price) : price_(price) {}
|
Article::Article(int price) : price_(price) {}
|
||||||
|
@ -24,4 +27,12 @@ Seller* Article::getSeller() { return sellerPtr_; }
|
||||||
|
|
||||||
int Article::getPrice() const { return price_; }
|
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_; }
|
int Article::getArticleNo() { return articleNo_; }
|
|
@ -29,6 +29,7 @@ class Article : public Entity
|
||||||
std::string getDescription();
|
std::string getDescription();
|
||||||
Seller* getSeller();
|
Seller* getSeller();
|
||||||
int getPrice() const;
|
int getPrice() const;
|
||||||
|
std::string getPriceAsString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Seller* sellerPtr_{};
|
Seller* sellerPtr_{};
|
||||||
|
|
|
@ -30,7 +30,8 @@ QVariant BasketModel::data(const QModelIndex& index, int role) const
|
||||||
case 2:
|
case 2:
|
||||||
return article->getSeller()->getSellerNo();
|
return article->getSeller()->getSellerNo();
|
||||||
case 3:
|
case 3:
|
||||||
return article->getPrice();
|
//return article->getPrice();
|
||||||
|
return article->getPriceAsString().c_str();
|
||||||
default:
|
default:
|
||||||
return "???";
|
return "???";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue