Migrated old visualization of the bidding round statuses with donut charts from the legacy BeetRound project.

This commit is contained in:
2026-02-16 18:48:05 +01:00
parent f8201ead71
commit 1e64dda701
11 changed files with 551 additions and 49 deletions

View File

@ -0,0 +1,44 @@
#include "biddingroundprogresslayout.h"
#include <QLabel>
#include <QProgressBar>
BiddingRoundProgressLayout::BiddingRoundProgressLayout(const int nCurrentBiddings,
const int nExpectedBiddings,
QWidget* parent)
: QHBoxLayout(parent)
, m_nCurrentBiddings(nCurrentBiddings)
, m_nExpectedBiddings(nExpectedBiddings) {
QLabel* nBidsText = new QLabel("Abgegeben:");
addWidget(nBidsText);
m_nBiddings1Label = new QLabel(QString::number(m_nCurrentBiddings));
addWidget(m_nBiddings1Label);
QLabel* nExpectedText = new QLabel("Erwartet:");
addWidget(nExpectedText);
m_nExpectedBidding1Label = new QLabel(QString::number(m_nExpectedBiddings));
addWidget(m_nExpectedBidding1Label);
m_biddingRound1ProgressBar = new QProgressBar(parent);
m_biddingRound1ProgressBar->setMinimum(0);
m_biddingRound1ProgressBar->setMaximum(m_nExpectedBiddings);
m_biddingRound1ProgressBar->setValue(m_nCurrentBiddings);
addWidget(m_biddingRound1ProgressBar);
}
void BiddingRoundProgressLayout::setCurrentBiddings(const int value) {
m_nCurrentBiddings = value;
const QString bidCountString = QString::number(value);
m_nBiddings1Label->setText(bidCountString);
m_biddingRound1ProgressBar->setValue(value);
}
void BiddingRoundProgressLayout::setExpectedBiddings(const int value) {
m_nExpectedBiddings = value;
const QString expectedBiddingsString = QString::number(value);
m_nExpectedBidding1Label->setText(expectedBiddingsString);
m_biddingRound1ProgressBar->setMaximum(value);
}

View File

@ -0,0 +1,28 @@
#ifndef BIDDINGROUNDPROGRESSLAYOUT_H
#define BIDDINGROUNDPROGRESSLAYOUT_H
#include <QHBoxLayout>
class QLabel;
class QProgressBar;
class BiddingRoundProgressLayout : public QHBoxLayout {
Q_OBJECT
public:
BiddingRoundProgressLayout(const int nCurrentBiddings,
const int nExpectedBiddings,
QWidget* parent = nullptr);
void setCurrentBiddings(const int value);
void setExpectedBiddings(const int value);
private:
int m_nCurrentBiddings;
int m_nExpectedBiddings;
QLabel* m_nBiddings1Label = nullptr;
QLabel* m_nExpectedBidding1Label = nullptr;
QProgressBar* m_biddingRound1ProgressBar = nullptr;
};
#endif // BIDDINGROUNDPROGRESSLAYOUT_H

View File

@ -0,0 +1,110 @@
#include "biddingroundstatuswidget.h"
#include <QChartView>
#include <QLabel>
#include <QPieSeries>
#include <QVBoxLayout>
BiddingRoundStatusWidget::BiddingRoundStatusWidget(const QString& title,
const int placedBiddings,
const int expectedBiddings,
const int financialNeed,
const int currentSum,
const qreal currentAverage,
QWidget* parent)
: QWidget{parent}
, m_title(title)
, m_financialNeed(financialNeed)
, m_currentSum(currentSum) {
m_moneyDonutSeries = new QPieSeries();
m_moneyDonutSeries->setHoleSize(0.35);
const QString sumText = QString("Summe: %1 €").arg(currentSum);
m_sumSlice = m_moneyDonutSeries->append(sumText, currentSum);
m_sumSlice->setLabelVisible();
const int currentGap = m_financialNeed - currentSum;
const QString gapText = QString("offen: %1 €").arg(currentGap);
m_gapSlice = m_moneyDonutSeries->append(gapText, currentGap);
m_gapSlice->setLabelVisible();
m_chartView = new QChartView();
m_chartView->setMinimumWidth(100);
// m_chartView->setMaximumWidth(500);
m_chartView->setRenderHint(QPainter::Antialiasing);
m_chartView->chart()->setTitle(m_title);
m_chartView->chart()->addSeries(m_moneyDonutSeries);
m_chartView->chart()->legend()->setAlignment(Qt::AlignBottom);
m_chartView->chart()->setTheme(QChart::ChartThemeBlueCerulean);
m_chartView->chart()->legend()->setFont(QFont("Arial", 8));
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(m_chartView, 5);
QBoxLayout* progressLayout = createProgressLayout(placedBiddings, expectedBiddings);
layout->addLayout(progressLayout);
/// bidding average
QHBoxLayout* averageLayout = new QHBoxLayout();
m_biddingAverageDescription = new QLabel("Durchschnittsgebot: ");
const QString currencyString = createCurrencyString(currentAverage);
m_biddingAverageValue = new QLabel(currencyString);
averageLayout->addWidget(m_biddingAverageDescription);
averageLayout->addWidget(m_biddingAverageValue);
layout->addLayout(averageLayout);
setLayout(layout);
}
void BiddingRoundStatusWidget::onExpectedBiddingsChanged(const int nExpected) {
m_biddingRoundProgress->setExpectedBiddings(nExpected);
}
void BiddingRoundStatusWidget::onNPlacedBiddingsChanged(const int nPlaced) {
m_biddingRoundProgress->setCurrentBiddings(nPlaced);
}
void BiddingRoundStatusWidget::onBiddingSumChanged(const int sum) {
m_currentSum = sum;
updateDonutChart();
}
void BiddingRoundStatusWidget::onBiddingAverageChanged(const qreal average) {
if (m_biddingAverageValue) {
m_biddingAverageValue->setText(createCurrencyString(average));
}
}
void BiddingRoundStatusWidget::onFinancialNeedChanged(const int financialNeed) {
m_financialNeed = financialNeed;
updateDonutChart();
}
QBoxLayout* BiddingRoundStatusWidget::createProgressLayout(const int nPlaced, const int nExpected) {
QVBoxLayout* progressLayout = new QVBoxLayout();
m_biddingRoundProgress = new BiddingRoundProgressLayout(nPlaced, nExpected);
progressLayout->addLayout(m_biddingRoundProgress);
return progressLayout;
}
void BiddingRoundStatusWidget::updateDonutChart() {
int currentGap;
if (m_currentSum < m_financialNeed) {
currentGap = m_financialNeed - m_currentSum;
} else {
currentGap = 0;
}
const QString sumText = QString("Summe: %1 €").arg(m_currentSum);
m_sumSlice->setValue(m_currentSum);
m_sumSlice->setLabel(sumText);
const QString gapText = QString("offen: %1 €").arg(currentGap);
m_gapSlice->setValue(currentGap);
m_gapSlice->setLabel(gapText);
const bool gapLabelVisible = currentGap != 0;
m_gapSlice->setLabelVisible(gapLabelVisible);
}
QString BiddingRoundStatusWidget::createCurrencyString(const qreal value) const {
return QString::number(value) + "";
}

View File

@ -0,0 +1,53 @@
#ifndef BIDDINGROUNDSTATUSWIDGET_H
#define BIDDINGROUNDSTATUSWIDGET_H
#include "biddingroundprogresslayout.h"
#include <QWidget>
class QBoxLayout;
class QChartView;
class QPieSeries;
class QPieSlice;
class BiddingRoundStatusWidget : public QWidget {
Q_OBJECT
public:
explicit BiddingRoundStatusWidget(const QString& title,
const int placedBiddings,
const int expectedBiddings,
const int financialNeed,
const int currentSum,
const qreal currentAverage,
QWidget* parent = nullptr);
public slots:
void onExpectedBiddingsChanged(const int nExpected);
void onNPlacedBiddingsChanged(const int nPlaced);
void onBiddingSumChanged(const int sum);
void onBiddingAverageChanged(const qreal average);
void onFinancialNeedChanged(const int financialNeed);
signals:
private:
QString m_title;
int m_financialNeed;
int m_currentSum;
QChartView* m_chartView = nullptr;
QPieSeries* m_moneyDonutSeries = nullptr;
QPieSlice* m_sumSlice = nullptr;
QPieSlice* m_gapSlice = nullptr;
QLabel* m_biddingAverageDescription = nullptr;
QLabel* m_biddingAverageValue = nullptr;
BiddingRoundProgressLayout* m_biddingRoundProgress = nullptr;
QBoxLayout* createProgressLayout(const int nPlaced, const int nExpected);
void updateDonutChart();
QString createCurrencyString(const qreal value) const;
};
#endif // BIDDINGROUNDSTATUSWIDGET_H

View File

@ -1,5 +1,7 @@
#include "summarywidget.h"
#include "biddingroundstatuswidget.h"
#include <QLabel>
#include <QProperty>
#include <QSpinBox>
@ -11,20 +13,7 @@ SummaryWidget::SummaryWidget(std::shared_ptr<ModelSummary> modelSummary, QWidget
: QWidget{parent}
, m_modelSummary(modelSummary) {
/// Layouting
QVBoxLayout* mainLayout = new QVBoxLayout(this);
QHBoxLayout* headerLayout = new QHBoxLayout();
/// bindable (proof of concept) properties
QLabel* rowCountLabel = new QLabel("Row count:");
m_rowCountValueLabel = new QLabel("");
headerLayout->addWidget(rowCountLabel);
headerLayout->addWidget(m_rowCountValueLabel);
QHBoxLayout* nExpectedBiddingsLayout = new QHBoxLayout();
QLabel* nExpectedBiddingsLabel = new QLabel("Expected biddings:");
m_nExpectedBiddingsValueLabel = new QLabel("");
nExpectedBiddingsLayout->addWidget(nExpectedBiddingsLabel);
nExpectedBiddingsLayout->addWidget(m_nExpectedBiddingsValueLabel);
QVBoxLayout* mainLayout = new QVBoxLayout(this);
/// monthly need
QHBoxLayout* footerLayout = new QHBoxLayout();
@ -39,35 +28,122 @@ SummaryWidget::SummaryWidget(std::shared_ptr<ModelSummary> modelSummary, QWidget
footerLayout->addWidget(m_financialNeedBox);
footerLayout->addStretch(1);
mainLayout->addLayout(headerLayout);
mainLayout->addLayout(nExpectedBiddingsLayout);
QBoxLayout* roundsLayout = createBiddingOverviewLayout();
mainLayout->addLayout(roundsLayout);
mainLayout->addLayout(footerLayout);
mainLayout->setSpacing(50);
setLayout(mainLayout);
setupBindableProperties();
setupConnections();
}
void SummaryWidget::onFinancialNeedChanged(int newFinancialNeed) {
// NEXT implement reaction on financial need changes
qCritical() << "Apply financial need changes!!!";
m_biddingStatus1->onFinancialNeedChanged(newFinancialNeed);
m_biddingStatus2->onFinancialNeedChanged(newFinancialNeed);
m_biddingStatus3->onFinancialNeedChanged(newFinancialNeed);
}
void SummaryWidget::setupBindableProperties() {
void SummaryWidget::onNExpectedBiddingChanged(int newNExpected) {
m_biddingStatus1->onExpectedBiddingsChanged(newNExpected);
m_biddingStatus2->onExpectedBiddingsChanged(newNExpected);
m_biddingStatus3->onExpectedBiddingsChanged(newNExpected);
}
void SummaryWidget::onNPlacedBiddingsChanged(const int roundNumber) {
switch (roundNumber) {
case 1:
m_biddingStatus1->onNPlacedBiddingsChanged(m_modelSummary->nPlacedBiddings1());
break;
case 2:
m_biddingStatus2->onNPlacedBiddingsChanged(m_modelSummary->nPlacedBiddings2());
break;
case 3:
m_biddingStatus3->onNPlacedBiddingsChanged(m_modelSummary->nPlacedBiddings3());
break;
default:
qWarning() << "Unknown round number:" << roundNumber;
break;
}
}
void SummaryWidget::onBiddingSumChanged(const int roundNumber) {
switch (roundNumber) {
case 1:
m_biddingStatus1->onBiddingSumChanged(m_modelSummary->biddingSum1());
break;
case 2:
m_biddingStatus2->onBiddingSumChanged(m_modelSummary->biddingSum2());
break;
case 3:
m_biddingStatus3->onBiddingSumChanged(m_modelSummary->biddingSum3());
break;
default:
qWarning() << "Unknown round number:" << roundNumber;
break;
}
}
void SummaryWidget::onBiddingAverageChanged(const int roundNumber) {
switch (roundNumber) {
case 1:
m_biddingStatus1->onBiddingAverageChanged(m_modelSummary->biddingAverage1());
break;
case 2:
m_biddingStatus2->onBiddingAverageChanged(m_modelSummary->biddingAverage2());
break;
case 3:
m_biddingStatus3->onBiddingAverageChanged(m_modelSummary->biddingAverage3());
break;
default:
qWarning() << "Unknown round number:" << roundNumber;
break;
}
}
QBoxLayout* SummaryWidget::createBiddingOverviewLayout() {
QHBoxLayout* layout = new QHBoxLayout();
const int expectedBiddings = m_modelSummary->nExpectedBiddings();
/// bidding round 1
const int placedBiddings1 = m_modelSummary->nPlacedBiddings1();
const int biddingSum1 = m_modelSummary->biddingSum1();
const qreal biddingAverage1 = m_modelSummary->biddingAverage1();
m_biddingStatus1 =
make_unique<BiddingRoundStatusWidget>("Bietrunde 1", placedBiddings1, expectedBiddings,
m_financialNeed, biddingSum1, biddingAverage1);
/// bidding round 2
const int placedBiddings2 = m_modelSummary->nPlacedBiddings2();
const int biddingSum2 = m_modelSummary->biddingSum2();
const qreal biddingAverage2 = m_modelSummary->biddingAverage2();
m_biddingStatus2 =
make_unique<BiddingRoundStatusWidget>("Bietrunde 2", placedBiddings2, expectedBiddings,
m_financialNeed, biddingSum2, biddingAverage2);
/// bidding round 3
const int placedBiddings3 = m_modelSummary->nPlacedBiddings3();
const int biddingSum3 = m_modelSummary->biddingSum3();
const qreal biddingAverage3 = m_modelSummary->biddingAverage3();
m_biddingStatus3 =
make_unique<BiddingRoundStatusWidget>("Bietrunde 3", placedBiddings3, expectedBiddings,
m_financialNeed, biddingSum3, biddingAverage3);
layout->addWidget(m_biddingStatus1.get());
layout->addWidget(m_biddingStatus2.get());
layout->addWidget(m_biddingStatus3.get());
return layout;
}
void SummaryWidget::setupConnections() {
// TODO figure out how to encapsulate each property binding into a dedicated function:
// "bindProperty(&bindable, &signal, &getter, widget)"
/// nRows
QProperty<int> nRows(-1);
QObject::connect(m_modelSummary.get(), &ModelSummary::rowCountChanged, [&]() {
m_rowCountValueLabel->setText(QString::number(m_modelSummary->rowCount()));
});
m_modelSummary->bindableRowCount().setBinding([&]() { return nRows.value(); });
/// nExpectedBiddings
QProperty<int> nExpectedBiddings(-1);
QObject::connect(m_modelSummary.get(), &ModelSummary::nExpectedBiddingsChanged, [&]() {
m_nExpectedBiddingsValueLabel->setText(QString::number(m_modelSummary->nExpectedBiddings()));
});
m_modelSummary->bindableNExpectedBiddings().setBinding(
[&]() { return nExpectedBiddings.value(); });
QObject::connect(m_modelSummary.get(), &ModelSummary::nExpectedBiddingsChanged,
[&]() { onNExpectedBiddingChanged(m_modelSummary->nExpectedBiddings()); });
QObject::connect(m_modelSummary.get(), &ModelSummary::nPlacedBiddingsChanged, this,
&SummaryWidget::onNPlacedBiddingsChanged);
QObject::connect(m_modelSummary.get(), &ModelSummary::biddingSumChanged, this,
&SummaryWidget::onBiddingSumChanged);
QObject::connect(m_modelSummary.get(), &ModelSummary::biddingAverageChanged, this,
&SummaryWidget::onBiddingAverageChanged);
}

View File

@ -3,9 +3,11 @@
#include <QWidget>
class BiddingRoundStatusWidget;
class ModelSummary;
class QLabel;
class QSpinBox;
class QBoxLayout;
class SummaryWidget : public QWidget {
Q_OBJECT
@ -15,10 +17,19 @@ class SummaryWidget : public QWidget {
private slots:
void onFinancialNeedChanged(int newFinancialNeed);
void onNExpectedBiddingChanged(int newNExpected);
void onNPlacedBiddingsChanged(const int roundNumber);
void onBiddingSumChanged(const int roundNumber);
void onBiddingAverageChanged(const int roundNumber);
private:
std::shared_ptr<ModelSummary> m_modelSummary;
std::unique_ptr<BiddingRoundStatusWidget> m_biddingStatus1;
std::unique_ptr<BiddingRoundStatusWidget> m_biddingStatus2;
std::unique_ptr<BiddingRoundStatusWidget> m_biddingStatus3;
// TODO read from settings (maybe via model/core; maybe set in constructor)
const int m_financialNeed = 13942;
QSpinBox* m_financialNeedBox = nullptr;
@ -26,7 +37,9 @@ class SummaryWidget : public QWidget {
QLabel* m_rowCountValueLabel;
QLabel* m_nExpectedBiddingsValueLabel;
void setupBindableProperties();
/// functions
QBoxLayout* createBiddingOverviewLayout();
void setupConnections();
};
#endif // SUMMARYWIDGET_H