• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

katecompletionmodel.h

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2005-2006 Hamish Rodda <rodda@kde.org>
00003    Copyright (C) 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
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     // Disabled in case of bugs, reenable once fully debugged.
00087     //virtual QMap<int, QVariant> itemData ( const QModelIndex & index ) const;
00088     virtual QModelIndex parent ( const QModelIndex & index ) const;
00089     virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
00090 
00091     // Disabled in case of bugs, reenable once fully debugged.
00092     //virtual QModelIndex sibling ( int row, int column, const QModelIndex & index ) const;
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     // Sorting
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     // Filtering
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     // A maximum depth of <= 0 equals don't filter by inheritance depth (i.e. infinity) and is default
00127     int maximumInheritanceDepth() const;
00128     void setMaximumInheritanceDepth(int maxDepth);
00129 
00130     // Grouping
00131     bool isGroupingEnabled() const;
00132 
00133     enum gm {
00134       ScopeType     = 0x1,
00135       Scope         = 0x2,
00136       AccessType    = 0x4,
00137       ItemType      = 0x8
00138     };
00139 
00140     enum { //An own property that will be used to mark the best-matches group internally
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     // Column merging
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     //Emitted whenever something has changed about the group of argument-hints
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     //Updates the best-matches group
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     // Represents a source row; provides sorting method
00205     class Item {
00206       public:
00207         Item(bool doInitialMatch, KateCompletionModel* model, const HierarchicalModelHandler& handler, ModelRow sourceRow);
00208 
00209         bool isValid() const;
00210         // Returns true if the item is not filtered and matches the current completion string
00211         bool isVisible() const;
00212         // Returns whether the item is filtered or not
00213         bool isFiltered() const;
00214         // Returns whether the item matches the current completion string
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         // Sorting operator
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         // True when currently matching completion string
00247         MatchType matchCompletion;
00248         // True when passes all active filters
00249         bool matchFilters, m_haveExactMatch;
00250 
00251         QString completionSortingName() const;
00252     };
00253 
00254   public:
00255     // Grouping and sorting of rows
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         //Returns whether this group should be ordered before other
00267         bool orderBefore(Group* other) const;
00268         //Returns a number that can be used for ordering
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     //-1 if none was set
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     //If this returns nonzero on an index, the index is the header of the returned group
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     //Returns whether the model needs to be reset
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     // ### Runtime state
00333     // General
00334     QList<KTextEditor::CodeCompletionModel*> m_completionModels;
00335     QMap<KTextEditor::CodeCompletionModel*, QString> m_currentMatch;
00336     Qt::CaseSensitivity m_matchCaseSensitivity;
00337 
00338     // Column merging
00339     QList< QList<int> > m_columnMerges;
00340 
00341     QTimer* m_updateBestMatchesTimer;
00342     
00343     Group* m_ungrouped;
00344     Group* m_argumentHints; //The argument-hints will be passed on to another model, to be shown in another widget
00345     Group* m_bestMatches; //A temporary group used for holding the best matches of all visible items
00346 
00347     // Storing the sorted order
00348     QList<Group*> m_rowTable;
00349     QList<Group*> m_emptyGroups;
00350     // Quick access to each specific group (if it exists)
00351     QMultiHash<int, Group*> m_groupHash;
00352     // Maps custom group-names to their specific groups
00353     QHash<QString, Group*> m_customGroupHash;
00354 
00355     // ### Configurable state
00356     // Sorting
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     // Filtering
00364     bool m_filteringEnabled;
00365     bool m_filterContextMatchesOnly;
00366     bool m_filterByAttribute;
00367     KTextEditor::CodeCompletionModel::CompletionProperties m_filterAttributes;
00368     int m_maximumInheritanceDepth;
00369 
00370     // Grouping
00371     bool m_groupingEnabled;
00372     GroupingMethods m_groupingMethod;
00373     bool m_accessConst, m_accessStatic, m_accesSignalSlot;
00374 
00375     // Column merging
00376     bool m_columnMergingEnabled/*, m_haveExactMatch*/;
00377 };
00378 
00379 Q_DECLARE_OPERATORS_FOR_FLAGS(KateCompletionModel::GroupingMethods)
00380 
00381 #endif

Kate

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal