#include "summarywidget.h" #include #include #include #include #include SummaryWidget::SummaryWidget(std::shared_ptr modelSummary, QWidget* parent) : 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); /// 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); mainLayout->addLayout(headerLayout); mainLayout->addLayout(nExpectedBiddingsLayout); mainLayout->addLayout(footerLayout); setLayout(mainLayout); setupBindableProperties(); } void SummaryWidget::onFinancialNeedChanged(int newFinancialNeed) { // NEXT implement reaction on financial need changes qCritical() << "Apply financial need changes!!!"; } void SummaryWidget::setupBindableProperties() { // TODO figure out how to encapsulate each property binding into a dedicated function: // "bindProperty(&bindable, &signal, &getter, widget)" /// nRows QProperty 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 nExpectedBiddings(-1); QObject::connect(m_modelSummary.get(), &ModelSummary::nExpectedBiddingsChanged, [&]() { m_nExpectedBiddingsValueLabel->setText(QString::number(m_modelSummary->nExpectedBiddings())); }); m_modelSummary->bindableNExpectedBiddings().setBinding( [&]() { return nExpectedBiddings.value(); }); }