forked from qt-creator/qt-creator
Optimize the taskCount tracking
Saving another 20%
This commit is contained in:
@@ -128,6 +128,9 @@ public:
|
||||
|
||||
QIcon taskTypeIcon(Task::TaskType t) const;
|
||||
|
||||
int taskCount();
|
||||
int errorTaskCount();
|
||||
|
||||
private:
|
||||
QHash<QString,QString> m_categories; // category id -> display name
|
||||
QList<Task> m_tasks; // all tasks (in order of insertion)
|
||||
@@ -137,6 +140,8 @@ private:
|
||||
int m_maxSizeOfFileName;
|
||||
const QIcon m_errorIcon;
|
||||
const QIcon m_warningIcon;
|
||||
int m_taskCount;
|
||||
int m_errorTaskCount;
|
||||
};
|
||||
|
||||
class TaskFilterModel : public QSortFilterProxyModel
|
||||
@@ -214,8 +219,21 @@ void TaskView::keyPressEvent(QKeyEvent *e)
|
||||
TaskModel::TaskModel() :
|
||||
m_maxSizeOfFileName(0),
|
||||
m_errorIcon(QLatin1String(":/projectexplorer/images/compile_error.png")),
|
||||
m_warningIcon(QLatin1String(":/projectexplorer/images/compile_warning.png"))
|
||||
m_warningIcon(QLatin1String(":/projectexplorer/images/compile_warning.png")),
|
||||
m_taskCount(0),
|
||||
m_errorTaskCount(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int TaskModel::taskCount()
|
||||
{
|
||||
return m_taskCount;
|
||||
}
|
||||
|
||||
int TaskModel::errorTaskCount()
|
||||
{
|
||||
return m_errorTaskCount;
|
||||
}
|
||||
|
||||
QIcon TaskModel::taskTypeIcon(Task::TaskType t) const
|
||||
@@ -270,6 +288,9 @@ void TaskModel::addTask(const Task &task)
|
||||
filename = task.file.mid(pos +1);
|
||||
|
||||
m_maxSizeOfFileName = qMax(m_maxSizeOfFileName, fm.width(filename));
|
||||
++m_taskCount;
|
||||
if (task.type == Task::Error)
|
||||
++m_errorTaskCount;
|
||||
}
|
||||
|
||||
void TaskModel::removeTask(const Task &task)
|
||||
@@ -278,6 +299,9 @@ void TaskModel::removeTask(const Task &task)
|
||||
int index = m_tasks.indexOf(task);
|
||||
beginRemoveRows(QModelIndex(), index, index);
|
||||
m_tasks.removeAt(index);
|
||||
--m_taskCount;
|
||||
if (task.type == Task::Error)
|
||||
--m_errorTaskCount;
|
||||
endRemoveRows();
|
||||
}
|
||||
}
|
||||
@@ -290,11 +314,14 @@ void TaskModel::clearTasks(const QString &categoryId)
|
||||
beginRemoveRows(QModelIndex(), 0, m_tasks.size() -1);
|
||||
m_tasks.clear();
|
||||
m_tasksInCategory.clear();
|
||||
m_taskCount = 0;
|
||||
m_errorTaskCount = 0;
|
||||
endRemoveRows();
|
||||
m_maxSizeOfFileName = 0;
|
||||
} else {
|
||||
int index = 0;
|
||||
int start = 0;
|
||||
int subErrorTaskCount = 0;
|
||||
while (index < m_tasks.size()) {
|
||||
while (index < m_tasks.size() && m_tasks.at(index).category != categoryId) {
|
||||
++start;
|
||||
@@ -303,6 +330,8 @@ void TaskModel::clearTasks(const QString &categoryId)
|
||||
if (index == m_tasks.size())
|
||||
break;
|
||||
while (index < m_tasks.size() && m_tasks.at(index).category == categoryId) {
|
||||
if (m_tasks.at(index).type == Task::Error)
|
||||
++subErrorTaskCount;
|
||||
++index;
|
||||
}
|
||||
// Index is now on the first non category
|
||||
@@ -314,6 +343,9 @@ void TaskModel::clearTasks(const QString &categoryId)
|
||||
|
||||
m_tasks.erase(m_tasks.begin() + start, m_tasks.begin() + index);
|
||||
|
||||
m_taskCount -= index - start;
|
||||
m_errorTaskCount -= subErrorTaskCount;
|
||||
|
||||
endRemoveRows();
|
||||
index = start;
|
||||
}
|
||||
@@ -683,21 +715,14 @@ void TaskWindow::filterCategoryTriggered(QAction *action)
|
||||
m_filter->setFilteredCategories(categories);
|
||||
}
|
||||
|
||||
int TaskWindow::taskCount(const QString &categoryId) const
|
||||
int TaskWindow::taskCount() const
|
||||
{
|
||||
return m_model->tasks(categoryId).count();
|
||||
return m_model->taskCount();
|
||||
}
|
||||
|
||||
int TaskWindow::errorTaskCount(const QString &categoryId) const
|
||||
int TaskWindow::errorTaskCount() const
|
||||
{
|
||||
int errorTaskCount = 0;
|
||||
|
||||
foreach (const Task &task, m_model->tasks(categoryId)) {
|
||||
if (task.type == Task::Error)
|
||||
++ errorTaskCount;
|
||||
}
|
||||
|
||||
return errorTaskCount;
|
||||
return m_model->errorTaskCount();
|
||||
}
|
||||
|
||||
int TaskWindow::priorityInStatusBar() const
|
||||
|
||||
Reference in New Issue
Block a user