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);
|
||||
CategoryData data;
|
||||
data.displayName = category.displayName;
|
||||
data.priority = category.priority;
|
||||
data.category = category;
|
||||
m_categories.insert(category.id, data);
|
||||
}
|
||||
|
||||
@@ -88,8 +87,8 @@ bool TaskModel::compareTasks(const Task &task1, const Task &task2)
|
||||
return task1.taskId < task2.taskId;
|
||||
|
||||
// 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 prio2 = m_categories.value(task2.category).priority;
|
||||
const int prio1 = m_categories.value(task1.category).category.priority;
|
||||
const int prio2 = m_categories.value(task2.category).category.priority;
|
||||
if (prio1 < prio2)
|
||||
return false;
|
||||
if (prio1 > prio2)
|
||||
@@ -296,16 +295,10 @@ Tasks TaskModel::tasks(const QModelIndexList &indexes) const
|
||||
[](const Task &t) { return !t.isNull(); });
|
||||
}
|
||||
|
||||
QList<Utils::Id> TaskModel::categoryIds() const
|
||||
QList<TaskCategory> TaskModel::categories() const
|
||||
{
|
||||
QList<Utils::Id> categories = m_categories.keys();
|
||||
categories.removeAll(Utils::Id()); // remove global category we added for bookkeeping
|
||||
return categories;
|
||||
}
|
||||
|
||||
QString TaskModel::categoryDisplayName(Utils::Id categoryId) const
|
||||
{
|
||||
return m_categories.value(categoryId).displayName;
|
||||
const QList<TaskCategory> cat = Utils::transform<QList>(m_categories, &CategoryData::category);
|
||||
return Utils::filtered(cat, [](const TaskCategory &c) { return c.id.isValid(); });
|
||||
}
|
||||
|
||||
int TaskModel::sizeOfFile(const QFont &font)
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "task.h"
|
||||
#include "taskhub.h"
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class TaskCategory;
|
||||
@@ -31,8 +32,7 @@ public:
|
||||
Task task(const QModelIndex &index) const;
|
||||
Tasks tasks(const QModelIndexList &indexes) const;
|
||||
|
||||
QList<Utils::Id> categoryIds() const;
|
||||
QString categoryDisplayName(Utils::Id categoryId) const;
|
||||
QList<TaskCategory> categories() const;
|
||||
void addCategory(const TaskCategory &category);
|
||||
|
||||
Tasks tasks(Utils::Id categoryId = Utils::Id()) const;
|
||||
@@ -86,8 +86,7 @@ private:
|
||||
errors = 0;
|
||||
}
|
||||
|
||||
QString displayName;
|
||||
int priority = 0;
|
||||
TaskCategory category;
|
||||
int count = 0;
|
||||
int warnings = 0;
|
||||
int errors = 0;
|
||||
|
@@ -465,27 +465,19 @@ void TaskWindow::setShowWarnings(bool show)
|
||||
|
||||
void TaskWindow::updateCategoriesMenu()
|
||||
{
|
||||
using NameToIdsConstIt = QMap<QString, Id>::ConstIterator;
|
||||
|
||||
d->m_categoriesMenu->clear();
|
||||
|
||||
const QList<Id> filteredCategories = d->m_filter->filteredCategories();
|
||||
const QList<TaskCategory> categories = Utils::sorted(d->m_model->categories(),
|
||||
&TaskCategory::displayName);
|
||||
|
||||
QMap<QString, Id> nameToIds;
|
||||
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();
|
||||
for (const TaskCategory &c : categories) {
|
||||
auto action = new QAction(d->m_categoriesMenu);
|
||||
action->setCheckable(true);
|
||||
action->setText(displayName);
|
||||
action->setChecked(!filteredCategories.contains(categoryId));
|
||||
connect(action, &QAction::triggered, this, [this, action, categoryId] {
|
||||
setCategoryVisibility(categoryId, action->isChecked());
|
||||
action->setText(c.displayName);
|
||||
action->setChecked(!filteredCategories.contains(c.id));
|
||||
connect(action, &QAction::triggered, this, [this, action, id = c.id] {
|
||||
setCategoryVisibility(id, action->isChecked());
|
||||
});
|
||||
d->m_categoriesMenu->addAction(action);
|
||||
}
|
||||
|
Reference in New Issue
Block a user