Fix the crash from previous commit for real

This commit is contained in:
Michael Zanetti 2021-12-18 23:59:45 +01:00
parent 720c421f43
commit 9c84650406
2 changed files with 10 additions and 7 deletions

View File

@ -111,7 +111,6 @@ void Things::addThings(const QList<Thing *> things)
} }
beginInsertRows(QModelIndex(), m_things.count(), m_things.count() + things.count() - 1); beginInsertRows(QModelIndex(), m_things.count(), m_things.count() + things.count() - 1);
m_things.append(things); m_things.append(things);
endInsertRows();
foreach (Thing *thing, things) { foreach (Thing *thing, things) {
thing->setParent(this); thing->setParent(this);
@ -132,6 +131,7 @@ void Things::addThings(const QList<Thing *> things)
}); });
emit thingAdded(thing); emit thingAdded(thing);
} }
endInsertRows();
emit countChanged(); emit countChanged();
} }

View File

@ -65,7 +65,10 @@ void ThingsProxy::setEngine(Engine *engine)
sort(0, sortOrder()); sort(0, sortOrder());
connect(sourceModel(), SIGNAL(countChanged()), this, SIGNAL(countChanged())); connect(sourceModel(), SIGNAL(countChanged()), this, SIGNAL(countChanged()));
connect(sourceModel(), &QAbstractItemModel::dataChanged, this, [this]() { connect(sourceModel(), &QAbstractItemModel::dataChanged, this, [this]() {
invalidateFilterInternal(); // Only invalidate the filter if we're actually interested in state changes
if (!m_sortStateName.isEmpty() || m_filterBatteryCritical || m_filterDisconnected || m_filterUpdates) {
invalidateFilterInternal();
}
}); });
} }
} }
@ -86,8 +89,11 @@ void ThingsProxy::setParentProxy(ThingsProxy *parentProxy)
return; return;
} }
connect(m_parentProxy, SIGNAL(countChanged()), this, SIGNAL(countChanged())); connect(m_parentProxy, SIGNAL(countChanged()), this, SIGNAL(countChanged()));
connect(m_parentProxy, &QAbstractItemModel::dataChanged, this, [this]() { connect(m_parentProxy, &QAbstractItemModel::dataChanged, this, [this]() {
if (m_engine) { if (m_engine &&
// Only invalidate the filter if we're actually interested in state changes
(!m_sortStateName.isEmpty() || m_filterBatteryCritical || m_filterDisconnected || m_filterUpdates)) {
invalidateFilterInternal(); invalidateFilterInternal();
} }
}); });
@ -583,10 +589,6 @@ bool ThingsProxy::lessThan(const QModelIndex &left, const QModelIndex &right) co
bool ThingsProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const bool ThingsProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{ {
Thing *thing = getInternal(source_row); Thing *thing = getInternal(source_row);
if (!thing) {
qCWarning(dcThingManager()) << "filterAcceptsRow called for a source row we can't find in the source model!";
return false;
}
if (!m_filterTagId.isEmpty()) { if (!m_filterTagId.isEmpty()) {
Tag *tag = m_engine->tagsManager()->tags()->findThingTag(thing->id().toString(), m_filterTagId); Tag *tag = m_engine->tagsManager()->tags()->findThingTag(thing->id().toString(), m_filterTagId);
if (!tag) { if (!tag) {
@ -635,6 +637,7 @@ bool ThingsProxy::filterAcceptsRow(int source_row, const QModelIndex &source_par
} }
} }
if (!m_shownThingClassIds.isEmpty()) { if (!m_shownThingClassIds.isEmpty()) {
if (!m_shownThingClassIds.contains(thing->thingClassId())) { if (!m_shownThingClassIds.contains(thing->thingClassId())) {
return false; return false;