File indexing completed on 2024-05-05 04:40:52

0001 /*
0002     SPDX-FileCopyrightText: 2007 David Nolden <david.nolden.kdevelop@art-master.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #ifndef DUCHAIN_ITEM_QUICKOPEN
0008 #define DUCHAIN_ITEM_QUICKOPEN
0009 
0010 #include <language/interfaces/quickopendataprovider.h>
0011 #include <language/interfaces/quickopenfilter.h>
0012 #include <language/duchain/duchainpointer.h>
0013 #include <language/duchain/declaration.h>
0014 
0015 namespace KDevelop {
0016 class IQuickOpen;
0017 }
0018 
0019 struct DUChainItem
0020 {
0021     DUChainItem()
0022     {
0023     }
0024     KDevelop::IndexedDeclaration m_item;
0025     QString m_text;
0026     KDevelop::Path m_projectPath;
0027     bool m_noHtmlDestription = false;
0028 };
0029 
0030 Q_DECLARE_TYPEINFO(DUChainItem, Q_MOVABLE_TYPE);
0031 
0032 class DUChainItemData
0033     : public KDevelop::QuickOpenDataBase
0034 {
0035 public:
0036     explicit DUChainItemData(const DUChainItem& item, bool openDefinition = false);
0037 
0038     QString text() const override;
0039     QString htmlDescription() const override;
0040     QList<QVariant> highlighting() const override;
0041 
0042     bool execute(QString& filterText) override;
0043 
0044     bool isExpandable() const override;
0045     QWidget* expandingWidget() const override;
0046 
0047     QIcon icon() const override;
0048     KDevelop::Path projectPath() const;
0049 
0050 private:
0051     const DUChainItem m_item;
0052     const bool m_openDefinition;
0053 };
0054 
0055 /**
0056  * A QuickOpenDataProvider that presents a list of declarations.
0057  * The declarations need to be set using setItems(..) in a re-implemented reset() function.
0058  * */
0059 
0060 class DUChainItemDataProvider
0061     : public KDevelop::QuickOpenDataProviderBase
0062     , public KDevelop::Filter<DUChainItem>
0063 {
0064     Q_OBJECT
0065 public:
0066     using Base = KDevelop::Filter<DUChainItem>;
0067 
0068     /// When openDefinitions is true, the definitions will be opened if available on execute().
0069     explicit DUChainItemDataProvider(KDevelop::IQuickOpen* quickopen, bool openDefinitions = false);
0070     void setFilterText(const QString& text) override;
0071     uint itemCount() const override;
0072     uint unfilteredItemCount() const override;
0073     KDevelop::QuickOpenDataPointer data(uint row) const override;
0074 
0075     void reset() override;
0076 protected:
0077     //Override to create own DUChainItemData derived classes
0078     DUChainItemData* createData(const DUChainItem& item) const;
0079 
0080     //Reimplemented from Base<..>
0081     QString itemText(const DUChainItem& data) const override;
0082 
0083     KDevelop::IQuickOpen* m_quickopen;
0084 private:
0085     bool m_openDefinitions;
0086 };
0087 
0088 #endif
0089