1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2018 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 "cpptools_global.h" 29 30 #include <utils/dropsupport.h> 31 #include <utils/treemodel.h> 32 33 #include <QSharedPointer> 34 35 #include <utility> 36 37 namespace CPlusPlus { class Document; } 38 39 namespace Utils { 40 class LineColumn; 41 class Link; 42 } 43 44 namespace CppTools { 45 46 class CPPTOOLS_EXPORT AbstractOverviewModel : public Utils::TreeModel<> 47 { 48 Q_OBJECT 49 50 public: 51 enum Role { 52 FileNameRole = Qt::UserRole + 1, 53 LineNumberRole 54 }; 55 rebuild(QSharedPointer<CPlusPlus::Document>)56 virtual void rebuild(QSharedPointer<CPlusPlus::Document>) {} rebuild(const QString &)57 virtual bool rebuild(const QString &) { return false; } 58 flags(const QModelIndex & index)59 Qt::ItemFlags flags(const QModelIndex &index) const override 60 { 61 if (!index.isValid()) 62 return Qt::NoItemFlags; 63 64 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; 65 } 66 supportedDragActions()67 Qt::DropActions supportedDragActions() const override 68 { 69 return Qt::MoveAction; 70 } 71 mimeTypes()72 QStringList mimeTypes() const override 73 { 74 return Utils::DropSupport::mimeTypesForFilePaths(); 75 } 76 mimeData(const QModelIndexList & indexes)77 QMimeData *mimeData(const QModelIndexList &indexes) const override 78 { 79 auto mimeData = new Utils::DropMimeData; 80 foreach (const QModelIndex &index, indexes) { 81 const QVariant fileName = data(index, FileNameRole); 82 if (!fileName.canConvert<QString>()) 83 continue; 84 const QVariant lineNumber = data(index, LineNumberRole); 85 if (!lineNumber.canConvert<unsigned>()) 86 continue; 87 mimeData->addFile(fileName.toString(), static_cast<int>(lineNumber.value<unsigned>())); 88 } 89 return mimeData; 90 } 91 isGenerated(const QModelIndex &)92 virtual bool isGenerated(const QModelIndex &) const { return false; } 93 virtual Utils::Link linkFromIndex(const QModelIndex &) const = 0; 94 virtual Utils::LineColumn lineColumnFromIndex(const QModelIndex &) const = 0; 95 96 using Range = std::pair<Utils::LineColumn, Utils::LineColumn>; 97 virtual Range rangeFromIndex(const QModelIndex &) const = 0; 98 99 signals: 100 void needsUpdate(); 101 }; 102 103 } // namespace CppTools 104