Added a second bound property (nExpectedBiddings) & cleaned up the code a little.
This commit is contained in:
@ -9,22 +9,44 @@
|
||||
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);
|
||||
|
||||
QHBoxLayout* footerLayout = new QHBoxLayout();
|
||||
QLabel* rowCountLabel = new QLabel("Row count:");
|
||||
m_rowCoundValueLabel = new QLabel(QString::number(nRows));
|
||||
|
||||
QObject::connect(m_modelSummary.get(), &ModelSummary::rowCountChanged, [&]() {
|
||||
m_rowCoundValueLabel->setText(QString::number(m_modelSummary->rowCount()));
|
||||
m_rowCountValueLabel->setText(QString::number(m_modelSummary->rowCount()));
|
||||
});
|
||||
m_modelSummary->bindableRowCount().setBinding([&]() { return nRows.value(); });
|
||||
|
||||
footerLayout->addWidget(rowCountLabel);
|
||||
footerLayout->addWidget(m_rowCoundValueLabel);
|
||||
mainLayout->addLayout(footerLayout);
|
||||
|
||||
setLayout(mainLayout);
|
||||
/// 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(); });
|
||||
}
|
||||
|
||||
@ -15,7 +15,10 @@ class SummaryWidget : public QWidget {
|
||||
private:
|
||||
std::shared_ptr<ModelSummary> m_modelSummary;
|
||||
|
||||
QLabel* m_rowCoundValueLabel;
|
||||
QLabel* m_rowCountValueLabel;
|
||||
QLabel* m_nExpectedBiddingsValueLabel;
|
||||
|
||||
void setupBindableProperties();
|
||||
};
|
||||
|
||||
#endif // SUMMARYWIDGET_H
|
||||
|
||||
Reference in New Issue
Block a user