WelcomePage: Only retrieve recent projects once

The recentProject list was retrieved for every ::data and ::rowCount
call. This triggered QFileInfo.exists call for each project
which was expensive. This fixes that so that the recent projects
are only filtered once for each model reset.

Change-Id: I6ce33a13c2446bece5b7dac1563ffa7bdc85bbaa
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2022-07-27 11:48:44 +02:00
parent 8d2f3ac3f2
commit 859f146760
2 changed files with 9 additions and 4 deletions

View File

@@ -78,15 +78,14 @@ ProjectModel::ProjectModel(QObject *parent)
int ProjectModel::rowCount(const QModelIndex &) const
{
return ProjectExplorerPlugin::recentProjects().count();
return m_projects.count();
}
QVariant ProjectModel::data(const QModelIndex &index, int role) const
{
const RecentProjectsEntries recentProjects = ProjectExplorerPlugin::recentProjects();
if (recentProjects.count() <= index.row())
if (m_projects.count() <= index.row())
return {};
RecentProjectsEntry data = recentProjects.at(index.row());
RecentProjectsEntry data = m_projects.at(index.row());
switch (role) {
case Qt::DisplayRole:
return data.second;
@@ -120,6 +119,7 @@ QHash<int, QByteArray> ProjectModel::roleNames() const
void ProjectModel::resetProjects()
{
beginResetModel();
m_projects = ProjectExplorerPlugin::recentProjects();
endResetModel();
}

View File

@@ -25,6 +25,8 @@
#pragma once
#include "projectexplorer.h"
#include <coreplugin/iwelcomepage.h>
#include <QAbstractListModel>
@@ -49,6 +51,9 @@ public:
public slots:
void resetProjects();
private:
RecentProjectsEntries m_projects;
};
class ProjectWelcomePage : public Core::IWelcomePage