File indexing completed on 2024-04-28 05:49:08
0001 /* This file is part of the Kate project. 0002 * 0003 * SPDX-FileCopyrightText: 2010 Christoph Cullmann <cullmann@kde.org> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <KTextEditor/Document> 0011 #include <QStandardItem> 0012 0013 namespace KTextEditor 0014 { 0015 class Document; 0016 0017 } 0018 0019 /** 0020 * Class representing a item inside a project. 0021 * Items can be: projects, directories, files 0022 */ 0023 class KateProjectItem : public QStandardItem 0024 { 0025 public: 0026 /** 0027 * Possible Types 0028 * We start with 1 to have 0 as invalid value! 0029 */ 0030 enum Type { LinkedProject = 1, Project = 2, Directory = 3, File = 4 }; 0031 0032 /** 0033 * Our defined roles 0034 */ 0035 enum Role { TypeRole = Qt::UserRole + 42, ProjectRole }; 0036 0037 /** 0038 * construct new item with given text 0039 * @param type type for this item 0040 * @param text text for this item 0041 */ 0042 KateProjectItem(Type type, const QString &text); 0043 0044 /** 0045 * deconstruct project 0046 */ 0047 ~KateProjectItem() override; 0048 0049 /** 0050 * Overwritten data method for on-demand icon creation and co. 0051 * @param role role to get data for 0052 * @return data for role 0053 */ 0054 QVariant data(int role = Qt::UserRole + 1) const override; 0055 void setData(const QVariant &value, int role) override; 0056 0057 /** 0058 * We want case-insensitive sorting and directories first! 0059 * @param other other element to compare with 0060 * @return is this element less than? 0061 */ 0062 bool operator<(const QStandardItem &other) const override; 0063 0064 public: 0065 void slotModifiedChanged(KTextEditor::Document *); 0066 void slotModifiedOnDisk(KTextEditor::Document *document, bool isModified, KTextEditor::Document::ModifiedOnDiskReason reason); 0067 0068 private: 0069 QIcon *icon() const; 0070 0071 private: 0072 /** 0073 * type 0074 */ 0075 const Type m_type; 0076 0077 /** 0078 * cached icon 0079 */ 0080 mutable QIcon *m_icon = nullptr; 0081 0082 /** 0083 * for document icons 0084 */ 0085 QString m_emblem; 0086 };