#include "reportmodel.h" #include #include #include ReportModel::ReportModel(Marketplace* market, QObject* parent) : QAbstractTableModel(parent), market_(market) { QSettings settings; feeInPercent_ = settings.value("global/feeInPercent").toInt(); maxFeeInCent_ = settings.value("global/maxFeeInEuro").toInt() * 100; } int ReportModel::rowCount([[maybe_unused]] const QModelIndex& parent) const { return static_cast(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: return QFontDatabase::systemFont(QFontDatabase::FixedFont); default: return myFont; } } if (role == Qt::TextAlignmentRole) { switch (index.column()) { case 4: [[fallthrough]]; case 5: [[fallthrough]]; case 6: 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: return seller->getId(); 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: return paymentAsString(seller->sumInCents(), feeInPercent_, maxFeeInCent_).c_str(); 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 ""; }