File indexing completed on 2024-05-19 12:23:50
0001 /* 0002 SPDX-FileCopyrightText: 2005 Adam Treat <treat@kde.org> 0003 SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KDEVPLATFORM_PLUGIN_KDEVDOCUMENTMODEL_H 0009 #define KDEVPLATFORM_PLUGIN_KDEVDOCUMENTMODEL_H 0010 0011 #include <QStandardItem> 0012 #include <QStandardItemModel> 0013 #include <QUrl> 0014 0015 #include <interfaces/idocument.h> 0016 0017 #include <QIcon> 0018 0019 class KDevDocumentItem; 0020 class KDevCategoryItem; 0021 class KDevFileItem; 0022 0023 class KDevDocumentItem: public QStandardItem 0024 { 0025 public: 0026 explicit KDevDocumentItem( const QString &name ); 0027 ~KDevDocumentItem() override; 0028 0029 virtual KDevCategoryItem *categoryItem() const 0030 { 0031 return nullptr; 0032 } 0033 virtual KDevFileItem *fileItem() const 0034 { 0035 return nullptr; 0036 } 0037 0038 QIcon icon() const; 0039 0040 KDevelop::IDocument::DocumentState documentState() const; 0041 void setDocumentState( KDevelop::IDocument::DocumentState state ); 0042 0043 const QUrl url() const; 0044 void setUrl(const QUrl &url); 0045 0046 QVariant data(int role) const override; 0047 0048 enum Roles { 0049 UrlRole = Qt::UserRole + 1 0050 }; 0051 0052 protected: 0053 QString m_fileIcon; 0054 0055 private: 0056 QUrl m_url; 0057 KDevelop::IDocument::DocumentState m_documentState; 0058 }; 0059 0060 class KDevCategoryItem: public KDevDocumentItem 0061 { 0062 public: 0063 explicit KDevCategoryItem( const QString &name ); 0064 ~KDevCategoryItem() override; 0065 0066 KDevCategoryItem *categoryItem() const override 0067 { 0068 return const_cast<KDevCategoryItem*>( this ); 0069 } 0070 0071 QList<KDevFileItem*> fileList() const; 0072 KDevFileItem* file( const QUrl &url ) const; 0073 }; 0074 0075 class KDevFileItem: public KDevDocumentItem 0076 { 0077 public: 0078 explicit KDevFileItem( const QUrl &url ); 0079 ~KDevFileItem() override; 0080 0081 KDevFileItem *fileItem() const override 0082 { 0083 return const_cast<KDevFileItem*>( this ); 0084 } 0085 }; 0086 0087 class KDevDocumentModel: public QStandardItemModel 0088 { 0089 Q_OBJECT 0090 0091 public: 0092 explicit KDevDocumentModel( QObject *parent = nullptr ); 0093 ~KDevDocumentModel() override; 0094 0095 QList<KDevCategoryItem*> categoryList() const; 0096 KDevCategoryItem* category( const QString& category ) const; 0097 }; 0098 0099 #endif // KDEVPLATFORM_PLUGIN_KDEVDOCUMENTMODEL_H