KDECore
kcompletion_private.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
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
00101
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
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
00132
00133
00134 KCompTreeNode *next;
00135 private:
00136 uint myWeight;
00137 KCompTreeNodeList myChildren;
00138 static KZoneAllocator alloc;
00139 };
00140
00141
00142
00143
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