modellist: reduce updateData indent

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
Jared Van Bortel 2024-10-04 18:42:47 -04:00
parent 9ec0f92f67
commit 62186a007e
2 changed files with 190 additions and 175 deletions

View File

@ -821,17 +821,23 @@ QVariant ModelList::data(const QModelIndex &index, int role) const
void ModelList::updateData(const QString &id, const QVector<QPair<int, QVariant>> &data)
{
Q_ASSERT(QThread::currentThread() == thread());
int index;
QMutexLocker lock(&m_mutex);
updateDataInternal(id, data, lock, /*relock*/ false);
}
void ModelList::updateDataInternal(const QString &id, const QVector<QPair<int, QVariant>> &data,
QMutexLocker<QMutex> &lock, bool relock)
{
QMutexLocker locker(&m_mutex);
Q_ASSERT(QThread::currentThread() == thread());
Q_ASSERT(lock.isLocked());
if (!m_modelMap.contains(id)) {
qWarning() << "ERROR: cannot update as model map does not contain" << id;
return;
}
ModelInfo *info = m_modelMap.value(id);
index = m_models.indexOf(info);
int index = m_models.indexOf(info);
if (index == -1) {
qWarning() << "ERROR: cannot update as model list does not contain" << id;
return;
@ -1009,9 +1015,12 @@ void ModelList::updateData(const QString &id, const QVector<QPair<int, QVariant>
return ModelList::lessThan(lhs, rhs, s, d);
});
}
}
lock.unlock();
emit dataChanged(createIndex(index, 0), createIndex(index, 0));
emit selectableModelListChanged();
if (relock)
lock.relock();
}
void ModelList::resortModel()

View File

@ -23,6 +23,8 @@
using namespace Qt::Literals::StringLiterals;
template <typename> class QMutexLocker;
struct ModelInfo {
Q_GADGET
@ -495,6 +497,10 @@ private Q_SLOTS:
void handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
private:
// call with lock held
void updateDataInternal(const QString &id, const QVector<QPair<int, QVariant>> &data, QMutexLocker<QMutex> &lock,
bool relock = true);
void removeInternal(const ModelInfo &model);
void clearDiscoveredModels();
bool modelExists(const QString &fileName) const;