Kate
katecompletionmodel.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KATECOMPLETIONMODEL_H
00021 #define KATECOMPLETIONMODEL_H
00022
00023 #include <QtGui/QAbstractProxyModel>
00024 #include <QtCore/QPair>
00025 #include <QtCore/QList>
00026 #include <QPersistentModelIndex>
00027
00028 #include <ktexteditor/codecompletionmodel.h>
00029
00030 #include "expandingtree/expandingwidgetmodel.h"
00031
00032 class KateCompletionWidget;
00033 class KateArgumentHintModel;
00034 class KateView;
00035 class QWidget;
00036 class QTextEdit;
00037 class QTimer;
00038 class HierarchicalModelHandler;
00039
00046 class KateCompletionModel : public ExpandingWidgetModel
00047 {
00048 Q_OBJECT
00049
00050 public:
00051 KateCompletionModel(KateCompletionWidget* parent = 0L);
00052 ~KateCompletionModel();
00053
00054 QList<KTextEditor::CodeCompletionModel*> completionModels() const;
00055 void clearCompletionModels();
00056 void addCompletionModel(KTextEditor::CodeCompletionModel* model);
00057 void setCompletionModel(KTextEditor::CodeCompletionModel* model);
00058 void setCompletionModels(const QList<KTextEditor::CodeCompletionModel*>& models);
00059 void removeCompletionModel(KTextEditor::CodeCompletionModel* model);
00060
00061 KateView* view() const;
00062 KateCompletionWidget* widget() const;
00063
00064 QString currentCompletion(KTextEditor::CodeCompletionModel* model) const;
00065 void setCurrentCompletion(KTextEditor::CodeCompletionModel* model, const QString& completion);
00066
00067 Qt::CaseSensitivity matchCaseSensitivity() const;
00068 void setMatchCaseSensitivity( Qt::CaseSensitivity cs );
00069
00070 static QString columnName(int column);
00071 int translateColumn(int sourceColumn) const;
00072
00073 static QString propertyName(KTextEditor::CodeCompletionModel::CompletionProperty property);
00074
00075 virtual void rowSelected(const QModelIndex& row);
00076
00077 virtual bool indexIsItem(const QModelIndex& index) const;
00078
00079 virtual int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
00080 virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
00081 virtual Qt::ItemFlags flags ( const QModelIndex & index ) const;
00082 virtual bool hasChildren ( const QModelIndex & parent = QModelIndex() ) const;
00083 virtual bool hasIndex ( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
00084 virtual QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
00085
00086
00087
00088 virtual QModelIndex parent ( const QModelIndex & index ) const;
00089 virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
00090
00091
00092
00093 virtual void sort ( int column, Qt::SortOrder order = Qt::AscendingOrder );
00094
00096 virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
00097
00099 virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
00100
00101
00102 bool isSortingEnabled() const;
00103 bool isSortingAlphabetical() const;
00104 bool isSortingByInheritanceDepth() const;
00105 void setSortingByInheritanceDepth(bool byIneritance);
00106 void setSortingAlphabetical(bool alphabetical);
00107
00108 Qt::CaseSensitivity sortingCaseSensitivity() const;
00109 void setSortingCaseSensitivity(Qt::CaseSensitivity cs);
00110
00111 bool isSortingReverse() const;
00112 void setSortingReverse(bool reverse);
00113
00114
00115 bool isFilteringEnabled() const;
00116
00117 bool filterContextMatchesOnly() const;
00118 void setFilterContextMatchesOnly(bool filter);
00119
00120 bool filterByAttribute() const;
00121 void setFilterByAttribute(bool filter);
00122
00123 KTextEditor::CodeCompletionModel::CompletionProperties filterAttributes() const;
00124 void setFilterAttributes(KTextEditor::CodeCompletionModel::CompletionProperties attributes);
00125
00126
00127 int maximumInheritanceDepth() const;
00128 void setMaximumInheritanceDepth(int maxDepth);
00129
00130
00131 bool isGroupingEnabled() const;
00132
00133 enum gm {
00134 ScopeType = 0x1,
00135 Scope = 0x2,
00136 AccessType = 0x4,
00137 ItemType = 0x8
00138 };
00139
00140 enum {
00141 BestMatchesProperty = 2*KTextEditor::CodeCompletionModel::LastProperty
00142 };
00143
00144 Q_DECLARE_FLAGS(GroupingMethods, gm)
00145
00146 static const int ScopeTypeMask = 0x380000;
00147 static const int AccessTypeMask = 0x7;
00148 static const int ItemTypeMask = 0xfe0;
00149
00150 GroupingMethods groupingMethod() const;
00151 void setGroupingMethod(GroupingMethods m);
00152
00153 bool accessIncludeConst() const;
00154 void setAccessIncludeConst(bool include);
00155 bool accessIncludeStatic() const;
00156 void setAccessIncludeStatic(bool include);
00157 bool accessIncludeSignalSlot() const;
00158 void setAccessIncludeSignalSlot(bool include);
00159
00160
00161 bool isColumnMergingEnabled() const;
00162
00163 const QList< QList<int> >& columnMerges() const;
00164 void setColumnMerges(const QList< QList<int> >& columnMerges);
00165
00166 void debugStats();
00167
00169 bool shouldMatchHideCompletionList() const;
00170
00171 protected:
00172 virtual int contextMatchQuality(const QModelIndex & index) const;
00173
00174 Q_SIGNALS:
00175 void expandIndex(const QModelIndex& index);
00176
00177 void argumentHintsChanged();
00178 void contentGeometryChanged();
00179
00180 public Q_SLOTS:
00181 void setSortingEnabled(bool enable);
00182 void setFilteringEnabled(bool enable);
00183 void setGroupingEnabled(bool enable);
00184 void setColumnMergingEnabled(bool enable);
00185
00186 private Q_SLOTS:
00187 void slotRowsInserted( const QModelIndex & parent, int start, int end );
00188 void slotRowsRemoved( const QModelIndex & parent, int start, int end );
00189 void slotModelReset();
00190
00191
00192 void updateBestMatches();
00193
00194 private:
00195
00196 typedef QPair<KTextEditor::CodeCompletionModel*, QModelIndex> ModelRow;
00197 virtual int contextMatchQuality(const ModelRow& sourceRow) const;
00198
00199 QTreeView* treeView() const;
00200
00201 friend class KateArgumentHintModel;
00202 ModelRow modelRowPair(const QModelIndex& index) const;
00203
00204
00205 class Item {
00206 public:
00207 Item(bool doInitialMatch, KateCompletionModel* model, const HierarchicalModelHandler& handler, ModelRow sourceRow);
00208
00209 bool isValid() const;
00210
00211 bool isVisible() const;
00212
00213 bool isFiltered() const;
00214
00215 bool isMatching() const;
00216
00217 bool filter();
00218 enum MatchType {
00219 NoMatch = 0,
00220 StartsWithMatch,
00221 PerfectMatch
00222 };
00223 MatchType match();
00224
00225 const ModelRow& sourceRow() const;
00226
00227
00228 bool operator<(const Item& rhs) const;
00229
00230 bool haveExactMatch() const {
00231 return m_haveExactMatch;
00232 }
00233
00234 void clearExactMatch() {
00235 m_haveExactMatch = false;
00236 }
00237
00238 private:
00239 KateCompletionModel* model;
00240 ModelRow m_sourceRow;
00241
00242 mutable QString m_nameColumn, m_completionSortingName;
00243
00244 int inheritanceDepth;
00245
00246
00247 MatchType matchCompletion;
00248
00249 bool matchFilters, m_haveExactMatch;
00250
00251 QString completionSortingName() const;
00252 };
00253
00254 public:
00255
00256 class Group {
00257 public:
00258 explicit Group(KateCompletionModel* model);
00259
00260 void addItem(Item i, bool notifyModel = false);
00262 bool removeItem(const ModelRow& row);
00263 void resort();
00264 void refilter();
00265 void clear();
00266
00267 bool orderBefore(Group* other) const;
00268
00269 int orderNumber() const;
00270
00274 int rowOf(ModelRow item) {
00275 for(int a = 0; a < filtered.size(); ++a)
00276 if(filtered[a].sourceRow() == item)
00277 return a;
00278 return -1;
00279 }
00280
00281 KateCompletionModel* model;
00282 int attribute;
00283 QString title, scope;
00284 QList<Item> filtered;
00285 QList<Item> prefilter;
00286 bool isEmpty;
00287
00288 int customSortingKey;
00289 };
00290
00291 bool hasGroups() const;
00292
00293 private:
00294 void createGroups();
00297 QSet<Group*> createItems(const HierarchicalModelHandler&, const QModelIndex& i, bool notifyModel = false);
00300 QSet<Group*> deleteItems(const QModelIndex& i);
00301 Group* createItem(const HierarchicalModelHandler&, const QModelIndex& i, bool notifyModel = false);
00302 void clearGroups(bool reset = true);
00303 void hideOrShowGroup(Group* g, bool notifyModel = true);
00305 Group* fetchGroup(int attribute, const QString& scope = QString(), bool forceGrouping = false);
00306
00307 Group* groupForIndex(const QModelIndex& index) const;
00308 inline Group* groupOfParent(const QModelIndex& child) const { return static_cast<Group*>(child.internalPointer()); }
00309 QModelIndex indexForRow(Group* g, int row) const;
00310 QModelIndex indexForGroup(Group* g) const;
00311
00312 enum changeTypes {
00313 Broaden,
00314 Narrow,
00315 Change
00316 };
00317
00318
00319 bool changeCompletions(Group* g, changeTypes changeType);
00320
00321 bool hasCompletionModel() const;
00322
00324 int groupingAttributes(int attribute) const;
00325 int countBits(int value) const;
00326
00327 void resort();
00328 void refilter();
00329
00330 bool m_hasGroups;
00331
00332
00333
00334 QList<KTextEditor::CodeCompletionModel*> m_completionModels;
00335 QMap<KTextEditor::CodeCompletionModel*, QString> m_currentMatch;
00336 Qt::CaseSensitivity m_matchCaseSensitivity;
00337
00338
00339 QList< QList<int> > m_columnMerges;
00340
00341 QTimer* m_updateBestMatchesTimer;
00342
00343 Group* m_ungrouped;
00344 Group* m_argumentHints;
00345 Group* m_bestMatches;
00346
00347
00348 QList<Group*> m_rowTable;
00349 QList<Group*> m_emptyGroups;
00350
00351 QMultiHash<int, Group*> m_groupHash;
00352
00353 QHash<QString, Group*> m_customGroupHash;
00354
00355
00356
00357 bool m_sortingEnabled;
00358 bool m_sortingAlphabetical;
00359 bool m_isSortingByInheritance;
00360 Qt::CaseSensitivity m_sortingCaseSensitivity;
00361 QHash< int, QList<int> > m_sortingGroupingOrder;
00362
00363
00364 bool m_filteringEnabled;
00365 bool m_filterContextMatchesOnly;
00366 bool m_filterByAttribute;
00367 KTextEditor::CodeCompletionModel::CompletionProperties m_filterAttributes;
00368 int m_maximumInheritanceDepth;
00369
00370
00371 bool m_groupingEnabled;
00372 GroupingMethods m_groupingMethod;
00373 bool m_accessConst, m_accessStatic, m_accesSignalSlot;
00374
00375
00376 bool m_columnMergingEnabled;
00377 };
00378
00379 Q_DECLARE_OPERATORS_FOR_FLAGS(KateCompletionModel::GroupingMethods)
00380
00381 #endif