00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 static QSqlCursor * curs = new QSqlCursor( "System_categories", TRUE ) ;
00011
00020 void QlabCategoryList::init()
00021 {
00022 categoryList->setColumnWidthMode( 0, QListView::Manual ) ;
00023 categoryList->setColumnWidthMode( 1, QListView::Maximum ) ;
00024 categoryList->setColumnWidth( 0, 100 ) ;
00025 categoryList->setColumnWidth( 1, 200 ) ;
00026 categoryList->setColumnWidth( 2, 0 ) ;
00027 if ( catType.isEmpty() || inInit ) {
00028 return ;
00029 }
00030 inInit = TRUE ;
00031 QSqlCursor * module = new QSqlCursor( "System_modules", TRUE ) ;
00032 module->setFilter( QString( "mod_name='%1'" ).arg( catType ) ) ;
00033 module->select() ;
00034 if ( module->next() ) {
00035 activeModule = module->value( "recid" ).toInt() ;
00036 QSqlCursor * catcursor = new QSqlCursor( "System_categories", TRUE ) ;
00037 catcursor->setFilter( QString( "cat_appname='%1' AND active='%2'" )
00038 .arg( activeModule )
00039 .arg( active ? 1 : 0 ) ) ;
00040 QStringList idx ;
00041 idx << "cat_parent" << "recid" ;
00042 catcursor->index( idx ) ;
00043 catcursor->select() ;
00044 QListViewItem * element ;
00045 categoryList->clear() ;
00046 element = new QListViewItem( categoryList, tr( "ROOT" ), tr( "Main" ), "0" ) ;
00047 while ( catcursor->next() ) {
00048 element = categoryList->findItem( catcursor->value( "cat_parent").toString(), 2 ) ;
00049 element = new QListViewItem( element,
00050 catcursor->value( "cat_abridged" ).toString(),
00051 catcursor->value( "cat_name" ).toString(),
00052 catcursor->value( "recid" ).toString() ) ;
00053 }
00054 categoryList->setSelected( categoryList->firstChild(), TRUE ) ;
00055 categoryList->setOpen( categoryList->selectedItem(), TRUE ) ;
00056 categoryChanged( categoryList->currentItem() ) ;
00057 }
00058 inInit = FALSE ;
00059 }
00060
00061
00068 int QlabCategoryList::currentCategory()
00069 {
00070 return categoryList->currentItem()->text( 2 ).toInt() ;
00071 }
00072
00073
00081 QString QlabCategoryList::categoryType() const
00082 {
00083 return catType ;
00084 }
00085
00086
00100 void QlabCategoryList::setCategoryType( const QString & newType )
00101 {
00102 catType = newType ;
00103 init() ;
00104 }
00105
00106
00123 void QlabCategoryList::setShowActive( bool act )
00124 {
00125 active = act ;
00126 init() ;
00127 emit categoryViewChanged( active ) ;
00128 }
00129
00130
00145 void QlabCategoryList::refresh()
00146 {
00147 init() ;
00148 }
00149
00150
00160 QSqlRecord * QlabCategoryList::addSubCategory()
00161 {
00162 curs->setFilter( QString( "recid='%1'" ).arg( ( categoryList->selectedItem()->text(2) ).toInt() ) ) ;
00163 curs->select() ;
00164 curs->next() ;
00165 int cat_access = curs->value( "cat_access" ).toInt() ;
00166 QString cat_data = curs->value( "cat_data" ).toString() ;
00167 curs->setFilter( "" ) ;
00168 curs->select() ;
00169 buffer = curs->primeInsert() ;
00170 buffer->setValue( "recid", 0 ) ;
00171 buffer->setValue( "cat_appname", activeModule ) ;
00172 buffer->setValue( "cat_parent", ( categoryList->selectedItem()->text(2) ).toInt() ) ;
00173 buffer->setValue( "cat_access", cat_access ) ;
00174 buffer->setValue( "cat_data", cat_data ) ;
00175 buffer->setValue( "active", active ? 1 : 0 ) ;
00176 return buffer ;
00177 }
00178
00179
00189 QSqlRecord * QlabCategoryList::editCurrentCategory()
00190 {
00191 curs->setFilter( QString( "recid='%1'" ).arg( ( categoryList->selectedItem()->text(2) ).toInt() ) ) ;
00192 curs->select() ;
00193 curs->next() ;
00194 buffer = curs->primeUpdate() ;
00195 return buffer ;
00196 }
00197
00198
00214 bool QlabCategoryList::deleteCurrentCategory()
00215 {
00216 curs->setFilter( QString( "recid='%1' AND active='1'" )
00217 .arg( categoryList->currentItem()->text( 2 ) ) ) ;
00218 curs->select() ;
00219 if ( curs->next() ) {
00220 buffer = curs->primeUpdate() ;
00221 buffer->setValue( "active", active ? 0 : 1 ) ;
00222 curs->update() ;
00223 QListViewItem * elem = categoryList->selectedItem() ;
00224 categoryList->setCurrentItem( elem->parent() ) ;
00225 categoryList->ensureItemVisible( elem->parent() ) ;
00226 delete elem ;
00227 } else {
00228 refresh() ;
00229 }
00230 curs->setFilter( "" ) ;
00231 return TRUE ;
00232 }
00233
00234
00242 bool QlabCategoryList::validateChanges()
00243 {
00244 buffer->setValue( "lastchanged", QDateTime::currentDateTime() ) ;
00245 buffer->setValue( "lastchangedID", LabUser->value( "recid" ).toInt() ) ;
00246 if ( buffer->value( "recid" ).toInt() == 0 ) {
00247
00248 buffer->setValue( "recid", SequenceGetNextValue( "System_categories" ) ) ;
00249 buffer->setValue( "created", QDateTime::currentDateTime() ) ;
00250 buffer->setValue( "lastchangedreason", "Creation" ) ;
00251 return ( curs->insert() == 1 ) ;
00252 } else {
00253 return ( curs->update() == 1 ) ;
00254 }
00255 }
00256
00257
00274 void QlabCategoryList::reparent( int source, int newParent )
00275 {
00276 curs->setFilter( QString( "recid='%1'" ).arg( source ) ) ;
00277 curs->select() ;
00278 curs->next() ;
00279 QSqlRecord * buffer = curs->primeUpdate() ;
00280 buffer->setValue( "cat_parent", newParent ) ;
00281 curs->update() ;
00282
00283 init() ;
00284 QListViewItem * element = categoryList->findItem( QString( "%1").arg( source ), 2 ) ;
00285 categoryList->setSelected( element, TRUE ) ;
00286 categoryList->setOpen( categoryList->selectedItem(), TRUE ) ;
00287 emit categoryRemapped( source ) ;
00288 curs->setFilter( "" ) ;
00289 }
00290
00291
00292 void QlabCategoryList::categoryChanged( QListViewItem * item )
00293 {
00294 emit selectionChanged( item->text( 2 ).toInt() ) ;
00295 }
00296
00297
00298
00307 bool QlabCategoryList::showActive() const
00308 {
00309 return active ;
00310 }