forked from qt-creator/qt-creator
Tasks: Save TaskCategory objects in the model
So data can be accessed more directly, instead of going through individual methods categoryIds and categoryDisplayName. Change-Id: Idb36050762e507480ba69de6a32b5f6f9bec8b75 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -64,8 +64,7 @@ void TaskModel::addCategory(const TaskCategory &category)
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(category.id.isValid(), return);
|
QTC_ASSERT(category.id.isValid(), return);
|
||||||
CategoryData data;
|
CategoryData data;
|
||||||
data.displayName = category.displayName;
|
data.category = category;
|
||||||
data.priority = category.priority;
|
|
||||||
m_categories.insert(category.id, data);
|
m_categories.insert(category.id, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,8 +87,8 @@ bool TaskModel::compareTasks(const Task &task1, const Task &task2)
|
|||||||
return task1.taskId < task2.taskId;
|
return task1.taskId < task2.taskId;
|
||||||
|
|
||||||
// Higher-priority task should appear higher up in the view and thus compare less-than.
|
// Higher-priority task should appear higher up in the view and thus compare less-than.
|
||||||
const int prio1 = m_categories.value(task1.category).priority;
|
const int prio1 = m_categories.value(task1.category).category.priority;
|
||||||
const int prio2 = m_categories.value(task2.category).priority;
|
const int prio2 = m_categories.value(task2.category).category.priority;
|
||||||
if (prio1 < prio2)
|
if (prio1 < prio2)
|
||||||
return false;
|
return false;
|
||||||
if (prio1 > prio2)
|
if (prio1 > prio2)
|
||||||
@@ -296,16 +295,10 @@ Tasks TaskModel::tasks(const QModelIndexList &indexes) const
|
|||||||
[](const Task &t) { return !t.isNull(); });
|
[](const Task &t) { return !t.isNull(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Utils::Id> TaskModel::categoryIds() const
|
QList<TaskCategory> TaskModel::categories() const
|
||||||
{
|
{
|
||||||
QList<Utils::Id> categories = m_categories.keys();
|
const QList<TaskCategory> cat = Utils::transform<QList>(m_categories, &CategoryData::category);
|
||||||
categories.removeAll(Utils::Id()); // remove global category we added for bookkeeping
|
return Utils::filtered(cat, [](const TaskCategory &c) { return c.id.isValid(); });
|
||||||
return categories;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString TaskModel::categoryDisplayName(Utils::Id categoryId) const
|
|
||||||
{
|
|
||||||
return m_categories.value(categoryId).displayName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int TaskModel::sizeOfFile(const QFont &font)
|
int TaskModel::sizeOfFile(const QFont &font)
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
#include "taskhub.h"
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
class TaskCategory;
|
class TaskCategory;
|
||||||
@@ -31,8 +32,7 @@ public:
|
|||||||
Task task(const QModelIndex &index) const;
|
Task task(const QModelIndex &index) const;
|
||||||
Tasks tasks(const QModelIndexList &indexes) const;
|
Tasks tasks(const QModelIndexList &indexes) const;
|
||||||
|
|
||||||
QList<Utils::Id> categoryIds() const;
|
QList<TaskCategory> categories() const;
|
||||||
QString categoryDisplayName(Utils::Id categoryId) const;
|
|
||||||
void addCategory(const TaskCategory &category);
|
void addCategory(const TaskCategory &category);
|
||||||
|
|
||||||
Tasks tasks(Utils::Id categoryId = Utils::Id()) const;
|
Tasks tasks(Utils::Id categoryId = Utils::Id()) const;
|
||||||
@@ -86,8 +86,7 @@ private:
|
|||||||
errors = 0;
|
errors = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString displayName;
|
TaskCategory category;
|
||||||
int priority = 0;
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int warnings = 0;
|
int warnings = 0;
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
|
@@ -465,27 +465,19 @@ void TaskWindow::setShowWarnings(bool show)
|
|||||||
|
|
||||||
void TaskWindow::updateCategoriesMenu()
|
void TaskWindow::updateCategoriesMenu()
|
||||||
{
|
{
|
||||||
using NameToIdsConstIt = QMap<QString, Id>::ConstIterator;
|
|
||||||
|
|
||||||
d->m_categoriesMenu->clear();
|
d->m_categoriesMenu->clear();
|
||||||
|
|
||||||
const QList<Id> filteredCategories = d->m_filter->filteredCategories();
|
const QList<Id> filteredCategories = d->m_filter->filteredCategories();
|
||||||
|
const QList<TaskCategory> categories = Utils::sorted(d->m_model->categories(),
|
||||||
|
&TaskCategory::displayName);
|
||||||
|
|
||||||
QMap<QString, Id> nameToIds;
|
for (const TaskCategory &c : categories) {
|
||||||
const QList<Id> ids = d->m_model->categoryIds();
|
|
||||||
for (const Id categoryId : ids)
|
|
||||||
nameToIds.insert(d->m_model->categoryDisplayName(categoryId), categoryId);
|
|
||||||
|
|
||||||
const NameToIdsConstIt cend = nameToIds.constEnd();
|
|
||||||
for (NameToIdsConstIt it = nameToIds.constBegin(); it != cend; ++it) {
|
|
||||||
const QString &displayName = it.key();
|
|
||||||
const Id categoryId = it.value();
|
|
||||||
auto action = new QAction(d->m_categoriesMenu);
|
auto action = new QAction(d->m_categoriesMenu);
|
||||||
action->setCheckable(true);
|
action->setCheckable(true);
|
||||||
action->setText(displayName);
|
action->setText(c.displayName);
|
||||||
action->setChecked(!filteredCategories.contains(categoryId));
|
action->setChecked(!filteredCategories.contains(c.id));
|
||||||
connect(action, &QAction::triggered, this, [this, action, categoryId] {
|
connect(action, &QAction::triggered, this, [this, action, id = c.id] {
|
||||||
setCategoryVisibility(categoryId, action->isChecked());
|
setCategoryVisibility(id, action->isChecked());
|
||||||
});
|
});
|
||||||
d->m_categoriesMenu->addAction(action);
|
d->m_categoriesMenu->addAction(action);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user