예제 #1
0
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());
        }
      }
    }
  }
}
예제 #2
0
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 );
}
예제 #3
0
CalcPartList TemplKatalogView::currentItemsCalcParts()
{
  TemplKatalogListView* listview = static_cast<TemplKatalogListView*>(getListView());
  CalcPartList cpList;

  if( listview )
  {
    FloskelTemplate *currTempl = static_cast<FloskelTemplate*> (listview->currentItemData());
    if ( currTempl ) {
      cpList = currTempl->getCalcPartsList();
    }
  }
  return cpList;
}
예제 #4
0
CalcPartList TemplKatalogListView::itemsCalcParts( QTreeWidgetItem* it )
{
  CalcPartList cpList;

  if ( ! it ) {
    it = currentItem();
  }

  if ( ! it ) return cpList;

  FloskelTemplate *flos = it->data(0, Qt::UserRole).value<FloskelTemplate*>();
  if ( flos ) {
    kDebug() << "We have calc parts: " << flos->getCalcPartsList().count()<< endl;
    cpList = flos->getCalcPartsList();
  }
  return cpList;
}
예제 #5
0
CalcPartList TemplKatalogListView::itemsCalcParts( QTreeWidgetItem* it )
{
  CalcPartList cpList;

  if ( ! it ) {
    it = currentItem();
  }

  if ( ! it ) return cpList;

  FloskelTemplate *flos = static_cast<FloskelTemplate*>( m_dataDict[ it ] );
  if ( flos ) {
    // qDebug () << "We have calc parts: " << flos->getCalcPartsList().count()<< endl;
    cpList = flos->getCalcPartsList();
  }
  return cpList;
}
예제 #6
0
bool TemplKatalogView::currentItemToDocPosition( DocPosition& pos )
{
  TemplKatalogListView* listview = static_cast<TemplKatalogListView*>(getListView());
  bool res = false;
  if( listview )
  {
    FloskelTemplate *currTempl = static_cast<FloskelTemplate*> (listview->currentItemData());
    if( currTempl ) {
      // create a new position and offer it to the document manager
      pos.setText( currTempl->getText() );
      pos.setUnit( currTempl->unit() );
      pos.setUnitPrice( currTempl->unitPrice() );
      pos.setAmount( 1.0 );
      res = true;
    }
  }
  return res;
}
예제 #7
0
DocPosition TemplKatalogListView::itemToDocPosition( QTreeWidgetItem *it )
{
  DocPosition pos;
  if ( ! it ) {
    it = currentItem();
  }

  if ( ! it ) return pos;

  FloskelTemplate *flos = it->data(0, Qt::UserRole).value<FloskelTemplate*>();

  if ( flos ) {
    pos.setText( flos->getText() );
    pos.setUnit( flos->unit() );
    pos.setUnitPrice( flos->unitPrice() );
  } else {
    kDebug() << "Can not find a template for the item" << endl;
  }

  return pos;
}
예제 #8
0
DocPosition TemplKatalogListView::itemToDocPosition( QTreeWidgetItem *it )
{
  DocPosition pos;
  if ( ! it ) {
    it = currentItem();
  }

  if ( ! it ) return pos;

  FloskelTemplate *flos = static_cast<FloskelTemplate*>( m_dataDict[ it ] );

  if ( flos ) {
    pos.setText( flos->getText() );
    pos.setUnit( flos->unit() );
    pos.setUnitPrice( flos->unitPrice() );
  } else {
    // qDebug () << "Can not find a template for the item" << endl;
  }

  return pos;
}
예제 #9
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();
}