void TemplKatalogView::slNewTemplate() { KatalogListView *listView = getListView(); if( !listView ) return; // create new template object FloskelTemplate *flosTempl = new FloskelTemplate(); flosTempl->setText( i18n( "<new template>" ) ); // find the corresponding parent (==chapter) item QTreeWidgetItem *parentItem = static_cast<QTreeWidgetItem*>(listView->currentItem()); if( parentItem ) { // if it is not a chapter nor root, take the parent if( ! (listView->isRoot(parentItem) || listView->isChapter(parentItem)) ) { parentItem = (QTreeWidgetItem*) parentItem->parent(); } } if( parentItem ) { // try to find out which catalog is open/current CatalogChapter *chap = static_cast<CatalogChapter*>( listView->itemData( parentItem ) ); if( chap ) { flosTempl->setChapterId( chap->id().toInt(), true ); } } TemplKatalogListView *templListView = static_cast<TemplKatalogListView*>(listView); QTreeWidgetItem *item = templListView->addFlosTemplate(parentItem, flosTempl); listView->scrollToItem( item ); listView->setCurrentItem( item ); openDialog( item, flosTempl, true ); }
void MaterialKatalogView::slNewTemplate() { KatalogListView *listview = getListView(); if( !listview ) return; MaterialKatalogListView *matListView = static_cast<MaterialKatalogListView*>(listview); StockMaterial *newMat = new StockMaterial(); newMat->setName( i18n( "<new material>" ) ); QTreeWidgetItem *parentItem = static_cast<QTreeWidgetItem*>( listview->currentItem() ); if ( parentItem ) { if ( ! ( matListView->isRoot( parentItem ) || matListView->isChapter( parentItem ) ) ) { parentItem = ( QTreeWidgetItem* ) parentItem->parent(); } } if( parentItem && listview->isChapter( parentItem )) { // try to find out which catalog is open/current CatalogChapter *chap = static_cast<CatalogChapter*>(listview->itemData( parentItem )); newMat->setChapter( chap->id().toInt() ); } mNewItem = matListView->addMaterialToView( parentItem, newMat ); openDialog( mNewItem, newMat, true ); }
StockMaterialList MatKatalog::getRecordList( const CatalogChapter& chapter ) { StockMaterialList list; int chapID = chapter.id().toInt(); StockMaterialListIterator it( mAllMaterial ); while( it.hasNext() ) { StockMaterial *mat = it.next(); if ( mat->chapter() == chapID ) { list.append( mat ); } } return list; }
void TemplKatalogListView::slotUpdateSequence() { if( ! mSortChapterItem ) { return; } dbID parentID; CatalogChapter *parentChap = chapterFromTreeItem(mSortChapterItem); if( parentChap ) { parentID = parentChap->id(); } else { parentID = 0; // root item } int childCount = mSortChapterItem->childCount(); if( ! childCount ) return; emit sequenceUpdateMaximum( childCount-1 ); QSqlQuery query; query.prepare("UPDATE Catalog SET sortKey=? WHERE TemplID=?"); int sequenceCnt = 1; // Start at 1 for( int i = 0; i < childCount; i++ ) { QTreeWidgetItem *item = mSortChapterItem->child( i ); emit sequenceUpdateProgress( i ); // set the sortKey to the sequence counter i if( ! (isChapter( item ) /* || isRoot( item ) */ ) ) { CatalogTemplate *catTmpl = templFromTreeItem(item); FloskelTemplate *flos = static_cast<FloskelTemplate*>( catTmpl ); kDebug() << "Updating item " << flos->getTemplID() << " to sort key " << sequenceCnt; if( flos ) { query.bindValue( 0, sequenceCnt++ ); query.bindValue( 1, flos->getTemplID() ); query.exec(); } } } KatalogListView::slotUpdateSequence(); }