150 lines
5.4 KiB
C++
150 lines
5.4 KiB
C++
#include "summarywidget.h"
|
|
|
|
#include "biddingroundstatuswidget.h"
|
|
|
|
#include <QLabel>
|
|
#include <QProperty>
|
|
#include <QSpinBox>
|
|
#include <QVBoxLayout>
|
|
|
|
#include <model/modelsummary.h>
|
|
|
|
SummaryWidget::SummaryWidget(std::shared_ptr<ModelSummary> modelSummary, QWidget* parent)
|
|
: QWidget{parent}
|
|
, m_modelSummary(modelSummary) {
|
|
/// Layouting
|
|
QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
|
|
|
/// monthly need
|
|
QHBoxLayout* footerLayout = new QHBoxLayout();
|
|
QLabel* financialNeedLabel = new QLabel("monatlicher Finanzbedarf:");
|
|
m_financialNeedBox = new QSpinBox();
|
|
m_financialNeedBox->setMaximum(50000);
|
|
m_financialNeedBox->setValue(m_financialNeed);
|
|
connect(m_financialNeedBox, &QSpinBox::valueChanged, this,
|
|
&SummaryWidget::onFinancialNeedChanged);
|
|
|
|
footerLayout->addWidget(financialNeedLabel);
|
|
footerLayout->addWidget(m_financialNeedBox);
|
|
footerLayout->addStretch(1);
|
|
|
|
QBoxLayout* roundsLayout = createBiddingOverviewLayout();
|
|
mainLayout->addLayout(roundsLayout);
|
|
mainLayout->addLayout(footerLayout);
|
|
|
|
mainLayout->setSpacing(50);
|
|
setLayout(mainLayout);
|
|
|
|
setupConnections();
|
|
}
|
|
|
|
void SummaryWidget::onFinancialNeedChanged(int newFinancialNeed) {
|
|
m_biddingStatus1->onFinancialNeedChanged(newFinancialNeed);
|
|
m_biddingStatus2->onFinancialNeedChanged(newFinancialNeed);
|
|
m_biddingStatus3->onFinancialNeedChanged(newFinancialNeed);
|
|
}
|
|
|
|
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)"
|
|
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);
|
|
}
|