Quark  0.1
BasicTableModelMenuAdapter< T > Class Template Referenceabstract

A model adapter that populates a QMenu with items that correspond to items in an AbstractTableModel. More...

#include <BasicTableModelMenuAdapter.h++>

Inheritance diagram for BasicTableModelMenuAdapter< T >:

Public Types

enum  Option { InsertAtTop = 1 << 0, Checkable = 1 << 1, Exclusive = 1 << 2 }
 Item model menu adapter options. More...
 

Public Member Functions

 BasicTableModelMenuAdapter (const AbstractTableModel< T > *model, QMenu *menu, Options options=0)
 Constructs a new BasicTableModelMenuAdapter for the given model and menu. More...
 
virtual ~BasicTableModelMenuAdapter ()
 Destructor. More...
 
void setSelectedItem (const T *item)
 Selects the (checkable) menu item corresponding to the given model item. More...
 
 Q_DECLARE_FLAGS (Options, Option)
 
void sync ()
 Synchronizes the menu with the model. More...
 

Protected Member Functions

virtual QString getMenuLabelForItem (const T &item) const =0
 Returns the menu item label that should be used for the given item in the model. More...
 
virtual void handleItemSelection (const T *item)=0
 Called when a checkable menu item has been selected. More...
 

Detailed Description

template<class T>
class quark::gui::BasicTableModelMenuAdapter< T >

A model adapter that populates a QMenu with items that correspond to items in an AbstractTableModel.

The adapter automatically keeps the menu up to date with respect to the model; as items are added to or removed from the model, the corresponding menu items will be added to or removed from the menu.

This is an abstract class; subclasses must implement getMenuLabelForItem() and handleItemSelection().

Author
Mark Lindner

Member Enumeration Documentation

◆ Option

enum Option
inherited

Item model menu adapter options.

Enumerator
InsertAtTop 

An option indicating that the menu items should be inserted above any menu items that existed in the menu at the time of this adapter's construction.

By default, items are added below existing items.

Checkable 

An option indicating that the menu items created by this adapter are checkable.

Exclusive 

An option indicating that the menu items created by this adapter are mutually exclusive; that is, only one may be checked at any given time.

This option is only meaningful if the Checkable option is also set.

Constructor & Destructor Documentation

◆ BasicTableModelMenuAdapter()

BasicTableModelMenuAdapter ( const AbstractTableModel< T > *  model,
QMenu *  menu,
Options  options = 0 
)

Constructs a new BasicTableModelMenuAdapter for the given model and menu.

Parameters
modelThe model.
menuThe menu
optionsOptions for the adapter.

◆ ~BasicTableModelMenuAdapter()

virtual ~BasicTableModelMenuAdapter ( )
virtual

Destructor.

Member Function Documentation

◆ getMenuLabelForItem()

virtual QString getMenuLabelForItem ( const T &  item) const
protectedpure virtual

Returns the menu item label that should be used for the given item in the model.

Parameters
itemThe model item.
Returns
The menu item label.

Implemented in RecentFileTableModelMenuAdapter.

◆ handleItemSelection()

virtual void handleItemSelection ( const T *  item)
protectedpure virtual

Called when a checkable menu item has been selected.

Parameters
itemThe model item corresponding to the menu item that was selected.

Implemented in RecentFileTableModelMenuAdapter.

◆ Q_DECLARE_FLAGS()

Q_DECLARE_FLAGS ( Options  ,
Option   
)
inherited

◆ setSelectedItem()

void setSelectedItem ( const T *  item)

Selects the (checkable) menu item corresponding to the given model item.

Parameters
itemThe model item.

◆ sync()

void sync ( )
inherited

Synchronizes the menu with the model.

This method must be called at least once to populate the menu with any items that may exist in the model.


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