⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcgroupview.cpp

📁 Bookcase 是一个用于KDE的个人的书籍管理。它使用XML文件存储格式
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  QString key = groupKey(unit_->collection(), group);  ParentItem* par = m_groupDict.find(key);  if(!par) {    return;  }  BCUnitItem* unitItem = 0;  QListViewItem* item = par->firstChild();  for( ; item; item = item->nextSibling()) {    unitItem = static_cast<BCUnitItem*>(item);    if(unitItem->unit() == unit_) {      break;    }  }  blockSignals(true);  setSelected(unitItem, true);  blockSignals(false);  ensureItemVisible(unitItem);}void BCGroupView::slotToggleItem(QListViewItem* item_) {  if(!item_) {    return;  }  item_->setOpen(!item_->isOpen());}void BCGroupView::slotExpandAll(int depth_/*=-1*/) {  QListViewItem* item;  if(depth_ == -1) {    item = selectedItem();    if(!item) {      return;    }    depth_ = item->depth();  }  switch(depth_) {    //TODO: should be iterating over all collections    case 0:      item = firstChild();      break;    case 1:      item = firstChild()->firstChild();      break;    default:      return;  }  // now open all siblings  for( ; item; item = item->nextSibling()) {    item->setOpen(true);  }}void BCGroupView::slotCollapseAll(int depth_/*=-1*/) {  if(childCount() == 0) {    return;  }  QListViewItem* item;  if(depth_ == -1) {    item = selectedItem();    if(!item) {      return;    }    depth_ = item->depth();  }    switch(depth_) {    //TODO: should be iterating over all collections    case 0:      item = firstChild();      break;    case 1:      item = firstChild()->firstChild();      break;    default:      return;  }  // now close all siblings  for( ; item; item = item->nextSibling()) {    item->setOpen(false);  }}void BCGroupView::slotRMB(QListViewItem* item_, const QPoint& point_, int) {  if(!item_) {    return;  }  setSelected(item_, true);    if(item_->depth() == 0 && m_collMenu.count() > 0) {    m_collMenu.popup(point_);  } else if(item_->depth() == 1 && m_groupMenu.count() > 0) {    m_groupMenu.popup(point_);  } else if(item_->depth() == 2 && m_unitMenu.count() > 0) {    m_unitMenu.popup(point_);  }}void BCGroupView::slotHandleRename() {  QListViewItem* item = currentItem();  // items at depth==0 are for collections  if(item && item->depth() == 0) {    QString newName;    bool ok;    newName = KLineEditDlg::getText(i18n("New Collection Name"), item->text(0), &ok, this);    if(ok) {      item->setText(0, newName);      emit signalRenameCollection(static_cast<ParentItem*>(item)->id(), newName);    }  }}void BCGroupView::slotCollapsed(QListViewItem* item_) {  // only change icon for collection and group items  if(item_->depth() < 2) {    item_->setPixmap(0, m_groupClosedPixmap);  }}void BCGroupView::slotExpanded(QListViewItem* item_) {  // only change icon for collection and group items  if(item_->depth() < 2) {    item_->setPixmap(0, m_groupOpenPixmap);  }}void BCGroupView::slotClearSelection() {  selectAll(false);}void BCGroupView::slotAddCollection(BCCollection* coll_) {  if(!coll_) {    kdWarning() << "BCGroupView::slotAddCollection() - null coll pointer!" << endl;    return;  }  //  kdDebug() << "BCGroupView::slotAddCollection" << endl;  QString groupBy;  QString unitName = coll_->unitName();  if(m_collGroupBy.contains(unitName)) {    groupBy = m_collGroupBy.find(unitName).data();  } else {    groupBy = coll_->defaultGroupAttribute();    m_collGroupBy.insert(unitName, groupBy);//    kdDebug() << "\tm_groupAttribute was empty, now is " << groupBy << endl;  }  ParentItem* collItem = populateCollection(coll_, groupBy);  if(!collItem) {    return;  }    setSelected(collItem, true);  slotCollapseAll();  ensureItemVisible(collItem);  collItem->setOpen(true);//  kdDebug() << "BCGroupView::slotAddCollection - done" << endl;}void BCGroupView::setGroupAttribute(BCCollection* coll_, const QString& groupAtt_) {//  kdDebug() << "BCGroupView::setGroupAttribute - " << groupAtt_ << endl;  // as a hack, when a new collection is added,  this gets called  // if the collection item is empty, go ahead and populate it  // even if the group attribute has not changed  ParentItem* collItem = locateItem(coll_);  QString unitName = coll_->unitName();  if(!m_collGroupBy.contains(unitName)     || m_collGroupBy.find(unitName).data() != groupAtt_     || collItem->childCount() == 0) {    m_collGroupBy.insert(unitName, groupAtt_);    populateCollection(coll_, groupAtt_);  }//  kdDebug() << "BCGroupView::setGroupAttribute - done" << endl;}bool BCGroupView::showCount() const {  return m_showCount;}void BCGroupView::showCount(bool showCount_, const BCCollectionList& list_) {//  kdDebug() << "BCGroupView::showCount()" << endl;  if(m_showCount != showCount_) {    m_showCount = showCount_;    // now just repaint all the child items, paintCell(() will take care of the update    QListViewItemIterator it(this);    for( ; it.current(); ++it) {      if(it.current()->depth() == 1) {        it.current()->repaint();      }    }  }}ParentItem* BCGroupView::populateCollection(BCCollection* coll_,  const QString& groupBy_/*=QString::null*/) {//  kdDebug() << "BCGroupView::populateCollection()" << endl;  BCUnitGroupDict* dict;  if(groupBy_.isEmpty()) {    QString groupBy;    QString unitName = coll_->unitName();    if(m_collGroupBy.contains(unitName)) {      groupBy = m_collGroupBy.find(unitName).data();    } else {      groupBy = coll_->defaultGroupAttribute();      m_collGroupBy.insert(unitName, groupBy);//      kdDebug() << "\tm_groupAttribute was empty, now is " << groupBy << endl;    }    dict = coll_->unitGroupDictByName(groupBy);  } else {    dict = coll_->unitGroupDictByName(groupBy_);    if(!dict) {      kdDebug() << "BCGroupView::populateCollection() - no dict found for " << groupBy_ << endl;      return 0;    }  }  //if there is not a root item for the collection, it is created  ParentItem* collItem = locateItem(coll_);  // delete all the children;  if(collItem->childCount() > 0) {//    kdDebug() << "\tdeleting all the children" << endl;    QListViewItem* child = collItem->firstChild();    QListViewItem* next;    while(child) {      next = child->nextSibling();      QString key = groupKey(collItem, child);      m_groupDict.remove(key);      delete child;      child = next;    }  }  QPixmap icon = KGlobal::iconLoader()->loadIcon(coll_->iconName(), KIcon::User);  // iterate over all the groups in the dict  // e.g. if the dict is "author", loop over all the author groups  QDictIterator<BCUnitGroup> it(*dict);  for( ; it.current(); ++it) {    ParentItem* par = insertItem(collItem, it.current());    QPtrListIterator<BCUnit> unitIt(*it.current());    for( ; unitIt.current(); ++unitIt) {      QString title = unitIt.current()->title();      BCUnitItem* item = new BCUnitItem(par, title, unitIt.current());      item->setPixmap(0, icon);    }  }  return collItem;}void BCGroupView::slotHandleDelete() {  BCUnitItem* item = static_cast<BCUnitItem*>(currentItem());  if(!item || !item->unit()) {    return;  }  emit signalDeleteUnit(item->unit());}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -