• Skip to content
  • Skip to link menu
KDE 4.2 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 
00168   protected:
00169     virtual int contextMatchQuality(const QModelIndex& row) const;
00170 
00171   Q_SIGNALS:
00172     void expandIndex(const QModelIndex& index);
00173     //Emitted whenever something has changed about the group of argument-hints
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     //Updates the best-matches group
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     // Represents a source row; provides sorting method
00199     class Item {
00200       public:
00201         Item(bool doInitialMatch, KateCompletionModel* model, const HierarchicalModelHandler& handler, ModelRow sourceRow);
00202 
00203         bool isValid() const;
00204         // Returns true if the item is not filtered and matches the current completion string
00205         bool isVisible() const;
00206         // Returns whether the item is filtered or not
00207         bool isFiltered() const;
00208         // Returns whether the item matches the current completion string
00209         bool isMatching() const;
00210 
00211         bool filter();
00212         bool match();
00213 
00214         const ModelRow& sourceRow() const;
00215 
00216         // Sorting operator
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         // True when currently matching completion string
00228         bool matchCompletion;
00229         // True when passes all active filters
00230         bool matchFilters;
00231 
00232         QString completionSortingName() const;
00233     };
00234 
00235   public:
00236     // Grouping and sorting of rows
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         //Returns whether this group should be ordered before other
00248         bool orderBefore(Group* other) const;
00249         //Returns a number that can be used for ordering
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     //-1 if none was set
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     //If this returns nonzero on an index, the index is the header of the returned group
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     // ### Runtime state
00317     // General
00318     QList<KTextEditor::CodeCompletionModel*> m_completionModels;
00319     QMap<KTextEditor::CodeCompletionModel*, QString> m_currentMatch;
00320     Qt::CaseSensitivity m_matchCaseSensitivity;
00321 
00322     // Column merging
00323     QList< QList<int> > m_columnMerges;
00324 
00325     QTimer* m_updateBestMatchesTimer;
00326     
00327     Group* m_ungrouped;
00328     Group* m_argumentHints; //The argument-hints will be passed on to another model, to be shown in another widget
00329     Group* m_bestMatches; //A temporary group used for holding the best matches of all visible items
00330 
00331     // Storing the sorted order
00332     QList<Group*> m_rowTable;
00333     QList<Group*> m_emptyGroups;
00334     // Quick access to each specific group (if it exists)
00335     QMultiHash<int, Group*> m_groupHash;
00336     // Maps custom group-names to their specific groups
00337     QHash<QString, Group*> m_customGroupHash;
00338 
00339     // ### Configurable state
00340     // Sorting
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     // Filtering
00348     bool m_filteringEnabled;
00349     bool m_filterContextMatchesOnly;
00350     bool m_filterByAttribute;
00351     KTextEditor::CodeCompletionModel::CompletionProperties m_filterAttributes;
00352     int m_maximumInheritanceDepth;
00353 
00354     // Grouping
00355     bool m_groupingEnabled;
00356     GroupingMethods m_groupingMethod;
00357     bool m_accessConst, m_accessStatic, m_accesSignalSlot;
00358 
00359     // Column merging
00360     bool m_columnMergingEnabled;
00361 };
00362 
00363 Q_DECLARE_OPERATORS_FOR_FLAGS(KateCompletionModel::GroupingMethods)
00364 
00365 #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
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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