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