The calculation of how many harvest shares are expected in total.
This commit is contained in:
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user