2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-09-20 09:42:10 +00:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-09-20 09:42:10 +00:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-09-20 09:42:10 +00:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-09-20 09:42:10 +00:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-09-20 09:42:10 +00:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-09-20 09:42:10 +00:00
|
|
|
|
|
|
|
|
#include "taskmodel.h"
|
|
|
|
|
|
|
|
|
|
#include "task.h"
|
2013-11-25 11:58:32 +01:00
|
|
|
#include "taskhub.h"
|
2011-09-20 09:42:10 +00:00
|
|
|
|
2012-01-26 13:38:25 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2011-09-20 09:42:10 +00:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFontMetrics>
|
2011-09-20 09:42:10 +00:00
|
|
|
|
2016-08-03 23:29:58 +03:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2011-09-20 09:42:10 +00:00
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
/////
|
|
|
|
|
// TaskModel
|
|
|
|
|
/////
|
|
|
|
|
|
2016-04-15 15:00:22 +02:00
|
|
|
TaskModel::TaskModel(QObject *parent) : QAbstractItemModel(parent)
|
2011-09-20 09:42:10 +00:00
|
|
|
{
|
2012-01-26 13:38:25 +01:00
|
|
|
m_categories.insert(Core::Id(), CategoryData());
|
2011-09-20 09:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
int TaskModel::taskCount(Core::Id categoryId)
|
2011-09-20 09:42:10 +00:00
|
|
|
{
|
2012-01-26 13:38:25 +01:00
|
|
|
return m_categories.value(categoryId).count;
|
2011-09-20 09:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
int TaskModel::errorTaskCount(Core::Id categoryId)
|
2011-09-20 09:42:10 +00:00
|
|
|
{
|
2012-01-26 13:38:25 +01:00
|
|
|
return m_categories.value(categoryId).errors;
|
2011-09-20 09:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
int TaskModel::warningTaskCount(Core::Id categoryId)
|
2011-09-20 09:42:10 +00:00
|
|
|
{
|
2012-01-26 13:38:25 +01:00
|
|
|
return m_categories.value(categoryId).warnings;
|
2011-09-20 09:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
int TaskModel::unknownTaskCount(Core::Id categoryId)
|
2012-09-18 17:09:17 +02:00
|
|
|
{
|
|
|
|
|
return m_categories.value(categoryId).count
|
|
|
|
|
- m_categories.value(categoryId).errors
|
|
|
|
|
- m_categories.value(categoryId).warnings;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-20 09:42:10 +00:00
|
|
|
bool TaskModel::hasFile(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
int row = index.row();
|
|
|
|
|
if (!index.isValid() || row < 0 || row >= m_tasks.count())
|
|
|
|
|
return false;
|
|
|
|
|
return !m_tasks.at(row).file.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
void TaskModel::addCategory(Core::Id categoryId, const QString &categoryName)
|
2011-09-20 09:42:10 +00:00
|
|
|
{
|
2015-06-23 13:15:17 +02:00
|
|
|
QTC_ASSERT(categoryId.isValid(), return);
|
2011-09-20 09:42:10 +00:00
|
|
|
CategoryData data;
|
|
|
|
|
data.displayName = categoryName;
|
|
|
|
|
m_categories.insert(categoryId, data);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
QList<Task> TaskModel::tasks(Core::Id categoryId) const
|
2011-09-20 09:42:10 +00:00
|
|
|
{
|
2015-06-23 13:15:17 +02:00
|
|
|
if (!categoryId.isValid())
|
2011-09-20 09:42:10 +00:00
|
|
|
return m_tasks;
|
|
|
|
|
|
|
|
|
|
QList<Task> taskList;
|
|
|
|
|
foreach (const Task &t, m_tasks) {
|
2015-06-23 13:15:17 +02:00
|
|
|
if (t.category == categoryId)
|
2011-09-20 09:42:10 +00:00
|
|
|
taskList.append(t);
|
|
|
|
|
}
|
|
|
|
|
return taskList;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-22 14:13:53 +01:00
|
|
|
bool sortById(const Task &task, unsigned int id)
|
|
|
|
|
{
|
|
|
|
|
return task.taskId < id;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-20 09:42:10 +00:00
|
|
|
void TaskModel::addTask(const Task &task)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_categories.keys().contains(task.category));
|
|
|
|
|
CategoryData &data = m_categories[task.category];
|
2012-01-26 13:38:25 +01:00
|
|
|
CategoryData &global = m_categories[Core::Id()];
|
2011-09-20 09:42:10 +00:00
|
|
|
|
2016-08-03 23:29:58 +03:00
|
|
|
auto it = std::lower_bound(m_tasks.begin(), m_tasks.end(),task.taskId, sortById);
|
2012-02-22 14:13:53 +01:00
|
|
|
int i = it - m_tasks.begin();
|
|
|
|
|
beginInsertRows(QModelIndex(), i, i);
|
|
|
|
|
m_tasks.insert(it, task);
|
2011-09-20 09:42:10 +00:00
|
|
|
data.addTask(task);
|
|
|
|
|
global.addTask(task);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskModel::removeTask(const Task &task)
|
|
|
|
|
{
|
|
|
|
|
int index = m_tasks.indexOf(task);
|
|
|
|
|
if (index >= 0) {
|
|
|
|
|
const Task &t = m_tasks.at(index);
|
|
|
|
|
|
|
|
|
|
beginRemoveRows(QModelIndex(), index, index);
|
|
|
|
|
m_categories[task.category].removeTask(t);
|
2012-01-26 13:38:25 +01:00
|
|
|
m_categories[Core::Id()].removeTask(t);
|
2011-09-20 09:42:10 +00:00
|
|
|
m_tasks.removeAt(index);
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-29 16:15:25 +01:00
|
|
|
int TaskModel::rowForId(unsigned int id)
|
|
|
|
|
{
|
2016-08-03 23:29:58 +03:00
|
|
|
auto it = std::lower_bound(m_tasks.constBegin(), m_tasks.constEnd(), id, sortById);
|
2012-02-29 16:15:25 +01:00
|
|
|
if (it == m_tasks.constEnd())
|
|
|
|
|
return -1;
|
|
|
|
|
return it - m_tasks.constBegin();
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-12 16:56:25 +01:00
|
|
|
void TaskModel::updateTaskFileName(unsigned int id, const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
int i = rowForId(id);
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(i != -1, return);
|
2012-03-12 16:56:25 +01:00
|
|
|
if (m_tasks.at(i).taskId == id) {
|
|
|
|
|
m_tasks[i].file = Utils::FileName::fromString(fileName);
|
|
|
|
|
emit dataChanged(index(i, 0), index(i, 0));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-03 16:07:13 +01:00
|
|
|
void TaskModel::updateTaskLineNumber(unsigned int id, int line)
|
|
|
|
|
{
|
2012-02-29 16:15:25 +01:00
|
|
|
int i = rowForId(id);
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(i != -1, return);
|
2012-02-22 14:16:53 +01:00
|
|
|
if (m_tasks.at(i).taskId == id) {
|
|
|
|
|
m_tasks[i].movedLine = line;
|
|
|
|
|
emit dataChanged(index(i, 0), index(i, 0));
|
2012-02-03 16:07:13 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
void TaskModel::clearTasks(Core::Id categoryId)
|
2011-09-20 09:42:10 +00:00
|
|
|
{
|
2018-07-12 22:17:17 +02:00
|
|
|
using IdCategoryConstIt = QHash<Core::Id,CategoryData>::ConstIterator;
|
2013-03-14 14:14:48 +01:00
|
|
|
|
2015-06-23 13:15:17 +02:00
|
|
|
if (!categoryId.isValid()) {
|
2017-02-21 12:33:35 +01:00
|
|
|
if (m_tasks.isEmpty())
|
2011-09-20 09:42:10 +00:00
|
|
|
return;
|
|
|
|
|
beginRemoveRows(QModelIndex(), 0, m_tasks.count() -1);
|
|
|
|
|
m_tasks.clear();
|
2013-03-14 14:14:48 +01:00
|
|
|
const IdCategoryConstIt cend = m_categories.constEnd();
|
|
|
|
|
for (IdCategoryConstIt it = m_categories.constBegin(); it != cend; ++it)
|
|
|
|
|
m_categories[it.key()].clear();
|
2011-09-20 09:42:10 +00:00
|
|
|
endRemoveRows();
|
|
|
|
|
} else {
|
|
|
|
|
int index = 0;
|
|
|
|
|
int start = 0;
|
2012-01-26 13:38:25 +01:00
|
|
|
CategoryData &global = m_categories[Core::Id()];
|
2011-09-20 09:42:10 +00:00
|
|
|
CategoryData &cat = m_categories[categoryId];
|
|
|
|
|
|
|
|
|
|
while (index < m_tasks.count()) {
|
|
|
|
|
while (index < m_tasks.count() && m_tasks.at(index).category != categoryId) {
|
|
|
|
|
++start;
|
|
|
|
|
++index;
|
|
|
|
|
}
|
|
|
|
|
if (index == m_tasks.count())
|
|
|
|
|
break;
|
|
|
|
|
while (index < m_tasks.count() && m_tasks.at(index).category == categoryId)
|
|
|
|
|
++index;
|
|
|
|
|
|
|
|
|
|
// Index is now on the first non category
|
|
|
|
|
beginRemoveRows(QModelIndex(), start, index - 1);
|
|
|
|
|
|
|
|
|
|
for (int i = start; i < index; ++i) {
|
|
|
|
|
global.removeTask(m_tasks.at(i));
|
|
|
|
|
cat.removeTask(m_tasks.at(i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_tasks.erase(m_tasks.begin() + start, m_tasks.begin() + index);
|
|
|
|
|
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
index = start;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_maxSizeOfFileName = 0;
|
|
|
|
|
m_lastMaxSizeIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex TaskModel::index(int row, int column, const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
if (parent.isValid())
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
return createIndex(row, column);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex TaskModel::parent(const QModelIndex &child) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(child)
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TaskModel::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
return parent.isValid() ? 0 : m_tasks.count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TaskModel::columnCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
return parent.isValid() ? 0 : 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant TaskModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
2015-02-04 14:41:55 +01:00
|
|
|
int row = index.row();
|
|
|
|
|
if (!index.isValid() || row < 0 || row >= m_tasks.count() || index.column() != 0)
|
2011-09-20 09:42:10 +00:00
|
|
|
return QVariant();
|
|
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (role == TaskModel::File)
|
2012-01-26 13:38:25 +01:00
|
|
|
return m_tasks.at(index.row()).file.toString();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (role == TaskModel::Line)
|
2012-02-03 16:07:13 +01:00
|
|
|
return m_tasks.at(index.row()).line;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (role == TaskModel::MovedLine)
|
2012-02-03 16:07:13 +01:00
|
|
|
return m_tasks.at(index.row()).movedLine;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (role == TaskModel::Description)
|
2011-09-20 09:42:10 +00:00
|
|
|
return m_tasks.at(index.row()).description;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (role == TaskModel::FileNotFound)
|
2012-01-26 13:38:25 +01:00
|
|
|
return m_fileNotFound.value(m_tasks.at(index.row()).file.toString());
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (role == TaskModel::Type)
|
2011-09-20 09:42:10 +00:00
|
|
|
return (int)m_tasks.at(index.row()).type;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (role == TaskModel::Category)
|
2012-01-26 13:38:25 +01:00
|
|
|
return m_tasks.at(index.row()).category.uniqueIdentifier();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (role == TaskModel::Icon)
|
2013-11-12 21:59:43 +01:00
|
|
|
return m_tasks.at(index.row()).icon;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (role == TaskModel::Task_t)
|
2011-09-20 09:42:10 +00:00
|
|
|
return QVariant::fromValue(task(index));
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Task TaskModel::task(const QModelIndex &index) const
|
|
|
|
|
{
|
2015-02-04 14:41:55 +01:00
|
|
|
int row = index.row();
|
|
|
|
|
if (!index.isValid() || row < 0 || row >= m_tasks.count())
|
2011-09-20 09:42:10 +00:00
|
|
|
return Task();
|
2015-02-04 14:41:55 +01:00
|
|
|
return m_tasks.at(row);
|
2011-09-20 09:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-26 13:38:25 +01:00
|
|
|
QList<Core::Id> TaskModel::categoryIds() const
|
2011-09-20 09:42:10 +00:00
|
|
|
{
|
2012-01-26 13:38:25 +01:00
|
|
|
QList<Core::Id> categories = m_categories.keys();
|
|
|
|
|
categories.removeAll(Core::Id()); // remove global category we added for bookkeeping
|
|
|
|
|
return categories;
|
2011-09-20 09:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
QString TaskModel::categoryDisplayName(Core::Id categoryId) const
|
2011-09-20 09:42:10 +00:00
|
|
|
{
|
|
|
|
|
return m_categories.value(categoryId).displayName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TaskModel::sizeOfFile(const QFont &font)
|
|
|
|
|
{
|
|
|
|
|
int count = m_tasks.count();
|
|
|
|
|
if (count == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (m_maxSizeOfFileName > 0 && font == m_fileMeasurementFont && m_lastMaxSizeIndex == count - 1)
|
|
|
|
|
return m_maxSizeOfFileName;
|
|
|
|
|
|
|
|
|
|
QFontMetrics fm(font);
|
|
|
|
|
m_fileMeasurementFont = font;
|
|
|
|
|
|
|
|
|
|
for (int i = m_lastMaxSizeIndex; i < count; ++i) {
|
2012-01-26 13:38:25 +01:00
|
|
|
QString filename = m_tasks.at(i).file.toString();
|
2011-09-20 09:42:10 +00:00
|
|
|
const int pos = filename.lastIndexOf(QLatin1Char('/'));
|
|
|
|
|
if (pos != -1)
|
|
|
|
|
filename = filename.mid(pos +1);
|
|
|
|
|
|
2019-02-11 10:32:46 +01:00
|
|
|
m_maxSizeOfFileName = qMax(m_maxSizeOfFileName, fm.horizontalAdvance(filename));
|
2011-09-20 09:42:10 +00:00
|
|
|
}
|
|
|
|
|
m_lastMaxSizeIndex = count - 1;
|
|
|
|
|
return m_maxSizeOfFileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TaskModel::sizeOfLineNumber(const QFont &font)
|
|
|
|
|
{
|
|
|
|
|
if (m_sizeOfLineNumber == 0 || font != m_lineMeasurementFont) {
|
|
|
|
|
QFontMetrics fm(font);
|
|
|
|
|
m_lineMeasurementFont = font;
|
2019-02-11 10:32:46 +01:00
|
|
|
m_sizeOfLineNumber = fm.horizontalAdvance(QLatin1String("88888"));
|
2011-09-20 09:42:10 +00:00
|
|
|
}
|
|
|
|
|
return m_sizeOfLineNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskModel::setFileNotFound(const QModelIndex &idx, bool b)
|
|
|
|
|
{
|
2015-02-04 14:41:55 +01:00
|
|
|
int row = idx.row();
|
|
|
|
|
if (!idx.isValid() || row < 0 || row >= m_tasks.count())
|
|
|
|
|
return;
|
|
|
|
|
m_fileNotFound.insert(m_tasks[row].file.toUserOutput(), b);
|
|
|
|
|
emit dataChanged(idx, idx);
|
2011-09-20 09:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////
|
|
|
|
|
// TaskFilterModel
|
|
|
|
|
/////
|
|
|
|
|
|
2012-02-22 11:40:25 +01:00
|
|
|
TaskFilterModel::TaskFilterModel(TaskModel *sourceModel, QObject *parent) : QAbstractItemModel(parent),
|
2014-04-10 12:10:39 +02:00
|
|
|
m_sourceModel(sourceModel)
|
2011-09-20 09:42:10 +00:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_sourceModel);
|
2014-04-10 12:10:39 +02:00
|
|
|
updateMapping();
|
|
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_sourceModel, &QAbstractItemModel::rowsInserted,
|
|
|
|
|
this, &TaskFilterModel::handleNewRows);
|
2018-06-27 15:26:46 +02:00
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_sourceModel, &QAbstractItemModel::rowsAboutToBeRemoved,
|
|
|
|
|
this, &TaskFilterModel::handleRowsAboutToBeRemoved);
|
2018-06-27 15:26:46 +02:00
|
|
|
connect(m_sourceModel, &QAbstractItemModel::rowsRemoved,
|
|
|
|
|
this, [this](const QModelIndex &parent, int, int) {
|
|
|
|
|
QTC_ASSERT(!parent.isValid(), return);
|
2018-07-09 09:52:09 +02:00
|
|
|
if (m_beginRemoveRowsSent) {
|
|
|
|
|
m_beginRemoveRowsSent = false;
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
2018-06-27 15:26:46 +02:00
|
|
|
});
|
|
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_sourceModel, &QAbstractItemModel::modelReset,
|
2018-06-27 15:26:46 +02:00
|
|
|
this, &TaskFilterModel::invalidateFilter);
|
|
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_sourceModel, &QAbstractItemModel::dataChanged,
|
|
|
|
|
this, &TaskFilterModel::handleDataChanged);
|
2011-09-20 09:42:10 +00:00
|
|
|
|
|
|
|
|
m_includeUnknowns = m_includeWarnings = m_includeErrors = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex TaskFilterModel::index(int row, int column, const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
if (parent.isValid())
|
|
|
|
|
return QModelIndex();
|
2012-09-21 16:15:44 +02:00
|
|
|
return createIndex(row, column);
|
2011-09-20 09:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex TaskFilterModel::parent(const QModelIndex &child) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(child)
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TaskFilterModel::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
if (parent.isValid())
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return m_mapping.count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TaskFilterModel::columnCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
if (parent.isValid())
|
|
|
|
|
return 0;
|
|
|
|
|
return m_sourceModel->columnCount(parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant TaskFilterModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
return m_sourceModel->data(mapToSource(index), role);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QPair<int, int> findFilteredRange(int first, int last, const QList<int> &list)
|
|
|
|
|
{
|
2016-08-03 23:29:58 +03:00
|
|
|
auto filteredFirst = std::lower_bound(list.constBegin(), list.constEnd(), first);
|
|
|
|
|
auto filteredLast = std::upper_bound(filteredFirst, list.constEnd(), last);
|
2011-09-20 09:42:10 +00:00
|
|
|
return qMakePair(filteredFirst - list.constBegin(), filteredLast - list.constBegin() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskFilterModel::handleNewRows(const QModelIndex &index, int first, int last)
|
|
|
|
|
{
|
2018-06-27 15:26:46 +02:00
|
|
|
QTC_ASSERT(!index.isValid(), return);
|
2011-09-20 09:42:10 +00:00
|
|
|
|
2018-06-28 10:14:57 +02:00
|
|
|
const int newItemCount = last - first + 1;
|
|
|
|
|
|
2011-09-20 09:42:10 +00:00
|
|
|
QList<int> newMapping;
|
|
|
|
|
for (int i = first; i <= last; ++i) {
|
|
|
|
|
const Task &task = m_sourceModel->task(m_sourceModel->index(i, 0));
|
|
|
|
|
if (filterAcceptsTask(task))
|
|
|
|
|
newMapping.append(i);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 10:14:57 +02:00
|
|
|
const int newMappingCount = newMapping.count();
|
|
|
|
|
if (!newMappingCount)
|
2011-09-20 09:42:10 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int filteredFirst = -1;
|
|
|
|
|
if (last == m_sourceModel->rowCount() - 1)
|
|
|
|
|
filteredFirst = m_mapping.count();
|
|
|
|
|
else
|
2016-08-03 23:29:58 +03:00
|
|
|
filteredFirst = std::lower_bound(m_mapping.constBegin(), m_mapping.constEnd(), first) - m_mapping.constBegin();
|
2011-09-20 09:42:10 +00:00
|
|
|
|
2018-06-28 10:14:57 +02:00
|
|
|
const int filteredLast = filteredFirst + newMappingCount - 1;
|
2011-09-20 09:42:10 +00:00
|
|
|
beginInsertRows(QModelIndex(), filteredFirst, filteredLast);
|
|
|
|
|
if (filteredFirst == m_mapping.count()) {
|
|
|
|
|
m_mapping.append(newMapping);
|
|
|
|
|
} else {
|
2018-06-28 10:14:57 +02:00
|
|
|
const QList<int> rest = m_mapping.mid(filteredFirst);
|
2011-09-20 09:42:10 +00:00
|
|
|
|
2018-06-28 10:14:57 +02:00
|
|
|
m_mapping.reserve(m_mapping.count() + newMappingCount);
|
2011-09-20 09:42:10 +00:00
|
|
|
m_mapping.erase(m_mapping.begin() + filteredFirst, m_mapping.end());
|
|
|
|
|
m_mapping.append(newMapping);
|
2018-06-28 10:14:57 +02:00
|
|
|
for (int pos : rest)
|
|
|
|
|
m_mapping.append(pos + newItemCount);
|
2011-09-20 09:42:10 +00:00
|
|
|
}
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-05 14:32:40 +02:00
|
|
|
void TaskFilterModel::handleRowsAboutToBeRemoved(const QModelIndex &index, int first, int last)
|
2011-09-20 09:42:10 +00:00
|
|
|
{
|
2018-07-09 09:52:09 +02:00
|
|
|
m_beginRemoveRowsSent = false;
|
2018-06-27 15:26:46 +02:00
|
|
|
QTC_ASSERT(!index.isValid(), return);
|
2011-09-20 09:42:10 +00:00
|
|
|
|
|
|
|
|
const QPair<int, int> range = findFilteredRange(first, last, m_mapping);
|
2018-11-22 10:12:21 +01:00
|
|
|
if (range.first <= range.second) { // remove corresponding rows in filtermodel
|
|
|
|
|
beginRemoveRows(QModelIndex(), range.first, range.second);
|
|
|
|
|
m_beginRemoveRowsSent = true;
|
|
|
|
|
m_mapping.erase(m_mapping.begin() + range.first, m_mapping.begin() + range.second + 1);
|
|
|
|
|
}
|
|
|
|
|
// adapt existing mapping to removed source indices
|
2018-06-27 15:26:46 +02:00
|
|
|
const int sourceRemovedCount = (last - first) + 1;
|
2011-09-20 09:42:10 +00:00
|
|
|
for (int i = range.first; i < m_mapping.count(); ++i)
|
2018-06-27 15:26:46 +02:00
|
|
|
m_mapping[i] = m_mapping.at(i) - sourceRemovedCount;
|
2011-09-20 09:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
2014-05-05 17:15:20 +03:00
|
|
|
void TaskFilterModel::handleDataChanged(const QModelIndex &top, const QModelIndex &bottom)
|
2011-09-20 09:42:10 +00:00
|
|
|
{
|
|
|
|
|
const QPair<int, int> range = findFilteredRange(top.row(), bottom.row(), m_mapping);
|
|
|
|
|
if (range.first > range.second)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
emit dataChanged(index(range.first, top.column()), index(range.second, bottom.column()));
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-29 16:15:25 +01:00
|
|
|
QModelIndex TaskFilterModel::mapFromSource(const QModelIndex &idx) const
|
|
|
|
|
{
|
2018-06-27 15:26:46 +02:00
|
|
|
if (!idx.isValid())
|
2012-02-29 16:15:25 +01:00
|
|
|
return QModelIndex();
|
2018-06-27 15:26:46 +02:00
|
|
|
auto it = std::lower_bound(m_mapping.constBegin(), m_mapping.constEnd(), idx.row());
|
|
|
|
|
QTC_ASSERT(it != m_mapping.constEnd() && idx.row() == *it, return QModelIndex());
|
2012-02-29 16:15:25 +01:00
|
|
|
return index(it - m_mapping.constBegin(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-20 09:42:10 +00:00
|
|
|
QModelIndex TaskFilterModel::mapToSource(const QModelIndex &index) const
|
|
|
|
|
{
|
2018-06-27 15:26:46 +02:00
|
|
|
if (!index.isValid())
|
2011-09-20 09:42:10 +00:00
|
|
|
return QModelIndex();
|
2018-06-27 15:26:46 +02:00
|
|
|
int row = index.row();
|
|
|
|
|
QTC_ASSERT(row >= 0 && row < m_mapping.count(), return QModelIndex());
|
2011-09-20 09:42:10 +00:00
|
|
|
return m_sourceModel->index(m_mapping.at(row), index.column(), index.parent());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskFilterModel::invalidateFilter()
|
|
|
|
|
{
|
|
|
|
|
beginResetModel();
|
2014-04-10 12:10:39 +02:00
|
|
|
updateMapping();
|
2011-09-20 09:42:10 +00:00
|
|
|
endResetModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskFilterModel::updateMapping() const
|
|
|
|
|
{
|
|
|
|
|
m_mapping.clear();
|
|
|
|
|
for (int i = 0; i < m_sourceModel->rowCount(); ++i) {
|
|
|
|
|
QModelIndex index = m_sourceModel->index(i, 0);
|
|
|
|
|
const Task &task = m_sourceModel->task(index);
|
|
|
|
|
if (filterAcceptsTask(task))
|
|
|
|
|
m_mapping.append(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskFilterModel::filterAcceptsTask(const Task &task) const
|
|
|
|
|
{
|
|
|
|
|
bool accept = true;
|
|
|
|
|
switch (task.type) {
|
|
|
|
|
case Task::Unknown:
|
|
|
|
|
accept = m_includeUnknowns;
|
|
|
|
|
break;
|
|
|
|
|
case Task::Warning:
|
|
|
|
|
accept = m_includeWarnings;
|
|
|
|
|
break;
|
|
|
|
|
case Task::Error:
|
|
|
|
|
accept = m_includeErrors;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_categoryIds.contains(task.category))
|
|
|
|
|
accept = false;
|
|
|
|
|
|
|
|
|
|
return accept;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ProjectExplorer
|