1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include "documentmodel.h" 29 #include "ieditor.h" 30 31 #include <QAbstractItemModel> 32 #include <QHash> 33 #include <QIcon> 34 #include <QList> 35 #include <QMap> 36 37 namespace Core { 38 namespace Internal { 39 40 class DocumentModelPrivate : public QAbstractItemModel 41 { 42 Q_OBJECT 43 44 public: 45 ~DocumentModelPrivate() override; 46 47 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 48 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 49 Qt::ItemFlags flags(const QModelIndex &index) const override; 50 QMimeData *mimeData(const QModelIndexList &indexes) const override; parent(const QModelIndex &)51 QModelIndex parent(const QModelIndex &/*index*/) const override { return QModelIndex(); } 52 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 53 QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override; 54 55 Qt::DropActions supportedDragActions() const override; 56 QStringList mimeTypes() const override; 57 58 void addEntry(DocumentModel::Entry *entry); 59 void removeDocument(int idx); 60 61 Utils::optional<int> indexOfFilePath(const Utils::FilePath &filePath) const; 62 Utils::optional<int> indexOfDocument(IDocument *document) const; 63 64 bool disambiguateDisplayNames(DocumentModel::Entry *entry); 65 66 static void setPinned(DocumentModel::Entry *entry, bool pinned); 67 68 static QIcon lockedIcon(); 69 static QIcon pinnedIcon(); 70 static void addEditor(IEditor *editor, bool *isNewDocument); 71 static DocumentModel::Entry *addSuspendedDocument(const QString &fileName, 72 const QString &displayName, 73 Utils::Id id); 74 static DocumentModel::Entry *firstSuspendedEntry(); 75 static DocumentModel::Entry *removeEditor(IEditor *editor); 76 static void removeEntry(DocumentModel::Entry *entry); 77 enum PinnedFileRemovalPolicy { 78 DoNotRemovePinnedFiles, 79 RemovePinnedFiles 80 }; 81 static void removeAllSuspendedEntries(PinnedFileRemovalPolicy pinnedFileRemovalPolicy 82 = RemovePinnedFiles); 83 84 void itemChanged(IDocument *document); 85 86 class DynamicEntry 87 { 88 public: 89 DocumentModel::Entry *entry; 90 int pathComponents; 91 92 DynamicEntry(DocumentModel::Entry *e); 93 DocumentModel::Entry *operator->() const; 94 void disambiguate(); 95 void setNumberedName(int number); 96 }; 97 98 QList<DocumentModel::Entry *> m_entries; 99 QMap<IDocument *, QList<IEditor *> > m_editors; 100 QHash<Utils::FilePath, DocumentModel::Entry *> m_entryByFixedPath; 101 }; 102 103 } // Internal 104 } // Core 105