2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01: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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include "OverviewModel.h"
|
|
|
|
|
#include "Overview.h"
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <Scope.h>
|
|
|
|
|
#include <Literals.h>
|
|
|
|
|
#include <Symbols.h>
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace CPlusPlus;
|
|
|
|
|
|
|
|
|
|
OverviewModel::OverviewModel(QObject *parent)
|
|
|
|
|
: QAbstractItemModel(parent)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
OverviewModel::~OverviewModel()
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
bool OverviewModel::hasDocument() const
|
2008-12-02 14:09:21 +01:00
|
|
|
{
|
|
|
|
|
return _cppDocument;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
Document::Ptr OverviewModel::document() const
|
2008-12-02 14:09:21 +01:00
|
|
|
{
|
|
|
|
|
return _cppDocument;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
unsigned OverviewModel::globalSymbolCount() const
|
|
|
|
|
{
|
|
|
|
|
unsigned count = 0;
|
|
|
|
|
if (_cppDocument)
|
|
|
|
|
count += _cppDocument->globalSymbolCount();
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Symbol *OverviewModel::globalSymbolAt(unsigned index) const
|
|
|
|
|
{ return _cppDocument->globalSymbolAt(index); }
|
|
|
|
|
|
|
|
|
|
QModelIndex OverviewModel::index(int row, int column, const QModelIndex &parent) const
|
|
|
|
|
{
|
2008-12-08 17:47:54 +01:00
|
|
|
if (!parent.isValid()) {
|
|
|
|
|
if (row == 0) // account for no symbol item
|
|
|
|
|
return createIndex(row, column);
|
|
|
|
|
Symbol *symbol = globalSymbolAt(row-1); // account for no symbol item
|
2008-12-02 12:01:29 +01:00
|
|
|
return createIndex(row, column, symbol);
|
|
|
|
|
} else {
|
|
|
|
|
Symbol *parentSymbol = static_cast<Symbol *>(parent.internalPointer());
|
2008-12-10 15:43:17 +01:00
|
|
|
Q_ASSERT(parentSymbol);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-06-15 11:28:18 +02:00
|
|
|
if (Template *t = parentSymbol->asTemplate())
|
|
|
|
|
if (Symbol *templateParentSymbol = t->declaration())
|
|
|
|
|
parentSymbol = templateParentSymbol;
|
|
|
|
|
|
2010-08-11 12:26:02 +02:00
|
|
|
Scope *scope = parentSymbol->asScope();
|
|
|
|
|
Q_ASSERT(scope != 0);
|
|
|
|
|
return createIndex(row, 0, scope->memberAt(row));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex OverviewModel::parent(const QModelIndex &child) const
|
|
|
|
|
{
|
|
|
|
|
Symbol *symbol = static_cast<Symbol *>(child.internalPointer());
|
2008-12-08 17:47:54 +01:00
|
|
|
if (!symbol) // account for no symbol item
|
|
|
|
|
return QModelIndex();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-08-26 16:16:22 +02:00
|
|
|
if (Scope *scope = symbol->enclosingScope()) {
|
2012-06-15 11:28:18 +02:00
|
|
|
if (scope->isTemplate() && scope->enclosingScope())
|
|
|
|
|
scope = scope->enclosingScope();
|
2010-08-26 16:16:22 +02:00
|
|
|
if (scope->enclosingScope()) {
|
2008-12-08 17:47:54 +01:00
|
|
|
QModelIndex index;
|
2010-08-26 16:16:22 +02:00
|
|
|
if (scope->enclosingScope() && scope->enclosingScope()->enclosingScope()) // the parent doesn't have a parent
|
2010-08-11 12:26:02 +02:00
|
|
|
index = createIndex(scope->index(), 0, scope);
|
2008-12-08 17:47:54 +01:00
|
|
|
else //+1 to account for no symbol item
|
2010-08-11 12:26:02 +02:00
|
|
|
index = createIndex(scope->index() + 1, 0, scope);
|
2008-12-08 17:47:54 +01:00
|
|
|
return index;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int OverviewModel::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
if (hasDocument()) {
|
2008-12-08 17:47:54 +01:00
|
|
|
if (!parent.isValid()) {
|
|
|
|
|
return globalSymbolCount()+1; // account for no symbol item
|
2008-12-02 12:01:29 +01:00
|
|
|
} else {
|
2008-12-08 17:47:54 +01:00
|
|
|
if (!parent.parent().isValid() && parent.row() == 0) // account for no symbol item
|
|
|
|
|
return 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
Symbol *parentSymbol = static_cast<Symbol *>(parent.internalPointer());
|
2008-12-10 15:43:17 +01:00
|
|
|
Q_ASSERT(parentSymbol);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-06-15 11:28:18 +02:00
|
|
|
if (Template *t = parentSymbol->asTemplate())
|
|
|
|
|
if (Symbol *templateParentSymbol = t->declaration())
|
|
|
|
|
parentSymbol = templateParentSymbol;
|
|
|
|
|
|
2010-08-11 12:26:02 +02:00
|
|
|
if (Scope *parentScope = parentSymbol->asScope()) {
|
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 (!parentScope->isFunction() && !parentScope->isObjCMethod())
|
2010-08-11 12:26:02 +02:00
|
|
|
return parentScope->memberCount();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2008-12-08 17:47:54 +01:00
|
|
|
return 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
2008-12-08 17:47:54 +01:00
|
|
|
if (!parent.isValid())
|
|
|
|
|
return 1; // account for no symbol item
|
2008-12-02 12:01:29 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int OverviewModel::columnCount(const QModelIndex &) const
|
2008-12-02 14:09:21 +01:00
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QVariant OverviewModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
2008-12-08 17:47:54 +01:00
|
|
|
// account for no symbol item
|
|
|
|
|
if (!index.parent().isValid() && index.row() == 0) {
|
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
if (rowCount() > 1)
|
|
|
|
|
return tr("<Select Symbol>");
|
|
|
|
|
else
|
|
|
|
|
return tr("<No Symbols>");
|
|
|
|
|
default:
|
|
|
|
|
return QVariant();
|
|
|
|
|
} //switch
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole: {
|
|
|
|
|
Symbol *symbol = static_cast<Symbol *>(index.internalPointer());
|
|
|
|
|
QString name = _overview.prettyName(symbol->name());
|
|
|
|
|
if (name.isEmpty())
|
|
|
|
|
name = QLatin1String("anonymous");
|
2009-07-31 16:03:48 +02:00
|
|
|
if (symbol->isObjCForwardClassDeclaration())
|
|
|
|
|
name = QLatin1String("@class ") + name;
|
|
|
|
|
if (symbol->isObjCForwardProtocolDeclaration() || symbol->isObjCProtocol())
|
|
|
|
|
name = QLatin1String("@protocol ") + name;
|
2009-08-05 18:30:18 +02:00
|
|
|
if (symbol->isObjCClass()) {
|
|
|
|
|
ObjCClass *clazz = symbol->asObjCClass();
|
|
|
|
|
if (clazz->isInterface())
|
|
|
|
|
name = QLatin1String("@interface ") + name;
|
|
|
|
|
else
|
|
|
|
|
name = QLatin1String("@implementation ") + name;
|
|
|
|
|
|
|
|
|
|
if (clazz->isCategory())
|
|
|
|
|
name += QLatin1String(" (") + _overview.prettyName(clazz->categoryName()) + QLatin1Char(')');
|
|
|
|
|
}
|
2010-01-22 13:24:06 +01:00
|
|
|
if (symbol->isObjCPropertyDeclaration())
|
|
|
|
|
name = QLatin1String("@property ") + name;
|
2012-06-15 11:28:18 +02:00
|
|
|
if (Template *t = symbol->asTemplate())
|
|
|
|
|
if (Symbol *templateDeclaration = t->declaration()) {
|
|
|
|
|
QStringList parameters;
|
|
|
|
|
for (unsigned i = 0; i < t->templateParameterCount(); ++i)
|
|
|
|
|
parameters.append(_overview.prettyName(t->templateParameterAt(i)->name()));
|
|
|
|
|
name += QLatin1Char('<') + parameters.join(QLatin1String(", ")) + QLatin1Char('>');
|
|
|
|
|
symbol = templateDeclaration;
|
|
|
|
|
}
|
2009-08-05 18:30:18 +02:00
|
|
|
if (symbol->isObjCMethod()) {
|
|
|
|
|
ObjCMethod *method = symbol->asObjCMethod();
|
|
|
|
|
if (method->isStatic())
|
|
|
|
|
name = QLatin1Char('+') + name;
|
|
|
|
|
else
|
|
|
|
|
name = QLatin1Char('-') + name;
|
2010-08-12 12:35:22 +02:00
|
|
|
} else if (! symbol->isScope() || symbol->isFunction()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
QString type = _overview.prettyType(symbol->type());
|
2012-06-15 12:04:21 +02:00
|
|
|
if (Function *f = symbol->type()->asFunctionType()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
name += type;
|
2012-06-15 12:04:21 +02:00
|
|
|
type = _overview.prettyType(f->returnType());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2012-06-15 12:04:21 +02:00
|
|
|
if (! type.isEmpty())
|
|
|
|
|
name += QLatin1String(": ") + type;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case Qt::EditRole: {
|
|
|
|
|
Symbol *symbol = static_cast<Symbol *>(index.internalPointer());
|
|
|
|
|
QString name = _overview.prettyName(symbol->name());
|
|
|
|
|
if (name.isEmpty())
|
|
|
|
|
name = QLatin1String("anonymous");
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case Qt::DecorationRole: {
|
|
|
|
|
Symbol *symbol = static_cast<Symbol *>(index.internalPointer());
|
|
|
|
|
return _icons.iconForSymbol(symbol);
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case FileNameRole: {
|
|
|
|
|
Symbol *symbol = static_cast<Symbol *>(index.internalPointer());
|
|
|
|
|
return QString::fromUtf8(symbol->fileName(), symbol->fileNameLength());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LineNumberRole: {
|
|
|
|
|
Symbol *symbol = static_cast<Symbol *>(index.internalPointer());
|
|
|
|
|
return symbol->line();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return QVariant();
|
|
|
|
|
} // switch
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Symbol *OverviewModel::symbolFromIndex(const QModelIndex &index) const
|
2008-12-02 14:09:21 +01:00
|
|
|
{
|
|
|
|
|
return static_cast<Symbol *>(index.internalPointer());
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
void OverviewModel::rebuild(Document::Ptr doc)
|
|
|
|
|
{
|
2012-09-20 10:31:34 +02:00
|
|
|
beginResetModel();
|
2008-12-02 12:01:29 +01:00
|
|
|
_cppDocument = doc;
|
2012-09-20 10:31:34 +02:00
|
|
|
endResetModel();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|