• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • completion
katecompletionmodel.h
Go to the documentation of this file.
1 /* This file is part of the KDE libraries and the Kate part.
2  *
3  * Copyright (C) 2005-2006 Hamish Rodda <rodda@kde.org>
4  * Copyright (C) 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de>
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 KATECOMPLETIONMODEL_H
23 #define KATECOMPLETIONMODEL_H
24 
25 #include <QtGui/QAbstractProxyModel>
26 #include <QtCore/QPair>
27 #include <QtCore/QList>
28 
29 #include <ktexteditor/codecompletionmodel.h>
30 
31 #include "katepartprivate_export.h"
32 #include "expandingtree/expandingwidgetmodel.h"
33 
34 class KateCompletionWidget;
35 class KateArgumentHintModel;
36 class KateView;
37 class QWidget;
38 class QTextEdit;
39 class QTimer;
40 class HierarchicalModelHandler;
41 
48 class KATEPART_TESTS_EXPORT KateCompletionModel : public ExpandingWidgetModel
49 {
50  Q_OBJECT
51 
52  public:
53  KateCompletionModel(KateCompletionWidget* parent = 0L);
54  ~KateCompletionModel();
55 
56  QList<KTextEditor::CodeCompletionModel*> completionModels() const;
57  void clearCompletionModels();
58  void addCompletionModel(KTextEditor::CodeCompletionModel* model);
59  void setCompletionModel(KTextEditor::CodeCompletionModel* model);
60  void setCompletionModels(const QList<KTextEditor::CodeCompletionModel*>& models);
61  void removeCompletionModel(KTextEditor::CodeCompletionModel* model);
62 
63  KateView* view() const;
64  KateCompletionWidget* widget() const;
65 
66  QString currentCompletion(KTextEditor::CodeCompletionModel* model) const;
67  void setCurrentCompletion(KTextEditor::CodeCompletionModel* model, const QString& completion);
68 
69  Qt::CaseSensitivity matchCaseSensitivity() const;
70  void setMatchCaseSensitivity( Qt::CaseSensitivity cs );
71 
72  static QString columnName(int column);
73  int translateColumn(int sourceColumn) const;
74 
75  static QString propertyName(KTextEditor::CodeCompletionModel::CompletionProperty property);
76 
79  QString commonPrefix(QModelIndex selectedIndex) const;
80 
81  virtual void rowSelected(const QModelIndex& row);
82 
83  virtual bool indexIsItem(const QModelIndex& index) const;
84 
85  virtual int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
86  virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
87  virtual Qt::ItemFlags flags ( const QModelIndex & index ) const;
88  virtual bool hasChildren ( const QModelIndex & parent = QModelIndex() ) const;
89  virtual bool hasIndex ( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
90  virtual QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
91 
92  // Disabled in case of bugs, reenable once fully debugged.
93  //virtual QMap<int, QVariant> itemData ( const QModelIndex & index ) const;
94  virtual QModelIndex parent ( const QModelIndex & index ) const;
95  virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
96 
97  // Disabled in case of bugs, reenable once fully debugged.
98  //virtual QModelIndex sibling ( int row, int column, const QModelIndex & index ) const;
99  virtual void sort ( int column, Qt::SortOrder order = Qt::AscendingOrder );
100 
102  virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
103 
105  virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
106 
107  // Sorting
108  bool isSortingEnabled() const;
109  bool isSortingAlphabetical() const;
110  bool isSortingByInheritanceDepth() const;
111  void setSortingByInheritanceDepth(bool byIneritance);
112  void setSortingAlphabetical(bool alphabetical);
113 
114  Qt::CaseSensitivity sortingCaseSensitivity() const;
115  void setSortingCaseSensitivity(Qt::CaseSensitivity cs);
116 
117  bool isSortingReverse() const;
118  void setSortingReverse(bool reverse);
119 
120  // Filtering
121  bool isFilteringEnabled() const;
122 
123  bool filterContextMatchesOnly() const;
124  void setFilterContextMatchesOnly(bool filter);
125 
126  bool filterByAttribute() const;
127  void setFilterByAttribute(bool filter);
128 
129  KTextEditor::CodeCompletionModel::CompletionProperties filterAttributes() const;
130  void setFilterAttributes(KTextEditor::CodeCompletionModel::CompletionProperties attributes);
131 
132  // A maximum depth of <= 0 equals don't filter by inheritance depth (i.e. infinity) and is default
133  int maximumInheritanceDepth() const;
134  void setMaximumInheritanceDepth(int maxDepth);
135 
136  // Grouping
137  bool isGroupingEnabled() const;
138 
139  enum gm {
140  ScopeType = 0x1,
141  Scope = 0x2,
142  AccessType = 0x4,
143  ItemType = 0x8
144  };
145 
146  enum { //An own property that will be used to mark the best-matches group internally
147  BestMatchesProperty = 2*KTextEditor::CodeCompletionModel::LastProperty
148  };
149 
150  Q_DECLARE_FLAGS(GroupingMethods, gm)
151 
152  static const int ScopeTypeMask = 0x380000;
153  static const int AccessTypeMask = 0x7;
154  static const int ItemTypeMask = 0xfe0;
155 
156  GroupingMethods groupingMethod() const;
157  void setGroupingMethod(GroupingMethods m);
158 
159  bool accessIncludeConst() const;
160  void setAccessIncludeConst(bool include);
161  bool accessIncludeStatic() const;
162  void setAccessIncludeStatic(bool include);
163  bool accessIncludeSignalSlot() const;
164  void setAccessIncludeSignalSlot(bool include);
165 
166  // Column merging
167  bool isColumnMergingEnabled() const;
168 
169  const QList< QList<int> >& columnMerges() const;
170  void setColumnMerges(const QList< QList<int> >& columnMerges);
171 
172  void debugStats();
173 
175  bool shouldMatchHideCompletionList() const;
176 
177  uint filteredItemCount() const;
178 
179  protected:
180  virtual int contextMatchQuality(const QModelIndex & index) const;
181 
182  Q_SIGNALS:
183  void expandIndex(const QModelIndex& index);
184  //Emitted whenever something has changed about the group of argument-hints
185  void argumentHintsChanged();
186 
187  public Q_SLOTS:
188  void setSortingEnabled(bool enable);
189  void setFilteringEnabled(bool enable);
190  void setGroupingEnabled(bool enable);
191  void setColumnMergingEnabled(bool enable);
192 
193  private Q_SLOTS:
194  void slotRowsInserted( const QModelIndex & parent, int start, int end );
195  void slotRowsRemoved( const QModelIndex & parent, int start, int end );
196  void slotModelReset();
197 
198  //Updates the best-matches group
199  void updateBestMatches();
200  //Makes sure that the ungrouped group contains each item only once
201  //Must only be called right after the group was created
202  void makeGroupItemsUnique(bool onlyFiltered = false);
203 
204  private:
205 
206  typedef QPair<KTextEditor::CodeCompletionModel*, QModelIndex> ModelRow;
207  virtual int contextMatchQuality(const ModelRow& sourceRow) const;
208 
209  QTreeView* treeView() const;
210 
211  friend class KateArgumentHintModel;
212  ModelRow modelRowPair(const QModelIndex& index) const;
213 
214  // Represents a source row; provides sorting method
215  class Item {
216  public:
217  Item(bool doInitialMatch, KateCompletionModel* model, const HierarchicalModelHandler& handler, ModelRow sourceRow);
218 
219  bool isValid() const;
220  // Returns true if the item is not filtered and matches the current completion string
221  bool isVisible() const;
222  // Returns whether the item is filtered or not
223  bool isFiltered() const;
224  // Returns whether the item matches the current completion string
225  bool isMatching() const;
226 
227  bool filter();
228 
229  enum MatchType {
230  NoMatch = 0,
231  PerfectMatch,
232  StartsWithMatch,
233  AbbreviationMatch,
234  ContainsMatch
235  };
236  MatchType match();
237 
238  const ModelRow& sourceRow() const;
239 
240  // Sorting operator
241  bool operator<(const Item& rhs) const;
242 
243  bool haveExactMatch() const {
244  return m_haveExactMatch;
245  }
246 
247  void clearExactMatch() {
248  m_haveExactMatch = false;
249  }
250 
251  QString name() const {
252  return m_nameColumn;
253  }
254 
255  private:
256  KateCompletionModel* model;
257  ModelRow m_sourceRow;
258 
259  mutable QString m_nameColumn;
260 
261  int inheritanceDepth;
262 
263  // True when currently matching completion string
264  MatchType matchCompletion : 6;
265  // True when passes all active filters
266  bool matchFilters : 1;
267  bool m_haveExactMatch : 1;
268 
269  QString completionSortingName() const;
270  };
271 
272  public:
273  // Grouping and sorting of rows
274  class Group {
275  public:
276  explicit Group(KateCompletionModel* model);
277 
278  void addItem(Item i, bool notifyModel = false);
280  bool removeItem(const ModelRow& row);
281  void resort();
282  void refilter();
283  void clear();
284  //Returns whether this group should be ordered before other
285  bool orderBefore(Group* other) const;
286  //Returns a number that can be used for ordering
287  int orderNumber() const;
288 
292  int rowOf(ModelRow item) {
293  for(int a = 0; a < filtered.size(); ++a)
294  if(filtered[a].sourceRow() == item)
295  return a;
296  return -1;
297  }
298 
299  KateCompletionModel* model;
300  int attribute;
301  QString title, scope;
302  QList<Item> filtered;
303  QList<Item> prefilter;
304  bool isEmpty;
305  //-1 if none was set
306  int customSortingKey;
307  };
308 
309  bool hasGroups() const;
310 
311  private:
312  QString commonPrefixInternal(const QString &forcePrefix) const;
314  void createGroups();
317  QSet<Group*> createItems(const HierarchicalModelHandler&, const QModelIndex& i, bool notifyModel = false);
320  QSet<Group*> deleteItems(const QModelIndex& i);
321  Group* createItem(const HierarchicalModelHandler&, const QModelIndex& i, bool notifyModel = false);
323  void clearGroups();
324  void hideOrShowGroup(Group* g, bool notifyModel = false);
326  Group* fetchGroup(int attribute, const QString& scope = QString(), bool forceGrouping = false);
327  //If this returns nonzero on an index, the index is the header of the returned group
328  Group* groupForIndex(const QModelIndex& index) const;
329  inline Group* groupOfParent(const QModelIndex& child) const { return static_cast<Group*>(child.internalPointer()); }
330  QModelIndex indexForRow(Group* g, int row) const;
331  QModelIndex indexForGroup(Group* g) const;
332 
333  enum changeTypes {
334  Broaden,
335  Narrow,
336  Change
337  };
338 
339  //Returns whether the model needs to be reset
340  void changeCompletions(Group* g, changeTypes changeType, bool notifyModel);
341 
342  bool hasCompletionModel() const;
343 
345  int groupingAttributes(int attribute) const;
346  int countBits(int value) const;
347 
348  void resort();
349  void refilter();
350 
351  static bool matchesAbbreviation(const QString& word, const QString& typed);
352 
353  bool m_hasGroups;
354 
355  // ### Runtime state
356  // General
357  QList<KTextEditor::CodeCompletionModel*> m_completionModels;
358  QMap<KTextEditor::CodeCompletionModel*, QString> m_currentMatch;
359  Qt::CaseSensitivity m_matchCaseSensitivity;
360 
361  // Column merging
362  QList< QList<int> > m_columnMerges;
363 
364  QTimer* m_updateBestMatchesTimer;
365 
366  Group* m_ungrouped;
367  Group* m_argumentHints; //The argument-hints will be passed on to another model, to be shown in another widget
368  Group* m_bestMatches; //A temporary group used for holding the best matches of all visible items
369 
370  // Storing the sorted order
371  QList<Group*> m_rowTable;
372  QList<Group*> m_emptyGroups;
373  // Quick access to each specific group (if it exists)
374  QMultiHash<int, Group*> m_groupHash;
375  // Maps custom group-names to their specific groups
376  QHash<QString, Group*> m_customGroupHash;
377 
378  // ### Configurable state
379  // Sorting
380  bool m_sortingEnabled;
381  bool m_sortingAlphabetical;
382  bool m_isSortingByInheritance;
383  Qt::CaseSensitivity m_sortingCaseSensitivity;
384  QHash< int, QList<int> > m_sortingGroupingOrder;
385 
386  // Filtering
387  bool m_filteringEnabled;
388  bool m_filterContextMatchesOnly;
389  bool m_filterByAttribute;
390  KTextEditor::CodeCompletionModel::CompletionProperties m_filterAttributes;
391  int m_maximumInheritanceDepth;
392 
393  // Grouping
394  bool m_groupingEnabled;
395  GroupingMethods m_groupingMethod;
396  bool m_accessConst, m_accessStatic, m_accesSignalSlot;
397 
398  // Column merging
399  bool m_columnMergingEnabled/*, m_haveExactMatch*/;
400 
401  friend class CompletionTest;
402 };
403 
404 Q_DECLARE_OPERATORS_FOR_FLAGS(KateCompletionModel::GroupingMethods)
405 
406 #endif
QAbstractItemModel::hasIndex
bool hasIndex(int row, int column, const QModelIndex &parent) const
operator<
bool operator<(const KateTextLayout &r, const KTextEditor::Cursor &c)
Definition: katetextlayout.cpp:78
KateCompletionModel::Group::prefilter
QList< Item > prefilter
Definition: katecompletionmodel.h:303
QModelIndex
KateCompletionModel::Group::model
KateCompletionModel * model
Definition: katecompletionmodel.h:299
KateCompletionModel::Group::customSortingKey
int customSortingKey
Definition: katecompletionmodel.h:306
QWidget
QAbstractItemModel::rowCount
virtual int rowCount(const QModelIndex &parent) const =0
ExpandingWidgetModel::rowSelected
virtual void rowSelected(const QModelIndex &row)
Notifies underlying models that the item was selected, collapses any previous partially expanded line...
Definition: expandingwidgetmodel.cpp:157
KateArgumentHintModel
Definition: kateargumenthintmodel.h:30
KateCompletionModel::Group::attribute
int attribute
Definition: katecompletionmodel.h:300
QAbstractTableModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
QMap< KTextEditor::CodeCompletionModel *, QString >
KATEPART_TESTS_EXPORT
#define KATEPART_TESTS_EXPORT
Definition: katepartprivate_export.h:36
KateCompletionModel
This class has the responsibility for filtering, sorting, and manipulating code completion data provi...
Definition: katecompletionmodel.h:48
typedef
expandingwidgetmodel.h
QAbstractItemModel::sort
virtual void sort(int column, Qt::SortOrder order)
QAbstractItemModel::match
virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits, QFlags< Qt::MatchFlag > flags) const
QObject::name
const char * name() const
KateCompletionWidget
This is the code completion's main widget, and also contains the core interface logic.
Definition: katecompletionwidget.h:55
QTimer
ExpandingWidgetModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Does not request data from index, this only returns local data like highlighting for expanded rows an...
Definition: expandingwidgetmodel.cpp:88
QHash
katepartprivate_export.h
KateCompletionModel::Group::rowOf
int rowOf(ModelRow item)
Returns the row in the this group's filtered list of the given model-row in a source-model -1 if the ...
Definition: katecompletionmodel.h:292
QModelIndex::internalPointer
void * internalPointer() const
QSet
QString
QList< KTextEditor::CodeCompletionModel * >
QPair
KateView
Definition: kateview.h:77
KateCompletionModel::gm
gm
Definition: katecompletionmodel.h:139
KateCompletionModel::Group
Definition: katecompletionmodel.h:274
QTreeView
QAbstractItemModel::hasChildren
virtual bool hasChildren(const QModelIndex &parent) const
KateCompletionModel::Group::isEmpty
bool isEmpty
Definition: katecompletionmodel.h:304
QAbstractItemModel::columnCount
virtual int columnCount(const QModelIndex &parent) const =0
QAbstractItemModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
QObject::parent
QObject * parent() const
QTextEdit
KateCompletionModel::Group::title
QString title
Definition: katecompletionmodel.h:301
KateCompletionModel::Group::filtered
QList< Item > filtered
Definition: katecompletionmodel.h:302
QMultiHash
ExpandingWidgetModel::indexIsItem
virtual bool indexIsItem(const QModelIndex &index) const =0
Should return true if the given row should be painted like a contained item(as opposed to label-rows ...
QVariant
ExpandingWidgetModel
Cares about expanding/un-expanding items in a tree-view together with ExpandingDelegate.
Definition: expandingwidgetmodel.h:36
Qt::ItemFlags
typedef ItemFlags
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal