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

KDECore

kcompletion_private.h

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002     Copyright (C) 1999 Carsten Pfeiffer <pfeiffer@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 as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
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 
00021 #ifndef KCOMPLETION_PRIVATE_H
00022 #define KCOMPLETION_PRIVATE_H
00023 
00024 #include <qstring.h>
00025 #include <ksortablevaluelist.h>
00026 
00027 class KCompTreeNode;
00028 
00029 #include <kallocator.h>
00030 
00034 class KDECORE_EXPORT KCompTreeNodeList
00035 {
00036 public:
00037     KCompTreeNodeList() : first(0), last(0), m_count(0) {}
00038     KCompTreeNode *begin() const { return first; }
00039     KCompTreeNode *end() const { return last; }
00040 
00041     KCompTreeNode *at(uint index) const;
00042     void append(KCompTreeNode *item); 
00043     void prepend(KCompTreeNode *item); 
00044     void insert(KCompTreeNode *after, KCompTreeNode *item);
00045     KCompTreeNode *remove(KCompTreeNode *item);
00046     uint count() const { return m_count; }
00047 
00048 private:
00049     KCompTreeNode *first, *last;
00050     uint m_count;
00051 };
00052 
00053 typedef KCompTreeNodeList KCompTreeChildren;
00054 
00084 class KDECORE_EXPORT KCompTreeNode : public QChar
00085 {
00086 public:
00087     KCompTreeNode() : QChar(), myWeight(0) {}
00088     KCompTreeNode( const QChar& ch, uint weight = 0 )
00089         : QChar( ch ),
00090           myWeight( weight ) {}
00091     ~KCompTreeNode();
00092 
00093     void * operator new( size_t s ) {
00094       return alloc.allocate( s );
00095     }
00096     void operator delete( void * s ) {
00097       alloc.deallocate( s );
00098     }
00099 
00100     // Returns a child of this node matching ch, if available.
00101     // Otherwise, returns 0L
00102     inline KCompTreeNode * find( const QChar& ch ) const {
00103       KCompTreeNode * cur = myChildren.begin();
00104       while (cur && (*cur != ch)) cur = cur->next;
00105       return cur;
00106     }
00107     KCompTreeNode * insert( const QChar&, bool sorted );
00108     void        remove( const QString& );
00109 
00110     inline int      childrenCount() const { return myChildren.count(); }
00111 
00112     // weighting
00113     inline void confirm()   { myWeight++;       }
00114     inline void confirm(uint w) { myWeight += w;    }
00115     inline void decline()   { myWeight--;       }
00116     inline uint weight() const  { return myWeight;  }
00117 
00118     inline const KCompTreeChildren * children() const {
00119     return &myChildren;
00120     }
00121     inline const KCompTreeNode * childAt(int index) const {
00122     return myChildren.at(index);
00123     }
00124     inline const KCompTreeNode * firstChild() const {
00125     return myChildren.begin();
00126     }
00127     inline const KCompTreeNode * lastChild()  const {
00128     return myChildren.end();
00129     }
00130 
00131     /* We want to handle a list of KCompTreeNodes on our own, to not
00132        need to use QValueList<>.  And to make it even more fast we don't
00133        use an accessor, but just a public member.  */
00134     KCompTreeNode *next;
00135 private:
00136     uint myWeight;
00137     KCompTreeNodeList   myChildren;
00138     static KZoneAllocator alloc;
00139 };
00140 
00141 
00142 
00143 // some more helper stuff
00144 typedef KSortableValueList<QString> KCompletionMatchesList;
00145 
00149 class KDECORE_EXPORT KCompletionMatchesWrapper
00150 {
00151 public:
00152     KCompletionMatchesWrapper( bool sort = false )
00153         : sortedList( sort ? new KCompletionMatchesList : 0L ),
00154           dirty( false )
00155     {}
00156     ~KCompletionMatchesWrapper() {
00157         delete sortedList;
00158     }
00159 
00160     void setSorting( bool sort ) {
00161         if ( sort && !sortedList )
00162             sortedList = new KCompletionMatchesList;
00163         else if ( !sort ) {
00164             delete sortedList;
00165             sortedList = 0L;
00166         }
00167         stringList.clear();
00168         dirty = false;
00169     }
00170 
00171     bool sorting() const {
00172         return sortedList != 0L;
00173     }
00174 
00175     void append( int i, const QString& string ) {
00176         if ( sortedList )
00177             sortedList->insert( i, string );
00178         else
00179             stringList.append( string );
00180         dirty = true;
00181     }
00182 
00183     void clear() {
00184         if ( sortedList )
00185             sortedList->clear();
00186         stringList.clear();
00187         dirty = false;
00188     }
00189 
00190     uint count() const {
00191         if ( sortedList )
00192             return sortedList->count();
00193         return stringList.count();
00194     }
00195 
00196     bool isEmpty() const {
00197         return count() == 0;
00198     }
00199 
00200     QString first() const {
00201         return list().first();
00202     }
00203 
00204     QString last() const {
00205         return list().last();
00206     }
00207 
00208     QStringList list() const;
00209 
00210     mutable QStringList stringList;
00211     KCompletionMatchesList *sortedList;
00212     mutable bool dirty;
00213 };
00214 
00215 
00216 #endif // KCOMPLETION_PRIVATE_H

KDECore

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

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
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