Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

categoryeditor.ui.h

00001 /****************************************************************************
00002 ** ui.h extension file, included from the uic-generated form implementation.
00003 **
00004 ** If you wish to add, delete or rename functions or slots use
00005 ** Qt Designer which will update this file, preserving your code. Create an
00006 ** init() function in place of a constructor, and a destroy() function in
00007 ** place of a destructor.
00008 *****************************************************************************/
00009 
00014 void CategoryEditor::init()
00015 {
00016 }
00017 
00023 void CategoryEditor::validateChanges()
00024 {
00025     qDebug( "Validating changes" ) ;
00026     QSqlRecord * buffer ;
00027     QListViewItem *item = cursor->currentItem() ;
00028     int catid ;
00029     if ( mode == 1 ) {
00030         qDebug( "Creating" ) ;
00031                 // Create Mode
00032                 buffer = categories->primeInsert() ;
00033                 catid =SequenceGetNextValue( "System_categories" ).toInt() ;
00034                 buffer->setValue( "recid",  catid ) ;
00035                 buffer->setValue( "cat_parent", item->text( 2 ).toInt() ) ;
00036                 buffer->setValue( "cat_appname", application ) ;
00037                 buffer->setValue( "created", QDateTime::currentDateTime() ) ;
00038                 buffer->setValue( "lastchanged", QDateTime::currentDateTime() ) ;
00039                 buffer->setValue( "lastchangedreason", "Creation" ) ;
00040     } else {
00041                 // Edit Mode
00042                 buffer = categories->primeUpdate() ;
00043                 catid = buffer->value( "recid" ).toInt() ;
00044                 buffer->setValue( "lastchanged", QDateTime::currentDateTime() ) ;
00045                 buffer->setValue( "lastchangedreason", "Edition" ) ;
00046     }
00047     buffer->setValue( "cat_abridged", cat_abridged->text().upper() ) ;
00048     buffer->setValue( "cat_name", cat_name->text() ) ;
00049     buffer->setValue( "cat_description", cat_description->text() ) ;
00050     buffer->setValue( "cat_access", cat_access->getId() ) ;
00051     buffer->setValue( "active", active->isChecked() ? 1 : 0 ) ;
00052     // Now we have to see options
00053     int optnum = optionsTable->numRows() ;
00054         qDebug( QString( "Got %1 Rows to save" ).arg( optnum ) ) ;
00055     if ( mode == 1 ) {
00056         // Create Mode
00057                 for ( int i = 0; i < optnum; i++ ) {
00058                     qDebug( QString( "Saving option %1" ).arg( i ) ) ;
00059                     QSqlRecord * line = options->primeInsert() ;
00060                     qDebug( "recid" ) ;
00061                     line->setValue( "recid", SequenceGetNextValue( "System_categories_options" ).toInt() ) ;
00062                     qDebug( "parent_id" ) ;
00063                     line->setValue( "parent_id", 0 ) ;
00064                     qDebug( "cat_id" ) ;
00065                     line->setValue( "cat_id", catid ) ;
00066                     qDebug( "label" ) ;
00067                     line->setValue( "option_label", optionsTable->text( i, 0 ) ) ;
00068                     qDebug( "name" ) ;
00069                     line->setValue( "option_name", optionsTable->cellWidget( i, 1 )->name() ) ;
00070                     QSqlQuery q( QString( "SELECT recid FROM System_widgets WHERE wid_class='%1'" )
00071                                 .arg( optionsTable->cellWidget( i, 1 )->className() ) ) ;
00072                     q.next() ;
00073                     qDebug( "type" ) ;
00074                     line->setValue( "option_type", q.value( 0 ).toInt() ) ;
00075                     qDebug( "evaluator" ) ;
00076                     QWidget * wid =  optionsTable->cellWidget( i, 1 ) ;
00077                     QMetaObject * mo = wid->metaObject() ;
00078                     QString wclass = wid->className() ;
00079                     wclass = wclass.lower() ;
00080                     QStrList list = mo->slotNames() ;
00081                     if ( list.find( "getId" ) ) {
00082                         if ( wclass == "qlabaccessmodeselector" ) {
00083                             QlabAccessModeSelector * mw = (QlabAccessModeSelector *)wid ;
00084                             line->setValue( "option_data", mw->getId() ) ;
00085                         } else if ( wclass == "labbillmodesselector" ) {
00086                             LabBillModesSelector * mw = (LabBillModesSelector *)wid ;
00087                             line->setValue( "option_data", mw->getId() ) ;
00088                         } else if ( wclass == "labcontactselector" ) {
00089                             LabContactSelector * mw = (LabContactSelector *)wid ;
00090                             line->setValue( "option_data", mw->getId() ) ;
00091                         } else if ( wclass == "labcountryselector" ) {
00092                             LabCountrySelector * mw = (LabCountrySelector *)wid ;
00093                             line->setValue( "option_data", mw->getId() ) ;
00094                         } else if ( wclass == "labcurrencyselector" ) {
00095                             LabCurrencySelector * mw = (LabCurrencySelector *)wid ;
00096                             line->setValue( "option_data", mw->getId() ) ;
00097                         } else if ( wclass == "labdiscountruleselector" ) {
00098                             LabDiscountRuleSelector * mw = (LabDiscountRuleSelector *)wid ;
00099                             line->setValue( "option_data", mw->getId() ) ;
00100                         } else if ( wclass == "labglaccountselector" ) {
00101                             LabGlAccountSelector * mw = (LabGlAccountSelector *)wid ;
00102                             line->setValue( "option_data", mw->getId() ) ;
00103                         } else if ( wclass == "labinvbrandsselector" ) {
00104                             LabInvBrandsSelector * mw = (LabInvBrandsSelector *)wid ;
00105                             line->setValue( "option_data", mw->getId() ) ;
00106                         } else if ( wclass == "labpaymodesselector" ) {
00107                             LabPayModesSelector * mw = (LabPayModesSelector *)wid ;
00108                             line->setValue( "option_data", mw->getId() ) ;
00109                         } else if ( wclass == "labtaxselector" ) {
00110                             LabTaxSelector * mw = (LabTaxSelector *)wid ;
00111                             line->setValue( "option_data", mw->getId() ) ;
00112                         } 
00113                     } else {
00114                         QLineEdit * mw = (QLineEdit * )optionsTable->cellWidget( i, 1 ) ;
00115                         QString value = mw->text() ;
00116                         line->setValue( "option_data", value ) ;
00117                     }
00118                     line->setValue( "option_pos", i +1 ) ;
00119                     options->insert() ;
00120                 }
00121                 QListViewItem * item = cursor->currentItem() ;
00122                 item = new QListViewItem( item,
00123                                      buffer->value( "cat_abridged" ).toString(),
00124                                      buffer->value( "cat_name" ).toString(),
00125                                      buffer->value( "recid" ).toString() ) ;
00126                 cursor->setCurrentItem( item ) ;
00127                 cursor->setSelected( item, TRUE ) ;
00128                 cursor->ensureItemVisible( item ) ;
00129                 
00130     } else {
00131                 // Edit Mode
00132                 options->setFilter( QString( "cat_id=%1" ).arg( item->text( 2 ) ) ) ;
00133                 options->setSort( QSqlIndex( "option_pos" ) ) ;
00134                 options->select() ;
00135                 qDebug( options->lastQuery() ) ;
00136                 int i = 0 ;
00137                 while ( options->next() ) {
00138                     QSqlRecord * line = options->primeUpdate() ;
00139                     QWidget * wid =  optionsTable->cellWidget( i, 1 ) ;
00140                     QMetaObject * mo = wid->metaObject() ;
00141                     QString wclass = wid->className() ;
00142                     wclass = wclass.lower() ;
00143                     QStrList list = mo->slotNames() ;
00144                     if ( list.find( "getId" ) ) {
00145                         if ( wclass == "qlabaccessmodeselector" ) {
00146                             QlabAccessModeSelector * mw = (QlabAccessModeSelector *)wid ;
00147                             line->setValue( "option_data", mw->getId() ) ;
00148                         } else if ( wclass == "labbillmodesselector" ) {
00149                             LabBillModesSelector * mw = (LabBillModesSelector *)wid ;
00150                             line->setValue( "option_data", mw->getId() ) ;
00151                         } else if ( wclass == "labcontactselector" ) {
00152                             LabContactSelector * mw = (LabContactSelector *)wid ;
00153                             line->setValue( "option_data", mw->getId() ) ;
00154                         } else if ( wclass == "labcountryselector" ) {
00155                             LabCountrySelector * mw = (LabCountrySelector *)wid ;
00156                             line->setValue( "option_data", mw->getId() ) ;
00157                         } else if ( wclass == "labcurrencyselector" ) {
00158                             LabCurrencySelector * mw = (LabCurrencySelector *)wid ;
00159                             line->setValue( "option_data", mw->getId() ) ;
00160                         } else if ( wclass == "labdiscountruleselector" ) {
00161                             LabDiscountRuleSelector * mw = (LabDiscountRuleSelector *)wid ;
00162                             line->setValue( "option_data", mw->getId() ) ;
00163                         } else if ( wclass == "labglaccountselector" ) {
00164                             LabGlAccountSelector * mw = (LabGlAccountSelector *)wid ;
00165                             line->setValue( "option_data", mw->getId() ) ;
00166                         } else if ( wclass == "labinvbrandsselector" ) {
00167                             LabInvBrandsSelector * mw = (LabInvBrandsSelector *)wid ;
00168                             line->setValue( "option_data", mw->getId() ) ;
00169                         } else if ( wclass == "labpaymodesselector" ) {
00170                             LabPayModesSelector * mw = (LabPayModesSelector *)wid ;
00171                             line->setValue( "option_data", mw->getId() ) ;
00172                         } else if ( wclass == "labtaxselector" ) {
00173                             LabTaxSelector * mw = (LabTaxSelector *)wid ;
00174                             line->setValue( "option_data", mw->getId() ) ; 
00175                         }
00176                     } else {
00177                                 QLineEdit * mw = (QLineEdit * )optionsTable->cellWidget( i, 1 ) ;
00178                                 QString value = mw->text() ;
00179                                 line->setValue( "option_data", value );
00180                         }
00181                         options->update( FALSE ) ;
00182                         i++ ;
00183                 }
00184     }
00185     if ( mode == 1 ) {
00186         categories->insert() ;
00187     } else {
00188         categories->update() ;
00189     }
00190     qDebug( categories->lastQuery() ) ;
00191     accept() ;
00192 }
00193 
00194 
00195 void CategoryEditor::optionAdd()
00196 {
00197     OptionDesigner * dialog = new OptionDesigner( this, "Option Designer", TRUE ) ;
00198     QListViewItem * item = cursor->currentItem() ;
00199     dialog->setRecipient( "System_categories_options", item->text( 2 ).toInt(), "cat_id" ) ;
00200     if ( dialog->exec() == QDialog::Accepted ) {
00201         options->setFilter( QString( "cat_id=%1" ).arg( item->text( 2 ) ) ) ;
00202         options->setSort( QSqlIndex( "option_pos" ) ) ;
00203         options->select() ;
00204         int num = options->size() ;
00205         int curr = 0 ;
00206         while ( options->next() ) {
00207             if ( curr != num -1 ) {
00208                 curr ++ ;
00209             } else {
00210                 optionsTable->setText( curr, 0, options->value( "option_label" ).toString() ) ;
00211                 QString  wid_name = options->value( "option_name" ).toString() ;
00212                 QString wid_data = options->value( "option_data" ).toString() ;
00213                 QWidget * target = (QWidget *)optionsTable ;
00214                 labFactory->postWidget( options->value( "option_type" ).toInt(), wid_name, wid_data, target, curr, 1 ) ;
00215                 optionsTable->selectRow( num - 1 ) ;
00216             }
00217         }
00218     }
00219     delete dialog ;
00220 }
00221 
00222 
00223 void CategoryEditor::optionDel()
00224 {
00225 
00226 }
00227 
00228 
00229 void CategoryEditor::optionUp()
00230 {
00231     int curr = optionsTable->currentRow() ;
00232     qDebug( QString( "current row is %1" ).arg( curr ) ) ;
00233     if ( curr > 0 ) {
00234         optionsTable->swapRows( curr, curr -1 ) ;
00235         optionsTable->selectRow( curr -1 ) ;
00236         optionsTable->repaint( TRUE ) ;
00237     }
00238 }
00239 
00240 
00241 void CategoryEditor::optionDown()
00242 {
00243     int curr = optionsTable->currentRow() ;
00244     qDebug( QString( "current row is %1" ).arg( curr ) ) ;
00245     if ( curr < optionsTable->numRows() -1  ) {
00246         optionsTable->swapRows( curr, curr +1 ) ;
00247         optionsTable->selectRow( curr +1 ) ;    
00248         optionsTable->repaint( TRUE ) ;
00249     }
00250 }
00251 
00252 
00253 bool CategoryEditor::setMode( int md, QListView * c, int app )
00254 {
00255     qDebug( "Setting Mode" ) ;
00256     mode = md ;
00257     cursor = c ;
00258     application = app ;
00259     categories = new QSqlCursor( "System_categories", TRUE ) ;
00260     QListViewItem * item = c->currentItem() ;
00261     if ( item->text( 2 ) != "0" ) {
00262                 categories->setFilter( QString( "recid=%1" ).arg( item->text( 2 ) ) ) ;
00263                 categories->select() ;
00264                 if ( !categories->next() ) {
00265                         // Means someone directly tweaked categories table by hand.
00266                         // We have to post a fatal Error and reject the whole thing.
00267                         QMessageBox::critical( this, tr( "Category Editor Error"),
00268                                         tr( "Unable to find needed category\n\n"
00269                                                         "This means someone deleted this category\n"
00270                                                         "at the same time you wanted to edit it.\n\n"
00271                                                         "I must reject your request and clean up your\n"
00272                                                         "category list. Sorry for the inconvenience\n" ),
00273                                         tr( "Ok" ) , 0, 0 )   ;
00274                         cursor->setCurrentItem( item->parent() ) ;
00275                     cursor->ensureItemVisible( item->parent() ) ;
00276                 delete item  ;
00277                         return FALSE ;
00278                 }
00279     }
00280     options = new QSqlCursor( "System_categories_options", TRUE ) ;
00281     options->setFilter( QString( "cat_id=%1" ).arg( item->text( 2 ) ) ) ;
00282     options->setSort( QSqlIndex( "option_pos" ) ) ;
00283     options->select() ;
00284     int num = options->size() ;
00285     while ( optionsTable->numRows() > 0 ) {
00286         optionsTable->removeRow( 0 ) ;
00287     }
00288     optionsTable->setNumRows( num ) ;
00289     int currRow = 0 ;
00290     switch ( md ) {
00291         case 1 : 
00292             editModeLabel->setText( tr( "Creation" ) ) ; 
00293             if ( item->text( 2 ) != "0" ) {
00294                 cat_access->setActive( categories->value( "cat_access" ).toInt() ) ;
00295                 active->setChecked( categories->value( "active" ).toBool() ) ;
00296                 cat_abridged->setText( "" ) ;
00297             }
00298             break ;
00299         case 2 : 
00300                 editModeLabel->setText( tr( "Edition" ) ) ; 
00301                 cat_abridged->setText( categories->value( "cat_abridged" ).toString() ) ;
00302                 cat_name->setText( categories->value( "cat_name" ).toString() ) ;
00303                 cat_description->setText( categories->value( "cat_description" ).toString() ) ;
00304                 created->setText( categories->value( "created" ).toString() ) ;
00305                 lastchanged->setText( categories->value( "lastchanged" ).toString() ) ;
00306                 lastchangedreason->setText( categories->value( "lastchangedreason" ).toString() ) ;
00307                 cat_access->setActive( categories->value( "cat_access" ).toInt() ) ;
00308                 active->setChecked( categories->value( "active" ).toBool() ) ;
00309                 break ;
00310             }
00311     while ( options->next() ) {
00312         optionsTable->setText( currRow, 0, options->value( "option_label" ).toString() ) ;
00313         QString  wid_name = options->value( "option_name" ).toString() ;
00314         QString opt_data = options->value( "option_data" ).toString() ;
00315         QWidget * target = (QWidget *)optionsTable ;
00316         labFactory->postWidget( options->value( "option_type" ).toInt(), wid_name, opt_data, target, currRow, 1 ) ;
00317         currRow++ ;                                                    
00318     }
00319     if ( optionsTable->numRows() > 0 ) {
00320         optionsTable->selectRow( 0 ) ;
00321     }
00322     return TRUE ;
00323 }
00324 
00325 
00326 void CategoryEditor::optionSelChanged()
00327 {
00328     qDebug( "optionSelChanged() is fired" ) ;
00329     qDebug( QString("Row is : %1, Column is : %2").arg( optionsTable->currentRow() ).arg( optionsTable->currentColumn() ) ) ;
00330 }

 

L.A.B. Project © 2001-2004 LAB Project & DJ Anubis