Migrated old visualization of the bidding round statuses with donut charts from the legacy BeetRound project.
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user