Logo Search packages:      
Sourcecode: packagesearch version File versions

tagselectionlistview.h

//
// C++ Interface: tagselectionlistview.h
//
// Description: 
//
//
// Author: Benjamin Mesing <bensmail@gmx.net>, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
// The first version of this file was generated by umbrello 
// on Tue May 18 2004 at 20:13:27

#ifndef __TAGSELECTIONLISTVIEW_H_2004_05_18
#define __TAGSELECTIONLISTVIEW_H_2004_05_18

#include <string>
#include <iterator>
#include <assert.h>

#include <qlistview.h>

#include <TagCollection.h>
#include <HandleMaker.h>

#include "tagselectionview.h"
#include "taglistviewitem.h"
// #include "tagitem.h"

using namespace std;

// class TagListViewItem;
// class TagListItem;

namespace NWidgets
{

/** @brief This class offers a listview that allows the selection of multiple tags.
  *
  * The tags are arranged in a listview tree.
  *
  * I am really sorry not to offer a template class, but QT does not support signals and
  * slots for templates :-(
  * @author Benjamin Mesing
  */
00046 class TagSelectionListView : public QListView, public TagSelectionView 
{
      Q_OBJECT
      /** The tag collection this List refers to. 
        *
        * It won't be deleted/created by this class. Use setColl() to set it to a new value. 
        * Make sure that it allways point to a valid object - i.e. don't delete the object points 
        * to without setting it to 0. If it is set to 0 it will be ignored.\n
        * Use it only if you want to select tags to include -> because it won't work for tags to 
        * exclude.
        */
00057       Tagcoll::TagCollection<int, string>* _pColl; 
      /** Holds the items selected */
00059       set<TagItem*> _selected;
      string _filterByNamePattern;
protected:
      /** @brief This function makes all items in the tree visible.
        *
        * This is necessary as QListViewItem setVisible() also makes all beneath the parents visible,
        * this behavoir is kinda odd because it does only occur if we go from a less detailed listview
        * to a more detailed one.  
        */
      void makeAllVisible();
      /** @returns if the handed list item is visible. */
00070       bool isVisible(const TagListViewItem* pItem)    { return pItem->isVisible(); };
      /** @brief Hides all tags where selecting would result in an empty result list. 
        * 
        * This iterates over all visible items and checks if they may be selected according to
        * the demand stated above. If #_pColl is not set (i.e. equals 0) the function does nothing.
        * @pre all items that shall be processed must be visible. 
        * @see #_filterByNamePattern, filter()
        */
      void filterByTagSet();
      /** @brief Filters all items which contain filter in their longTagname.
        * 
        * Items will be compared against the _filterByNamePattern */
      virtual void filterByName();

      /** This runs the items through all filters available. */
      void filter();
      /** @brief Intercept the clicking of the right mouse button, and avoid selection by it. */
      virtual void contentsMousePressEvent(QMouseEvent* pE );

protected slots:
      void onContextMenuRequested(QListViewItem* item, const QPoint& pos, int col); 
      /** This will be connected to the selection changed signal. It emits the 
        * tagItemsSelected() signal. */
      virtual void onSelectionChanged();
public slots:
      /** Expands all nodes of the listview. */
      void expandAll();
      /** Collapses all nodes of the listview except the root. */
      void collapseAll();
      /** Sets the #_pColl property. */
00100       void setColl(Tagcoll::TagCollection<int, string>* pColl)    { _pColl=pColl; }
      /** Sets the #_filterByNamePattern property. */
00102       void setFilterByNamePattern(const string& filterByNamePattern)  
            { _filterByNamePattern=filterByNamePattern; filter(); }
public:
      /** @brief Constructor creates an empty list for selection of tags.
        *
        * Call loadTagDatabase() to fill the list with tags.
        */
      TagSelectionListView(QWidget *parent, const char *name);
      /** This provides an STL compatible iterator over the datastructure. 
        * 
        * This uses the QListViewIterator as baseclass and inherits its functionality. Especially the 
        * IteratorFlags are a very usefull feature.\n
        * The constructor adds the QListViewItemIterator::Selectable flag as the root "/" which is
        * not selectable should not be iterated
        */
00117       class iterator : private QListViewItemIterator,  
            public std::iterator<bidirectional_iterator_tag, TagSelectionListView*>
      {
            /** Stores the flag as the QListViewItemIterator copy ctor is buggy. */
00121             IteratorFlag _flags;
      public:
            /** For stl conformance. */
/*          typedef input_iterator_tag iterator_category;   // we do not have a random access iterator*/
            /** Create an iterator that iterates the items.
              * @param _pSelectionView tag list view to be iterated
              * @param flags QListViewItemIterator::IteratorFlag to be used, additionally the 
              * QListViewItemIterator::Selectable flag will be added 
              */
00130             iterator(TagSelectionListView* _pSelectionView, IteratorFlag flags) : 
                  QListViewItemIterator(_pSelectionView, flags | Selectable ) 
            { _flags = IteratorFlag(flags | Selectable); };
            /** Create an iterator that iterates all items except the root "/"*/
00134             iterator(TagSelectionListView* _pSelectionView) : 
                  QListViewItemIterator(_pSelectionView, Selectable) 
            { _flags = IteratorFlag(Selectable); };
            /** Create an empty iterator.*/
00138             iterator() : 
                  QListViewItemIterator() 
            { _flags = IteratorFlag(0); };
            
            /** Copy constructor - offered cause the QListViewItemIterator copy ctor is buggy. */
00143             iterator(const iterator& it) : QListViewItemIterator(it.current(), it._flags) 
            {
                  _flags = it._flags;
            };
      private:
            iterator& operator=(const iterator& it) { return *this; };
      public:
            
            /** Go to the next element. */
            using QListViewItemIterator::operator++;
            /** Go to the previous element. */
            using QListViewItemIterator::operator--;
            /** @returns the TagListViewItem referenced by the iterator. */
00156             TagListViewItem* operator*() 
            {     
                  return static_cast<TagListViewItem*>(QListViewItemIterator::operator*());
            }
            /** @returns a pointer to the TagListViewItem referenced by the iterator. */
00161             TagListViewItem* operator->() 
            {
                  return static_cast<TagListViewItem*>(QListViewItemIterator::operator*());
            }
            /** @returns if the two iterators point to the same object. */
00166             bool operator==(iterator it) 
            {
                  return (current() == it.current());
            }
            /** @returns if the two iterators point to different objects. */
00171             bool operator!=(iterator it) 
            {
                  return (current() != it.current());
            }
      };
      /** Not yet implemented. */
00177       class const_iterator
      {
      
      };

      /** @brief Creates an iterator that points to the first element.
        * 
        * @param flags QListViewItemIterator::IteratorFlag to be used, additionally the 
        * QListViewItemIterator::Selectable flag will be added */
00186       iterator begin(QListViewItemIterator::IteratorFlag flags)   { return iterator(this, flags); };
      /** @brief Creates an iterator that points to the first element. */
00188       iterator begin()  { return iterator(this); };
      /** @returns the element that follows the last element */
00190       iterator end()          { return iterator(); };
      /** @returns the #_pColl property. */
00192       Tagcoll::TagCollection<int, string>* coll() const     { return _pColl; }

      /**
        * Accessor Methods
       */

      /** @returns a set containing all items currently selected. */
00199       set<TagItem*> getSelected()
      { return set<TagItem*>(begin(QListViewItemIterator::Selected) ,end()); }
      /** Returns if any items are selected. */
00202       bool selectedEmpty()
      { return _selected.empty(); }

      
      /** @returns the #_filterByNamePattern property. */
00207       const string& filterByNamePattern() const      { return _filterByNamePattern; }

      // documented in base class 
      // as a simple assumption this is true when the list is not empty
00211       virtual bool hasData() const { return childCount() != 0; };

      // documented in base class currently with empty implementation
00214       virtual void addTagItem(TagItem* pItem, TagItem* pParent=0) {};
      // documented in base class currently with empty implementation
00216       virtual void addTagItem(TagItem* pItem, const string& parentFullTagName) {};
      /** @brief Deselects the tag with the given name.
        * 
        * @param fullTagname tag to be deselected  */
      virtual void deselectTag(const string& fullTagname);
      /** @brief Deselects all tags. */
      virtual void deselectAll();
      /** @brief Clears the view and emits the tagItemsSelected() signal. */
      virtual void clear();
      // documented in baseclass
      ///@todo covariant returns are currently not implemented by the gcc :-( Recheck it every new release!
//    virtual TagListViewItem* getTagItem(const string& fullName);
      virtual TagItem* getTagItem(const string& fullName);
      /** @brief Returns the first element that matches the given name.
        * 
        * Added for your convenience. This directly calls getTagItem(). */
00232       TagListViewItem* thisGetTagItem(const string& fullName)
      { return static_cast<TagListViewItem*>(getTagItem(fullName)); };
      /** @brief Sets a new vocabulary data.
        *
        * Call this whenever you want to change the vocabulary data.\n
        * Even if it is the same as the old one it will be reloaded. */
      virtual void loadVocabulary(const Tagcoll::FacetSet& vocabulary);
signals:
      /** @brief The signal will be emitted, whenever the selection changes.
        *
        * @param tags the items that were selected by the user.
        * @implements signal_tagItemsSelected() */
      void tagItemsSelected(const set<TagItem*>& tags);
};

}     // namespace NWidgets

#endif // __TAGSELECTIONLISTVIEW_H_2004_05_18


Generated by  Doxygen 1.6.0   Back to index