Migrated old visualization of the bidding round statuses with donut charts from the legacy BeetRound project.
This commit is contained in:
@ -10,6 +10,11 @@ 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::nPlacedBiddingsChanged, this,
|
||||
&ModelSummary::nPlacedBiddingsChanged);
|
||||
connect(m_model.get(), &TableModel::biddingSumChanged, this, &ModelSummary::biddingSumChanged);
|
||||
connect(m_model.get(), &TableModel::biddingAverageChanged, this,
|
||||
&ModelSummary::biddingAverageChanged);
|
||||
}
|
||||
|
||||
ModelSummary::~ModelSummary() {}
|
||||
@ -26,7 +31,14 @@ QBindable<int> ModelSummary::bindableRowCount() {
|
||||
|
||||
int ModelSummary::nExpectedBiddings() const { return m_model->nExpectedBiddings(); }
|
||||
|
||||
QBindable<int> ModelSummary::bindableNExpectedBiddings() {
|
||||
m_nExpectedBiddings = m_model->nExpectedBiddings();
|
||||
return &m_nExpectedBiddings;
|
||||
}
|
||||
int ModelSummary::nPlacedBiddings1() const { return m_model->nPlacedBiddings1(); }
|
||||
int ModelSummary::nPlacedBiddings2() const { return m_model->nPlacedBiddings2(); }
|
||||
int ModelSummary::nPlacedBiddings3() const { return m_model->nPlacedBiddings3(); }
|
||||
|
||||
int ModelSummary::biddingSum1() const { return m_model->biddingSum1(); }
|
||||
int ModelSummary::biddingSum2() const { return m_model->biddingSum2(); }
|
||||
int ModelSummary::biddingSum3() const { return m_model->biddingSum3(); }
|
||||
|
||||
qreal ModelSummary::biddingAverage1() const { return m_model->biddingAverage1(); }
|
||||
qreal ModelSummary::biddingAverage2() const { return m_model->biddingAverage2(); }
|
||||
qreal ModelSummary::biddingAverage3() const { return m_model->biddingAverage3(); }
|
||||
|
||||
@ -12,8 +12,6 @@ class ModelSummary : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged BINDABLE bindableRowCount)
|
||||
Q_PROPERTY(int nExpectedBiddings READ nExpectedBiddings NOTIFY nExpectedBiddingsChanged BINDABLE
|
||||
bindableNExpectedBiddings)
|
||||
|
||||
public:
|
||||
ModelSummary(shared_ptr<TableModel> model, QObject* parent = nullptr);
|
||||
@ -22,20 +20,30 @@ class ModelSummary : public QObject {
|
||||
int rowCount() const;
|
||||
QBindable<int> bindableRowCount();
|
||||
int nExpectedBiddings() const;
|
||||
QBindable<int> bindableNExpectedBiddings();
|
||||
int nPlacedBiddings1() const;
|
||||
int nPlacedBiddings2() const;
|
||||
int nPlacedBiddings3() const;
|
||||
|
||||
int biddingSum1() const;
|
||||
int biddingSum2() const;
|
||||
int biddingSum3() const;
|
||||
|
||||
qreal biddingAverage1() const;
|
||||
qreal biddingAverage2() const;
|
||||
qreal biddingAverage3() const;
|
||||
|
||||
signals:
|
||||
void rowCountChanged();
|
||||
|
||||
void nExpectedBiddingsChanged();
|
||||
void nPlacedBiddingsChanged(const int roundNumber);
|
||||
void biddingSumChanged(const int roundNumber);
|
||||
void biddingAverageChanged(const int roundNumber);
|
||||
|
||||
private:
|
||||
shared_ptr<TableModel> m_model;
|
||||
|
||||
Q_OBJECT_BINDABLE_PROPERTY(ModelSummary, int, m_rowCount, &ModelSummary::rowCountChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(ModelSummary,
|
||||
int,
|
||||
m_nExpectedBiddings,
|
||||
&ModelSummary::nExpectedBiddingsChanged);
|
||||
};
|
||||
|
||||
#endif // MODELSUMMARY_H
|
||||
|
||||
@ -291,6 +291,18 @@ void TableModel::onRowCountChanged(const QModelIndex& parent, int first, int las
|
||||
}
|
||||
emit rowCountChanged();
|
||||
emit nExpectedBiddingsChanged();
|
||||
|
||||
emit nPlacedBiddingsChanged(1);
|
||||
emit nPlacedBiddingsChanged(2);
|
||||
emit nPlacedBiddingsChanged(3);
|
||||
|
||||
emit biddingSumChanged(1);
|
||||
emit biddingSumChanged(2);
|
||||
emit biddingSumChanged(3);
|
||||
|
||||
emit biddingAverageChanged(1);
|
||||
emit biddingAverageChanged(2);
|
||||
emit biddingAverageChanged(3);
|
||||
}
|
||||
|
||||
int TableModel::nExpectedBiddings() const {
|
||||
@ -303,6 +315,35 @@ int TableModel::nExpectedBiddings() const {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int TableModel::nPlacedBiddings1() const { return nPlacedBiddings(Bidding1Role); }
|
||||
int TableModel::nPlacedBiddings2() const { return nPlacedBiddings(Bidding2Role); }
|
||||
int TableModel::nPlacedBiddings3() const { return nPlacedBiddings(Bidding3Role); }
|
||||
|
||||
int TableModel::biddingSum1() const { return biddingSum(Bidding1Role); }
|
||||
int TableModel::biddingSum2() const { return biddingSum(Bidding2Role); }
|
||||
int TableModel::biddingSum3() const { return biddingSum(Bidding3Role); }
|
||||
|
||||
qreal TableModel::biddingAverage1() const {
|
||||
const UserRoles biddingRole = Bidding1Role;
|
||||
const qreal averageBidding = averageBiddingAmount(biddingRole);
|
||||
qInfo() << "average calculation (1):" << averageBidding;
|
||||
return averageBidding;
|
||||
}
|
||||
|
||||
qreal TableModel::biddingAverage2() const {
|
||||
const UserRoles biddingRole = Bidding2Role;
|
||||
const qreal averageBidding = averageBiddingAmount(biddingRole);
|
||||
qInfo() << "average calculation (2):" << averageBidding;
|
||||
return averageBidding;
|
||||
}
|
||||
qreal TableModel::biddingAverage3() const {
|
||||
const UserRoles biddingRole = Bidding3Role;
|
||||
const qreal averageBidding = averageBiddingAmount(biddingRole);
|
||||
qInfo() << "average calculation (3):" << averageBidding;
|
||||
return averageBidding;
|
||||
}
|
||||
|
||||
void TableModel::execInsertItems(const int firstRow, const QList<ModelItemValues> valueList) {
|
||||
const int nRows = valueList.size();
|
||||
qDebug() << "Inserting" << nRows << "items...";
|
||||
@ -339,7 +380,37 @@ void TableModel::execEditItemData(const int row, const QMap<int, QVariant>& chan
|
||||
emit dataChanged(firstIndex, lastIndex, roles.toVector());
|
||||
|
||||
// NEXT check which roles are changed & trigger only changed properties
|
||||
emit nExpectedBiddingsChanged();
|
||||
if (roles.contains(BiddingTypeRole) || roles.contains(ShareAmountRole)) {
|
||||
emit nExpectedBiddingsChanged();
|
||||
}
|
||||
if (roles.contains(ShareAmountRole) || roles.contains(ShareTypeRole)) {
|
||||
emit nPlacedBiddingsChanged(1);
|
||||
emit nPlacedBiddingsChanged(2);
|
||||
emit nPlacedBiddingsChanged(3);
|
||||
emit biddingSumChanged(1);
|
||||
emit biddingSumChanged(2);
|
||||
emit biddingSumChanged(3);
|
||||
emit biddingAverageChanged(1);
|
||||
emit biddingAverageChanged(2);
|
||||
emit biddingAverageChanged(3);
|
||||
} else {
|
||||
/// no changes to share amount or type, but maybe to the biddings:
|
||||
if (roles.contains(Bidding1Role)) {
|
||||
emit nPlacedBiddingsChanged(1);
|
||||
emit biddingSumChanged(1);
|
||||
emit biddingAverageChanged(1);
|
||||
}
|
||||
if (roles.contains(Bidding2Role)) {
|
||||
emit nPlacedBiddingsChanged(2);
|
||||
emit biddingSumChanged(2);
|
||||
emit biddingAverageChanged(2);
|
||||
}
|
||||
if (roles.contains(Bidding3Role)) {
|
||||
emit nPlacedBiddingsChanged(3);
|
||||
emit biddingSumChanged(3);
|
||||
emit biddingAverageChanged(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -435,3 +506,64 @@ bool TableModel::isItemEqualToItemValues(const QModelIndex& itemIndex,
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int TableModel::nPlacedBiddings(const UserRoles biddingRole) const {
|
||||
int result = 0;
|
||||
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
|
||||
int localBidding = (*i)->data(biddingRole).toInt();
|
||||
if (localBidding > 0) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int TableModel::biddingSum(const UserRoles biddingRole) const {
|
||||
int result = 0;
|
||||
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
|
||||
result += (*i)->data(biddingRole).toInt();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
qreal TableModel::averageBiddingAmount(const UserRoles biddingRole) const {
|
||||
qInfo() << "Calculating average bidding for role:" << ROLE_NAMES.value(biddingRole);
|
||||
const qreal localTotalSharesWithBiddings = totalSharesWithBiddings(biddingRole);
|
||||
|
||||
if (localTotalSharesWithBiddings <= 0) {
|
||||
qInfo() << "No biddings found. Aborting calculation...";
|
||||
return 0;
|
||||
}
|
||||
|
||||
const qreal localTotalBiddingAmount = biddingSum(biddingRole);
|
||||
const qreal alternateBiddingAverage = localTotalBiddingAmount / localTotalSharesWithBiddings;
|
||||
qDebug() << "Total bidding amount:" << localTotalBiddingAmount;
|
||||
qDebug() << "Total bidding shares:" << localTotalSharesWithBiddings;
|
||||
return alternateBiddingAverage;
|
||||
}
|
||||
|
||||
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 shareType = (*i)->data(ShareTypeRole).toString();
|
||||
const bool isValid = bidding != 0 && shareAmount != 0;
|
||||
if (isValid) {
|
||||
// qInfo() << "Including entry in bidding average calculation. MailRole:"
|
||||
// << (*i)->data(MailRole);
|
||||
// qreal bidForWholeShare = 0;
|
||||
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;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
qInfo() << "Biddings exist for " << result << "shares!";
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -56,9 +56,28 @@ class TableModel : public QAbstractTableModel {
|
||||
const QList<ModelItemValues>& itemValuesList,
|
||||
const QModelIndex& parentIndex = QModelIndex());
|
||||
|
||||
/// property functions
|
||||
int nExpectedBiddings() const;
|
||||
int nPlacedBiddings1() const;
|
||||
int nPlacedBiddings2() const;
|
||||
int nPlacedBiddings3() const;
|
||||
|
||||
int biddingSum1() const;
|
||||
int biddingSum2() const;
|
||||
int biddingSum3() const;
|
||||
|
||||
qreal biddingAverage1() const;
|
||||
qreal biddingAverage2() const;
|
||||
qreal biddingAverage3() const;
|
||||
|
||||
signals:
|
||||
void rowCountChanged();
|
||||
|
||||
void nExpectedBiddingsChanged();
|
||||
void nPlacedBiddingsChanged(const int roundNumber);
|
||||
void biddingSumChanged(const int roundNumber);
|
||||
void biddingAverageChanged(const int roundNumber);
|
||||
|
||||
private slots:
|
||||
void onRowCountChanged(const QModelIndex& parent, int first, int last);
|
||||
|
||||
@ -81,6 +100,11 @@ class TableModel : public QAbstractTableModel {
|
||||
QModelIndex searchItemIndex(const ModelItemValues givenItemValues) const;
|
||||
bool isItemEqualToItemValues(const QModelIndex& itemIndex,
|
||||
const ModelItemValues givenItemValues) const;
|
||||
|
||||
int nPlacedBiddings(const UserRoles biddingRole) const;
|
||||
int biddingSum(const UserRoles biddingRole) const;
|
||||
qreal averageBiddingAmount(const UserRoles biddingRole) const;
|
||||
qreal totalSharesWithBiddings(const UserRoles biddingRole) const;
|
||||
};
|
||||
|
||||
#endif // TABLEMODEL_H
|
||||
|
||||
Reference in New Issue
Block a user