📄 bookcasedoc.cpp
字号:
collElem.setAttribute(QString::fromLatin1("title"), collIt.current()->title()); QDomElement attsElem = doc.createElement(QString::fromLatin1("attributes")); collElem.appendChild(attsElem); // the XSLT sheet gets the header title from this // outside the loop for efficiency; QDomElement attElem; BCAttributeListIterator attIt(collIt.current()->attributeList()); for(attIt.toFirst(); attIt.current(); ++attIt) { attElem = doc.createElement(QString::fromLatin1("attribute")); attElem.setAttribute(QString::fromLatin1("name"), attIt.current()->name()); attElem.setAttribute(QString::fromLatin1("title"), attIt.current()->title()); attsElem.appendChild(attElem); } QString value; // outside the loop for efficiency; QDomElement unitElem, titleElem, valueElem; BCUnitGroupDict* dict = collIt.current()->unitGroupDictByName(dictName_); if(!dict) { kdWarning() << "BookcaseDoc::exportXML() - no dict found for " << dictName_ << endl; return QDomDocument(); } // dictName_ equals group->attributeName() for all these QDictIterator<BCUnitGroup> groupIt(*dict); for( ; groupIt.current(); ++groupIt) { BCUnitListIterator it(*groupIt.current()); for( ; it.current(); ++it) { unitElem = doc.createElement(collIt.current()->unitName()); titleElem = doc.createElement(QString::fromLatin1("title")); titleElem.appendChild(doc.createTextNode(it.current()->title())); unitElem.appendChild(titleElem); valueElem = doc.createElement(dictName_); valueElem.appendChild(doc.createTextNode(groupIt.current()->groupName())); unitElem.appendChild(valueElem); for(attIt.toFirst(); attIt.current(); ++attIt) { // don't include the grouped attribute twice nor the title again if(attIt.current()->name() == dictName_ || attIt.current()->name() == QString::fromLatin1("title")) { continue; } if(format_) { value = it.current()->attributeFormatted(attIt.current()->name(), attIt.current()->flags()); } else { value = it.current()->attribute(attIt.current()->name()); } if(!value.isEmpty()) { valueElem = doc.createElement(attIt.current()->name()); unitElem.appendChild(valueElem); if(attIt.current()->type() != BCAttribute::Bool) { valueElem.appendChild(doc.createTextNode(value)); } } } // end attribute loop collElem.appendChild(unitElem); } // end unit loop } // end group loop } // end collection loop QFile f(QString::fromLatin1("/tmp/test.xml")); if(f.open(IO_WriteOnly)) { QTextStream t(&f); t << doc.toCString().data(); } f.close(); return doc;}void BookcaseDoc::slotAddCollection(BCCollection* coll_) { if(!coll_) { return; } m_collList.append(coll_); emit signalCollectionAdded(coll_); setModified(true);}void BookcaseDoc::slotDeleteCollection(BCCollection* coll_) { if(!coll_) { return; } emit signalCollectionDeleted(coll_); m_collList.remove(coll_); setModified(true);}void BookcaseDoc::slotSaveUnit(BCUnit* unit_) { if(!unit_) { return; } if(unit_->collection()->unitList().containsRef(unit_) == 0) { slotAddUnit(unit_); return; }// kdDebug() << "BookcaseDoc::slotSaveUnit() - modifying an existing unit." << endl; unit_->collection()->updateDicts(unit_); emit signalUnitModified(unit_); setModified(true);}void BookcaseDoc::slotAddUnit(BCUnit* unit_) { if(!unit_) { return; }// emit signalStatusMsg(i18n("Adding a new %1...").arg(unit_->collection()->unitTitle())); unit_->collection()->addUnit(unit_); emit signalUnitAdded(unit_); setModified(true);}void BookcaseDoc::slotDeleteUnit(BCUnit* unit_) { if(!unit_) { return; }// emit signalStatusMsg(i18n("Deleting the %1...").arg(unit_->collection()->unitTitle())); // must emit the signal before the unit is deleted since otherwise, the pointer is null emit signalUnitDeleted(unit_); bool deleted = unit_->collection()->deleteUnit(unit_); if(deleted) { setModified(true); } else { // revert the signal??? emit signalUnitAdded(unit_); setModified(false); }}void BookcaseDoc::slotRenameCollection(int id_, const QString& newTitle_) { BCCollection* coll = collectionById(id_); if(coll) { coll->setTitle(newTitle_); setModified(true); }}bool BookcaseDoc::isEmpty() const { //an empty doc may contain a collection, but no units if(m_collList.isEmpty()) { return true; } BCCollectionListIterator collIt(m_collList); for( ; collIt.current(); ++collIt) { if(!collIt.current()->unitList().isEmpty()) { return false; } } return true;} QDomDocument* BookcaseDoc::importBibtex(const KURL& url_) { QDomDocument* dom = new QDomDocument(); return dom;}void BookcaseDoc::search(const QString& text_, const QString& attTitle_, int options_) {// kdDebug() << "BookcaseDoc::search() - looking for " << text_ << " in " << attTitle_ << endl; BCAttribute* att = 0; BCCollection* coll = 0; BCAttributeList empty; BCAttributeListIterator attIt(empty); bool searchAll = (options_ & AllAttributes); bool backwards = (options_ & FindBackwards); bool asRegExp = (options_ & AsRegExp); bool fromBeginning = (options_ & FromBeginning); bool caseSensitive = (options_ & CaseSensitive); Bookcase* app = bookcaseParent(parent()); BCUnitItem* item = app->selectedOrFirstItem(); if(!item) {// kdDebug() << "BookcaseDoc::search() - empty document" << endl; // doc has no items return; } // if fromBeginning is used, then take the first one if(fromBeginning) { // if backwards and beginning, start at end, this is slow to travers if(backwards) { item = static_cast<BCUnitItem*>(item->listView()->lastItem()); } else { item = static_cast<BCUnitItem*>(item->listView()->firstChild()); } } else { // don't want to continually search the same one, so if the returned item // is the same as the selected one, then skip to the next if(item == static_cast<BCUnitItem*>(item->listView()->selectedItem())) { if(backwards) { item = static_cast<BCUnitItem*>(item->itemAbove()); } else { item = static_cast<BCUnitItem*>(item->nextSibling()); } } } bool found = false; BCUnit* unit; while(item) { unit = item->unit();// kdDebug() << "\tsearching " << unit->title() << endl;; // if there's no current collection, or the collection has changed, update // the pointer and the attribute pointer and iterator if(!coll || coll != unit->collection()) { coll = unit->collection(); if(searchAll) { attIt = BCAttributeListIterator(coll->attributeList()); } else { att = coll->attributeByTitle(attTitle_); } } // reset if we're searching all if(searchAll) { att = attIt.toFirst(); } // if we're not searching all, then we break out // if we are searching all, then att will finally be 0 when the iterator gets to the end while(att && !found) {// kdDebug() << "\t\tsearching " << att->title() << endl; // if RegExp is used, then the text is a regexp pattern if(asRegExp) { QRegExp rx(text_); if(caseSensitive) { rx.setCaseSensitive(true); } if(unit->attribute(att->name()).contains(rx)) { found = true; } // else if not a regexp } else { if(caseSensitive) { if(unit->attribute(att->name()).contains(text_)) { found = true; } } else { // we're not case sensitive so compare lower-case to lower-case if(unit->attribute(att->name()).lower().contains(text_.lower())) { found = true; } } } // end of while(att ... // if a unit is found, emit selected signal and return if(found) {// kdDebug() << "\tfound " << unit->attribute(att->name()) << endl; emit signalUnitSelected(unit); return; } // if not, then continue the search. If we're searching all, update the pointer, // otherwise break out and go to next item if(searchAll) { ++attIt; att = attIt.current(); } else { break; } } // get next item if(backwards) { // there is no QListViewItem::prevSibling() // itemABove() works since I know there are no parents in the detailed view item = static_cast<BCUnitItem*>(item->itemAbove()); } else { item = static_cast<BCUnitItem*>(item->nextSibling()); } } // if this point is reached, no match was found KMessageBox::information(app, i18n("Search string '%1' not found.").arg(text_));}BCAttributeList BookcaseDoc::uniqueAttributes(int type_ /* =0 */) const { BCAttributeList list; BCCollectionListIterator it(collectionList()); for( ; it.current(); ++it) { if(type_ == 0 || it.current()->collectionType() == type_) { if(list.isEmpty()) { list = it.current()->attributeList(); } else { BCAttributeListIterator attIt(it.current()->attributeList()); for( ; attIt.current(); ++attIt) { if(list.containsRef(attIt.current()) == 0) { list.append(attIt.current()); } } } } } return list;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -