MCPcopy Create free account
hub / github.com/KDE/kdevelop / data

Method data

plugins/cmake/cmakecodecompletionmodel.cpp:172–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170}
171
172QVariant 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 }

Callers

nothing calls this directly

Calls 15

isLocalFileMethod · 0.80
toLocalFileMethod · 0.80
joinMethod · 0.80
QStringClass · 0.70
QVariantClass · 0.50
isValidMethod · 0.45
rowMethod · 0.45
columnMethod · 0.45
sizeMethod · 0.45
toStringMethod · 0.45
identifierMethod · 0.45
iconNameMethod · 0.45

Tested by

no test coverage detected