-rw-r--r-- | noncore/apps/checkbook/listedit.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/apps/checkbook/listedit.cpp b/noncore/apps/checkbook/listedit.cpp index 5026c9d..2612488 100644 --- a/noncore/apps/checkbook/listedit.cpp +++ b/noncore/apps/checkbook/listedit.cpp | |||
@@ -115,129 +115,129 @@ void ListEdit::slotAdd() | |||
115 | _currentItem=new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7] ); | 115 | _currentItem=new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7] ); |
116 | 116 | ||
117 | // fix uniques | 117 | // fix uniques |
118 | fixTypes(); | 118 | fixTypes(); |
119 | 119 | ||
120 | // display col 0 of new value | 120 | // display col 0 of new value |
121 | QPoint pnt; | 121 | QPoint pnt; |
122 | slotClick(_currentItem, pnt, 0); | 122 | slotClick(_currentItem, pnt, 0); |
123 | _typeTable->setSelected( _currentItem, true ); | 123 | _typeTable->setSelected( _currentItem, true ); |
124 | 124 | ||
125 | // make it selected | 125 | // make it selected |
126 | _typeEdit->setCursorPosition(0); | 126 | _typeEdit->setCursorPosition(0); |
127 | _typeEdit->setSelection(0, _typeEdit->text().length() ); | 127 | _typeEdit->setSelection(0, _typeEdit->text().length() ); |
128 | } | 128 | } |
129 | 129 | ||
130 | // --- slotDel ------------------------------------------------------------- | 130 | // --- slotDel ------------------------------------------------------------- |
131 | void ListEdit::slotDel() | 131 | void ListEdit::slotDel() |
132 | { | 132 | { |
133 | if( !_currentItem ) return; | 133 | if( !_currentItem ) return; |
134 | delete _currentItem; | 134 | delete _currentItem; |
135 | _currentItem=NULL; | 135 | _currentItem=NULL; |
136 | _typeEdit->setText(""); | 136 | _typeEdit->setText(""); |
137 | _stack->raiseWidget(_typeEdit); | 137 | _stack->raiseWidget(_typeEdit); |
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | // --- fixTypes ---------------------------------------------------------------- | 141 | // --- fixTypes ---------------------------------------------------------------- |
142 | // Makes sure all entries have a unique name and empty entries are replaced | 142 | // Makes sure all entries have a unique name and empty entries are replaced |
143 | // by a generic string. The first version performs the operation on a particular | 143 | // by a generic string. The first version performs the operation on a particular |
144 | // column, whereas the 2nd does it for all unique columns. | 144 | // column, whereas the 2nd does it for all unique columns. |
145 | class ColMap { | 145 | class ColMap { |
146 | public: | 146 | public: |
147 | ColMap(QString sValue, QListViewItem *pEntry) { | 147 | ColMap(QString sValue, QListViewItem *pEntry) { |
148 | _sValue=sValue; | 148 | _sValue=sValue; |
149 | _pEntry=pEntry; | 149 | _pEntry=pEntry; |
150 | } | 150 | } |
151 | QString &getValue() { return(_sValue); } | 151 | QString &getValue() { return(_sValue); } |
152 | QListViewItem *getItem() { return(_pEntry); } | 152 | QListViewItem *getItem() { return(_pEntry); } |
153 | 153 | ||
154 | protected: | 154 | protected: |
155 | QString _sValue; | 155 | QString _sValue; |
156 | QListViewItem *_pEntry; | 156 | QListViewItem *_pEntry; |
157 | }; | 157 | }; |
158 | 158 | ||
159 | class ColList : public QList<QString> | 159 | class ColList : public QList<QString> |
160 | { | 160 | { |
161 | public: | 161 | public: |
162 | ColList() : QList<QString>() { } | 162 | ColList() : QList<QString>() { } |
163 | 163 | ||
164 | protected: | 164 | protected: |
165 | int compareItems(QCollection::Item, QCollection::Item); | 165 | int compareItems(QCollection::Item, QCollection::Item); |
166 | }; | 166 | }; |
167 | 167 | ||
168 | int ColList::compareItems(QCollection::Item i1, QCollection::Item i2) { | 168 | int ColList::compareItems(QCollection::Item i1, QCollection::Item i2) { |
169 | return( ((QString *)i1)->compare(*(QString *)i2) ); | 169 | return( ((QString *)i1)->compare(*(QString *)i2) ); |
170 | } | 170 | } |
171 | 171 | ||
172 | void ListEdit::fixTypes(int iColumn) | 172 | void ListEdit::fixTypes(int iColumn) |
173 | { | 173 | { |
174 | // get column def | 174 | // get column def |
175 | ColumnDef *pDef=this->at(iColumn); | 175 | ColumnDef *pDef=this->at(iColumn); |
176 | 176 | ||
177 | // create map of entries | 177 | // create map of entries |
178 | if( !_typeTable->childCount() ) return; | 178 | if( !_typeTable->childCount() ) return; |
179 | ColMap **colMap=new (ColMap *)[_typeTable->childCount()]; | 179 | ColMap **colMap=new ColMap *[_typeTable->childCount()]; |
180 | QListViewItem *cur=_typeTable->firstChild(); | 180 | QListViewItem *cur=_typeTable->firstChild(); |
181 | ColList lst; | 181 | ColList lst; |
182 | for(int i=0; i<_typeTable->childCount(); i++) { | 182 | for(int i=0; i<_typeTable->childCount(); i++) { |
183 | colMap[i]=new ColMap(cur->text(iColumn), cur); | 183 | colMap[i]=new ColMap(cur->text(iColumn), cur); |
184 | lst.append( &(colMap[i]->getValue()) ); | 184 | lst.append( &(colMap[i]->getValue()) ); |
185 | cur=cur->nextSibling(); | 185 | cur=cur->nextSibling(); |
186 | } | 186 | } |
187 | 187 | ||
188 | // fix empty entries | 188 | // fix empty entries |
189 | int i=0; | 189 | int i=0; |
190 | for(QString *ptr=lst.first(); ptr; ptr=lst.next()) { | 190 | for(QString *ptr=lst.first(); ptr; ptr=lst.next()) { |
191 | *ptr=ptr->stripWhiteSpace(); | 191 | *ptr=ptr->stripWhiteSpace(); |
192 | if( ptr->isEmpty() ) { | 192 | if( ptr->isEmpty() ) { |
193 | i++; | 193 | i++; |
194 | if( i==1 ) *ptr=pDef->getNewValue(); | 194 | if( i==1 ) *ptr=pDef->getNewValue(); |
195 | else ptr->sprintf("%s %d", (const char *)pDef->getNewValue(), i); | 195 | else ptr->sprintf("%s %d", (const char *)pDef->getNewValue(), i); |
196 | } | 196 | } |
197 | } | 197 | } |
198 | 198 | ||
199 | // fix dups | 199 | // fix dups |
200 | lst.sort(); | 200 | lst.sort(); |
201 | QString repl; | 201 | QString repl; |
202 | for(uint iCur=0; iCur<lst.count()-1; iCur++) { | 202 | for(uint iCur=0; iCur<lst.count()-1; iCur++) { |
203 | QString *current=lst.at(iCur); | 203 | QString *current=lst.at(iCur); |
204 | for(uint iNext=iCur+1; iNext<lst.count(); iNext++ ) { | 204 | for(uint iNext=iCur+1; iNext<lst.count(); iNext++ ) { |
205 | if( *current!=*lst.at(iNext) ) continue; | 205 | if( *current!=*lst.at(iNext) ) continue; |
206 | for(int i=2; ; i++) { | 206 | for(int i=2; ; i++) { |
207 | repl.sprintf("%s %d", (const char *)*current, i); | 207 | repl.sprintf("%s %d", (const char *)*current, i); |
208 | bool bDup=false; | 208 | bool bDup=false; |
209 | uint iChk=iNext+1; | 209 | uint iChk=iNext+1; |
210 | while( iChk<lst.count() ) { | 210 | while( iChk<lst.count() ) { |
211 | QString *chk=lst.at(iChk); | 211 | QString *chk=lst.at(iChk); |
212 | if( !chk->startsWith(*current) ) break; | 212 | if( !chk->startsWith(*current) ) break; |
213 | if( *chk==repl ) { | 213 | if( *chk==repl ) { |
214 | bDup=true; | 214 | bDup=true; |
215 | break; | 215 | break; |
216 | } | 216 | } |
217 | iChk++; | 217 | iChk++; |
218 | } | 218 | } |
219 | if( !bDup ) { | 219 | if( !bDup ) { |
220 | *lst.at(iNext)=repl; | 220 | *lst.at(iNext)=repl; |
221 | break; | 221 | break; |
222 | } | 222 | } |
223 | } | 223 | } |
224 | } | 224 | } |
225 | } | 225 | } |
226 | lst.sort(); | 226 | lst.sort(); |
227 | 227 | ||
228 | // copy back clean up col map | 228 | // copy back clean up col map |
229 | for(int i=0; i<_typeTable->childCount(); i++) { | 229 | for(int i=0; i<_typeTable->childCount(); i++) { |
230 | colMap[i]->getItem()->setText(iColumn, colMap[i]->getValue()); | 230 | colMap[i]->getItem()->setText(iColumn, colMap[i]->getValue()); |
231 | delete colMap[i]; | 231 | delete colMap[i]; |
232 | } | 232 | } |
233 | delete colMap; | 233 | delete colMap; |
234 | } | 234 | } |
235 | 235 | ||
236 | void ListEdit::fixTypes() | 236 | void ListEdit::fixTypes() |
237 | { | 237 | { |
238 | int i; | 238 | int i; |
239 | ColumnDef *pDef; | 239 | ColumnDef *pDef; |
240 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { | 240 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { |
241 | if( pDef->hasFlag(ColumnDef::typeUnique) ) | 241 | if( pDef->hasFlag(ColumnDef::typeUnique) ) |
242 | fixTypes(i); | 242 | fixTypes(i); |
243 | } | 243 | } |