Logo Search packages:      
Sourcecode: ktechlab version File versions  Download package

Item * ItemLibrary::createItem ( const QString &  id,
ItemDocument itemDocument,
bool  newItem,
const char *  newId = 0L,
bool  finishCreation = true 
)

Creates a new item with the given id, and returns a pointer to it

Definition at line 348 of file itemlibrary.cpp.

References LibraryItem::activeID(), LibraryItem::createItemFnPtr(), Subcircuits::createSubcircuit(), Item::finishedCreation(), libraryItem(), and Item::m_type.

Referenced by MechanicsDocument::addItem(), ICNDocument::addItem(), ItemView::createDragItem(), Subcircuits::createSubcircuit(), and ItemDocumentData::mergeWithDocument().

{
      Item *item = 0;
      if ( id.startsWith("sc/") )
      {
            // Is a subcircuit...
            
            CircuitDocument *circuitDocument = dynamic_cast<CircuitDocument*>(itemDocument);
            if (!circuitDocument)
            {
                  kdWarning() << "Cannot create subcircuit without a circuit document" << endl;
                  return 0;
            }
            
            QString temp = id;
            int numId = temp.remove("sc/").toInt();
            
            item = subcircuits()->createSubcircuit( numId,  circuitDocument, newItem, newId );
      } else { 
            LibraryItem * li = libraryItem( id );
            
            if ( !li )
                  kdWarning() << "Could not find the item constructor for id " << id << endl;
            else {
                  item = li->createItemFnPtr()( itemDocument, newItem, newId );
                  item->m_type = li->activeID();
            }
      }

      if ( finishCreation && item )
            item->finishedCreation();

      return item;
}


Generated by  Doxygen 1.6.0   Back to index