The calculation of how many harvest shares are expected in total.

This commit is contained in:
2026-02-21 22:54:59 +01:00
parent 6b383b8f55
commit d800ecfed7
7 changed files with 71 additions and 3 deletions

View File

@ -10,6 +10,8 @@ ModelSummary::ModelSummary(std::shared_ptr<TableModel> model, QObject* parent)
// TODO ? use existing model signals (dataChanged(role),...) instead of special signals
connect(m_model.get(), &TableModel::nExpectedBiddingsChanged, this,
&ModelSummary::nExpectedBiddingsChanged);
connect(m_model.get(), &TableModel::nTotalExpectedSharesChanged, this,
&ModelSummary::nTotalExpectedSharesChanged);
connect(m_model.get(), &TableModel::nPlacedBiddingsChanged, this,
&ModelSummary::nPlacedBiddingsChanged);
connect(m_model.get(), &TableModel::biddingSumChanged, this, &ModelSummary::biddingSumChanged);
@ -29,6 +31,8 @@ QBindable<int> ModelSummary::bindableRowCount() {
return &m_rowCount;
}
qreal ModelSummary::nTotalExpectedShares() const { return m_model->nTotalExpectedShares(); }
int ModelSummary::nExpectedBiddings() const { return m_model->nExpectedBiddings(); }
int ModelSummary::nPlacedBiddings1() const { return m_model->nPlacedBiddings1(); }

View File

@ -19,6 +19,8 @@ class ModelSummary : public QObject {
int rowCount() const;
QBindable<int> bindableRowCount();
qreal nTotalExpectedShares() const;
int nExpectedBiddings() const;
int nPlacedBiddings1() const;
int nPlacedBiddings2() const;
@ -36,6 +38,7 @@ class ModelSummary : public QObject {
void rowCountChanged();
void nExpectedBiddingsChanged();
void nTotalExpectedSharesChanged();
void nPlacedBiddingsChanged(const int roundNumber);
void biddingSumChanged(const int roundNumber);
void biddingAverageChanged(const int roundNumber);

View File

@ -340,6 +340,30 @@ void TableModel::insertItems(int startPosition,
m_undoStack->push(insertCommand);
}
qreal TableModel::nTotalExpectedShares() const {
qreal result = 0;
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
/// if BiddingTypeRole is not empty
const QString biddingType = (*i)->data(BiddingTypeRole).toString();
const qreal shareAmount = (*i)->data(ShareAmountRole).toReal();
if (biddingType.isEmpty() || shareAmount == 0.0) {
continue;
}
/// add amount
const QString shareType = (*i)->data(ShareTypeRole).toString();
if (shareType == "bezahlt") {
result += shareAmount;
} else if (shareType == "teils/teils") {
result += shareAmount / 2;
} else {
qInfo() << "Share type not 'bezahlt' nor 'teils/teils'. Will be ignored..";
qDebug() << "Share type:" << shareType;
}
}
qInfo() << "Biddings expected for " << result << "shares!";
return result;
}
int TableModel::nExpectedBiddings() const {
int result = 0;
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
@ -397,6 +421,7 @@ void TableModel::onRowCountChanged(const QModelIndex& parent, int first, int las
}
emit rowCountChanged();
emit nExpectedBiddingsChanged();
emit nTotalExpectedSharesChanged();
emit nPlacedBiddingsChanged(1);
emit nPlacedBiddingsChanged(2);
@ -449,6 +474,7 @@ void TableModel::execEditItemData(const int row, const QMap<int, QVariant>& chan
if (roles.contains(BiddingTypeRole) || roles.contains(ShareAmountRole) ||
roles.contains(ShareTypeRole)) {
emit nExpectedBiddingsChanged();
emit nTotalExpectedSharesChanged();
}
if (roles.contains(ShareAmountRole) || roles.contains(ShareTypeRole)) {
emit nPlacedBiddingsChanged(1);

View File

@ -63,6 +63,7 @@ class TableModel : public QAbstractTableModel {
const QModelIndex& parentIndex = QModelIndex());
/// property functions
qreal nTotalExpectedShares() const;
int nExpectedBiddings() const;
int nPlacedBiddings1() const;
int nPlacedBiddings2() const;
@ -80,6 +81,7 @@ class TableModel : public QAbstractTableModel {
void rowCountChanged();
void nExpectedBiddingsChanged();
void nTotalExpectedSharesChanged();
void nPlacedBiddingsChanged(const int roundNumber);
void biddingSumChanged(const int roundNumber);
void biddingAverageChanged(const int roundNumber);