summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/listedit.cpp
Unidiff
Diffstat (limited to 'noncore/apps/checkbook/listedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/listedit.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/noncore/apps/checkbook/listedit.cpp b/noncore/apps/checkbook/listedit.cpp
index 37f05f0..d00e305 100644
--- a/noncore/apps/checkbook/listedit.cpp
+++ b/noncore/apps/checkbook/listedit.cpp
@@ -1,264 +1,264 @@
1/* 1/*
2                This file is part of the OPIE Project 2                This file is part of the OPIE Project
3 =. 3 =.
4             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> 4             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org>
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can 6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public 8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License, 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version. 11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that 13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details. 18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .: 19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU 20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file; 21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the 22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc., 23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330, 24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include "listedit.h" 29#include "listedit.h"
30#include <qlayout.h> 30#include <qlayout.h>
31#include <qlineedit.h> 31#include <qlineedit.h>
32#include <qlistview.h> 32#include <qlistview.h>
33#include <qwidgetstack.h> 33#include <qwidgetstack.h>
34#include <qcombobox.h> 34#include <qcombobox.h>
35#include <qpushbutton.h> 35#include <qpushbutton.h>
36#include <qpe/resource.h> 36#include <qpe/resource.h>
37 37
38 38
39// --- ListEdit --------------------------------------------------------------- 39// --- ListEdit ---------------------------------------------------------------
40ListEdit::ListEdit( QWidget *parent, const char *sName ) 40ListEdit::ListEdit( QWidget *parent, const char *sName )
41 : QWidget(parent, sName), TableDef(sName) 41 : QWidget(parent, sName), TableDef(sName)
42{ 42{
43 // get font height 43 // get font height
44 int fh = fontMetrics().height(); 44 int fh = fontMetrics().height();
45 45
46 // create layout 46 // create layout
47 QGridLayout *layout=new QGridLayout(this); 47 QGridLayout *layout=new QGridLayout(this);
48 layout->setSpacing( 2 ); 48 layout->setSpacing( 2 );
49 layout->setMargin( 4 ); 49 layout->setMargin( 4 );
50 50
51 // type table 51 // type table
52 _typeTable = new QListView( this ); 52 _typeTable = new QListView( this );
53 ColumnDef *def=first(); 53 ColumnDef *def=first();
54 while( def ) { 54 while( def ) {
55 _typeTable->addColumn( def->getName() ); 55 _typeTable->addColumn( def->getName() );
56 def=next(); 56 def=next();
57 } 57 }
58 connect( _typeTable, SIGNAL( clicked(QListViewItem *, const QPoint &, int) ), this, SLOT( slotClick(QListViewItem *, const QPoint &, int ) ) ); 58 connect( _typeTable, SIGNAL( clicked(QListViewItem*,const QPoint&,int) ), this, SLOT( slotClick(QListViewItem*,const QPoint&,int) ) );
59 layout->addMultiCellWidget(_typeTable, 0,4,0,4); 59 layout->addMultiCellWidget(_typeTable, 0,4,0,4);
60 _currentItem=NULL; 60 _currentItem=NULL;
61 61
62 // edit field 62 // edit field
63 _stack=new QWidgetStack( this ); 63 _stack=new QWidgetStack( this );
64 _stack->setMaximumHeight(fh+5); 64 _stack->setMaximumHeight(fh+5);
65 layout->addMultiCellWidget(_stack, 5,5,0,2); 65 layout->addMultiCellWidget(_stack, 5,5,0,2);
66 _typeEdit = new QLineEdit( _stack ); 66 _typeEdit = new QLineEdit( _stack );
67 _stack->raiseWidget(_typeEdit ); 67 _stack->raiseWidget(_typeEdit );
68 connect( _typeEdit, SIGNAL( textChanged(const QString &) ), this, SLOT( slotEditChanged(const QString &) ) ); 68 connect( _typeEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotEditChanged(const QString&) ) );
69 69
70 // combo box 70 // combo box
71 _box=new QComboBox( _stack ); 71 _box=new QComboBox( _stack );
72 connect( _box, SIGNAL( activated(const QString &) ), this, SLOT( slotActivated(const QString &) ) ); 72 connect( _box, SIGNAL( activated(const QString&) ), this, SLOT( slotActivated(const QString&) ) );
73 73
74 74
75 // add button 75 // add button
76 QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/add" ), tr( "Add" ), this ); 76 QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/add" ), tr( "Add" ), this );
77 connect( btn, SIGNAL( clicked() ), this, SLOT( slotAdd() ) ); 77 connect( btn, SIGNAL( clicked() ), this, SLOT( slotAdd() ) );
78 layout->addWidget( btn, 5, 3 ); 78 layout->addWidget( btn, 5, 3 );
79 79
80 // delete button 80 // delete button
81 btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), this ); 81 btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), this );
82 connect( btn, SIGNAL( clicked() ), this, SLOT( slotDel() ) ); 82 connect( btn, SIGNAL( clicked() ), this, SLOT( slotDel() ) );
83 layout->addWidget( btn, 5, 4 ); 83 layout->addWidget( btn, 5, 4 );
84} 84}
85 85
86// --- ~ListEdit -------------------------------------------------------------- 86// --- ~ListEdit --------------------------------------------------------------
87ListEdit::~ListEdit() 87ListEdit::~ListEdit()
88{ 88{
89} 89}
90 90
91 91
92// --- slotEditTypeChanged ---------------------------------------------------- 92// --- slotEditTypeChanged ----------------------------------------------------
93void ListEdit::slotEditChanged(const QString &str) 93void ListEdit::slotEditChanged(const QString &str)
94{ 94{
95 if( !_currentItem || _currentColumn<0 ) return; 95 if( !_currentItem || _currentColumn<0 ) return;
96 _currentItem->setText(_currentColumn, str); 96 _currentItem->setText(_currentColumn, str);
97} 97}
98 98
99// --- slotAddType ------------------------------------------------------------ 99// --- slotAddType ------------------------------------------------------------
100void ListEdit::slotAdd() 100void ListEdit::slotAdd()
101{ 101{
102 // construct new row 102 // construct new row
103 QString args[8]; 103 QString args[8];
104 ColumnDef *pCol=this->first(); 104 ColumnDef *pCol=this->first();
105 int i=0; 105 int i=0;
106 while( pCol && i<8 ) { 106 while( pCol && i<8 ) {
107 args[i++]=pCol->getNewValue(); 107 args[i++]=pCol->getNewValue();
108 pCol=this->next(); 108 pCol=this->next();
109 } 109 }
110 _currentItem=new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7] ); 110 _currentItem=new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7] );
111 111
112 // fix uniques 112 // fix uniques
113 fixTypes(); 113 fixTypes();
114 114
115 // display col 0 of new value 115 // display col 0 of new value
116 QPoint pnt; 116 QPoint pnt;
117 slotClick(_currentItem, pnt, 0); 117 slotClick(_currentItem, pnt, 0);
118 _typeTable->setSelected( _currentItem, true ); 118 _typeTable->setSelected( _currentItem, true );
119 119
120 // make it selected 120 // make it selected
121 _typeEdit->setCursorPosition(0); 121 _typeEdit->setCursorPosition(0);
122 _typeEdit->setSelection(0, _typeEdit->text().length() ); 122 _typeEdit->setSelection(0, _typeEdit->text().length() );
123} 123}
124 124
125// --- slotDel ------------------------------------------------------------- 125// --- slotDel -------------------------------------------------------------
126void ListEdit::slotDel() 126void ListEdit::slotDel()
127{ 127{
128 if( !_currentItem ) return; 128 if( !_currentItem ) return;
129 delete _currentItem; 129 delete _currentItem;
130 _currentItem=NULL; 130 _currentItem=NULL;
131 _typeEdit->setText(""); 131 _typeEdit->setText("");
132 _stack->raiseWidget(_typeEdit); 132 _stack->raiseWidget(_typeEdit);
133} 133}
134 134
135 135
136// --- fixTypes ---------------------------------------------------------------- 136// --- fixTypes ----------------------------------------------------------------
137// Makes sure all entries have a unique name and empty entries are replaced 137// Makes sure all entries have a unique name and empty entries are replaced
138// by a generic string. The first version performs the operation on a particular 138// by a generic string. The first version performs the operation on a particular
139// column, whereas the 2nd does it for all unique columns. 139// column, whereas the 2nd does it for all unique columns.
140class ColMap { 140class ColMap {
141 public: 141 public:
142 ColMap(QString sValue, QListViewItem *pEntry) { 142 ColMap(QString sValue, QListViewItem *pEntry) {
143 _sValue=sValue; 143 _sValue=sValue;
144 _pEntry=pEntry; 144 _pEntry=pEntry;
145 } 145 }
146 QString &getValue() { return(_sValue); } 146 QString &getValue() { return(_sValue); }
147 QListViewItem *getItem() { return(_pEntry); } 147 QListViewItem *getItem() { return(_pEntry); }
148 148
149 protected: 149 protected:
150 QString _sValue; 150 QString _sValue;
151 QListViewItem *_pEntry; 151 QListViewItem *_pEntry;
152}; 152};
153 153
154class ColList : public QList<QString> 154class ColList : public QList<QString>
155{ 155{
156 public: 156 public:
157 ColList() : QList<QString>() { } 157 ColList() : QList<QString>() { }
158 158
159 protected: 159 protected:
160 int compareItems(QCollection::Item, QCollection::Item); 160 int compareItems(QCollection::Item, QCollection::Item);
161}; 161};
162 162
163int ColList::compareItems(QCollection::Item i1, QCollection::Item i2) { 163int ColList::compareItems(QCollection::Item i1, QCollection::Item i2) {
164 return( ((QString *)i1)->compare(*(QString *)i2) ); 164 return( ((QString *)i1)->compare(*(QString *)i2) );
165} 165}
166 166
167void ListEdit::fixTypes(int iColumn) 167void ListEdit::fixTypes(int iColumn)
168{ 168{
169 // get column def 169 // get column def
170 ColumnDef *pDef=this->at(iColumn); 170 ColumnDef *pDef=this->at(iColumn);
171 171
172 // create map of entries 172 // create map of entries
173 if( !_typeTable->childCount() ) return; 173 if( !_typeTable->childCount() ) return;
174 ColMap **colMap=new (ColMap *)[_typeTable->childCount()]; 174 ColMap **colMap=new (ColMap *)[_typeTable->childCount()];
175 QListViewItem *cur=_typeTable->firstChild(); 175 QListViewItem *cur=_typeTable->firstChild();
176 ColList lst; 176 ColList lst;
177 for(int i=0; i<_typeTable->childCount(); i++) { 177 for(int i=0; i<_typeTable->childCount(); i++) {
178 colMap[i]=new ColMap(cur->text(iColumn), cur); 178 colMap[i]=new ColMap(cur->text(iColumn), cur);
179 lst.append( &(colMap[i]->getValue()) ); 179 lst.append( &(colMap[i]->getValue()) );
180 cur=cur->nextSibling(); 180 cur=cur->nextSibling();
181 } 181 }
182 182
183 // fix empty entries 183 // fix empty entries
184 int i=0; 184 int i=0;
185 for(QString *ptr=lst.first(); ptr; ptr=lst.next()) { 185 for(QString *ptr=lst.first(); ptr; ptr=lst.next()) {
186 *ptr=ptr->stripWhiteSpace(); 186 *ptr=ptr->stripWhiteSpace();
187 if( ptr->isEmpty() ) { 187 if( ptr->isEmpty() ) {
188 i++; 188 i++;
189 if( i==1 ) *ptr=pDef->getNewValue(); 189 if( i==1 ) *ptr=pDef->getNewValue();
190 else ptr->sprintf("%s %d", (const char *)pDef->getNewValue(), i); 190 else ptr->sprintf("%s %d", (const char *)pDef->getNewValue(), i);
191 } 191 }
192 } 192 }
193 193
194 // fix dups 194 // fix dups
195 lst.sort(); 195 lst.sort();
196 QString repl; 196 QString repl;
197 for(uint iCur=0; iCur<lst.count()-1; iCur++) { 197 for(uint iCur=0; iCur<lst.count()-1; iCur++) {
198 QString *current=lst.at(iCur); 198 QString *current=lst.at(iCur);
199 for(uint iNext=iCur+1; iNext<lst.count(); iNext++ ) { 199 for(uint iNext=iCur+1; iNext<lst.count(); iNext++ ) {
200 if( *current!=*lst.at(iNext) ) continue; 200 if( *current!=*lst.at(iNext) ) continue;
201 for(int i=2; ; i++) { 201 for(int i=2; ; i++) {
202 repl.sprintf("%s %d", (const char *)*current, i); 202 repl.sprintf("%s %d", (const char *)*current, i);
203 bool bDup=false; 203 bool bDup=false;
204 uint iChk=iNext+1; 204 uint iChk=iNext+1;
205 while( iChk<lst.count() ) { 205 while( iChk<lst.count() ) {
206 QString *chk=lst.at(iChk); 206 QString *chk=lst.at(iChk);
207 if( !chk->startsWith(*current) ) break; 207 if( !chk->startsWith(*current) ) break;
208 if( *chk==repl ) { 208 if( *chk==repl ) {
209 bDup=true; 209 bDup=true;
210 break; 210 break;
211 } 211 }
212 iChk++; 212 iChk++;
213 } 213 }
214 if( !bDup ) { 214 if( !bDup ) {
215 *lst.at(iNext)=repl; 215 *lst.at(iNext)=repl;
216 break; 216 break;
217 } 217 }
218 } 218 }
219 } 219 }
220 } 220 }
221 lst.sort(); 221 lst.sort();
222 222
223 // copy back clean up col map 223 // copy back clean up col map
224 for(int i=0; i<_typeTable->childCount(); i++) { 224 for(int i=0; i<_typeTable->childCount(); i++) {
225 colMap[i]->getItem()->setText(iColumn, colMap[i]->getValue()); 225 colMap[i]->getItem()->setText(iColumn, colMap[i]->getValue());
226 delete colMap[i]; 226 delete colMap[i];
227 } 227 }
228 delete colMap; 228 delete colMap;
229} 229}
230 230
231void ListEdit::fixTypes() 231void ListEdit::fixTypes()
232{ 232{
233 int i; 233 int i;
234 ColumnDef *pDef; 234 ColumnDef *pDef;
235 for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { 235 for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) {
236 if( pDef->hasFlag(ColumnDef::typeUnique) ) 236 if( pDef->hasFlag(ColumnDef::typeUnique) )
237 fixTypes(i); 237 fixTypes(i);
238 } 238 }
239 _typeTable->sort(); 239 _typeTable->sort();
240} 240}
241 241
242 242
243// --- storeInList ------------------------------------------------------------ 243// --- storeInList ------------------------------------------------------------
244void ListEdit::storeInList(QStringList &lst) 244void ListEdit::storeInList(QStringList &lst)
245{ 245{
246 // delete old content 246 // delete old content
247 lst.clear(); 247 lst.clear();
248 248
249 // add new one 249 // add new one
250 fixTypes(); 250 fixTypes();
251 QListViewItem *itm=_typeTable->firstChild(); 251 QListViewItem *itm=_typeTable->firstChild();
252 while( itm ) { 252 while( itm ) {
253 int i=0; 253 int i=0;
254 QString sAdd; 254 QString sAdd;
255 ColumnDef *pDef; 255 ColumnDef *pDef;
256 for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { 256 for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) {
257 if( i>=1 ) sAdd+=";"; 257 if( i>=1 ) sAdd+=";";
258 sAdd += itm->text(i); 258 sAdd += itm->text(i);
259 } 259 }
260 lst.append( sAdd ); 260 lst.append( sAdd );
261 itm=itm->nextSibling(); 261 itm=itm->nextSibling();
262 } 262 }
263} 263}
264 264