• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

KCategorizedView Class Reference

Item view for listing items in a categorized fashion optionally. More...

#include <kcategorizedview.h>

Inheritance diagram for KCategorizedView:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 KCategorizedView (QWidget *parent=0)
 ~KCategorizedView ()
bool alternatingBlockColors () const
KCategoryDrawer * categoryDrawer () const
int categorySpacing () const
bool collapsibleBlocks () const
virtual QModelIndex indexAt (const QPoint &point) const
virtual void reset ()
void setAlternatingBlockColors (bool enable)
void setCategoryDrawer (KCategoryDrawer *categoryDrawer)
void setCategorySpacing (int categorySpacing)
void setCollapsibleBlocks (bool enable)
void setGridSize (const QSize &size)
void setGridSizeOwn (const QSize &size)
virtual void setModel (QAbstractItemModel *model)
virtual QRect visualRect (const QModelIndex &index) const

Protected Slots

virtual KDE_DEPRECATED void rowsInsertedArtifficial (const QModelIndex &parent, int start, int end)
virtual KDE_DEPRECATED void rowsRemoved (const QModelIndex &parent, int start, int end)
virtual void slotLayoutChanged ()

Protected Member Functions

virtual void currentChanged (const QModelIndex &current, const QModelIndex &previous)
virtual void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)
virtual void dragEnterEvent (QDragEnterEvent *event)
virtual void dragLeaveEvent (QDragLeaveEvent *event)
virtual void dragMoveEvent (QDragMoveEvent *event)
virtual void dropEvent (QDropEvent *event)
virtual void leaveEvent (QEvent *event)
virtual void mouseMoveEvent (QMouseEvent *event)
virtual void mousePressEvent (QMouseEvent *event)
virtual void mouseReleaseEvent (QMouseEvent *event)
virtual QModelIndex moveCursor (CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
virtual void paintEvent (QPaintEvent *event)
virtual void resizeEvent (QResizeEvent *event)
virtual void rowsAboutToBeRemoved (const QModelIndex &parent, int start, int end)
virtual void rowsInserted (const QModelIndex &parent, int start, int end)
virtual void setSelection (const QRect &rect, QItemSelectionModel::SelectionFlags flags)
virtual void startDrag (Qt::DropActions supportedActions)
virtual void updateGeometries ()

Detailed Description

Item view for listing items in a categorized fashion optionally.

KCategorizedView basically has the same functionality as QListView, only that it also lets you layout items in a way that they are categorized visually.

For it to work you will need to set a KCategorizedSortFilterProxyModel and a KCategoryDrawer with methods setModel() and setCategoryDrawer() respectively. Also, the model will need to be flagged as categorized with KCategorizedSortFilterProxyModel::setCategorizedModel(true).

The way it works (if categorization enabled):

  • When sorting, it does more things than QListView does. It will ask the model for the special role CategorySortRole (
    See also:
    KCategorizedSortFilterProxyModel). This can return a QString or an int in order to tell the view the order of categories. In this sense, for instance, if we are sorting by name ascending, "A" would be before than "B". If we are sorting by size ascending, 512 bytes would be before 1024 bytes. This way categories are also sorted.
  • When the view has to paint, it will ask the model with the role CategoryDisplayRole (
    See also:
    KCategorizedSortFilterProxyModel). It will for instance return "F" for "foo.pdf" if we are sorting by name ascending, or "Small" if a certain item has 100 bytes, for example.
    For drawing categories, KCategoryDrawer will be used. You can inherit this class to do your own drawing.
Note:
All examples cited before talk about filesystems and such, but have present that this is a completely generic class, and it can be used for whatever your purpose is. For instance when talking about animals, you can separate them by "Mammal" and "Oviparous". In this very case, for example, the CategorySortRole and the CategoryDisplayRole could be the same ("Mammal" and "Oviparous").
There is a really performance boost if CategorySortRole returns an int instead of a QString. Have present that this role is asked (n * log n) times when sorting and compared. Comparing ints is always faster than comparing strings, whithout mattering how fast the string comparison is. Consider thinking of a way of returning ints instead of QStrings if your model can contain a high number of items.
Warning:
Note that for really drawing items in blocks you will need some things to be done:
  • The model set to this view has to be (or inherit if you want to do special stuff in it) KCategorizedSortFilterProxyModel.
  • This model needs to be set setCategorizedModel to true.
  • Set a category drawer by calling setCategoryDrawer.
See also:
KCategorizedSortFilterProxyModel, KCategoryDrawer
Author:
Rafael Fernández López <ereslibre@kde.org>

Definition at line 79 of file kcategorizedview.h.


Constructor & Destructor Documentation

KCategorizedView::KCategorizedView ( QWidget *  parent = 0  ) 

Definition at line 475 of file kcategorizedview.cpp.

KCategorizedView::~KCategorizedView (  ) 

Definition at line 481 of file kcategorizedview.cpp.


Member Function Documentation

bool KCategorizedView::alternatingBlockColors (  )  const
Since:
4.4

Definition at line 644 of file kcategorizedview.cpp.

KCategoryDrawer * KCategorizedView::categoryDrawer (  )  const

Returns the current category drawer.

Definition at line 604 of file kcategorizedview.cpp.

int KCategorizedView::categorySpacing (  )  const
Since:
4.4

Definition at line 625 of file kcategorizedview.cpp.

bool KCategorizedView::collapsibleBlocks (  )  const
Since:
4.4

Definition at line 654 of file kcategorizedview.cpp.

void KCategorizedView::currentChanged ( const QModelIndex &  current,
const QModelIndex &  previous 
) [protected, virtual]

Reimplemented from QAbstractItemView.

Definition at line 1228 of file kcategorizedview.cpp.

void KCategorizedView::dataChanged ( const QModelIndex &  topLeft,
const QModelIndex &  bottomRight 
) [protected, virtual]

Reimplemented from QAbstractItemView.

Definition at line 1234 of file kcategorizedview.cpp.

void KCategorizedView::dragEnterEvent ( QDragEnterEvent *  event  )  [protected, virtual]

Reimplemented from QAbstractItemView.

Definition at line 922 of file kcategorizedview.cpp.

void KCategorizedView::dragLeaveEvent ( QDragLeaveEvent *  event  )  [protected, virtual]

Reimplemented from QAbstractItemView.

Definition at line 927 of file kcategorizedview.cpp.

void KCategorizedView::dragMoveEvent ( QDragMoveEvent *  event  )  [protected, virtual]

Reimplemented from QAbstractItemView.

Definition at line 917 of file kcategorizedview.cpp.

void KCategorizedView::dropEvent ( QDropEvent *  event  )  [protected, virtual]

Reimplemented from QAbstractItemView.

Definition at line 932 of file kcategorizedview.cpp.

QModelIndex KCategorizedView::indexAt ( const QPoint &  point  )  const [virtual]

Reimplemented from QAbstractItemView.

Definition at line 664 of file kcategorizedview.cpp.

void KCategorizedView::leaveEvent ( QEvent *  event  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 903 of file kcategorizedview.cpp.

void KCategorizedView::mouseMoveEvent ( QMouseEvent *  event  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 872 of file kcategorizedview.cpp.

void KCategorizedView::mousePressEvent ( QMouseEvent *  event  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 886 of file kcategorizedview.cpp.

void KCategorizedView::mouseReleaseEvent ( QMouseEvent *  event  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 896 of file kcategorizedview.cpp.

QModelIndex KCategorizedView::moveCursor ( CursorAction  cursorAction,
Qt::KeyboardModifiers  modifiers 
) [protected, virtual]

Reimplemented from QAbstractItemView.

Definition at line 939 of file kcategorizedview.cpp.

void KCategorizedView::paintEvent ( QPaintEvent *  event  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 712 of file kcategorizedview.cpp.

void KCategorizedView::reset (  )  [virtual]

Reimplemented from QAbstractItemView.

Definition at line 706 of file kcategorizedview.cpp.

void KCategorizedView::resizeEvent ( QResizeEvent *  event  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 822 of file kcategorizedview.cpp.

void KCategorizedView::rowsAboutToBeRemoved ( const QModelIndex &  parent,
int  start,
int  end 
) [protected, virtual]

Reimplemented from QAbstractItemView.

Definition at line 1056 of file kcategorizedview.cpp.

void KCategorizedView::rowsInserted ( const QModelIndex &  parent,
int  start,
int  end 
) [protected, virtual]

Reimplemented from QAbstractItemView.

Definition at line 1260 of file kcategorizedview.cpp.

void KCategorizedView::rowsInsertedArtifficial ( const QModelIndex &  parent,
int  start,
int  end 
) [protected, virtual, slot]

For internal use only.

Warning:
Deprecated since 4.4.

Definition at line 1268 of file kcategorizedview.cpp.

void KCategorizedView::rowsRemoved ( const QModelIndex &  parent,
int  start,
int  end 
) [protected, virtual, slot]

For internal use only.

Warning:
Deprecated since 4.4.

Definition at line 1277 of file kcategorizedview.cpp.

void KCategorizedView::setAlternatingBlockColors ( bool  enable  ) 
Since:
4.4

Definition at line 649 of file kcategorizedview.cpp.

void KCategorizedView::setCategoryDrawer ( KCategoryDrawer *  categoryDrawer  ) 

The category drawer that will be used for drawing categories.

Definition at line 609 of file kcategorizedview.cpp.

void KCategorizedView::setCategorySpacing ( int  categorySpacing  ) 
Since:
4.4

Definition at line 630 of file kcategorizedview.cpp.

void KCategorizedView::setCollapsibleBlocks ( bool  enable  ) 
Since:
4.4

Definition at line 659 of file kcategorizedview.cpp.

void KCategorizedView::setGridSize ( const QSize &  size  ) 

Definition at line 512 of file kcategorizedview.cpp.

void KCategorizedView::setGridSizeOwn ( const QSize &  size  ) 
Warning:
note that setGridSize is not virtual in the base class (QListView), so if you are calling to this method, make sure you have a KCategorizedView pointer around. This means that something like:
     QListView *lv = new KCategorizedView();
     lv->setGridSize(mySize);

will not call to the expected setGridSize method. Instead do something like this:

     QListView *lv;
     ...
     KCategorizedView *cv = qobject_cast<KCategorizedView*>(lv);
     if (cv) {
         cv->setGridSizeOwn(mySize);
     } else {
         lv->setGridSize(mySize);
     }
Note:
this method will call to QListView::setGridSize among other operations.
Since:
4.4

Definition at line 517 of file kcategorizedview.cpp.

void KCategorizedView::setModel ( QAbstractItemModel *  model  )  [virtual]

Reimplemented from QAbstractItemView.

Definition at line 486 of file kcategorizedview.cpp.

void KCategorizedView::setSelection ( const QRect &  rect,
QItemSelectionModel::SelectionFlags  flags 
) [protected, virtual]

Reimplemented from QAbstractItemView.

Definition at line 828 of file kcategorizedview.cpp.

void KCategorizedView::slotLayoutChanged (  )  [protected, virtual, slot]

For internal use only.

Reposition items as needed.

Definition at line 1286 of file kcategorizedview.cpp.

void KCategorizedView::startDrag ( Qt::DropActions  supportedActions  )  [protected, virtual]

Reimplemented from QAbstractItemView.

Definition at line 912 of file kcategorizedview.cpp.

void KCategorizedView::updateGeometries (  )  [protected, virtual]

Reimplemented from QAbstractItemView.

Definition at line 1175 of file kcategorizedview.cpp.

QRect KCategorizedView::visualRect ( const QModelIndex &  index  )  const [virtual]

Reimplemented from QAbstractItemView.

Definition at line 523 of file kcategorizedview.cpp.


The documentation for this class was generated from the following files:
  • kcategorizedview.h
  • kcategorizedview.cpp

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  •     Sodep
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal