Added more model tests and fixed the calculations for nPlacedBiddings, biddingSum and totalSharesWithBiddings if there are conflicting entries (shareType: "erarbeitet" but a bidding is placed).
This commit is contained in:
@ -437,9 +437,9 @@ void TableModel::execEditItemData(const int row, const QMap<int, QVariant>& chan
|
||||
bool isDataChanged = item->setItemData(changedValues);
|
||||
|
||||
if (isDataChanged) {
|
||||
/// FIXME due to the mapping from roles to the DisplayRole of different columns the complete row
|
||||
/// is getting notified about (potential) data changes; dataChanged should be called only for
|
||||
/// the affected columns
|
||||
/// FIXME due to the mapping from roles to the DisplayRole of different columns the complete
|
||||
/// row is getting notified about (potential) data changes; dataChanged should be called only
|
||||
/// for the affected columns
|
||||
const QModelIndex firstIndex = this->index(row, 0);
|
||||
const QModelIndex lastIndex = this->index(row, USER_FACING_ROLES.size() - 1);
|
||||
QList<int> roles = changedValues.keys();
|
||||
@ -577,6 +577,15 @@ bool TableModel::isItemEqualToItemValues(const QModelIndex& itemIndex,
|
||||
int TableModel::nPlacedBiddings(const UserRoles biddingRole) const {
|
||||
int result = 0;
|
||||
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
|
||||
const QString biddingType = (*i)->data(BiddingTypeRole).toString();
|
||||
const qreal shareAmount = (*i)->data(ShareAmountRole).toReal();
|
||||
const QString shareType = (*i)->data(ShareTypeRole).toString();
|
||||
if (biddingType.isEmpty() || shareAmount == 0.0) {
|
||||
continue;
|
||||
}
|
||||
if (shareType == "erarbeitet" || shareType == "") {
|
||||
continue;
|
||||
}
|
||||
int localBidding = (*i)->data(biddingRole).toInt();
|
||||
if (localBidding > 0) {
|
||||
result++;
|
||||
@ -588,6 +597,15 @@ int TableModel::nPlacedBiddings(const UserRoles biddingRole) const {
|
||||
int TableModel::biddingSum(const UserRoles biddingRole) const {
|
||||
int result = 0;
|
||||
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
|
||||
const QString biddingType = (*i)->data(BiddingTypeRole).toString();
|
||||
const qreal shareAmount = (*i)->data(ShareAmountRole).toReal();
|
||||
const QString shareType = (*i)->data(ShareTypeRole).toString();
|
||||
if (biddingType.isEmpty() || shareAmount == 0.0) {
|
||||
continue;
|
||||
}
|
||||
if (shareType == "erarbeitet" || shareType == "") {
|
||||
continue;
|
||||
}
|
||||
result += (*i)->data(biddingRole).toInt();
|
||||
}
|
||||
return result;
|
||||
@ -612,10 +630,14 @@ qreal TableModel::averageBiddingAmount(const UserRoles biddingRole) const {
|
||||
qreal TableModel::totalSharesWithBiddings(const UserRoles biddingRole) const {
|
||||
qreal result = 0;
|
||||
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
|
||||
const qreal bidding = (*i)->data(biddingRole).toReal();
|
||||
const qreal shareAmount = (*i)->data(ShareAmountRole).toReal();
|
||||
const QString biddingType = (*i)->data(BiddingTypeRole).toString();
|
||||
const qreal shareAmount = (*i)->data(ShareAmountRole).toReal();
|
||||
if (biddingType.isEmpty() || shareAmount == 0.0) {
|
||||
continue;
|
||||
}
|
||||
const int bidding = (*i)->data(biddingRole).toInt();
|
||||
const QString shareType = (*i)->data(ShareTypeRole).toString();
|
||||
const bool isValid = bidding != 0 && shareAmount != 0;
|
||||
const bool isValid = bidding != 0 && shareAmount != 0.0;
|
||||
if (isValid) {
|
||||
// qInfo() << "Including entry in bidding average calculation. MailRole:"
|
||||
// << (*i)->data(MailRole);
|
||||
|
||||
Reference in New Issue
Block a user