diff --git a/UIs/BeetRoundWidgets/widgets/summarywidget.cpp b/UIs/BeetRoundWidgets/widgets/summarywidget.cpp index bfe9904..66b7ac5 100644 --- a/UIs/BeetRoundWidgets/widgets/summarywidget.cpp +++ b/UIs/BeetRoundWidgets/widgets/summarywidget.cpp @@ -9,22 +9,44 @@ 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); - - 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 nExpectedBiddings(-1); + QObject::connect(m_modelSummary.get(), &ModelSummary::nExpectedBiddingsChanged, [&]() { + m_nExpectedBiddingsValueLabel->setText(QString::number(m_modelSummary->nExpectedBiddings())); + }); + m_modelSummary->bindableNExpectedBiddings().setBinding( + [&]() { return nExpectedBiddings.value(); }); } diff --git a/UIs/BeetRoundWidgets/widgets/summarywidget.h b/UIs/BeetRoundWidgets/widgets/summarywidget.h index 7d851d6..9f17d70 100644 --- a/UIs/BeetRoundWidgets/widgets/summarywidget.h +++ b/UIs/BeetRoundWidgets/widgets/summarywidget.h @@ -15,7 +15,10 @@ class SummaryWidget : public QWidget { private: std::shared_ptr m_modelSummary; - QLabel* m_rowCoundValueLabel; + QLabel* m_rowCountValueLabel; + QLabel* m_nExpectedBiddingsValueLabel; + + void setupBindableProperties(); }; #endif // SUMMARYWIDGET_H diff --git a/libs/BeetRoundCore/model/modelsummary.cpp b/libs/BeetRoundCore/model/modelsummary.cpp index 7be6e09..33566ea 100644 --- a/libs/BeetRoundCore/model/modelsummary.cpp +++ b/libs/BeetRoundCore/model/modelsummary.cpp @@ -7,6 +7,9 @@ ModelSummary::ModelSummary(std::shared_ptr model, QObject* parent) , m_model(model) { Q_ASSERT(model); connect(m_model.get(), &TableModel::rowCountChanged, this, &ModelSummary::rowCountChanged); + // TODO ? use existing model signals (dataChanged(role),...) instead of special signals + connect(m_model.get(), &TableModel::nExpectedBiddingsChanged, this, + &ModelSummary::nExpectedBiddingsChanged); } ModelSummary::~ModelSummary() {} @@ -20,3 +23,10 @@ QBindable ModelSummary::bindableRowCount() { m_rowCount = m_model->rowCount(); return &m_rowCount; } + +int ModelSummary::nExpectedBiddings() const { return m_model->nExpectedBiddings(); } + +QBindable ModelSummary::bindableNExpectedBiddings() { + m_nExpectedBiddings = m_model->nExpectedBiddings(); + return &m_nExpectedBiddings; +} diff --git a/libs/BeetRoundCore/model/modelsummary.h b/libs/BeetRoundCore/model/modelsummary.h index 4379c7f..075b572 100644 --- a/libs/BeetRoundCore/model/modelsummary.h +++ b/libs/BeetRoundCore/model/modelsummary.h @@ -12,6 +12,8 @@ class ModelSummary : public QObject { Q_OBJECT Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged BINDABLE bindableRowCount) + Q_PROPERTY(int nExpectedBiddings READ nExpectedBiddings NOTIFY nExpectedBiddingsChanged BINDABLE + bindableNExpectedBiddings) public: ModelSummary(shared_ptr model, QObject* parent = nullptr); @@ -19,14 +21,21 @@ class ModelSummary : public QObject { int rowCount() const; QBindable bindableRowCount(); + int nExpectedBiddings() const; + QBindable bindableNExpectedBiddings(); signals: void rowCountChanged(); + void nExpectedBiddingsChanged(); private: shared_ptr m_model; Q_OBJECT_BINDABLE_PROPERTY(ModelSummary, int, m_rowCount, &ModelSummary::rowCountChanged); + Q_OBJECT_BINDABLE_PROPERTY(ModelSummary, + int, + m_nExpectedBiddings, + &ModelSummary::nExpectedBiddingsChanged); }; #endif // MODELSUMMARY_H diff --git a/libs/BeetRoundCore/model/tablemodel.cpp b/libs/BeetRoundCore/model/tablemodel.cpp index d4f599a..18855a1 100644 --- a/libs/BeetRoundCore/model/tablemodel.cpp +++ b/libs/BeetRoundCore/model/tablemodel.cpp @@ -290,8 +290,19 @@ void TableModel::onRowCountChanged(const QModelIndex& parent, int first, int las return; } emit rowCountChanged(); + emit nExpectedBiddingsChanged(); } +int TableModel::nExpectedBiddings() const { + int result = 0; + for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) { + const QString biddingType = (*i)->data(BiddingTypeRole).toString(); + if (!biddingType.isEmpty()) { + result++; + } + } + return result; +} void TableModel::execInsertItems(const int firstRow, const QList valueList) { const int nRows = valueList.size(); qDebug() << "Inserting" << nRows << "items..."; @@ -326,6 +337,9 @@ void TableModel::execEditItemData(const int row, const QMap& chan QList roles = changedValues.keys(); roles.insert(0, Qt::DisplayRole); emit dataChanged(firstIndex, lastIndex, roles.toVector()); + + // NEXT check which roles are changed & trigger only changed properties + emit nExpectedBiddingsChanged(); } }