/**************************************************************************** ** ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of Qt Creator. ** ** 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. ** ** GNU Lesser General Public License Usage ** 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. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ****************************************************************************/ #include "OverviewModel.h" #include "Overview.h" #include #include #include using namespace CPlusPlus; OverviewModel::OverviewModel(QObject *parent) : QAbstractItemModel(parent) { } OverviewModel::~OverviewModel() { } bool OverviewModel::hasDocument() const { return _cppDocument; } Document::Ptr OverviewModel::document() const { return _cppDocument; } 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 { 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 return createIndex(row, column, symbol); } else { Symbol *parentSymbol = static_cast(parent.internalPointer()); Q_ASSERT(parentSymbol); if (Template *t = parentSymbol->asTemplate()) if (Symbol *templateParentSymbol = t->declaration()) parentSymbol = templateParentSymbol; Scope *scope = parentSymbol->asScope(); Q_ASSERT(scope != 0); return createIndex(row, 0, scope->memberAt(row)); } } QModelIndex OverviewModel::parent(const QModelIndex &child) const { Symbol *symbol = static_cast(child.internalPointer()); if (!symbol) // account for no symbol item return QModelIndex(); if (Scope *scope = symbol->enclosingScope()) { if (scope->isTemplate() && scope->enclosingScope()) scope = scope->enclosingScope(); if (scope->enclosingScope()) { QModelIndex index; if (scope->enclosingScope() && scope->enclosingScope()->enclosingScope()) // the parent doesn't have a parent index = createIndex(scope->index(), 0, scope); else //+1 to account for no symbol item index = createIndex(scope->index() + 1, 0, scope); return index; } } return QModelIndex(); } int OverviewModel::rowCount(const QModelIndex &parent) const { if (hasDocument()) { if (!parent.isValid()) { return globalSymbolCount()+1; // account for no symbol item } else { if (!parent.parent().isValid() && parent.row() == 0) // account for no symbol item return 0; Symbol *parentSymbol = static_cast(parent.internalPointer()); Q_ASSERT(parentSymbol); if (Template *t = parentSymbol->asTemplate()) if (Symbol *templateParentSymbol = t->declaration()) parentSymbol = templateParentSymbol; if (Scope *parentScope = parentSymbol->asScope()) { if (!parentScope->isFunction() && !parentScope->isObjCMethod()) { return parentScope->memberCount(); } } return 0; } } if (!parent.isValid()) return 1; // account for no symbol item return 0; } int OverviewModel::columnCount(const QModelIndex &) const { return 1; } QVariant OverviewModel::data(const QModelIndex &index, int role) const { // account for no symbol item if (!index.parent().isValid() && index.row() == 0) { switch (role) { case Qt::DisplayRole: if (rowCount() > 1) return tr("