File indexing completed on 2024-05-05 05:51:37
0001 /* 0002 SPDX-FileCopyrightText: 2020 Waqar Ahmed <waqar.17a@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #include "gotoglobalsymbolmodel.h" 0007 0008 #include <QIcon> 0009 0010 GotoGlobalSymbolModel::GotoGlobalSymbolModel(QObject *parent) 0011 : QAbstractTableModel(parent) 0012 { 0013 } 0014 0015 int GotoGlobalSymbolModel::columnCount(const QModelIndex &) const 0016 { 0017 return 1; 0018 } 0019 0020 int GotoGlobalSymbolModel::rowCount(const QModelIndex &) const 0021 { 0022 return m_rows.size(); 0023 } 0024 0025 QString GotoGlobalSymbolModel::filterName(QString tagName) 0026 { 0027 // remove anon namespace 0028 int __anonIdx = tagName.indexOf(QStringLiteral("__anon")); 0029 if (__anonIdx != -1) { 0030 int scopeOpIdx = tagName.indexOf(QStringLiteral("::"), __anonIdx) + 2; 0031 tagName.remove(__anonIdx, scopeOpIdx - __anonIdx); 0032 } 0033 return tagName; 0034 } 0035 0036 QVariant GotoGlobalSymbolModel::data(const QModelIndex &index, int role) const 0037 { 0038 if (!index.isValid()) { 0039 return QVariant(); 0040 } 0041 0042 static const QIcon defIcon = QIcon::fromTheme(QStringLiteral("code-block")); 0043 static const QIcon funcIcon = QIcon::fromTheme(QStringLiteral("code-function")); 0044 static const QIcon varIcon = QIcon::fromTheme(QStringLiteral("code-variable")); 0045 0046 const Tags::TagEntry &row = m_rows.at(index.row()); 0047 if (role == Qt::DisplayRole) { 0048 if (index.column() == 0) { 0049 return filterName(row.tag); 0050 } 0051 } else if (role == Qt::UserRole) { 0052 return row.tag; 0053 } else if (role == Qt::DecorationRole) { 0054 if (row.type == QLatin1String("function") || row.type == QLatin1String("member")) { 0055 return funcIcon; 0056 } else if (row.type.startsWith(QLatin1String("var"))) { 0057 return varIcon; 0058 } else { 0059 return defIcon; 0060 } 0061 } else if (role == Pattern) { 0062 return row.pattern; 0063 } else if (role == FileUrl) { 0064 return row.file; 0065 } 0066 0067 return QVariant(); 0068 } 0069 0070 #include "moc_gotoglobalsymbolmodel.cpp"