Skip to content

Commit

Permalink
list performance
Browse files Browse the repository at this point in the history
  • Loading branch information
kaniol-lck committed Jul 1, 2024
1 parent 8a3c6e6 commit 0120bda
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 55 deletions.
5 changes: 3 additions & 2 deletions src/modrinth/modrinthmodinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ ModrinthModInfo ModrinthModInfo::fromVariant(const QVariant &variant)
if(it != ModrinthAPI::getCategories().end()){
auto [name, iconName] = *it;
modInfo.importTag(Tag(name, TagCategory::ModrinthCategory, ":/image/modrinth/" + iconName));
qDebug() << iconName;
} else if(auto loaderType = ModLoaderType::fromString(categoryId);
loaderType != ModLoaderType::Any && ModLoaderType::modrinth.contains(loaderType)){
loaderType != ModLoaderType::Any && ModLoaderType::modrinth.contains(loaderType)){
modInfo.loaderTypes_ << loaderType;
} else{
// qDebug() << "UNKNOWN MODRINTH CATEGORY ID:" << categoryId;
qDebug() << "UNKNOWN MODRINTH CATEGORY ID:" << categoryId;
}
}

Expand Down
42 changes: 28 additions & 14 deletions src/ui/curseforge/curseforgefilelistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,21 @@ void CurseforgeFileListWidget::updateIndexWidget()
else
//extra 2
endRow += 2;
for(int row = beginRow; row <= endRow && row < model_.rowCount(); row++){
for(int row = 0; row < model_.rowCount(); row++){
auto index = model_.index(row, 0);
if(ui->fileListView->indexWidget(index)) continue;
auto item = model_.item(row);
auto &&fileInfo = mod_->modInfo().latestIndexedFileList().at(item->data(Qt::UserRole + 1).toInt());
auto itemWidget = new CurseforgeFileItemWidget(this, mod_, fileInfo);
ui->fileListView->setIndexWidget(model_.indexFromItem(item), itemWidget);
item->setSizeHint(QSize(0, itemWidget->height()));
if(row >= beginRow && row <= endRow){
if(ui->fileListView->indexWidget(index)) continue;
auto item = model_.item(row);
auto &&fileInfo = mod_->modInfo().latestIndexedFileList().at(item->data(Qt::UserRole + 1).toInt());
auto itemWidget = new CurseforgeFileItemWidget(this, mod_, fileInfo);
ui->fileListView->setIndexWidget(model_.indexFromItem(item), itemWidget);
item->setSizeHint(QSize(0, itemWidget->height()));
} else{
if(auto widget = ui->fileListView->indexWidget(index)){
ui->fileListView->setIndexWidget(index, nullptr);
delete widget;
}
}
}
}

Expand All @@ -194,14 +201,21 @@ void CurseforgeFileListWidget::updateIndexWidget2()
else
//extra 2
endRow += 2;
for(int row = beginRow; row <= endRow && row < model2_.rowCount(); row++){
for(int row = 0; row < model2_.rowCount(); row++){
auto index = model2_.index(row, 0);
if(ui->allFileListView->indexWidget(index)) continue;
auto item = model2_.item(row);
auto &&fileInfo = mod_->modInfo().allFileList().at(item->data(Qt::UserRole + 1).toInt());
auto itemWidget = new CurseforgeFileItemWidget(this, mod_, fileInfo);
ui->allFileListView->setIndexWidget(model2_.indexFromItem(item), itemWidget);
item->setSizeHint(QSize(0, itemWidget->height()));
if(row >= beginRow && row <= endRow){
if(ui->allFileListView->indexWidget(index)) continue;
auto item = model2_.item(row);
auto &&fileInfo = mod_->modInfo().allFileList().at(item->data(Qt::UserRole + 1).toInt());
auto itemWidget = new CurseforgeFileItemWidget(this, mod_, fileInfo);
ui->allFileListView->setIndexWidget(model2_.indexFromItem(item), itemWidget);
item->setSizeHint(QSize(0, itemWidget->height()));
} else{
if(auto widget = ui->fileListView->indexWidget(index)){
ui->fileListView->setIndexWidget(index, nullptr);
delete widget;
}
}
}
}

Expand Down
15 changes: 11 additions & 4 deletions src/ui/explorebrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,18 @@ void ExploreBrowser::updateListViewIndexWidget()
else
//extra 2
endRow += 2;
for(int row = beginRow; row <= endRow && row < model()->rowCount(); row++){
for(int row = 0; row < model()->rowCount(); row++){
auto index = model()->index(row, 0);
if(modListView_->indexWidget(index)) continue;
if(auto widget = getListViewIndexWidget(index)){
modListView_->setIndexWidget(index, widget);
if(row >= beginRow && row <= endRow){
if(modListView_->indexWidget(index)) continue;
if(auto widget = getListViewIndexWidget(index)){
modListView_->setIndexWidget(index, widget);
}
} else{
if(auto widget = modListView_->indexWidget(index)){
modListView_->setIndexWidget(index, nullptr);
delete widget;
}
}
}
}
Expand Down
21 changes: 14 additions & 7 deletions src/ui/github/githubfilelistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,21 @@ void GitHubFileListWidget::updateIndexWidget()
else
//extra 2
endRow += 2;
for(int row = beginRow; row <= endRow && row < model_->rowCount(); row++){
for(int row = 0; row < model_->rowCount(); row++){
auto index = model_->index(row, 0);
if(ui->fileListView->indexWidget(index)) continue;
auto item = model_->item(row);
auto &&fileInfo = release_->info().assets().at(item->data(Qt::UserRole + 1).toInt());
auto itemWidget = new GitHubFileItemWidget(this, fileInfo);
ui->fileListView->setIndexWidget(model_->indexFromItem(item), itemWidget);
item->setSizeHint(QSize(0, itemWidget->height()));
if(row >= beginRow && row <= endRow){
if(ui->fileListView->indexWidget(index)) continue;
auto item = model_->item(row);
auto &&fileInfo = release_->info().assets().at(item->data(Qt::UserRole + 1).toInt());
auto itemWidget = new GitHubFileItemWidget(this, fileInfo);
ui->fileListView->setIndexWidget(model_->indexFromItem(item), itemWidget);
item->setSizeHint(QSize(0, itemWidget->height()));
} else{
if(auto widget = ui->fileListView->indexWidget(index)){
ui->fileListView->setIndexWidget(index, nullptr);
delete widget;
}
}
}
}

Expand Down
54 changes: 32 additions & 22 deletions src/ui/local/localfilelistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,23 @@ void LocalFileListWidget::updateIndexWidget()
else
//extra 2
endRow += 2;
for(int row = beginRow; row <= endRow && row < model_->rowCount(); row++){
for(int row = 0; row < model_->rowCount(); row++){
auto index = model_->index(row, 0);
if(ui->fileListView->indexWidget(index)) continue;
// qDebug() << "new widget at row" << row;
auto item = model_->item(row);
if(!item) continue;
auto mod = item->data().value<LocalMod*>();
if(mod){
auto modItemWidget = new LocalModItemWidget(ui->fileListView, mod);
// modItemWidget->setMinimal(true);
ui->fileListView->setIndexWidget(index, modItemWidget);
item->setSizeHint(QSize(0, modItemWidget->height()));
if(row >= beginRow && row <= endRow){
if(ui->fileListView->indexWidget(index)) continue;
auto item = model_->item(row);
if(!item) continue;
auto mod = item->data().value<LocalMod*>();
if(mod){
auto modItemWidget = new LocalModItemWidget(ui->fileListView, mod);
ui->fileListView->setIndexWidget(index, modItemWidget);
item->setSizeHint(QSize(0, modItemWidget->height()));
}
} else{
if(auto widget = ui->fileListView->indexWidget(index)){
ui->fileListView->setIndexWidget(index, nullptr);
delete widget;
}
}
}
}
Expand All @@ -158,18 +163,23 @@ void LocalFileListWidget::updateUpdateIndexWidget()
else
//extra 2
endRow += 2;
for(int row = beginRow; row <= endRow && row < updateModel_->rowCount(); row++){
for(int row = 0; row < updateModel_->rowCount(); row++){
auto index = updateModel_->index(row, 0);
if(ui->updateFileListView->indexWidget(index)) continue;
// qDebug() << "new widget at row" << row;
auto item = updateModel_->item(row);
if(!item) continue;
auto mod = item->data().value<LocalMod*>();
if(mod){
auto modItemWidget = new LocalModItemWidget(ui->updateFileListView, mod);
// modItemWidget->setMinimal(true);
ui->updateFileListView->setIndexWidget(index, modItemWidget);
item->setSizeHint(QSize(0, modItemWidget->height()));
if(row >= beginRow && row <= endRow){
if(ui->updateFileListView->indexWidget(index)) continue;
auto item = updateModel_->item(row);
if(!item) continue;
auto mod = item->data().value<LocalMod*>();
if(mod){
auto modItemWidget = new LocalModItemWidget(ui->updateFileListView, mod);
ui->updateFileListView->setIndexWidget(index, modItemWidget);
item->setSizeHint(QSize(0, modItemWidget->height()));
}
} else{
if(auto widget = ui->fileListView->indexWidget(index)){
ui->fileListView->setIndexWidget(index, nullptr);
delete widget;
}
}
}
}
Expand Down
19 changes: 13 additions & 6 deletions src/ui/modrinth/modrinthfilelistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,19 @@ void ModrinthFileListWidget::updateIndexWidget()
else
//extra 2
endRow += 2;
for(int row = beginRow; row <= endRow && row < model_.rowCount(); row++){
for(int row = 0; row < model_.rowCount(); row++){
auto index = model_.index(row, 0);
if(ui->fileListView->indexWidget(index)) continue;
auto &&fileInfo = mod_->modInfo().fileList().at(index.data(Qt::UserRole + 1).toInt());
auto itemWidget = new ModrinthFileItemWidget(this, mod_, fileInfo);
ui->fileListView->setIndexWidget(index, itemWidget);
model_.itemFromIndex(index)->setSizeHint(QSize(0, itemWidget->height()));
if(row >= beginRow && row <= endRow){
if(ui->fileListView->indexWidget(index)) continue;
auto &&fileInfo = mod_->modInfo().fileList().at(index.data(Qt::UserRole + 1).toInt());
auto itemWidget = new ModrinthFileItemWidget(this, mod_, fileInfo);
ui->fileListView->setIndexWidget(index, itemWidget);
model_.itemFromIndex(index)->setSizeHint(QSize(0, itemWidget->height()));
} else{
if(auto widget = ui->fileListView->indexWidget(index)){
ui->fileListView->setIndexWidget(index, nullptr);
delete widget;
}
}
}
}

0 comments on commit 0120bda

Please sign in to comment.