4 #include <QtGui/QMenuBar> 
    5 #include <QtGui/QToolBar> 
    7 std::vector<QAction*> 
GetActions(QList<QAction*> acts)
 
    9   std::vector<QAction*> res;
 
   10   QList<QAction*>::iterator it;
 
   12   for(it=acts.begin(); it != acts.end(); ++it)
 
   13     if((*it)->menu() == 0 && !((*it)->text().isEmpty()) && !(*it)->icon().isNull())
 
   20 QAbstractTableModel(parent)
 
   31   return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
 
   41     case Qt::TextAlignmentRole:
 
   42       return int(Qt::AlignVCenter | Qt::AlignLeft);
 
   47         QString name = m_actions[index.row()]->objectName();
 
   48         int pos = name.lastIndexOf(
".");
 
   50         return (pos < 0) ? m_actions[index.row()]->text() : name.mid(pos+1); 
 
   54     case Qt::DecorationRole:
 
   55       return m_actions[index.row()]->icon();
 
   58     case Qt::CheckStateRole:
 
   59       return (m_actionsActivation[index.row()]) ? Qt::Checked : Qt::Unchecked;
 
   80   return (
int)m_actions.size();
 
   90   if(role == Qt::CheckStateRole)
 
   91     m_actionsActivation[r] = (value.toInt() == Qt::Checked) ?  
true : 
false;
 
   93   QAction* act = m_actions[r];
 
   94   bool toAdd = m_actionsActivation[r];
 
   96   emit updateAction(act, toAdd);
 
  103   QList<QAction*>::const_iterator it;
 
  105   m_actionsActivation.clear();
 
  106   m_actionsActivation = std::vector<bool>(m_actions.size(), 
false);
 
  108   for(it = acts.begin(); it != acts.end(); ++it)
 
  110     for(
size_t i=0; i<m_actions.size(); i++)
 
  111       if((*it) == m_actions[i])
 
  112         m_actionsActivation[i] = 
true;
 
  120   QList<QAction*> acts = mnuBar->findChildren<QAction*>();
 
  123   m_actionsActivation = std::vector<bool>(m_actions.size(), 
false);
 
std::vector< QAction * > GetActions(QList< QAction * > acts)
 
Contains a definition for a model over the QMenuBar. 
 
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const 
 
MenuBarModel(QMenuBar *mnuBar, QObject *parent=0)
Constructor. 
 
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const 
 
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 
~MenuBarModel()
Destructor. 
 
virtual Qt::ItemFlags flags(const QModelIndex &index) const 
 
void setMenuBar(QMenuBar *mnuBar)
Sets the menu bar to be used in the model. 
 
void updateActionsState(const QList< QAction * > &acts)
Check the actions contained in acts. 
 
int columnCount(const QModelIndex &parent=QModelIndex()) const 
 
int rowCount(const QModelIndex &parent=QModelIndex()) const