Exemplo n.º 1
0
  void
  TreeCanvas::mousePressEvent(QMouseEvent* event) {
    if (mutex.tryLock()) {
      if (event->button() == Qt::LeftButton) {
        VisualNode* n = eventNode(event);
        if (compareNodes) {
          if (n != NULL && n->getStatus() != UNDETERMINED &&
              currentNode != NULL &&
              currentNode->getStatus() != UNDETERMINED) {
            Space* curSpace = NULL;
            Space* compareSpace = NULL;
            for (int i=0; i<comparators.size(); i++) {
              if (comparators[i].second) {
                if (curSpace == NULL) {
                  curSpace = currentNode->getSpace(*na,curBest,c_d,a_d);

                  if (!compareNodesBeforeFP || n->isRoot()) {
                    compareSpace = n->getSpace(*na,curBest,c_d,a_d);
                  } else {
                    VisualNode* p = n->getParent(*na);
                    compareSpace = p->getSpace(*na,curBest,c_d,a_d);
                    switch (compareSpace->status()) {
                    case SS_SOLVED:
                    case SS_FAILED:
                      break;
                    case SS_BRANCH:
                      compareSpace->commit(*p->getChoice(), 
                                           n->getAlternative(*na));
                      break;
                    default:
                      GECODE_NEVER;
                    }
                  }
                }
                try {
                  comparators[i].first->compare(*curSpace,*compareSpace);
                } catch (Exception& e) {
                  qFatal("Exception in comparator %d: %s.\n Stopping.",
                    i, e.what());
                }
              }
            }
          }
        } else {
          setCurrentNode(n);
        }
        compareNodes = false;
        setCursor(QCursor(Qt::ArrowCursor));
        if (n != NULL) {
          event->accept();
          mutex.unlock();
          return;
        }
      }
      mutex.unlock();
    }
    event->ignore();
  }
Exemplo n.º 2
0
 void
 TreeCanvas::contextMenuEvent(QContextMenuEvent* event) {
   if (mutex.tryLock()) {
     VisualNode* n = eventNode(event);
     if (n != NULL) {
       setCurrentNode(n);
       emit contextMenu(event);
       event->accept();
       mutex.unlock();
       return;
     }
     mutex.unlock();
   }
   event->ignore();
 }
Exemplo n.º 3
0
 void
 TreeCanvas::mouseDoubleClickEvent(QMouseEvent* event) {
   if (mutex.tryLock()) {
     if(event->button() == Qt::LeftButton) {
       VisualNode* n = eventNode(event);
       if(n == currentNode) {
         inspectCurrentNode();
         event->accept();
         mutex.unlock();
         return;
       }
     }
     mutex.unlock();
   }
   event->ignore();
 }
Exemplo n.º 4
0
 bool
 TreeCanvas::event(QEvent* event) {
   if (mutex.tryLock()) {
     if (event->type() == QEvent::ToolTip) {
       VisualNode* n = eventNode(event);
       if (n != NULL && !n->isHidden() &&
           (n->getStatus() == BRANCH || n->getStatus() == STOP)) {
         QHelpEvent* he = static_cast<QHelpEvent*>(event);
         QToolTip::showText(he->globalPos(),
                            QString(n->toolTip(curBest,c_d,a_d).c_str()));
       } else {
         QToolTip::hideText();
       }
     }
     mutex.unlock();
   }
   return QWidget::event(event);
 }