forked from qt-creator/qt-creator
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
(cherry picked from commit 859f146760
)
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -78,15 +78,14 @@ ProjectModel::ProjectModel(QObject *parent)
|
|||||||
|
|
||||||
int ProjectModel::rowCount(const QModelIndex &) const
|
int ProjectModel::rowCount(const QModelIndex &) const
|
||||||
{
|
{
|
||||||
return ProjectExplorerPlugin::recentProjects().count();
|
return m_projects.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ProjectModel::data(const QModelIndex &index, int role) const
|
QVariant ProjectModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
const RecentProjectsEntries recentProjects = ProjectExplorerPlugin::recentProjects();
|
if (m_projects.count() <= index.row())
|
||||||
if (recentProjects.count() <= index.row())
|
|
||||||
return {};
|
return {};
|
||||||
RecentProjectsEntry data = recentProjects.at(index.row());
|
RecentProjectsEntry data = m_projects.at(index.row());
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return data.second;
|
return data.second;
|
||||||
@@ -120,6 +119,7 @@ QHash<int, QByteArray> ProjectModel::roleNames() const
|
|||||||
void ProjectModel::resetProjects()
|
void ProjectModel::resetProjects()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
m_projects = ProjectExplorerPlugin::recentProjects();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "projectexplorer.h"
|
||||||
|
|
||||||
#include <coreplugin/iwelcomepage.h>
|
#include <coreplugin/iwelcomepage.h>
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
@@ -49,6 +51,9 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void resetProjects();
|
void resetProjects();
|
||||||
|
|
||||||
|
private:
|
||||||
|
RecentProjectsEntries m_projects;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ProjectWelcomePage : public Core::IWelcomePage
|
class ProjectWelcomePage : public Core::IWelcomePage
|
||||||
|
Reference in New Issue
Block a user