Ananas Library  0.9.5
edbtable.ui.h
1 /****************************************************************************
2 ** $Id: edbtable.ui.h,v 1.33 2006/04/04 13:20:40 gr Exp $
3 **
4 ** Code file of the edit databse table plugin of Ananas
5 ** Designer and Engine applications
6 **
7 ** Created : 20031201
8 **
9 ** Copyright (C) 2003-2004 Leader InfoTech. All rights reserved.
10 ** Copyright (C) 2003-2004 Grigory Panov, Yoshkar-Ola.
11 **
12 ** This file is part of the Ananas Plugins of the Ananas
13 ** automation accounting system.
14 **
15 ** This file may be distributed and/or modified under the terms of the
16 ** GNU General Public License version 2 as published by the Free Software
17 ** Foundation and appearing in the file LICENSE.GPL included in the
18 ** packaging of this file.
19 **
20 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
21 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 **
23 ** See http://www.leaderit.ru/page=ananas or email sales@leaderit.ru
24 ** See http://www.leaderit.ru/gpl/ for GPL licensing information.
25 **
26 ** Contact org@leaderit.ru if any conditions of this licensing are
27 ** not clear to you.
28 **
29 **********************************************************************/
30 
31 /****************************************************************************
32 ** ui.h extension file, included from the uic-generated form implementation.
33 **
34 ** If you wish to add, delete or rename functions or slots use
35 ** Qt Designer which will update this file, preserving your code. Create an
36 ** init() function in place of a constructor, and a destroy() function in
37 ** place of a destructor.
38 *****************************************************************************/
39 #include <stdlib.h>
40 #include "wdbtable.h"
41 
42 void eDBTable::init()
43 {
44 }
45 
46 
47 void
48 eDBTable::destroy()
49 {
50 // tablerow_free( r );
51 }
52 
53 
54 /*
55 void eDBTable::insertColumn(const char *Header, const char *Name,
56 int idxt, int cw, int tw, int td)
57 {
58 
59 tablefield *f;
60 char s[30];
61 
62 sprintf(s, "%s %i %i", (const char *)otypes[idxt], tw, td);
63 
64 f = tablefield_newsys(Name, s, "");
65 tablefield_setheader(f, Header);
66 f->sizex = cw;
67 f->flen = tw;
68 f->decimals = td;
69 f->ftypeindex = idxt;
70 tablerow_insertcolumn(r, f, -1);
71 
72 // blockSignals( true );
73 ListCol->insertItem(trUtf8(Header));
74 // eColHeader->setText( trUtf8(Header));
75 // eColName->setText(trUtf8(Name));
76 // eColWidth->setValue(cw);
77 // eColTWidth->setValue(tw);
78 // eColTDec->setValue(td);
79 // blockSignals( false );
80 if (ListCol->count()) ListCol->setCurrentItem(ListCol->count()-1);
81 
82 }
83 */
84 
85 
86 
87 void eDBTable::ColumnDel()
88 {
89 
90 int idx;
91 QString str;
92 idx = ListCol->currentItem();
93 if (idx != -1 && ListCol->count()>0)
94 {
95  str = fname[idx];
96  table->removeColumn(idx);
97  deletedFields.append(str);
98  deletedFieldsId.append(idlist[idx]);
99  idlist.remove(idlist.at(idx));
100  fname.remove(fname.at(idx));
101  cwidth.remove(cwidth.at(idx));
102  ListCol->removeItem(idx);
103 // table->removeColumn(idx);
104 }
105 }
106 
107 void eDBTable::ColumnL()
108 {
109  int idx;
110  QString str;
111  QStringList::Iterator it;
112  idx = ListCol->currentItem();
113  if(idx>0)
114  {
115  str = fname[idx];
116  it = fname.at(idx);
117  fname.remove(it);
118  it = fname.at(idx-1);
119  fname.insert(it,str);
120 
121  str = idlist[idx];
122  it = idlist.at(idx);
123  idlist.remove(it);
124  it = idlist.at(idx-1);
125  idlist.insert(it,str);
126 
127  str = cwidth[idx];
128  it = cwidth.at(idx);
129  cwidth.remove(it);
130  it = cwidth.at(idx-1);
131  cwidth.insert(it,str);
132 
133  str = ListCol->currentText();
134  ListCol->removeItem(idx);
135  ListCol->insertItem(str,idx-1);
136  ListCol->setSelected(idx-1,true);
137  }
138 }
139 
140 
141 void eDBTable::ColumnR()
142 {
143  uint idx;
144  QString str;
145  QStringList::Iterator it;
146  idx = ListCol->currentItem();
147  if(idx<ListCol->count()-1)
148  {
149  str = fname[idx];
150  it = fname.at(idx);
151  fname.remove(it);
152  it = fname.at(idx+1);
153  fname.insert(it,str);
154 
155  str = idlist[idx];
156  it = idlist.at(idx);
157  idlist.remove(it);
158  it = idlist.at(idx+1);
159  idlist.insert(it,str);
160 
161  str = cwidth[idx];
162  it = cwidth.at(idx);
163  cwidth.remove(it);
164  it = cwidth.at(idx+1);
165  cwidth.insert(it,str);
166 
167  str = ListCol->currentText();
168  ListCol->removeItem(idx);
169  ListCol->insertItem(str,idx+1);
170  ListCol->setSelected(idx+1,true);
171  }
172 
173 }
174 void eDBTable::ColumnSel(int col)
175 {
176 QString str,s;
177 int ind = 0;
178 QStringList lst;
179  eColHeader->blockSignals(true);
180  eColWidth->blockSignals(true);
181  eType->clear();
182  eColTWidth->setValue(0);
183  eColTDec->setValue(0);
184  eColHeader->setText("");
185  eColWidth->setValue(0);
186  eColName->setText("");
187 // str = table->getFieldType((const char*) ComboBoxTable->currentText().utf8(),(const char*)ListCol->currentText().utf8());
188  //if(eColHeader->text="")
189 // ListCol->blockSignals( TRUE );
190  //ListCol->changeItem(s, ListCol->currentItem());
191 
192 // printf(">>>read property DefHeaders in %s\n", table->name());
193 // lst = table->property("DefHeaders").toStringList();
194 // printf(">>>ok!\n");
195 // ListCol->clear();
196 // printf(">>>insert str list\n");
197 // ListCol->insertStringList(lst);
198 // ListCol->setCurrentItem(col);
199 // ListCol->blockSignals( FALSE );
200  if(col==-1 || ListCol->count()==0) return;
201 // printf(">>>set text in eColHeader\n");
202  eColHeader->setText(ListCol->currentText());
203  eColHeader->blockSignals(false);
204  ind = ListCol->currentItem();
205  str = cwidth[ind];
206  eColWidth->setValue(atoi(str));
207  eColWidth->blockSignals(false);
208  str = fname[ind];
209  eColName->setText(str);
210 // eType->clear();
211 // printf(">>>get fields type\n");
212 // str = eColName->text();
213 
214  str = table->getFieldType(idlist[ind].toInt());
215 // parse string with type, num, numdec
216  if(!str.isEmpty())
217  {
218  eType->setText(str.left(1));
219  str.remove(0,2);
220  if(!str.isEmpty())
221  {
222 // printf(">>>%s\n",str.ascii());
223  eColTWidth->setValue(atoi(str));
224  }
225  ind = str.find(" ");
226  if(ind)// poisk decimal chasti
227  {
228  s = str.remove(0,str.find(" "));
229  }
230  else
231  {
232  str="0";
233  }
234 // printf(">>>%s\n",str.ascii());
235  eColTDec->setValue(atoi(str));
236  }
237  else
238  {
239 // printf(">>>unknown field\n");
240  }
241  /*
242  tablefield *f;
243 
244  if (col >= 0 && col < tablerow_columns( r )) {
245  f = tablerow_column( r, col );
246  blockSignals( true );
247  eColHeader->setText(trUtf8(tablefield_header( f )));
248  eColWidth->setValue(f->sizex);
249  eType->setCurrentItem(f->ftypeindex);
250  eColName->setText(trUtf8(f->name));
251  eColTWidth->setValue(f->flen);
252  eColTDec->setValue(f->decimals);
253  blockSignals( false );
254  }
255 */
256 }
257 
258 
259 void eDBTable::ColumnUpd()
260 {
261 QStringList lst;
262 int id;
263 QValueList<int> listTableId;
264  id = table->getTableId(ComboBoxTable->currentItem()-1);
265  listTableId = table->getBindList();
266  if(listTableId.find(id)!=listTableId.end())
267  {
268  cfg_message(0,tr("table in use, please select another table"));
269  // ComboBoxTable->setCurrentItem(table->getTableInd(table->property("TableInd").toInt()));
270  ListCol->clear();
271  ListCol->insertItem("table in use!");
272  ListCol->setEnabled(false);
273  bOK->setEnabled(false);
274  ColumnSel(-1); // clear all line edit and labels
275  return;
276  }
277  if(!ListCol->isEnabled()) ListCol->setEnabled(true);
278  if(!bOK->isEnabled()) bOK->setEnabled(true);
279  lst = table->getFields(id);
280  ListCol->clear();
281  fname = lst;
282  idlist = table->getFields(id,true);
283  ListCol->insertStringList(lst,0);
284  cwidth.clear();
285  for(uint i=0; i<lst.count();i++)
286  {
287  cwidth << table->property("DefaultColWidth").toString();
288  }
289  //fname = table->fname;
290  findDeletedFields(id,idlist);
291 
292 }
293 
294 
295 void eDBTable::getData( wDBTable *t )
296 {
297 QStringList lst;
298 QString str, str2;
299 int i;
300 const QSqlFieldInfo *f;
301  if(ComboBoxTable->count())
302  {
303  // t->setProperty("TableInd", tables[ComboBoxTable->currentItem()].section("\t",0,0).toInt())
304  t->setProperty("TableInd",t->getTableId(ComboBoxTable->currentItem()-1));
305  i=0;
306  while(i<t->numCols())
307  {
308  t->removeColumn(0);
309  ++i;
310  }
311  t->cur->clear();
312  for(uint j=0; j<ListCol->count(); j++)
313  {
314  ListCol->setCurrentItem(j);
315  str = ListCol->currentText();
316  lst << str;
317  f = new QSqlFieldInfo(fname[j]);
318  t->cur->append(*f);
319  t->setSqlCursor(t->cur);
320  t->addColumn(f->name(),str,atoi(cwidth[j].ascii()));
321  t->refresh(QDataTable::RefreshColumns);
322  }
323  t->setProperty("DefHeaders",lst);
324  t->setProperty("DefFields",fname);
325  t->setProperty("DefIdList",idlist);
326  t->setProperty("ColWidth", cwidth);
327  }
328  else
329  {
330  t->setProperty("TableInd",-1);
331  }
332 }
333 
334 
335 void eDBTable::setData( wDBTable * t, aCfg *md )
336 
337 {
338 QStringList sl;
339 QString ft,h,n;
340 int idTable;
341 bool ok;
342 QStringList lst,lst_full;
343 aCfgItem own;
344 aWidget *wo;
345  table = t;
346 // md->print();
347 // own =
348  // wo = aWidget::parentContainer( t );
349  // if ( !wo ) return;
350  // tables = md->objTables( wo->getId() );
351  // QString wotype = wo->className();
352 // if ( wotype == "wDocument" ) tables.remove( tables[0] );
353 // if ( wotype == "wCatalogue" ) tables.remove( tables[1] );
354 // printf("tables=\n%s\n", ( const char *) tables.join("\n") );
355 // for ( unsigned int i=0; i < tables.count(); i++ ) {
356 // ComboBoxTable->insertItem( tables[ i ].section("\t", 1 ) );
357 // }
358 // ComboBoxTable->insertItem("None");
359  ComboBoxTable->insertStringList(table->list_available_tables, 1);
360  idTable = table->property("TableInd").toInt(&ok);
361  // printf("table ind = %i, id table =%i\n", t->getTableInd(idTable), idTable );
362 
363  ComboBoxTable->setCurrentItem(1+t->getTableInd(idTable));
364  if(ok && idTable>-1)
365  {
366  // v = new QVariant(lst);
367  // }
368  // else
369  // {
370  // table->setFields(t->getTableId(0));
371  // v = new QVariant(lst);
372  //table->setProperty("DefFields",*v);
373  // }
374  // v = new QVariant(lst);
375 // table->setProperty("DefHeaders",*v);
376  // table->setProperty("ColWidth",*v);
377  //ComboBoxTable->setFocus();
378 // tmp_table = *t;
379  lst = table->property("DefHeaders").toStringList();
380  ListCol->insertStringList(lst,0);
381  cwidth = table->property("ColWidth").toStringList();
382  fname = table->property("DefFields").toStringList();
383  idlist = table->property("DefIdList").toStringList();
384  findDeletedFields(idTable,idlist);
385  }
386  else
387  {
388  ColumnUpd();
389  }
390  ListCol->setFocus();
391  /* if(!ListCol->isEmpty())
392  {
393  ColumnSel(0);
394  }
395  */
396  /*
397  if (!t->getDefineCols().isEmpty()) {
398  sl = QStringList::split("\n",t->getDefineCols());
399  for (i = 0; i < sl.count(); i++) {
400  sscanf((const char *)sl[i].section("|",3,3),"%s %d %d", st, &l, &d);
401  if (st[0]=='O') ft.sprintf("O %d",l);
402  else ft=st;
403  w = sl[i].section("|",2,2).toInt();
404  h = sl[i].section("|",5,5);
405  n = sl[i].section("|",4,4);
406  for (idxt = otypes.count()-1; idxt>0; idxt--) {
407  if (ft[0]=='O' && otypes[idxt]==ft) break;
408  else if (otypes[idxt][0]==ft[0]) break;
409  }
410  printf("set data %i = %s %s %i %i %i\n", i,
411  (const char *)h, (const char *)n, idxt, w, l);
412  insertColumn(h,n,idxt,w,l,d);
413  }
414  }
415  */
416 
417 
418 }
419 
420 
421 void eDBTable::ColumnTextUpd( const QString &s )
422 {
423 CHECK_POINT
424 
425  int idx;
426  idx = ListCol->currentItem();
427  if (idx == -1) return;
428  ListCol->blockSignals( TRUE );
429  ListCol->changeItem(s, ListCol->currentItem());
430  ListCol->blockSignals( FALSE );
431 
432 }
433 
434 
435 void eDBTable::doOK()
436 {
437  getData(table);
438  accept();
439 }
440 
441 
442 void eDBTable::ColumnAdd()
443 {
444 QString s;
445 QString idx;
446 QStringList::Iterator it;
447  addfdialog e( this->topLevelWidget());
448  e.setData(deletedFields,deletedFields,deletedFieldsId);
449  if ( e.exec()==QDialog::Accepted )
450  {
451  idx = e.getData(false);
452 // printf(">>>idx = %s\n",idx.ascii());
453  if(idx=="0") return;
454  s = table->getFieldName(idx.toInt());
455  idlist << idx;
456 // printf(">>> add field = '%s'\n",s.ascii());
457  ListCol->insertItem(s,ListCol->count());
458  fname << s;
459  cwidth << table->property("DefaultColWidth").toString();
460  it = deletedFields.find(s);
461  deletedFields.remove(it);
462  it = deletedFieldsId.find(idx);
463  deletedFieldsId.remove(it);
464 // table->addColumn(s,s,100);
465  }
466 }
467 
468 
469 void eDBTable::ColWidthChange( int value )
470 {
471  int ind;
472  QString num;
473  ind = ListCol->currentItem();
474  if(ind!=-1)
475  {
476  cwidth[ind] = num.setNum(value);
477  }
478 
479 }
480 
481 
482 QStringList
483 eDBTable::findDeletedFields( int t_num ,QStringList idls)
484 {
485  QStringList lst_full;
486  deletedFields.clear();
487  //formiruem list udalennix poley
488  lst_full = table->getFields(t_num,true);
489  for(unsigned int i=0;i<lst_full.count();i++)
490  {
491 // printf(">>>field '%s'\n",lst_full[i].ascii());
492  if(idls.find(lst_full[i])==idls.end())
493  {
494  deletedFieldsId << lst_full[i];
495  deletedFields << table->getFieldName(lst_full[i].toInt());
496  }
497  }
498 return deletedFields;
499 }
500 
501 
502 void eDBTable::doCancel()
503 {
504 }
Definition: acfg.h:436
int getTableInd(int id)
Definition: wdbtable.cpp:717
int getTableId(int ind)
Definition: wdbtable.cpp:677
Definition: awidget.h:52
Definition: wdbtable.h:77