kima2/src/gui/reportmodel.cpp

108 lines
2.6 KiB
C++
Raw Normal View History

2018-07-30 09:50:54 +02:00
#include "reportmodel.h"
#include <QFont>
2018-08-08 09:16:23 +02:00
#include <QFontDatabase>
2018-07-30 15:19:29 +02:00
#include <QSettings>
2018-07-30 09:50:54 +02:00
ReportModel::ReportModel(Marketplace* market, QObject* parent)
: QAbstractTableModel(parent), market_(market)
{
2018-07-30 15:19:29 +02:00
QSettings settings;
feeInPercent_ = settings.value("global/feeInPercent").toInt();
maxFeeInCent_ = settings.value("global/maxFeeInEuro").toInt() * 100;
2018-07-30 09:50:54 +02:00
}
int ReportModel::rowCount([[maybe_unused]] const QModelIndex& parent) const
{
return static_cast<int>(market_->getSellers().size());
}
int ReportModel::columnCount([[maybe_unused]] const QModelIndex& parent) const { return 7; }
QVariant ReportModel::data(const QModelIndex& index, int role) const
{
if (role == Qt::FontRole) {
QFont myFont;
switch (index.column()) {
case 4:
[[fallthrough]];
case 5:
[[fallthrough]];
case 6:
2018-08-08 09:16:23 +02:00
return QFontDatabase::systemFont(QFontDatabase::FixedFont);
2018-07-30 09:50:54 +02:00
default:
return myFont;
}
}
if (role == Qt::TextAlignmentRole) {
switch (index.column()) {
case 4:
2018-07-30 14:43:02 +02:00
[[fallthrough]];
case 5:
[[fallthrough]];
case 6:
2018-07-30 09:50:54 +02:00
return Qt::AlignRight;
default:
return Qt::AlignLeft;
}
}
if (role != Qt::DisplayRole)
return QVariant();
if (market_->getSellers().size() == 0)
return QVariant();
Seller* seller = market_->getSellers().at(index.row()).get();
switch (index.column()) {
case 0:
2019-10-04 15:15:43 +02:00
return seller->getId();
2018-07-30 09:50:54 +02:00
case 1:
return seller->getSellerNo();
case 2:
return seller->getLastName().c_str();
case 3:
return seller->getFirstName().c_str();
case 4:
return seller->numArticlesSold();
case 5:
return seller->sumAsString().c_str();
case 6:
2018-07-30 15:19:29 +02:00
return paymentAsString(seller->sumInCents(), feeInPercent_, maxFeeInCent_).c_str();
2018-07-30 09:50:54 +02:00
default:
return "???";
}
}
QVariant ReportModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal) {
switch (section) {
case 0:
return "ID";
case 1:
return "Nummer";
case 2:
return "Nachname";
case 3:
return "Vorname";
case 4:
return "verkauft";
case 5:
return "Umsatz";
case 6:
return "Auszahlung";
default:
return "???";
}
// return QStringLiteral("%1").arg(section);
} else
return "";
2019-10-04 15:15:43 +02:00
}