Back to index

salome-gui  6.5.0
Public Member Functions | Protected Member Functions | Private Attributes
SALOME_PYQT_ModuleLight::XmlHandler Class Reference
Collaboration diagram for SALOME_PYQT_ModuleLight::XmlHandler:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 XmlHandler (SALOME_PYQT_ModuleLight *module, const QString &fileName)
 Constructor.
void createActions ()
 Parse XML file and create actions.
void createPopup (QMenu *menu, const QString &context, const QString &parent, const QString &object)
 Create popup menu.
void activateMenus (bool)
 Activate menus.

Protected Member Functions

void createToolBar (QDomNode &parentNode)
 Create a toolbar and insert actions to it.
void createMenu (QDomNode &parentNode, const int parentMenuId=-1, QMenu *parentPopup=0)
 Create main menu item and insert actions to it.
void insertPopupItems (QDomNode &parentNode, QMenu *menu)
 Fill popup menu with the items.

Private Attributes

SALOME_PYQT_ModuleLightmyModule
QDomDocument myDoc
QList< int > myMenuItems

Detailed Description

Definition at line 131 of file SALOME_PYQT_ModuleLight.cxx.


Constructor & Destructor Documentation

SALOME_PYQT_ModuleLight::XmlHandler::XmlHandler ( SALOME_PYQT_ModuleLight module,
const QString &  fileName 
)

Constructor.

Parameters:
moduleparent module pointer
fileNameXML file path

Definition at line 2108 of file SALOME_PYQT_ModuleLight.cxx.

: myModule( module )
{
  if ( fileName.isEmpty() ) 
    return;
  QFile aFile( fileName );
  if ( !aFile.open( QIODevice::ReadOnly ) )
    return;
  myDoc.setContent( &aFile );
  aFile.close();
}

Member Function Documentation

Activate menus.

Parameters:
enableif true menus are activated, otherwise menus are deactivated

Definition at line 2187 of file SALOME_PYQT_ModuleLight.cxx.

{
  if ( !myModule )
    return;

  QtxActionMenuMgr* mgr = myModule->menuMgr();
  int id;
  foreach( id, myMenuItems ) mgr->setEmptyEnabled( id, enable );
}

Parse XML file and create actions.

Called by SALOME_PYQT_ModuleLight::activate() in order to create actions (menus, toolbars).

Definition at line 2128 of file SALOME_PYQT_ModuleLight.cxx.

{
  // get document element
  QDomElement aDocElem = myDoc.documentElement();

  // create main menu actions
  QDomNodeList aMenuList = aDocElem.elementsByTagName( "menu-item" );
  for ( int i = 0; i < aMenuList.count(); i++ ) {
    QDomNode n = aMenuList.item( i );
    createMenu( n );
  }

  // create toolbars actions
  QDomNodeList aToolsList = aDocElem.elementsByTagName( "toolbar" );
  for ( int i = 0; i < aToolsList.count(); i++ ) {
    QDomNode n = aToolsList.item( i );
    createToolBar( n );
  }
}
void SALOME_PYQT_ModuleLight::XmlHandler::createMenu ( QDomNode &  parentNode,
const int  parentMenuId = -1,
QMenu *  parentPopup = 0 
) [protected]

Create main menu item and insert actions to it.

Parameters:
parentNodeXML node with menu description
parentMenuIdparent menu ID (-1 for top-level menu)
parentPopupparent popup menu (0 for top-level menu)

Definition at line 2204 of file SALOME_PYQT_ModuleLight.cxx.

{
  if ( !myModule || parentNode.isNull() )
    return;
  
  QDomElement parentElement = parentNode.toElement();
  if ( !parentElement.isNull() ) {
    QString plabel = attribute( parentElement, "label-id" );
    int     pid    = checkInt( attribute( parentElement, "item-id" ) );
    int     ppos   = checkInt( attribute( parentElement, "pos-id" ) );
    int     group  = checkInt( attribute( parentElement, "group-id" ), 
                               myModule->defaultMenuGroup() );
    if ( !plabel.isEmpty() ) {
      QMenu* popup = 0;
      int menuId = -1;
      // create menu
      menuId = myModule->createMenu( plabel,         // label
                                     parentMenuId,   // parent menu ID, -1 for top-level menu
                                     pid,            // ID
                                     group,          // group ID
                                     ppos );         // position
      myMenuItems.append( menuId );
      QDomNode node = parentNode.firstChild();
      while ( !node.isNull() ) {
        if ( node.isElement() ) {
          QDomElement elem = node.toElement();
          QString aTagName = tagName( elem );
          if ( aTagName == "popup-item" ) {
            int     id      = checkInt( attribute( elem, "item-id" ) );
            int     pos     = checkInt( attribute( elem, "pos-id" ) );
            int     group   = checkInt( attribute( elem, "group-id" ), 
                                        myModule->defaultMenuGroup() );
            QString label   = attribute( elem, "label-id" );
            QString icon    = attribute( elem, "icon-id" );
            QString tooltip = attribute( elem, "tooltip-id" );
            QString accel   = attribute( elem, "accel-id" );
            bool    toggle  = checkBool( attribute( elem, "toggle-id" ) );

            // -1 action ID is not allowed : it means that <item-id> attribute is missed in the XML file!
            // also check if the action with given ID is already created
            if ( id != -1 ) {
              // create menu action
              QAction* action = myModule->createAction( id,                     // ID
                                                        tooltip,                // tooltip
                                                        icon,                   // icon
                                                        label,                  // menu text
                                                        tooltip,                // status-bar text
                                                        QKeySequence( accel ),  // keyboard accelerator
                                                        toggle );               // toogled action
              myModule->createMenu( action,   // action
                                    menuId,   // parent menu ID
                                    id,       // ID (same as for createAction())
                                    group,    // group ID
                                    pos );    // position
            }
          }
          else if ( aTagName == "submenu" ) {
            // create sub-menu
            createMenu( node, menuId, popup );
          }
          else if ( aTagName == "separator" ) {
            // create menu separator
            int id    = checkInt( attribute( elem, "item-id" ) ); // separator can have ID
            int pos   = checkInt( attribute( elem, "pos-id" ) );
            int group = checkInt( attribute( elem, "group-id" ), 
                                  myModule->defaultMenuGroup() );
            QAction* action = myModule->separator();
            myModule->createMenu( action,  // separator action
                                  menuId,  // parent menu ID
                                  id,      // ID
                                  group,   // group ID
                                  pos );   // position
          }
        }
        node = node.nextSibling();
      }
    }
  }
}

Here is the call graph for this function:

void SALOME_PYQT_ModuleLight::XmlHandler::createPopup ( QMenu *  menu,
const QString &  context,
const QString &  parent,
const QString &  object 
)

Create popup menu.

Parameters:
menupopup menu
contextpopup menu context
contextpopup menu parent object name
contextpopup menu object name

Definition at line 2156 of file SALOME_PYQT_ModuleLight.cxx.

{
  // get document element
  QDomElement aDocElem = myDoc.documentElement();

  // get popup menus actions
  QDomNodeList aPopupList = aDocElem.elementsByTagName( "popupmenu" );
  for ( int i = 0; i < aPopupList.count(); i++ ) {
    QDomNode n = aPopupList.item( i );
    if ( !n.isNull() && n.isElement() ) {
      QDomElement e = n.toElement();
      // QString lab = attribute( e, "label-id" ); // not used // 
      QString ctx = attribute( e, "context-id" );
      QString prt = attribute( e, "parent-id"  );
      QString obj = attribute( e, "object-id"  );
      if ( ctx == context && prt == parent && obj == object )  {
        insertPopupItems( n, menu );
        break;
      }
    }
  }
}

Here is the call graph for this function:

void SALOME_PYQT_ModuleLight::XmlHandler::createToolBar ( QDomNode &  parentNode) [protected]

Create a toolbar and insert actions to it.

Parameters:
parentNodeXML node with toolbar description

Definition at line 2290 of file SALOME_PYQT_ModuleLight.cxx.

{
  if ( !myModule || parentNode.isNull() )
    return;

  QDomElement parentElement = parentNode.toElement();
  if ( !parentElement.isNull() ) {
    QString aLabel = attribute( parentElement, "label-id" );
    if ( !aLabel.isEmpty() ) {
      // create toolbar
      int tbId = myModule->createTool( aLabel );
      QDomNode node = parentNode.firstChild();
      while ( !node.isNull() ) {
        if ( node.isElement() ) {
          QDomElement elem = node.toElement();
          QString aTagName = tagName( elem );
          if ( aTagName == "toolbutton-item" ) {
            int     id      = checkInt( attribute( elem, "item-id" ) );
            int     pos     = checkInt( attribute( elem, "pos-id" ) );
            QString label   = attribute( elem, "label-id" );
            QString icon    = attribute( elem, "icon-id" );
            QString tooltip = attribute( elem, "tooltip-id" );
            QString accel   = attribute( elem, "accel-id" );
            bool    toggle  = checkBool( attribute( elem, "toggle-id" ) );

            // -1 action ID is not allowed : it means that <item-id> attribute is missed in the XML file!
            // also check if the action with given ID is already created
            if ( id != -1 ) {
              // create toolbar action
              QAction* action = myModule->createAction( id,                    // ID
                                                        tooltip,               // tooltip
                                                        icon,                  // icon
                                                        label,                 // menu text
                                                        tooltip,               // status-bar text
                                                        QKeySequence( accel ), // keyboard accelerator
                                                        toggle );              // toogled action
              myModule->createTool( action, tbId, -1, pos );
            }
          }
          else if ( aTagName == "separatorTB" || aTagName == "separator" ) {
            // create toolbar separator
            int pos = checkInt( attribute( elem, "pos-id" ) );
            QAction* action = myModule->separator();
            myModule->createTool( action, tbId, -1, pos );
          }
        }
        node = node.nextSibling();
      }
    }
  }
}

Here is the call graph for this function:

void SALOME_PYQT_ModuleLight::XmlHandler::insertPopupItems ( QDomNode &  parentNode,
QMenu *  menu 
) [protected]

Fill popup menu with the items.

Parameters:
parentNodeXML node with popup menu description
menupopup menu

Definition at line 2347 of file SALOME_PYQT_ModuleLight.cxx.

{
  if ( !myModule && parentNode.isNull() )
    return;

  // we create popup menus without help of QtxPopupMgr
  QDomNode node = parentNode.firstChild();
  while ( !node.isNull() ) { 
    if ( node.isElement() ) {
      QDomElement elem = node.toElement();
      QString aTagName = tagName( elem );
      QList<QAction*> actions = menu->actions();
      if ( aTagName == "popup-item" ) {
        // insert a command item
        int     id      = checkInt( attribute( elem, "item-id" ) );
        int     pos     = checkInt( attribute( elem, "pos-id" ) );
        QString label   = attribute( elem, "label-id" );
        QString icon    = attribute( elem, "icon-id" );
        QString tooltip = attribute( elem, "tooltip-id" );
        QString accel   = attribute( elem, "accel-id" );
        bool    toggle  = checkBool( attribute( elem, "toggle-id" ) );

        // -1 action ID is not allowed : it means that <item-id> attribute is missed in the XML file!
        // also check if the action with given ID is already created
        if ( id != -1 ) {
          QAction* action = myModule->createAction( id,                     // ID
                                                    tooltip,                // tooltip
                                                    icon,                   // icon
                                                    label,                  // menu text
                                                    tooltip,                // status-bar text
                                                    QKeySequence( accel ),  // keyboard accelerator
                                                    toggle );               // toogled action
          QAction* before = ( pos >= 0 && pos < actions.count() ) ? actions[ pos ] : 0;
          menu->insertAction( before, action );
        }
      }
      else if ( aTagName == "submenu" ) {
        // create sub-menu
        int     pos   = checkInt( attribute( elem, "pos-id" ) );
        QString label = attribute( elem, "label-id" );
        QString icon  = attribute( elem, "icon-id" );

        QIcon anIcon;
        if ( !icon.isEmpty() ) {
          QPixmap pixmap  = myModule->getApp()->resourceMgr()->loadPixmap( myModule->name(), icon );
          if ( !pixmap.isNull() )
            anIcon = QIcon( pixmap );
        }

        QMenu* newPopup = menu->addMenu( anIcon, label );
        QAction* before = ( pos >= 0 && pos < actions.count() ) ? actions[ pos ] : 0;
        menu->insertMenu( before, newPopup );
        insertPopupItems( node, newPopup );
      }
      else if ( aTagName == "separator" ) {
        // create menu separator
        int pos = checkInt( attribute( elem, "pos-id" ) );
        QAction* action = myModule->separator();
        QAction* before = ( pos >= 0 && pos < actions.count() ) ? actions[ pos ] : 0;
        menu->insertAction( before, action );
      }
    }
    node = node.nextSibling();
  }
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 153 of file SALOME_PYQT_ModuleLight.cxx.

Definition at line 154 of file SALOME_PYQT_ModuleLight.cxx.

Definition at line 152 of file SALOME_PYQT_ModuleLight.cxx.


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