void TemplKatalogView::slDeleteTemplate()
{
  kDebug() << "delete template hit";
  TemplKatalogListView* listview = static_cast<TemplKatalogListView*>(getListView());
  if( listview )
  {
    FloskelTemplate *currTempl = static_cast<FloskelTemplate*> (listview->currentItemData());
    if( currTempl ) {
      int id = currTempl->getTemplID();
      if( KMessageBox::questionYesNo( this,
                                     i18n( "Do you really want to delete the template from the catalog?" ),
                                     i18n( "Delete Template" ),
                                     KStandardGuiItem::yes(), KStandardGuiItem::no(), "DeleteTemplate" )
          == KMessageBox::Yes )
      {

        kDebug() << "Delete item with id " << id;
        TemplKatalog *k = static_cast<TemplKatalog*>( getKatalog( m_katalogName ) );

        if( k ) {
          k->deleteTemplate( id );
          listview->removeTemplateItem( listview->currentItem());
        }
      }
    }
  }
}
Exemple #2
0
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();
}