Added a second bound property (nExpectedBiddings) & cleaned up the code a little.
This commit is contained in:
@ -7,6 +7,9 @@ ModelSummary::ModelSummary(std::shared_ptr<TableModel> 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<int> ModelSummary::bindableRowCount() {
|
||||
m_rowCount = m_model->rowCount();
|
||||
return &m_rowCount;
|
||||
}
|
||||
|
||||
int ModelSummary::nExpectedBiddings() const { return m_model->nExpectedBiddings(); }
|
||||
|
||||
QBindable<int> ModelSummary::bindableNExpectedBiddings() {
|
||||
m_nExpectedBiddings = m_model->nExpectedBiddings();
|
||||
return &m_nExpectedBiddings;
|
||||
}
|
||||
|
||||
@ -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<TableModel> model, QObject* parent = nullptr);
|
||||
@ -19,14 +21,21 @@ class ModelSummary : public QObject {
|
||||
|
||||
int rowCount() const;
|
||||
QBindable<int> bindableRowCount();
|
||||
int nExpectedBiddings() const;
|
||||
QBindable<int> bindableNExpectedBiddings();
|
||||
|
||||
signals:
|
||||
void rowCountChanged();
|
||||
|
||||
void nExpectedBiddingsChanged();
|
||||
private:
|
||||
shared_ptr<TableModel> 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
|
||||
|
||||
@ -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<ModelItemValues> valueList) {
|
||||
const int nRows = valueList.size();
|
||||
qDebug() << "Inserting" << nRows << "items...";
|
||||
@ -326,6 +337,9 @@ void TableModel::execEditItemData(const int row, const QMap<int, QVariant>& chan
|
||||
QList<int> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user