lots of smaller improvements

This commit is contained in:
Martin Brodbeck 2018-07-30 14:43:02 +02:00
parent c3b17fbb8b
commit 84f71ea056
13 changed files with 49 additions and 24 deletions

View File

@ -31,9 +31,16 @@ int Article::getPrice() const { return price_; }
std::string Article::getPriceAsString() const std::string Article::getPriceAsString() const
{ {
std::stringstream sumStream; std::stringstream sumStream;
//sumStream.imbue(std::locale("de_DE.utf8")); // sumStream.imbue(std::locale("de_DE.utf8"));
sumStream << std::right << std::setw(12) << std::showbase << std::put_money(price_, false); sumStream << std::right << std::setw(10) << std::showbase << std::put_money(price_, false);
return sumStream.str(); return sumStream.str();
} }
int Article::getArticleNo() { return articleNo_; } int Article::getArticleNo() const { return articleNo_; }
std::string Article::getCompleteArticleNo() const
{
std::stringstream artNoStream;
artNoStream << sourceNo_ << "K" << std::setfill('0') << std::setw(5) << articleNo_;
return artNoStream.str();
}

View File

@ -25,7 +25,8 @@ class Article : public Entity
void setSale(Sale* salePtr); void setSale(Sale* salePtr);
void setSeller(Seller* sellerPtr); void setSeller(Seller* sellerPtr);
int getArticleNo(); int getArticleNo() const;
std::string getCompleteArticleNo() const;
std::string getDescription(); std::string getDescription();
Seller* getSeller(); Seller* getSeller();
Sale* getSale(); Sale* getSale();

View File

@ -11,7 +11,7 @@ class Entity
public: public:
enum class State { NEW, UPDATE, DELETE, OK }; enum class State { NEW, UPDATE, DELETE, OK };
//Entity() = default; // Entity() = default;
virtual ~Entity() = 0; virtual ~Entity() = 0;
void createUuid(); void createUuid();
@ -24,10 +24,12 @@ class Entity
virtual State getState() const; virtual State getState() const;
virtual int getSourceNo() const; virtual int getSourceNo() const;
protected:
int sourceNo_{};
private: private:
boost::uuids::uuid uuid_{}; boost::uuids::uuid uuid_{};
State state_{State::NEW}; State state_{State::NEW};
int sourceNo_{};
}; };
#endif // ENTITY_H #endif // ENTITY_H

View File

@ -89,14 +89,11 @@ void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
size_t Marketplace::basketSize() { return basket_.size(); } size_t Marketplace::basketSize() { return basket_.size(); }
void Marketplace::finishCurrentSale() void Marketplace::finishCurrentSale(std::unique_ptr<Sale> sale)
{ {
if (basket_.size() == 0) if (basket_.size() == 0)
return; return;
auto sale = std::make_unique<Sale>();
sale->createUuid();
for (auto iter = basket_.begin(); iter != basket_.end(); ++iter) { for (auto iter = basket_.begin(); iter != basket_.end(); ++iter) {
sale->addArticle((*iter).get()); sale->addArticle((*iter).get());
(*iter)->getSeller()->addArticle(std::move(*iter)); (*iter)->getSeller()->addArticle(std::move(*iter));
@ -125,7 +122,7 @@ std::string Marketplace::getBasketSumAsString()
// return sumStream.str(); // return sumStream.str();
std::stringstream sumStream; std::stringstream sumStream;
// sumStream.imbue(std::locale("de_DE.utf8")); // sumStream.imbue(std::locale("de_DE.utf8"));
sumStream << std::right << std::setw(12) << std::showbase << std::put_money(sumInCent, false); sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sumInCent, false);
return sumStream.str(); return sumStream.str();
} }
@ -148,7 +145,7 @@ double marketFee(int sum, int percent, int maxFee)
std::string marketFeeAsString(int sum, int percent, int maxFee) std::string marketFeeAsString(int sum, int percent, int maxFee)
{ {
std::stringstream feeStream; std::stringstream feeStream;
feeStream << std::right << std::setw(12) << std::showbase feeStream << std::right << std::setw(10) << std::showbase
<< std::put_money(marketFee(sum, percent, maxFee), false); << std::put_money(marketFee(sum, percent, maxFee), false);
return feeStream.str(); return feeStream.str();
} }
@ -156,7 +153,7 @@ std::string marketFeeAsString(int sum, int percent, int maxFee)
std::string paymentAsString(int sum, int percent) std::string paymentAsString(int sum, int percent)
{ {
std::stringstream feeStream; std::stringstream feeStream;
feeStream << std::right << std::setw(12) << std::showbase feeStream << std::right << std::setw(10) << std::showbase
<< std::put_money(sum - marketFee(sum, percent), false); << std::put_money(sum - marketFee(sum, percent), false);
return feeStream.str(); return feeStream.str();
} }

View File

@ -38,7 +38,7 @@ class Marketplace
Seller* findSellerWithSellerNo(int sellerNo); Seller* findSellerWithSellerNo(int sellerNo);
void addArticleToBasket(std::unique_ptr<Article> article); void addArticleToBasket(std::unique_ptr<Article> article);
size_t basketSize(); size_t basketSize();
void finishCurrentSale(); void finishCurrentSale(std::unique_ptr<Sale> sale);
void removeSale(boost::uuids::uuid uuid); void removeSale(boost::uuids::uuid uuid);
private: private:

View File

@ -34,7 +34,7 @@ int Sale::sumInCents()
std::string Sale::sumAsString() std::string Sale::sumAsString()
{ {
std::stringstream sumStream; std::stringstream sumStream;
sumStream << std::right << std::setw(12) << std::showbase << std::put_money(sumInCents(), false); sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sumInCents(), false);
return sumStream.str(); return sumStream.str();
} }

View File

@ -94,7 +94,7 @@ int Seller::sumInCents()
std::string Seller::sumAsString() std::string Seller::sumAsString()
{ {
std::stringstream sumStream; std::stringstream sumStream;
sumStream << std::right << std::setw(12) << std::showbase << std::put_money(sumInCents(), false); sumStream << std::right << std::setw(10) << std::showbase << std::put_money(sumInCents(), false);
return sumStream.str(); return sumStream.str();
} }

View File

@ -24,7 +24,8 @@ QVariant BasketModel::data(const QModelIndex& index, int role) const
case 0: case 0:
[[fallthrough]]; [[fallthrough]];
case 1: case 1:
[[fallthrough]]; myFont.setFamily("monospace");
return myFont;
case 2: case 2:
return myFont; return myFont;
case 3: case 3:
@ -45,7 +46,7 @@ QVariant BasketModel::data(const QModelIndex& index, int role) const
case 0: case 0:
return article->getUuidAsString().c_str(); return article->getUuidAsString().c_str();
case 1: case 1:
return article->getArticleNo(); return article->getCompleteArticleNo().c_str();
case 2: case 2:
return article->getSeller()->getSellerNo(); return article->getSeller()->getSellerNo();
case 3: case 3:
@ -96,7 +97,10 @@ void BasketModel::addArticle(Seller* seller, int price)
void BasketModel::finishSale() void BasketModel::finishSale()
{ {
emit beginRemoveRows(QModelIndex(), 0, marketplace_->getBasket().size() - 1); emit beginRemoveRows(QModelIndex(), 0, marketplace_->getBasket().size() - 1);
marketplace_->finishCurrentSale(); auto sale = std::make_unique<Sale>();
sale->createUuid();
sale->setSourceNo(QSettings().value("global/cashPointNo").toInt());
marketplace_->finishCurrentSale(std::move(sale));
emit endRemoveRows(); emit endRemoveRows();
emit basketDataChanged(); emit basketDataChanged();
} }

View File

@ -96,6 +96,7 @@ void MainWindow::onPaidButtonTriggered()
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale(); dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
ui_.lastPriceLabel1->setText(lastPrice); ui_.lastPriceLabel1->setText(lastPrice);
ui_.lastPriceLabel2->setText(lastPrice); ui_.lastPriceLabel2->setText(lastPrice);
ui_.basketSumLabel->setText(" 0,00 €");
statusBar()->showMessage("Verkaufsvorgang erfolgreich durchgeführt.", STATUSBAR_TIMEOUT); statusBar()->showMessage("Verkaufsvorgang erfolgreich durchgeführt.", STATUSBAR_TIMEOUT);
} }
} }
@ -128,8 +129,7 @@ void MainWindow::onSellerNoEditCheckSellerNo()
if (dialogResult == QDialog::Accepted) { if (dialogResult == QDialog::Accepted) {
int price = priceDialog.getPrice(); int price = priceDialog.getPrice();
dynamic_cast<BasketModel*>(ui_.basketView->model())->addArticle(seller, price); dynamic_cast<BasketModel*>(ui_.basketView->model())->addArticle(seller, price);
std::string sumStr = "Gesamt: " + marketplace_->getBasketSumAsString(); ui_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str());
ui_.basketSumLabel->setText(sumStr.c_str());
} }
} }

View File

@ -33,6 +33,7 @@
<widget class="QLabel" name="basketSumLabel"> <widget class="QLabel" name="basketSumLabel">
<property name="font"> <property name="font">
<font> <font>
<family>Monospace</family>
<pointsize>18</pointsize> <pointsize>18</pointsize>
<weight>75</weight> <weight>75</weight>
<bold>true</bold> <bold>true</bold>
@ -42,7 +43,7 @@
<enum>QFrame::Box</enum> <enum>QFrame::Box</enum>
</property> </property>
<property name="text"> <property name="text">
<string>Gesamt: ---</string> <string> 0,00 €</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
@ -298,6 +299,7 @@ drucken</string>
<widget class="QLabel" name="lastPriceLabel1"> <widget class="QLabel" name="lastPriceLabel1">
<property name="font"> <property name="font">
<font> <font>
<family>Monospace</family>
<pointsize>20</pointsize> <pointsize>20</pointsize>
<weight>75</weight> <weight>75</weight>
<bold>true</bold> <bold>true</bold>
@ -351,6 +353,7 @@ drucken</string>
<widget class="QLabel" name="lastPriceLabel2"> <widget class="QLabel" name="lastPriceLabel2">
<property name="font"> <property name="font">
<font> <font>
<family>Monospace</family>
<pointsize>20</pointsize> <pointsize>20</pointsize>
<weight>75</weight> <weight>75</weight>
<bold>true</bold> <bold>true</bold>

View File

@ -17,7 +17,14 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QTableView" name="reportView"/> <widget class="QTableView" name="reportView">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item> </item>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">

View File

@ -35,6 +35,10 @@ QVariant ReportModel::data(const QModelIndex& index, int role) const
if (role == Qt::TextAlignmentRole) { if (role == Qt::TextAlignmentRole) {
switch (index.column()) { switch (index.column()) {
case 4: case 4:
[[fallthrough]];
case 5:
[[fallthrough]];
case 6:
return Qt::AlignRight; return Qt::AlignRight;
default: default:
return Qt::AlignLeft; return Qt::AlignLeft;

View File

@ -108,7 +108,7 @@ QVariant SaleModel::data(const QModelIndex& index, int role) const
Article* article = static_cast<Article*>(index.internalPointer()); Article* article = static_cast<Article*>(index.internalPointer());
switch (index.column()) { switch (index.column()) {
case 0: case 0:
return article->getArticleNo(); return article->getCompleteArticleNo().c_str();
case 1: case 1:
return article->getPriceAsString().c_str(); return article->getPriceAsString().c_str();
case 2: case 2: