53 lines
1.9 KiB
C++
53 lines
1.9 KiB
C++
#include "summarywidget.h"
|
|
|
|
#include <QLabel>
|
|
#include <QProperty>
|
|
#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);
|
|
|
|
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<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(); });
|
|
}
|