• Skip to content
  • Skip to link menu
KDE 4.1 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 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
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     // Disabled in case of bugs, reenable once fully debugged.
00086     //virtual QMap<int, QVariant> itemData ( const QModelIndex & index ) const;
00087     virtual QModelIndex parent ( const QModelIndex & index ) const;
00088     virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
00089 
00090     // Disabled in case of bugs, reenable once fully debugged.
00091     //virtual QModelIndex sibling ( int row, int column, const QModelIndex & index ) const;
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     // Sorting
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     // Filtering
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     // A maximum depth of <= 0 equals don't filter by inheritance depth (i.e. infinity) and is default
00123     int maximumInheritanceDepth() const;
00124     void setMaximumInheritanceDepth(int maxDepth);
00125 
00126     // Grouping
00127     bool isGroupingEnabled() const;
00128 
00129     enum gm {
00130       ScopeType     = 0x1,
00131       Scope         = 0x2,
00132       AccessType    = 0x4,
00133       ItemType      = 0x8
00134     };
00135 
00136     enum { //An own property that will be used to mark the best-matches group internally
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     // Column merging
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     //Emitted whenever something has changed about the group of argument-hints
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     //Updates the best-matches group
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     // Represents a source row; provides sorting method
00195     class Item {
00196       public:
00197         Item(KateCompletionModel* model, const HierarchicalModelHandler& handler, ModelRow sourceRow);
00198 
00199         bool isValid() const;
00200         // Returns true if the item is not filtered and matches the current completion string
00201         bool isVisible() const;
00202         // Returns whether the item is filtered or not
00203         bool isFiltered() const;
00204         // Returns whether the item matches the current completion string
00205         bool isMatching() const;
00206 
00207         bool filter();
00208         bool match(const QString& newCompletion = QString());
00209 
00210         ModelRow sourceRow() const;
00211 
00212         // Sorting operator
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         // True when currently matching completion string
00225         bool matchCompletion;
00226         // True when passes all active filters
00227         bool matchFilters;
00228 
00229         QString completionSortingName() const;
00230     };
00231 
00232   public:
00233     // Grouping and sorting of rows
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         //Returns whether this group should be ordered before other
00245         bool orderBefore(Group* other) const;
00246         //Returns a number that can be used for ordering
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     //If this returns nonzero on an index, the index is the header of the returned group
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     // ### Runtime state
00300     // General
00301     QList<KTextEditor::CodeCompletionModel*> m_completionModels;
00302     QString m_currentMatch;
00303     Qt::CaseSensitivity m_matchCaseSensitivity;
00304 
00305     // Column merging
00306     QList< QList<int> > m_columnMerges;
00307 
00308     QTimer* m_updateBestMatchesTimer;
00309     
00310     Group* m_ungrouped;
00311     Group* m_argumentHints; //The argument-hints will be passed on to another model, to be shown in another widget
00312     Group* m_bestMatches; //A temporary group used for holding the best matches of all visible items
00313 
00314     // Storing the sorted order
00315     QList<Group*> m_rowTable;
00316     QList<Group*> m_emptyGroups;
00317     // Quick access to each specific group (if it exists)
00318     QMultiHash<int, Group*> m_groupHash;
00319 
00320     // ### Configurable state
00321     // Sorting
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     // Filtering
00330     bool m_filteringEnabled;
00331     bool m_filterContextMatchesOnly;
00332     bool m_filterByAttribute;
00333     KTextEditor::CodeCompletionModel::CompletionProperties m_filterAttributes;
00334     int m_maximumInheritanceDepth;
00335 
00336     // Grouping
00337     bool m_groupingEnabled;
00338     GroupingMethods m_groupingMethod;
00339     bool m_accessConst, m_accessStatic, m_accesSignalSlot;
00340 
00341     // Column merging
00342     bool m_columnMergingEnabled;
00343 };
00344 
00345 Q_DECLARE_OPERATORS_FOR_FLAGS(KateCompletionModel::GroupingMethods)
00346 
00347 #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
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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