Ejemplo n.º 1
0
CNode* CConfiguration::createNode(QDomElement element)
{
   Q3PtrList<CContextMenuConfig> contextNodes;
   QString                      uniqueID;
   QString                      displayName;
   QString                      imageActive;
   QString                      imageInactive;
   int                          refreshTimeout = 0;
   int                          positionX      = 0;
   int                          positionY      = 0;

   QDomNode currentNode = element.firstChild();
   while(!currentNode.isNull()) {
      if(QDomNode::ElementNode == currentNode.nodeType()) {
         if(currentNode.toElement().tagName() == QString(g_UIDTag)) {
            uniqueID = currentNode.toElement().text();
         }
         else if(currentNode.toElement().tagName() == QString(g_displayNameTag)) {
            displayName = currentNode.toElement().text();
         }
         else if(currentNode.toElement().tagName() == QString(g_refreshTimeoutTag)) {
            refreshTimeout = currentNode.toElement().text().toInt();
         }
         else if(currentNode.toElement().tagName() == QString(g_ActiveImageURLTag)) {
            imageActive = currentNode.toElement().text();
         }
         else if(currentNode.toElement().tagName() == QString(g_InactiveImageURLTag)) {
            imageInactive = currentNode.toElement().text();
         }
         else if(currentNode.toElement().tagName() == QString(g_NodePositionXTag)) {
            positionX = currentNode.toElement().text().toInt();
            if((positionX < 0) || (positionX > 100)) {
               QMessageBox::critical(0, "Error!", "Wrong SizeX: " + positionX);
            }
         }
         else if(currentNode.toElement().tagName() == QString(g_NodePositionYTag)) {
            positionY = currentNode.toElement().text().toInt();
            if((positionY < 0) || (positionY > 100)) {
               QMessageBox::critical(0, "Error!", "Wrong SizeY: " + positionY);
            }
         }
         else if(currentNode.toElement().tagName() == QString(g_ContextMenuEntryTag)) {
            contextNodes.append(createContextMenuEntry(displayName, currentNode.toElement()));
         }
         else if(currentNode.toElement().tagName() == QString(g_ContextMenuSeparatorTag)) {
            contextNodes.append(new CContextMenuConfig(m_CanvasWidget, "", "", ""));
         }
         else {
            QMessageBox::critical(0, "Error!", "Found unknown tag in config file: " +
                                  currentNode.toElement().tagName());
         }
      }

      currentNode = currentNode.nextSibling();
   }
   CNode* node = new CNode(uniqueID, displayName,
                           imageActive, imageInactive,
                           positionX, positionY, refreshTimeout);
   node->getContextMenuConfig() = contextNodes;
   return node;
}