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 00010 void QlabCategorySelector::init() 00011 { 00012 catCursor = new QSqlCursor( "System_categories", TRUE ) ; 00013 categoryList->setColumnWidth( 0, 100 ) ; 00014 categoryList->setColumnWidth( 2, 0 ) ; 00015 categoryList->setColumnWidthMode( 1, QListView::Maximum ) ; 00016 } 00017 00018 void QlabCategorySelector::selectionChanged( QListViewItem * item ) 00019 { 00020 if ( item->text( 2 ) == "0" ) { 00021 okButton->setEnabled( FALSE ) ; 00022 } else { 00023 okButton->setEnabled( TRUE ) ; 00024 catId = item->text( 2 ).toInt() ; 00025 } 00026 } 00027 00028 00029 void QlabCategorySelector::setApplicationName( const QString & name ) 00030 { 00031 QSqlQuery q( QString( "SELECT recid FROM System_modules " 00032 "WHERE mod_name='%1' ;").arg( name ) ) ; 00033 if ( q.next() ) { 00034 defaultFilter = QString( "cat_appname=%1").arg( q.value( 0 ).toString() ); 00035 activeFilter = "active=1" ; 00036 } else { 00037 qDebug( "Unknown Application Module" ) ; 00038 exit( 1 ) ; 00039 } 00040 fillTree() ; 00041 } 00042 00043 00044 00045 void QlabCategorySelector::fillTree() 00046 { 00047 QListViewItem * element ; 00048 categoryList->clear() ; 00049 catCursor->setFilter( QString( "%1 AND %2" ).arg( defaultFilter ).arg( activeFilter ) ) ; 00050 catCursor->index( "cat_parent" ) ; 00051 catCursor->select() ; 00052 element = new QListViewItem( categoryList, tr( "ROOT" ), tr( "Main" ), "0" ) ; 00053 while ( catCursor->next() ) { 00054 element = categoryList->findItem( catCursor->value( "cat_parent").toString(), 2 ) ; 00055 element = new QListViewItem( element, 00056 catCursor->value( "cat_abridged" ).toString(), 00057 catCursor->value( "cat_name" ).toString(), 00058 catCursor->value( "recid" ).toString() ) ; 00059 } 00060 categoryList->setSelected( categoryList->firstChild(), TRUE ) ; 00061 categoryList->setOpen( categoryList->selectedItem(), TRUE ) ; 00062 selectionChanged( categoryList->currentItem() ) ; 00063 } 00064 00065 00066 int QlabCategorySelector::getCategoryId() 00067 { 00068 return catId ; 00069 }