kima2/src/gui/reportmodel.cpp

103 lines
2.4 KiB
C++

#include "reportmodel.h"
#include <QFont>
ReportModel::ReportModel(Marketplace* market, QObject* parent)
: QAbstractTableModel(parent), market_(market)
{
}
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:
myFont.setFamily("monospace");
return myFont;
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->getUuidAsString().c_str();
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(), 20).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 "";
}