| 170 | } |
| 171 | |
| 172 | QVariant CMakeCodeCompletionModel::data (const QModelIndex & index, int role) const |
| 173 | { |
| 174 | if(!index.isValid()) |
| 175 | return QVariant(); |
| 176 | Type type=indexType(index.row()); |
| 177 | |
| 178 | if(role==Qt::DisplayRole && index.column()==CodeCompletionModel::Name) |
| 179 | { |
| 180 | int pos = index.row(); |
| 181 | switch(type) { |
| 182 | case Command: |
| 183 | return s_commands[pos-m_declarations.size()]; |
| 184 | case Path: |
| 185 | return m_paths[pos-m_declarations.size()]; |
| 186 | case Target: |
| 187 | case Variable: |
| 188 | case Macro: { |
| 189 | DUChainReadLocker lock(DUChain::lock()); |
| 190 | Declaration* dec=m_declarations[pos].data(); |
| 191 | |
| 192 | return dec ? dec->identifier().toString() : i18n("INVALID"); |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | else if(role==Qt::DisplayRole && index.column()==CodeCompletionModel::Prefix) |
| 197 | { |
| 198 | switch(type) |
| 199 | { |
| 200 | case Command: return i18nc("@item", "Command"); |
| 201 | case Variable: return i18nc("@item", "Variable"); |
| 202 | case Macro: return i18nc("@item", "Macro"); |
| 203 | case Path: return i18nc("@item", "Path"); |
| 204 | case Target: return i18nc("@item", "Target"); |
| 205 | } |
| 206 | } |
| 207 | else if(role==Qt::DecorationRole && index.column()==CodeCompletionModel::Icon) |
| 208 | { |
| 209 | switch(type) |
| 210 | { |
| 211 | case Command: return QIcon::fromTheme(QStringLiteral("code-block")); |
| 212 | case Variable: return QIcon::fromTheme(QStringLiteral("code-variable")); |
| 213 | case Macro: return QIcon::fromTheme(QStringLiteral("code-function")); |
| 214 | case Target: return QIcon::fromTheme(QStringLiteral("system-run")); |
| 215 | case Path: { |
| 216 | QUrl url = QUrl::fromUserInput(m_paths[index.row()-m_declarations.size()]); |
| 217 | QString iconName; |
| 218 | if (url.isLocalFile()) { |
| 219 | // don't read contents even if it is a local file |
| 220 | iconName = QMimeDatabase().mimeTypeForFile(url.toLocalFile(), QMimeDatabase::MatchExtension).iconName(); |
| 221 | } |
| 222 | else { |
| 223 | // remote always only looks at the extension |
| 224 | iconName = QMimeDatabase().mimeTypeForUrl(url).iconName(); |
| 225 | } |
| 226 | return QIcon::fromTheme(iconName); |
| 227 | } |
| 228 | } |
| 229 | } |
nothing calls this directly
no test coverage detected