FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | List of all members
qtgui::ItemViewButtons Class Reference

Provides buttons integrated to items displayed by QAbstractItemView. More...

#include <item_view_buttons.h>

Inheritance diagram for qtgui::ItemViewButtons:

Public Types

enum  ItemSide { ItemLeftSide, ItemRightSide }
 
enum  DisplayMode { DisplayOnDetection = 0x01, DisplayPermanent = 0x02, DisplayWhenItemSelected = 0x04 }
 
typedef QFlags< DisplayModeDisplayModes
 

Public Slots

void reset ()
 

Signals

void buttonClicked (int btnId, const QModelIndex &index)
 This signal is emitted when a button previously added with addButton() is clicked (i.e. pressed down then released while the mouse cursor is inside the button) More...
 

Public Member Functions

 ItemViewButtons (QAbstractItemView *view, QObject *parent=NULL)
 
 ~ItemViewButtons ()
 
QAbstractItemView * itemView () const
 
bool eventFilter (QObject *object, QEvent *event) Q_DECL_OVERRIDE
 
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
 
void addButton (int btnId, const QIcon &icon=QIcon(), const QString &toolTip=QString())
 Add a button to be furthered configured with setButtonXxx() functions. More...
 
void copyButtonProperties (int srcBtnId, int dstBtnId)
 Copy all properties of a button into another. More...
 
int buttonDetectionMatchRole (int btnId) const
 The role used when matching item data for button detection. More...
 
QVariant buttonDetectionMatchData (int btnId) const
 The data to be matched for button detection. More...
 
void setButtonDetection (int btnId, int matchRole, const QVariant &matchData)
 ItemViewButtons::setButtonDetection. More...
 
int buttonDisplayColumn (int btnId) const
 Index of the view column where the button is displayed (when detected) More...
 
void setButtonDisplayColumn (int btnId, int col=-1)
 
int buttonItemSide (int btnId) const
 Side in the item's cell where the button is displayed. More...
 
void setButtonItemSide (int btnId, ItemSide side)
 
DisplayModes buttonDisplayModes (int btnId) const
 Display modes of the button. More...
 
void setButtonDisplayModes (int btnId, DisplayModes modes)
 
QIcon buttonIcon (int btnId) const
 Icon of the button. More...
 
void setButtonIcon (int btnId, const QIcon &icon)
 
QSize buttonIconSize (int btnId) const
 Icon size of the button. More...
 
void setButtonIconSize (int btnId, const QSize &size)
 
QString buttonToolTip (int btnId) const
 Tool-tip of the button. More...
 
void setButtonToolTip (int btnId, const QString &toolTip)
 
void installDefaultItemDelegate ()
 
QStyledItemDelegate * createProxyItemDelegate (QStyledItemDelegate *sourceDelegate, QObject *parent=NULL) const
 

Protected Member Functions

virtual int buttonAtModelIndex (const QModelIndex &index) const
 

Detailed Description

Provides buttons integrated to items displayed by QAbstractItemView.

qtgui::ItemViewButtons allows to add buttons inside any QAbstractItemView without subclassing the item-view class.

It only requires that its paint() method is called whenever any view item has to be drawn. If you have a custom delegate (eg. a subclass of QStyledItemDelegate) then just call at some point qtgui::ItemViewButtons::paint() inside the delegate's paint() method :

void MyCustomDeleagate::paint(QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
QStyledItemDelegate::paint(painter, option, index);
// Specific paint operations ...
m_itemViewBtns->paint(painter, option, index);
}

If you do not want to modify your delegate class then createProxyItemDelegate() might be the right option : this will create a new delegate around yours with the paint() method correctly called.

If the item-view does not use any delegate then just call installDefaultItemDelegate()

ItemViewButtons notifies any button click with signal buttonClicked()

Examples:
qttools/item_view_buttons/main.cpp.

Member Typedef Documentation

Member Enumeration Documentation

Enumerator
DisplayOnDetection 
DisplayPermanent 
DisplayWhenItemSelected 
Enumerator
ItemLeftSide 
ItemRightSide 

Constructor & Destructor Documentation

qtgui::ItemViewButtons::ItemViewButtons ( QAbstractItemView *  view,
QObject *  parent = NULL 
)
qtgui::ItemViewButtons::~ItemViewButtons ( )

Member Function Documentation

void qtgui::ItemViewButtons::addButton ( int  btnId,
const QIcon &  icon = QIcon(),
const QString &  toolTip = QString() 
)

Add a button to be furthered configured with setButtonXxx() functions.

Parameters
btnIdIndex of the button (used later to reference the button)
iconIcon of the button (ItemViewButtons supports QIcon::Active which can be used to display an highlighted pixmap when the mouse is hovering the button)
toolTipTool-tip to be displayed when the mouse stays over the button

Does nothing if button index btnId is already used by some other button.

int qtgui::ItemViewButtons::buttonAtModelIndex ( const QModelIndex &  index) const
protectedvirtual
void qtgui::ItemViewButtons::buttonClicked ( int  btnId,
const QModelIndex &  index 
)
signal

This signal is emitted when a button previously added with addButton() is clicked (i.e. pressed down then released while the mouse cursor is inside the button)

Parameters
btnIdIdentifier of the button clicked (this is the id that was passed to addButton())
indexIndex of the item model where the button click occured
Examples:
qttools/item_view_buttons/main.cpp.
QVariant qtgui::ItemViewButtons::buttonDetectionMatchData ( int  btnId) const

The data to be matched for button detection.

Parameters
btnIdIndex of the button
Returns
QVariant() If button does not exist
See also
buttonDetectionMatchRole()
int qtgui::ItemViewButtons::buttonDetectionMatchRole ( int  btnId) const

The role used when matching item data for button detection.

Parameters
btnIdIndex of the button
Returns
-1 If button does not exist or if no matching role was set
See also
buttonDetectionMatchData()
QModelIndex::data()
Qt::ItemDataRole
int qtgui::ItemViewButtons::buttonDisplayColumn ( int  btnId) const

Index of the view column where the button is displayed (when detected)

Parameters
btnIdIndex of the button
Returns
-1 If button does not exist
ItemViewButtons::DisplayModes qtgui::ItemViewButtons::buttonDisplayModes ( int  btnId) const

Display modes of the button.

Parameters
btnIdIndex of the button
Returns
DisplayModes() If button does not exist
QIcon qtgui::ItemViewButtons::buttonIcon ( int  btnId) const

Icon of the button.

Parameters
btnIdIndex of the button
Returns
QIcon() If button does not exist
QSize qtgui::ItemViewButtons::buttonIconSize ( int  btnId) const

Icon size of the button.

Parameters
btnIdIndex of the button
Returns
QSize() If button does not exist
int qtgui::ItemViewButtons::buttonItemSide ( int  btnId) const

Side in the item's cell where the button is displayed.

Parameters
btnIdIndex of the button
Returns
-1 If button does not exist
QString qtgui::ItemViewButtons::buttonToolTip ( int  btnId) const

Tool-tip of the button.

Parameters
btnIdIndex of the button
Returns
QString() If button does not exist
void qtgui::ItemViewButtons::copyButtonProperties ( int  srcBtnId,
int  dstBtnId 
)

Copy all properties of a button into another.

Parameters
srcBtnIdIndex of the source button
dstBtnIdIndex of the destination button
QStyledItemDelegate * qtgui::ItemViewButtons::createProxyItemDelegate ( QStyledItemDelegate *  sourceDelegate,
QObject *  parent = NULL 
) const

Create a proxy delegate around sourceDelegate to be further installed with QAbstractItemView::setItemDelegate()

This is useful when you have a delegate for an item view but for some reason don't want to modify it to integrate with ItemViewButtons

bool qtgui::ItemViewButtons::eventFilter ( QObject *  object,
QEvent *  event 
)
void qtgui::ItemViewButtons::installDefaultItemDelegate ( )

Install a delegate for the attached view item, allowing the button mechanism to work

QAbstractItemView * qtgui::ItemViewButtons::itemView ( ) const
void qtgui::ItemViewButtons::paint ( QPainter *  painter,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
void qtgui::ItemViewButtons::reset ( )
slot
void qtgui::ItemViewButtons::setButtonDetection ( int  btnId,
int  matchRole,
const QVariant &  matchData 
)

ItemViewButtons::setButtonDetection.

Parameters
btnIdIndex of the button
matchRoleThe role used when matching item data for button detection. In case the button has to be displayed no matter the item, then set matchRole to -1
matchDataThe data to be matched for button detection
See also
buttonDetectionMatchData()
buttonDetectionMatchRole()
QModelIndex::data()
Qt::ItemDataRole
void qtgui::ItemViewButtons::setButtonDisplayColumn ( int  btnId,
int  col = -1 
)
void qtgui::ItemViewButtons::setButtonDisplayModes ( int  btnId,
DisplayModes  modes 
)
void qtgui::ItemViewButtons::setButtonIcon ( int  btnId,
const QIcon &  icon 
)
void qtgui::ItemViewButtons::setButtonIconSize ( int  btnId,
const QSize &  size 
)
void qtgui::ItemViewButtons::setButtonItemSide ( int  btnId,
ItemSide  side 
)
void qtgui::ItemViewButtons::setButtonToolTip ( int  btnId,
const QString &  toolTip 
)

The documentation for this class was generated from the following files: