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
00168 protected:
00169 virtual int contextMatchQuality(const QModelIndex& row) const;
00170
00171 Q_SIGNALS:
00172 void expandIndex(const QModelIndex& index);
00173
00174 void argumentHintsChanged();
00175 void contentGeometryChanged();
00176
00177 public Q_SLOTS:
00178 void setSortingEnabled(bool enable);
00179 void setFilteringEnabled(bool enable);
00180 void setGroupingEnabled(bool enable);
00181 void setColumnMergingEnabled(bool enable);
00182
00183 private Q_SLOTS:
00184 void slotRowsInserted( const QModelIndex & parent, int start, int end );
00185 void slotRowsRemoved( const QModelIndex & parent, int start, int end );
00186 void slotModelReset();
00187
00188
00189 void updateBestMatches();
00190
00191 private:
00192 QTreeView* treeView() const;
00193
00194 friend class KateArgumentHintModel;
00195 typedef QPair<KTextEditor::CodeCompletionModel*, QModelIndex> ModelRow;
00196 ModelRow modelRowPair(const QModelIndex& index) const;
00197
00198
00199 class Item {
00200 public:
00201 Item(bool doInitialMatch, KateCompletionModel* model, const HierarchicalModelHandler& handler, ModelRow sourceRow);
00202
00203 bool isValid() const;
00204
00205 bool isVisible() const;
00206
00207 bool isFiltered() const;
00208
00209 bool isMatching() const;
00210
00211 bool filter();
00212 bool match();
00213
00214 const ModelRow& sourceRow() const;
00215
00216
00217 bool operator<(const Item& rhs) const;
00218
00219 private:
00220 KateCompletionModel* model;
00221 ModelRow m_sourceRow;
00222
00223 mutable QString m_nameColumn, m_completionSortingName;
00224
00225 int inheritanceDepth;
00226
00227
00228 bool matchCompletion;
00229
00230 bool matchFilters;
00231
00232 QString completionSortingName() const;
00233 };
00234
00235 public:
00236
00237 class Group {
00238 public:
00239 explicit Group(KateCompletionModel* model);
00240
00241 void addItem(Item i, bool notifyModel = false);
00243 bool removeItem(const ModelRow& row);
00244 void resort();
00245 void refilter();
00246 void clear();
00247
00248 bool orderBefore(Group* other) const;
00249
00250 int orderNumber() const;
00251
00255 int rowOf(ModelRow item) {
00256 for(int a = 0; a < filtered.size(); ++a)
00257 if(filtered[a].sourceRow() == item)
00258 return a;
00259 return -1;
00260 }
00261
00262 KateCompletionModel* model;
00263 int attribute;
00264 QString title, scope;
00265 QList<Item> filtered;
00266 QList<Item> prefilter;
00267 bool isEmpty;
00268
00269 int customSortingKey;
00270 };
00271
00272 private:
00273 void createGroups();
00276 QSet<Group*> createItems(const HierarchicalModelHandler&, const QModelIndex& i, bool notifyModel = false);
00279 QSet<Group*> deleteItems(const QModelIndex& i);
00280 Group* createItem(const HierarchicalModelHandler&, const QModelIndex& i, bool notifyModel = false);
00281 void clearGroups();
00282 void hideOrShowGroup(Group* g);
00284 Group* fetchGroup(int attribute, const QString& scope = QString(), bool forceGrouping = false);
00285
00286 Group* groupForIndex(const QModelIndex& index) const;
00287 inline Group* groupOfParent(const QModelIndex& child) const { return static_cast<Group*>(child.internalPointer()); }
00288 QModelIndex indexForRow(Group* g, int row) const;
00289 QModelIndex indexForGroup(Group* g) const;
00290
00291 enum changeTypes {
00292 Broaden,
00293 Narrow,
00294 Change
00295 };
00296
00297
00298 void changeCompletions(Group* g, changeTypes changeType);
00299
00300 void deleteRows(Group* g, QMutableListIterator<Item>& filtered, int countBackwards, int startRow);
00301 void addRows(Group* g, QMutableListIterator<Item>& filtered, int startRow, const QList<Item>& newItems);
00302
00303 bool hasGroups() const;
00304 bool hasCompletionModel() const;
00305
00307 int groupingAttributes(int attribute) const;
00308 int countBits(int value) const;
00309
00310 void resort();
00311 void refilter();
00312 void rematch();
00313
00314 bool m_hasGroups;
00315
00316
00317
00318 QList<KTextEditor::CodeCompletionModel*> m_completionModels;
00319 QMap<KTextEditor::CodeCompletionModel*, QString> m_currentMatch;
00320 Qt::CaseSensitivity m_matchCaseSensitivity;
00321
00322
00323 QList< QList<int> > m_columnMerges;
00324
00325 QTimer* m_updateBestMatchesTimer;
00326
00327 Group* m_ungrouped;
00328 Group* m_argumentHints;
00329 Group* m_bestMatches;
00330
00331
00332 QList<Group*> m_rowTable;
00333 QList<Group*> m_emptyGroups;
00334
00335 QMultiHash<int, Group*> m_groupHash;
00336
00337 QHash<QString, Group*> m_customGroupHash;
00338
00339
00340
00341 bool m_sortingEnabled;
00342 bool m_sortingAlphabetical;
00343 bool m_isSortingByInheritance;
00344 Qt::CaseSensitivity m_sortingCaseSensitivity;
00345 QHash< int, QList<int> > m_sortingGroupingOrder;
00346
00347
00348 bool m_filteringEnabled;
00349 bool m_filterContextMatchesOnly;
00350 bool m_filterByAttribute;
00351 KTextEditor::CodeCompletionModel::CompletionProperties m_filterAttributes;
00352 int m_maximumInheritanceDepth;
00353
00354
00355 bool m_groupingEnabled;
00356 GroupingMethods m_groupingMethod;
00357 bool m_accessConst, m_accessStatic, m_accesSignalSlot;
00358
00359
00360 bool m_columnMergingEnabled;
00361 };
00362
00363 Q_DECLARE_OPERATORS_FOR_FLAGS(KateCompletionModel::GroupingMethods)
00364
00365 #endif