KTextEditor

codecompletionmodel.h
1 /* SPDX-License-Identifier: LGPL-2.0-or-later
2 
3  Copyright (C) 2007-2008 David Nolden <[email protected]>
4  Copyright (C) 2005-2006 Hamish Rodda <[email protected]>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #ifndef KTEXTEDITOR_CODECOMPLETIONMODEL_H
23 #define KTEXTEDITOR_CODECOMPLETIONMODEL_H
24 
25 #include <QModelIndex>
26 #include <ktexteditor/range.h>
27 #include <ktexteditor_export.h>
28 
29 namespace KTextEditor
30 {
31 class Document;
32 class View;
33 
81 class KTEXTEDITOR_EXPORT CodeCompletionModel : public QAbstractItemModel
82 {
83  Q_OBJECT
84 
85 public:
86  explicit CodeCompletionModel(QObject *parent);
87  ~CodeCompletionModel() override;
88 
89  enum Columns {
90  Prefix = 0,
95  Scope,
96  Name,
97  Arguments,
98  Postfix
99  };
100  static const int ColumnCount = Postfix + 1;
101 
104  NoProperty = 0x0,
105  FirstProperty = 0x1,
106 
107  // Access specifiers - no more than 1 per item
108  Public = 0x1,
109  Protected = 0x2,
110  Private = 0x4,
111 
112  // Extra access specifiers - any number per item
113  Static = 0x8,
114  Const = 0x10,
115 
116  // Type - no more than 1 per item (except for Template)
117  Namespace = 0x20,
118  Class = 0x40,
119  Struct = 0x80,
120  Union = 0x100,
121  Function = 0x200,
122  Variable = 0x400,
123  Enum = 0x800,
124  Template = 0x1000,
125  TypeAlias = 0x2000,
126 
127  // Special attributes - any number per item
128  Virtual = 0x4000,
129  Override = 0x8000,
130  Inline = 0x10000,
131  Friend = 0x20000,
132  Signal = 0x40000,
133  Slot = 0x80000,
134 
135  // Scope - no more than 1 per item
136  LocalScope = 0x100000,
137  NamespaceScope = 0x200000,
138  GlobalScope = 0x400000,
139 
140  // Keep this in sync so the code knows when to stop
141  LastProperty = GlobalScope
142  };
145 
146 
147  enum HighlightMethod { NoHighlighting = 0x0, InternalHighlighting = 0x1, CustomHighlighting = 0x2 };
150 
151 
152  enum ExtraItemDataRoles {
155  CompletionRole = Qt::UserRole,
156 
161 
177 
187 
194 
209 
218 
258 
289 
300 
326 
358 
363 
364  LastExtraItemDataRole
365  };
366 
367  void setRowCount(int rowCount);
368 
369  enum InvocationType { AutomaticInvocation, UserInvocation, ManualInvocation };
370 
382  virtual void completionInvoked(KTextEditor::View *view, const KTextEditor::Range &range, InvocationType invocationType);
383 
394  virtual void executeCompletionItem(KTextEditor::View *view, const Range &word, const QModelIndex &index) const;
395 
396  // Reimplementations
401  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
406  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
413  QMap<int, QVariant> itemData(const QModelIndex &index) const override;
419  QModelIndex parent(const QModelIndex &index) const override;
426  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
427 
432  bool hasGroups() const;
433 
434 Q_SIGNALS:
435 
454  void waitForReset();
455 
459  void hasGroupsChanged(KTextEditor::CodeCompletionModel *model, bool hasGroups);
460 
461 protected:
462  void setHasGroups(bool hasGroups);
463 
464 private:
465  class CodeCompletionModelPrivate *const d;
466 };
467 
468 Q_DECLARE_OPERATORS_FOR_FLAGS(CodeCompletionModel::CompletionProperties)
469 Q_DECLARE_OPERATORS_FOR_FLAGS(CodeCompletionModel::HighlightMethods)
470 
471 }
472 
473 #endif // KTEXTEDITOR_CODECOMPLETIONMODEL_H
Is requested before MatchQuality(..) is requested.
Returns the inheritance depth of the completion.
Variable for variable expansion.
Definition: variable.h:49
Allows an item to provide custom highlighting.
After a model returned true for a row on IsExpandable, the row may be expanded by the user...
Whenever an item is selected, this will be requested from the underlying model.
Icon representing the type of completion.
This allows items in the completion-list to be expandable.
UserRole
AccessibilityAccept will be requested on an item if it is expanded, contains an expanding-widget, and the user triggers a special shortcut to trigger the action associated with the position within the expanding-widget the user has navigated to using AccessibilityNext and AccessibilityPrevious.
Return a nonzero value here to enforce sorting the item at the end of the list.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
If requested, your model should try to determine whether the completion in question is a suitable mat...
This will be requested for each item to ask whether it should be included in computing a best-matches...
An object representing a section of text, from one Cursor to another.
Define which highlighting method will be used:
The model should return an index to the scope -1 represents no scope.
ExtraItemDataRoles
Meta information is passed through extra {Qt::ItemDataRole}s.
Using this Role, it is possible to greatly optimize the time needed to process very long completion-l...
The following three enumeration-values are only used on expanded completion-list items that contain a...
Is this completion-item an argument-hint? The model should return an integral positive number if the ...
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:155
AccessibilityPrevious will be requested on an item if it is expanded, contains an expanding-widget...
An item model for providing code completion, and meta information for enhanced presentation.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Jul 9 2020 22:56:52 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.