File indexing completed on 2024-04-21 15:24:07

0001 /*
0002     SPDX-FileCopyrightText: 2012 Milian Wolff <mail@milianw.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #ifndef PHPDOCSMODEL_H
0008 #define PHPDOCSMODEL_H
0009 
0010 #include <QStringListModel>
0011 
0012 #include <serialization/indexedstring.h>
0013 #include <language/duchain/declaration.h>
0014 
0015 namespace KDevelop
0016 {
0017     class Declaration;
0018     class ParseJob;
0019     class ReferencedTopDUContext;
0020 }
0021 
0022 class PhpDocsModel : public QAbstractListModel
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     explicit PhpDocsModel(QObject* parent = nullptr);
0028     ~PhpDocsModel() override;
0029 
0030     enum CustomDataRoles {
0031         /// returns the Declaration that a given index in the model represents
0032         DeclarationRole = Qt::UserRole
0033     };
0034 
0035     /**
0036      * You can use @p DeclarationRole to get the Declaration for a given index.
0037      * NOTE: If you use that, don't forget to lock the DUChain if you access the declaration!
0038      */
0039     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
0040     int rowCount(const QModelIndex& parent = QModelIndex()) const override;
0041     bool hasChildren(const QModelIndex& parent) const override;
0042 
0043     /// Returns the Declaration for a given index
0044     /// NOTE: Don't forget to lock the DUChain if you access the declaration!
0045     KDevelop::DeclarationPointer declarationForIndex(const QModelIndex& index) const;
0046 
0047     /// Returns the destination of the internal PHP function file
0048     /// @see PhpLanguageSupport
0049     KDevelop::IndexedString internalFunctionFile() const;
0050 
0051 private:
0052     /// fills model with all declarations from the internal PHP functions file
0053     void fillModel(const KDevelop::ReferencedTopDUContext& topContext);
0054 
0055     /// List of pointers to _all_ PHP internal declarations
0056     QList<KDevelop::DeclarationPointer> m_declarations;
0057 
0058     /// internal function file
0059     const KDevelop::IndexedString m_internalFunctionsFile;
0060 
0061 public slots:
0062     void updateReady( const KDevelop::IndexedString& url, const KDevelop::ReferencedTopDUContext& topContext );
0063 
0064 };
0065 
0066 #endif // PHPDOCSMODEL_H