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

Kate

  • sources
  • kde-4.12
  • 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  void contentGeometryChanged();
187 
188  public Q_SLOTS:
189  void setSortingEnabled(bool enable);
190  void setFilteringEnabled(bool enable);
191  void setGroupingEnabled(bool enable);
192  void setColumnMergingEnabled(bool enable);
193 
194  private Q_SLOTS:
195  void slotRowsInserted( const QModelIndex & parent, int start, int end );
196  void slotRowsRemoved( const QModelIndex & parent, int start, int end );
197  void slotModelReset();
198 
199  //Updates the best-matches group
200  void updateBestMatches();
201  //Makes sure that the ungrouped group contains each item only once
202  //Must only be called right after the group was created
203  void makeGroupItemsUnique(bool onlyFiltered = false);
204 
205  private:
206 
207  typedef QPair<KTextEditor::CodeCompletionModel*, QModelIndex> ModelRow;
208  virtual int contextMatchQuality(const ModelRow& sourceRow) const;
209 
210  QTreeView* treeView() const;
211 
212  friend class KateArgumentHintModel;
213  ModelRow modelRowPair(const QModelIndex& index) const;
214 
215  // Represents a source row; provides sorting method
216  class Item {
217  public:
218  Item(bool doInitialMatch, KateCompletionModel* model, const HierarchicalModelHandler& handler, ModelRow sourceRow);
219 
220  bool isValid() const;
221  // Returns true if the item is not filtered and matches the current completion string
222  bool isVisible() const;
223  // Returns whether the item is filtered or not
224  bool isFiltered() const;
225  // Returns whether the item matches the current completion string
226  bool isMatching() const;
227 
228  bool filter();
229 
230  enum MatchType {
231  NoMatch = 0,
232  PerfectMatch,
233  StartsWithMatch,
234  AbbreviationMatch,
235  ContainsMatch
236  };
237  MatchType match();
238 
239  const ModelRow& sourceRow() const;
240 
241  // Sorting operator
242  bool operator<(const Item& rhs) const;
243 
244  bool haveExactMatch() const {
245  return m_haveExactMatch;
246  }
247 
248  void clearExactMatch() {
249  m_haveExactMatch = false;
250  }
251 
252  QString name() const {
253  return m_nameColumn;
254  }
255 
256  private:
257  KateCompletionModel* model;
258  ModelRow m_sourceRow;
259 
260  mutable QString m_nameColumn;
261 
262  int inheritanceDepth;
263 
264  // True when currently matching completion string
265  MatchType matchCompletion : 6;
266  // True when passes all active filters
267  bool matchFilters : 1;
268  bool m_haveExactMatch : 1;
269 
270  QString completionSortingName() const;
271  };
272 
273  public:
274  // Grouping and sorting of rows
275  class Group {
276  public:
277  explicit Group(KateCompletionModel* model);
278 
279  void addItem(Item i, bool notifyModel = false);
281  bool removeItem(const ModelRow& row);
282  void resort();
283  void refilter();
284  void clear();
285  //Returns whether this group should be ordered before other
286  bool orderBefore(Group* other) const;
287  //Returns a number that can be used for ordering
288  int orderNumber() const;
289 
293  int rowOf(ModelRow item) {
294  for(int a = 0; a < filtered.size(); ++a)
295  if(filtered[a].sourceRow() == item)
296  return a;
297  return -1;
298  }
299 
300  KateCompletionModel* model;
301  int attribute;
302  QString title, scope;
303  QList<Item> filtered;
304  QList<Item> prefilter;
305  bool isEmpty;
306  //-1 if none was set
307  int customSortingKey;
308  };
309 
310  bool hasGroups() const;
311 
312  private:
313  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);
322  void clearGroups(bool reset = true);
323  void hideOrShowGroup(Group* g, bool notifyModel = true);
325  Group* fetchGroup(int attribute, const QString& scope = QString(), bool forceGrouping = false);
326  //If this returns nonzero on an index, the index is the header of the returned group
327  Group* groupForIndex(const QModelIndex& index) const;
328  inline Group* groupOfParent(const QModelIndex& child) const { return static_cast<Group*>(child.internalPointer()); }
329  QModelIndex indexForRow(Group* g, int row) const;
330  QModelIndex indexForGroup(Group* g) const;
331 
332  enum changeTypes {
333  Broaden,
334  Narrow,
335  Change
336  };
337 
338  //Returns whether the model needs to be reset
339  bool changeCompletions(Group* g, changeTypes changeType);
340 
341  bool hasCompletionModel() const;
342 
344  int groupingAttributes(int attribute) const;
345  int countBits(int value) const;
346 
347  void resort();
348  void refilter();
349 
350  static bool matchesAbbreviation(const QString& word, const QString& typed);
351 
352  bool m_hasGroups;
353 
354  // ### Runtime state
355  // General
356  QList<KTextEditor::CodeCompletionModel*> m_completionModels;
357  QMap<KTextEditor::CodeCompletionModel*, QString> m_currentMatch;
358  Qt::CaseSensitivity m_matchCaseSensitivity;
359 
360  // Column merging
361  QList< QList<int> > m_columnMerges;
362 
363  QTimer* m_updateBestMatchesTimer;
364 
365  Group* m_ungrouped;
366  Group* m_argumentHints; //The argument-hints will be passed on to another model, to be shown in another widget
367  Group* m_bestMatches; //A temporary group used for holding the best matches of all visible items
368 
369  // Storing the sorted order
370  QList<Group*> m_rowTable;
371  QList<Group*> m_emptyGroups;
372  // Quick access to each specific group (if it exists)
373  QMultiHash<int, Group*> m_groupHash;
374  // Maps custom group-names to their specific groups
375  QHash<QString, Group*> m_customGroupHash;
376 
377  // ### Configurable state
378  // Sorting
379  bool m_sortingEnabled;
380  bool m_sortingAlphabetical;
381  bool m_isSortingByInheritance;
382  Qt::CaseSensitivity m_sortingCaseSensitivity;
383  QHash< int, QList<int> > m_sortingGroupingOrder;
384 
385  // Filtering
386  bool m_filteringEnabled;
387  bool m_filterContextMatchesOnly;
388  bool m_filterByAttribute;
389  KTextEditor::CodeCompletionModel::CompletionProperties m_filterAttributes;
390  int m_maximumInheritanceDepth;
391 
392  // Grouping
393  bool m_groupingEnabled;
394  GroupingMethods m_groupingMethod;
395  bool m_accessConst, m_accessStatic, m_accesSignalSlot;
396 
397  // Column merging
398  bool m_columnMergingEnabled/*, m_haveExactMatch*/;
399 
400  friend class CompletionTest;
401 };
402 
403 Q_DECLARE_OPERATORS_FOR_FLAGS(KateCompletionModel::GroupingMethods)
404 
405 #endif
QVariant
operator<
bool operator<(const KateTextLayout &r, const KTextEditor::Cursor &c)
Definition: katetextlayout.cpp:78
KateCompletionModel::Group::prefilter
QList< Item > prefilter
Definition: katecompletionmodel.h:304
Group
KateCompletionModel::Group::model
KateCompletionModel * model
Definition: katecompletionmodel.h:300
KateCompletionModel::Group::customSortingKey
int customSortingKey
Definition: katecompletionmodel.h:307
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:301
QWidget
name
const char * name(StandardAction id)
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
QString
QHash
expandingwidgetmodel.h
KateCompletionWidget
This is the code completion's main widget, and also contains the core interface logic.
Definition: katecompletionwidget.h:55
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
QTreeView
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:293
clear
KAction * clear(const QObject *recvr, const char *slot, QObject *parent)
KateView
Definition: kateview.h:78
QSet
KateCompletionModel::gm
gm
Definition: katecompletionmodel.h:139
KateCompletionModel::Group
Definition: katecompletionmodel.h:275
KateCompletionModel::Group::isEmpty
bool isEmpty
Definition: katecompletionmodel.h:305
QPair
Item
KTextEditor::CodeCompletionModel::CompletionProperty
CompletionProperty
codecompletionmodel.h
KTextEditor::CodeCompletionModel::LastProperty
KateCompletionModel::Group::title
QString title
Definition: katecompletionmodel.h:302
KateCompletionModel::Group::filtered
QList< Item > filtered
Definition: katecompletionmodel.h:303
completion
const KShortcut & completion()
QMap< KTextEditor::CodeCompletionModel *, QString >
QTextEdit
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 ...
QList< KTextEditor::CodeCompletionModel * >
ExpandingWidgetModel
Cares about expanding/un-expanding items in a tree-view together with ExpandingDelegate.
Definition: expandingwidgetmodel.h:36
KTextEditor::CodeCompletionModel
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:51 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
  • Applications
  •   Libraries
  •     libkonq
  • 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