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 "iassistproposalmodel.h" 29 #include "assistenums.h" 30 31 #include <texteditor/completionsettings.h> 32 #include <texteditor/texteditor_global.h> 33 #include <utils/fuzzymatcher.h> 34 35 #include <QHash> 36 #include <QList> 37 QT_FORWARD_DECLARE_CLASS(QIcon)38QT_FORWARD_DECLARE_CLASS(QIcon) 39 40 namespace TextEditor { 41 42 class AssistProposalItemInterface; 43 44 class TEXTEDITOR_EXPORT GenericProposalModel : public IAssistProposalModel 45 { 46 public: 47 GenericProposalModel(); 48 ~GenericProposalModel() override; 49 50 void reset() override; 51 int size() const override; 52 QString text(int index) const override; 53 54 virtual QIcon icon(int index) const; 55 virtual QString detail(int index) const; 56 virtual Qt::TextFormat detailFormat(int index) const; 57 virtual int persistentId(int index) const; 58 virtual bool containsDuplicates() const; 59 virtual void removeDuplicates(); 60 virtual void filter(const QString &prefix); 61 virtual bool isSortable(const QString &prefix) const; 62 virtual void sort(const QString &prefix); 63 virtual bool supportsPrefixExpansion() const; 64 virtual QString proposalPrefix() const; 65 virtual bool keepPerfectMatch(AssistReason reason) const; 66 virtual AssistProposalItemInterface *proposalItem(int index) const; 67 68 void loadContent(const QList<AssistProposalItemInterface *> &items); 69 70 bool isPerfectMatch(const QString &prefix) const; 71 bool hasItemsToPropose(const QString &prefix, AssistReason reason) const; 72 73 bool isPrefiltered(const QString &prefix) const; 74 void setPrefilterPrefix(const QString &prefix); 75 76 FuzzyMatcher::CaseSensitivity convertCaseSensitivity(TextEditor::CaseSensitivity textEditorCaseSensitivity); 77 78 protected: 79 QList<AssistProposalItemInterface *> m_currentItems; 80 81 private: 82 QHash<QString, int> m_idByText; 83 QList<AssistProposalItemInterface *> m_originalItems; 84 QString m_prefilterPrefix; 85 bool m_duplicatesRemoved = false; 86 }; 87 88 using GenericProposalModelPtr = QSharedPointer<GenericProposalModel>; 89 90 } // TextEditor 91