#include "summarywidget.h" #include #include #include #include SummaryWidget::SummaryWidget(std::shared_ptr modelSummary, QWidget* parent) : QWidget{parent} , m_modelSummary(modelSummary) { /// Layouting QVBoxLayout* mainLayout = new QVBoxLayout(this); QHBoxLayout* rowCountLayout = new QHBoxLayout(); QLabel* rowCountLabel = new QLabel("Row count:"); m_rowCountValueLabel = new QLabel(""); rowCountLayout->addWidget(rowCountLabel); rowCountLayout->addWidget(m_rowCountValueLabel); QHBoxLayout* nExpectedBiddingsLayout = new QHBoxLayout(); QLabel* nExpectedBiddingsLabel = new QLabel("Expected biddings:"); m_nExpectedBiddingsValueLabel = new QLabel(""); nExpectedBiddingsLayout->addWidget(nExpectedBiddingsLabel); nExpectedBiddingsLayout->addWidget(m_nExpectedBiddingsValueLabel); mainLayout->addLayout(rowCountLayout); mainLayout->addLayout(nExpectedBiddingsLayout); setLayout(mainLayout); setupBindableProperties(); } 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(); }); }