Logo Search packages:      
Sourcecode: packagesearch version File versions

void NWidgets::TagSelectionListView::loadVocabulary ( const Tagcoll::FacetSet &  vocabulary  )  [virtual]

Sets a new vocabulary data.

Call this whenever you want to change the vocabulary data.
Even if it is the same as the old one it will be reloaded.

Todo:
add the long description as tooltip

Todo:
here loading fails under really strange circumstences - I assume a qt or debtags bug here though I am not sure about it. The plugin crashes if this is called some more often and I don't know why. Using pRoot as parent works completely and so does it with loading only the 5 first factes (see above) it even happens if I use QListViewItems instead of TagListViewItems so it strongly speaks for a QT or debtags bug

Implements TagSelectionView.

Definition at line 105 of file tagselectionlistview.cpp.

References _selected, and clear().

Referenced by NWidgets::SelectionInputAndDisplay::loadVocabulary().

{
      set<string> selectedTags;
      // collect the items currently selected
      transform (
            _selected.begin(), _selected.end(), 
            inserter(selectedTags, selectedTags.begin()),   // inserter to insert in the set
            mem_fun(&TagItem::fullTagname)
      );
      // This will be filled with the new tagItems that where selected in the old version.
      vector<TagListViewItem*> newSelected;
      clear();
      TagListViewItem* pRoot = new TagListViewItem(this, "/");    // insert as subitem of the root
      pRoot->setSelectable(false);
      pRoot->setOpen(true);
      // iterate over all facets
      int count = 0;
      // iterate over the facetset, a vocabulary entry is a pair of <tag, Record>
      // the whole algorithm does only work, because the Vocabulary class' content is arranged in
      // a map, which assures: it->first < (it+1)->first (and this way app comes before app::myApp)
      for ( Tagcoll::FacetSet::const_iterator it = vocabulary.begin(); it != vocabulary.end(); ++it )
      {
            ++count;
            // add the facet to the view
            /// @todo add the long description as tooltip
            const Tagcoll::Facet& facet = *it;
            if (facet.name().empty())     // it seems that there is the global facet, which contains the facets..
                  continue;
            TagListViewItem* pFacetItem = new TagListViewItem(pRoot, facet.name(), facet.sdesc());
            assert(pFacetItem);
            for ( Tagcoll::TagSet::iterator jt = facet.tags().begin(); jt != facet.tags().end(); ++jt)
            {
                  const Tagcoll::Tag& tag = *jt;
                  ///@todo here loading fails under really strange circumstences - I assume a qt 
                  /// or debtags bug here
                  /// though I am not sure about it. The plugin crashes if this is called some more often
                  /// and I don't know why. Using pRoot as parent works completely and so does it with
                  /// loading only the 5 first factes (see above)
                  /// it even happens if I use QListViewItems instead of TagListViewItems so it
                  /// strongly speaks for a QT or debtags bug
                  TagListViewItem* pItem = new TagListViewItem(
                        pFacetItem, facet.name() + "::" + tag.name(), tag.sdesc());
/*                TagListViewItem* pItem = new TagListViewItem(
                        pRoot, facet.name() + "::" + tag.name(), tag.sdesc());*/

                  if ( selectedTags.find(tag.name()) != selectedTags.end() )  // if the tag was selected before
                        newSelected.push_back(pItem); // add it to the new selected items
            }
            if ( selectedTags.find(facet.name()) != selectedTags.end() )      // if the tag was selected before
                  newSelected.push_back(pFacetItem);  // add it to the new selected items
      }
      for( vector<TagListViewItem*>::iterator it = newSelected.begin(); it != newSelected.end(); ++it)
            setSelected(*it,true);
}


Generated by  Doxygen 1.6.0   Back to index