mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-06-25 23:13:06 +00:00
Reduce copied code.
This commit is contained in:
parent
abd4703c79
commit
eecf351c64
@ -75,88 +75,60 @@ QHash<int, QByteArray> LocalDocsModel::roleNames() const
|
|||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalDocsModel::updateInstalled(int folder_id, bool b)
|
template<typename T>
|
||||||
|
void LocalDocsModel::updateField(int folder_id, T value,
|
||||||
|
const std::function<void(CollectionItem&, T)>& updater,
|
||||||
|
const QVector<int>& roles)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_collectionList.size(); ++i) {
|
for (int i = 0; i < m_collectionList.size(); ++i) {
|
||||||
if (m_collectionList.at(i).folder_id != folder_id)
|
if (m_collectionList.at(i).folder_id != folder_id)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
m_collectionList[i].installed = b;
|
updater(m_collectionList[i], value);
|
||||||
emit collectionItemUpdated(i, m_collectionList[i]);
|
emit dataChanged(this->index(i), this->index(i), roles);
|
||||||
emit dataChanged(this->index(i), this->index(i), {InstalledRole});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LocalDocsModel::updateInstalled(int folder_id, bool b)
|
||||||
|
{
|
||||||
|
updateField<bool>(folder_id, b,
|
||||||
|
[](CollectionItem& item, bool val) { item.installed = val; }, {InstalledRole});
|
||||||
|
}
|
||||||
|
|
||||||
void LocalDocsModel::updateIndexing(int folder_id, bool b)
|
void LocalDocsModel::updateIndexing(int folder_id, bool b)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_collectionList.size(); ++i) {
|
updateField<bool>(folder_id, b,
|
||||||
if (m_collectionList.at(i).folder_id != folder_id)
|
[](CollectionItem& item, bool val) { item.indexing = val; }, {IndexingRole});
|
||||||
continue;
|
|
||||||
|
|
||||||
m_collectionList[i].indexing = b;
|
|
||||||
emit collectionItemUpdated(i, m_collectionList[i]);
|
|
||||||
emit dataChanged(this->index(i), this->index(i), {IndexingRole});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalDocsModel::updateCurrentDocsToIndex(int folder_id, size_t currentDocsToIndex)
|
void LocalDocsModel::updateCurrentDocsToIndex(int folder_id, size_t currentDocsToIndex)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_collectionList.size(); ++i) {
|
updateField<size_t>(folder_id, currentDocsToIndex,
|
||||||
if (m_collectionList.at(i).folder_id != folder_id)
|
[](CollectionItem& item, size_t val) { item.currentDocsToIndex = val; }, {CurrentDocsToIndexRole});
|
||||||
continue;
|
|
||||||
|
|
||||||
m_collectionList[i].currentDocsToIndex = currentDocsToIndex;
|
|
||||||
emit collectionItemUpdated(i, m_collectionList[i]);
|
|
||||||
emit dataChanged(this->index(i), this->index(i), {CurrentDocsToIndexRole});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalDocsModel::updateTotalDocsToIndex(int folder_id, size_t totalDocsToIndex)
|
void LocalDocsModel::updateTotalDocsToIndex(int folder_id, size_t totalDocsToIndex)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_collectionList.size(); ++i) {
|
updateField<size_t>(folder_id, totalDocsToIndex,
|
||||||
if (m_collectionList.at(i).folder_id != folder_id)
|
[](CollectionItem& item, size_t val) { item.totalDocsToIndex = val; }, {TotalDocsToIndexRole});
|
||||||
continue;
|
|
||||||
|
|
||||||
m_collectionList[i].totalDocsToIndex = totalDocsToIndex;
|
|
||||||
emit collectionItemUpdated(i, m_collectionList[i]);
|
|
||||||
emit dataChanged(this->index(i), this->index(i), {TotalDocsToIndexRole});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalDocsModel::subtractCurrentBytesToIndex(int folder_id, size_t subtractedBytes)
|
void LocalDocsModel::subtractCurrentBytesToIndex(int folder_id, size_t subtractedBytes)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_collectionList.size(); ++i) {
|
updateField<size_t>(folder_id, subtractedBytes,
|
||||||
if (m_collectionList.at(i).folder_id != folder_id)
|
[](CollectionItem& item, size_t val) { item.currentBytesToIndex -= val; }, {CurrentBytesToIndexRole});
|
||||||
continue;
|
|
||||||
|
|
||||||
m_collectionList[i].currentBytesToIndex -= subtractedBytes;
|
|
||||||
emit collectionItemUpdated(i, m_collectionList[i]);
|
|
||||||
emit dataChanged(this->index(i), this->index(i), {CurrentBytesToIndexRole});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalDocsModel::updateCurrentBytesToIndex(int folder_id, size_t currentBytesToIndex)
|
void LocalDocsModel::updateCurrentBytesToIndex(int folder_id, size_t currentBytesToIndex)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_collectionList.size(); ++i) {
|
updateField<size_t>(folder_id, currentBytesToIndex,
|
||||||
if (m_collectionList.at(i).folder_id != folder_id)
|
[](CollectionItem& item, size_t val) { item.currentBytesToIndex = val; }, {CurrentBytesToIndexRole});
|
||||||
continue;
|
|
||||||
|
|
||||||
m_collectionList[i].currentBytesToIndex = currentBytesToIndex;
|
|
||||||
emit collectionItemUpdated(i, m_collectionList[i]);
|
|
||||||
emit dataChanged(this->index(i), this->index(i), {CurrentBytesToIndexRole});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalDocsModel::updateTotalBytesToIndex(int folder_id, size_t totalBytesToIndex)
|
void LocalDocsModel::updateTotalBytesToIndex(int folder_id, size_t totalBytesToIndex)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_collectionList.size(); ++i) {
|
updateField<size_t>(folder_id, totalBytesToIndex,
|
||||||
if (m_collectionList.at(i).folder_id != folder_id)
|
[](CollectionItem& item, size_t val) { item.totalBytesToIndex = val; }, {TotalBytesToIndexRole});
|
||||||
continue;
|
|
||||||
|
|
||||||
m_collectionList[i].totalBytesToIndex = totalBytesToIndex;
|
|
||||||
emit collectionItemUpdated(i, m_collectionList[i]);
|
|
||||||
emit dataChanged(this->index(i), this->index(i), {TotalBytesToIndexRole});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalDocsModel::addCollectionItem(const CollectionItem &item)
|
void LocalDocsModel::addCollectionItem(const CollectionItem &item)
|
||||||
|
@ -42,9 +42,6 @@ public:
|
|||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void collectionItemUpdated(int index, const CollectionItem& item);
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void updateInstalled(int folder_id, bool b);
|
void updateInstalled(int folder_id, bool b);
|
||||||
void updateIndexing(int folder_id, bool b);
|
void updateIndexing(int folder_id, bool b);
|
||||||
@ -60,7 +57,10 @@ public Q_SLOTS:
|
|||||||
void collectionListUpdated(const QList<CollectionItem> &collectionList);
|
void collectionListUpdated(const QList<CollectionItem> &collectionList);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateItem(int index, const CollectionItem& item);
|
template<typename T>
|
||||||
|
void updateField(int folder_id, T value,
|
||||||
|
const std::function<void(CollectionItem&, T)>& updater,
|
||||||
|
const QVector<int>& roles);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<CollectionItem> m_collectionList;
|
QList<CollectionItem> m_collectionList;
|
||||||
|
Loading…
Reference in New Issue
Block a user