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