00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <stdlib.h>
00040 #include "wdbtable.h"
00041
00042 void eDBTable::init()
00043 {
00044 }
00045
00046
00047 void
00048 eDBTable::destroy()
00049 {
00050
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 void eDBTable::ColumnDel()
00088 {
00089
00090 int idx;
00091 QString str;
00092 idx = ListCol->currentItem();
00093 if (idx != -1 && ListCol->count()>0)
00094 {
00095 str = fname[idx];
00096 table->removeColumn(idx);
00097 deletedFields.append(str);
00098 deletedFieldsId.append(idlist[idx]);
00099 idlist.remove(idlist.at(idx));
00100 fname.remove(fname.at(idx));
00101 cwidth.remove(cwidth.at(idx));
00102 ListCol->removeItem(idx);
00103
00104 }
00105 }
00106
00107 void eDBTable::ColumnL()
00108 {
00109 int idx;
00110 QString str;
00111 QStringList::Iterator it;
00112 idx = ListCol->currentItem();
00113 if(idx>0)
00114 {
00115 str = fname[idx];
00116 it = fname.at(idx);
00117 fname.remove(it);
00118 it = fname.at(idx-1);
00119 fname.insert(it,str);
00120
00121 str = idlist[idx];
00122 it = idlist.at(idx);
00123 idlist.remove(it);
00124 it = idlist.at(idx-1);
00125 idlist.insert(it,str);
00126
00127 str = cwidth[idx];
00128 it = cwidth.at(idx);
00129 cwidth.remove(it);
00130 it = cwidth.at(idx-1);
00131 cwidth.insert(it,str);
00132
00133 str = ListCol->currentText();
00134 ListCol->removeItem(idx);
00135 ListCol->insertItem(str,idx-1);
00136 ListCol->setSelected(idx-1,true);
00137 }
00138 }
00139
00140
00141 void eDBTable::ColumnR()
00142 {
00143 uint idx;
00144 QString str;
00145 QStringList::Iterator it;
00146 idx = ListCol->currentItem();
00147 if(idx<ListCol->count()-1)
00148 {
00149 str = fname[idx];
00150 it = fname.at(idx);
00151 fname.remove(it);
00152 it = fname.at(idx+1);
00153 fname.insert(it,str);
00154
00155 str = idlist[idx];
00156 it = idlist.at(idx);
00157 idlist.remove(it);
00158 it = idlist.at(idx+1);
00159 idlist.insert(it,str);
00160
00161 str = cwidth[idx];
00162 it = cwidth.at(idx);
00163 cwidth.remove(it);
00164 it = cwidth.at(idx+1);
00165 cwidth.insert(it,str);
00166
00167 str = ListCol->currentText();
00168 ListCol->removeItem(idx);
00169 ListCol->insertItem(str,idx+1);
00170 ListCol->setSelected(idx+1,true);
00171 }
00172
00173 }
00174 void eDBTable::ColumnSel(int col)
00175 {
00176 QString str,s;
00177 int ind = 0;
00178 QStringList lst;
00179 eColHeader->blockSignals(true);
00180 eColWidth->blockSignals(true);
00181 eType->clear();
00182 eColTWidth->setValue(0);
00183 eColTDec->setValue(0);
00184 eColHeader->setText("");
00185 eColWidth->setValue(0);
00186 eColName->setText("");
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 if(col==-1 || ListCol->count()==0) return;
00201
00202 eColHeader->setText(ListCol->currentText());
00203 eColHeader->blockSignals(false);
00204 ind = ListCol->currentItem();
00205 str = cwidth[ind];
00206 eColWidth->setValue(atoi(str));
00207 eColWidth->blockSignals(false);
00208 str = fname[ind];
00209 eColName->setText(str);
00210
00211
00212
00213
00214 str = table->getFieldType(idlist[ind].toInt());
00215
00216 if(!str.isEmpty())
00217 {
00218 eType->setText(str.left(1));
00219 str.remove(0,2);
00220 if(!str.isEmpty())
00221 {
00222
00223 eColTWidth->setValue(atoi(str));
00224 }
00225 ind = str.find(" ");
00226 if(ind)
00227 {
00228 s = str.remove(0,str.find(" "));
00229 }
00230 else
00231 {
00232 str="0";
00233 }
00234
00235 eColTDec->setValue(atoi(str));
00236 }
00237 else
00238 {
00239
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 }
00257
00258
00259 void eDBTable::ColumnUpd()
00260 {
00261 QStringList lst;
00262 int id;
00263 QValueList<int> listTableId;
00264 id = table->getTableId(ComboBoxTable->currentItem()-1);
00265 listTableId = table->getBindList();
00266 if(listTableId.find(id)!=listTableId.end())
00267 {
00268 cfg_message(0,tr("table in use, please select another table"));
00269
00270 ListCol->clear();
00271 ListCol->insertItem("table in use!");
00272 ListCol->setEnabled(false);
00273 bOK->setEnabled(false);
00274 ColumnSel(-1);
00275 return;
00276 }
00277 if(!ListCol->isEnabled()) ListCol->setEnabled(true);
00278 if(!bOK->isEnabled()) bOK->setEnabled(true);
00279 lst = table->getFields(id);
00280 ListCol->clear();
00281 fname = lst;
00282 idlist = table->getFields(id,true);
00283 ListCol->insertStringList(lst,0);
00284 cwidth.clear();
00285 for(uint i=0; i<lst.count();i++)
00286 {
00287 cwidth << table->property("DefaultColWidth").toString();
00288 }
00289
00290 findDeletedFields(id,idlist);
00291
00292 }
00293
00294
00295 void eDBTable::getData( wDBTable *t )
00296 {
00297 QStringList lst;
00298 QString str, str2;
00299 int i;
00300 const QSqlFieldInfo *f;
00301 if(ComboBoxTable->count())
00302 {
00303
00304 t->setProperty("TableInd",t->getTableId(ComboBoxTable->currentItem()-1));
00305 i=0;
00306 while(i<t->numCols())
00307 {
00308 t->removeColumn(0);
00309 ++i;
00310 }
00311 t->cur->clear();
00312 for(uint j=0; j<ListCol->count(); j++)
00313 {
00314 ListCol->setCurrentItem(j);
00315 str = ListCol->currentText();
00316 lst << str;
00317 f = new QSqlFieldInfo(fname[j]);
00318 t->cur->append(*f);
00319 t->setSqlCursor(t->cur);
00320 t->addColumn(f->name(),str,atoi(cwidth[j].ascii()));
00321 t->refresh(QDataTable::RefreshColumns);
00322 }
00323 t->setProperty("DefHeaders",lst);
00324 t->setProperty("DefFields",fname);
00325 t->setProperty("DefIdList",idlist);
00326 t->setProperty("ColWidth", cwidth);
00327 }
00328 else
00329 {
00330 t->setProperty("TableInd",-1);
00331 }
00332 }
00333
00334
00335 void eDBTable::setData( wDBTable * t, aCfg *md )
00336
00337 {
00338 QStringList sl;
00339 QString ft,h,n;
00340 int idTable;
00341 bool ok;
00342 QStringList lst,lst_full;
00343 aCfgItem own;
00344 aWidget *wo;
00345 table = t;
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 ComboBoxTable->insertStringList(table->list_available_tables, 1);
00360 idTable = table->property("TableInd").toInt(&ok);
00361
00362
00363 ComboBoxTable->setCurrentItem(1+t->getTableInd(idTable));
00364 if(ok && idTable>-1)
00365 {
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379 lst = table->property("DefHeaders").toStringList();
00380 ListCol->insertStringList(lst,0);
00381 cwidth = table->property("ColWidth").toStringList();
00382 fname = table->property("DefFields").toStringList();
00383 idlist = table->property("DefIdList").toStringList();
00384 findDeletedFields(idTable,idlist);
00385 }
00386 else
00387 {
00388 ColumnUpd();
00389 }
00390 ListCol->setFocus();
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418 }
00419
00420
00421 void eDBTable::ColumnTextUpd( const QString &s )
00422 {
00423 CHECK_POINT
00424
00425 int idx;
00426 idx = ListCol->currentItem();
00427 if (idx == -1) return;
00428 ListCol->blockSignals( TRUE );
00429 ListCol->changeItem(s, ListCol->currentItem());
00430 ListCol->blockSignals( FALSE );
00431
00432 }
00433
00434
00435 void eDBTable::doOK()
00436 {
00437 getData(table);
00438 accept();
00439 }
00440
00441
00442 void eDBTable::ColumnAdd()
00443 {
00444 QString s;
00445 QString idx;
00446 QStringList::Iterator it;
00447 addfdialog e( this->topLevelWidget());
00448 e.setData(deletedFields,deletedFields,deletedFieldsId);
00449 if ( e.exec()==QDialog::Accepted )
00450 {
00451 idx = e.getData(false);
00452
00453 if(idx=="0") return;
00454 s = table->getFieldName(idx.toInt());
00455 idlist << idx;
00456
00457 ListCol->insertItem(s,ListCol->count());
00458 fname << s;
00459 cwidth << table->property("DefaultColWidth").toString();
00460 it = deletedFields.find(s);
00461 deletedFields.remove(it);
00462 it = deletedFieldsId.find(idx);
00463 deletedFieldsId.remove(it);
00464
00465 }
00466 }
00467
00468
00469 void eDBTable::ColWidthChange( int value )
00470 {
00471 int ind;
00472 QString num;
00473 ind = ListCol->currentItem();
00474 if(ind!=-1)
00475 {
00476 cwidth[ind] = num.setNum(value);
00477 }
00478
00479 }
00480
00481
00482 QStringList
00483 eDBTable::findDeletedFields( int t_num ,QStringList idls)
00484 {
00485 QStringList lst_full;
00486 deletedFields.clear();
00487
00488 lst_full = table->getFields(t_num,true);
00489 for(unsigned int i=0;i<lst_full.count();i++)
00490 {
00491
00492 if(idls.find(lst_full[i])==idls.end())
00493 {
00494 deletedFieldsId << lst_full[i];
00495 deletedFields << table->getFieldName(lst_full[i].toInt());
00496 }
00497 }
00498 return deletedFields;
00499 }
00500
00501
00502 void eDBTable::doCancel()
00503 {
00504 }