use C++ features to show price

This commit is contained in:
Martin Brodbeck 2018-07-23 21:21:05 +02:00
parent 96d0a03ba8
commit fa7938ca20
3 changed files with 37 additions and 4 deletions

View File

@ -29,9 +29,9 @@ int Article::getPrice() const { return price_; }
std::string Article::getPriceAsString() const std::string Article::getPriceAsString() const
{ {
double sumInEuro = price_ / 100.0L;
std::stringstream sumStream; 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(); return sumStream.str();
} }

View File

@ -1,5 +1,7 @@
#include "basketmodel.h" #include "basketmodel.h"
#include <QFont>
BasketModel::BasketModel(Marketplace* market, QObject* parent) BasketModel::BasketModel(Marketplace* market, QObject* parent)
: QAbstractTableModel(parent), marketplace_(market) : 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 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) if (role != Qt::DisplayRole)
return QVariant(); return QVariant();
@ -30,7 +48,7 @@ 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(); return article->getPriceAsString().c_str();
default: default:
return "???"; return "???";

View File

@ -2,6 +2,14 @@
<ui version="4.0"> <ui version="4.0">
<class>PriceDialog</class> <class>PriceDialog</class>
<widget class="QDialog" name="PriceDialog"> <widget class="QDialog" name="PriceDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>171</width>
<height>71</height>
</rect>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Artikelpreis</string> <string>Artikelpreis</string>
</property> </property>
@ -19,7 +27,14 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QDoubleSpinBox" name="priceSpinBox"/> <widget class="QDoubleSpinBox" name="priceSpinBox">
<property name="maximum">
<double>999.990000000000009</double>
</property>
<property name="singleStep">
<double>0.500000000000000</double>
</property>
</widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">