1 /* 2 SPDX-FileCopyrightText: 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de> 3 4 SPDX-License-Identifier: LGPL-2.0-or-later 5 */ 6 7 #ifndef KDEVPLATFORM_ABSTRACTINCLUDEFILECOMPLETIONITEM_H 8 #define KDEVPLATFORM_ABSTRACTINCLUDEFILECOMPLETIONITEM_H 9 10 #include "codecompletionitem.h" 11 #include <language/languageexport.h> 12 #include "../util/includeitem.h" 13 #include "../duchain/duchain.h" 14 #include "../duchain/duchainlock.h" 15 #include "codecompletionmodel.h" 16 17 namespace KDevelop { 18 //A completion item used for completing include-files 19 template <typename NavigationWidget> 20 class AbstractIncludeFileCompletionItem 21 : public CompletionTreeItem 22 { 23 public: AbstractIncludeFileCompletionItem(const IncludeItem & include)24 AbstractIncludeFileCompletionItem(const IncludeItem& include) : includeItem(include) 25 { 26 } 27 data(const QModelIndex & index,int role,const KDevelop::CodeCompletionModel * model)28 QVariant data(const QModelIndex& index, int role, const KDevelop::CodeCompletionModel* model) const override 29 { 30 DUChainReadLocker lock(DUChain::lock(), 500); 31 if (!lock.locked()) { 32 qDebug() << "Failed to lock the du-chain in time"; 33 return QVariant(); 34 } 35 36 const IncludeItem& item(includeItem); 37 38 switch (role) { 39 case CodeCompletionModel::IsExpandable: 40 return QVariant(true); 41 case CodeCompletionModel::ExpandingWidget: { 42 auto* nav = new NavigationWidget(item, model->currentTopContext()); 43 44 QVariant v; 45 v.setValue<QWidget*>(( QWidget* )nav); 46 return v; 47 } 48 case Qt::DisplayRole: 49 switch (index.column()) { 50 case CodeCompletionModel::Prefix: 51 if (item.isDirectory) 52 return QStringLiteral("directory"); 53 else 54 return QStringLiteral("file"); 55 case CodeCompletionModel::Name: { 56 return item.isDirectory ? (item.name + QLatin1Char('/')) : item.name; 57 } 58 } 59 break; 60 case CodeCompletionModel::ItemSelected: 61 { 62 return QVariant(NavigationWidget::shortDescription(item)); 63 } 64 } 65 66 return QVariant(); 67 } 68 69 void execute(KTextEditor::View* view, const KTextEditor::Range& word) override = 0; 70 inheritanceDepth()71 int inheritanceDepth() const override 72 { 73 return includeItem.pathNumber; 74 } argumentHintDepth()75 int argumentHintDepth() const override 76 { 77 return 0; 78 } 79 80 IncludeItem includeItem; 81 }; 82 } 83 84 #endif // KDEVPLATFORM_ABSTRACTINCLUDEFILECOMPLETIONITEM_H 85