void RepoTreeModel::checkGroupRepo(const ServerRepo& repo) { QStandardItem *root = invisibleRootItem(); RepoCategoryItem *group = NULL; int row, n = root->rowCount(); // First find for create the group // Starts from row 2 because the first two rows are "My Libraries" and "Shared Libraries" for (row = 2; row < n; row ++) { RepoCategoryItem *item = (RepoCategoryItem *)(root->child(row)); if (item->groupId() == repo.group_id) { group = item; break; } } if (!group) { group = new RepoCategoryItem(repo.group_name, repo.group_id); appendRow(group); } // Find the repo in this group n = group->rowCount(); for (row = 0; row < n; row++) { RepoItem *item = (RepoItem *)(group->child(row)); if (item->repo().id == repo.id) { updateRepoItem(item, repo); return; } } // Current repo not in this group yet RepoItem *item = new RepoItem(repo); group->appendRow(item); }
void RepoTreeModel::forEachRepoItem(void (RepoTreeModel::*func)(RepoItem *, void *), void *data) { int row; int n; QStandardItem *root = invisibleRootItem(); n = root->rowCount(); for (row = 0; row < n; row++) { RepoCategoryItem *category = (RepoCategoryItem *)root->child(row); int j, total; total = category->rowCount(); for (j = 0; j < total; j++) { RepoItem *item = (RepoItem *)category->child(j); (this->*func)(item, data); } } }
void RepoTreeModel::onFilterTextChanged(const QString& text) { // Recalculate the matched repos count for each category QStandardItem *root = invisibleRootItem(); int row, n; n = root->rowCount(); QRegExp re = makeFilterRegExp(text); for (row = 0; row < n; row++) { RepoCategoryItem *category = (RepoCategoryItem *)root->child(row); int j, total, matched = 0; total = category->rowCount(); for (j = 0; j < total; j++) { RepoItem *item = (RepoItem *)category->child(j); if (item->repo().name.contains(re)) { matched++; } } category->setMatchedReposCount(matched); } }
void RepoTreeModel::checkGroupRepo(const ServerRepo& repo) { QStandardItem *root = invisibleRootItem(); RepoCategoryItem *group = NULL; int row, n = root->rowCount(); for (row = 0; row < n; row ++) { RepoCategoryItem *item = (RepoCategoryItem *)(root->child(row)); if (item->groupId() == repo.group_id) { group = item; break; } } if (!group) { if (repo.group_name == "Organization") { group = new RepoCategoryItem(CAT_INDEX_PUBLIC_REPOS, tr("Organization"), repo.group_id); // Insert pub repos after "recent updated", "my libraries", "shared libraries" insertRow(3, group); } else { group = new RepoCategoryItem(CAT_INDEX_GROUP_REPOS, repo.group_name, repo.group_id); appendRow(group); } } // Find the repo in this group n = group->rowCount(); for (row = 0; row < n; row++) { RepoItem *item = (RepoItem *)(group->child(row)); if (item->repo().id == repo.id) { updateRepoItem(item, repo); return; } } // Current repo not in this group yet RepoItem *item = new RepoItem(repo); group->appendRow(item); }