Exemplo n.º 1
0
/*
  <a href="omeditmessagesbrowser:///className?lineNumber=4></a>"
  */
void MessagesWidget::openErrorMessageClass(QUrl url)
{
  if (url.scheme() != "omeditmessagesbrowser") {
    /*! @todo Write error-message?! */
    return;
  }
  QString className = url.path();
  if (className.startsWith("/")) className.remove(0, 1);
  LibraryTreeItem *pLibraryTreeItem = mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem(className);
  if (pLibraryTreeItem) {
    mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->showModelWidget(pLibraryTreeItem);
    ModelWidget *pModelWidget = pLibraryTreeItem->getModelWidget();
    if (pModelWidget && pModelWidget->getEditor()) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
      QUrlQuery query(url);
	  int lineNumber = query.queryItemValue("lineNumber").toInt();
#else /* Qt4 */
      int lineNumber = url.queryItemValue("lineNumber").toInt();
#endif
      pModelWidget->getTextViewToolButton()->setChecked(true);
      pModelWidget->getEditor()->goToLineNumber(lineNumber);
    }
  }
}
Exemplo n.º 2
0
/*!
  Slot activated when mpOkButton clicked signal is raised.\n
  Adds or edit the breakpoint.
  */
void BreakpointDialog::addOrEditBreakpoint()
{
  int lineNumber = mpLineNumberTextBox->text().toInt();
  BreakpointMarker *pBreakpointMarker;
  QFileInfo fileInfo(mpFileNameTextBox->text());
  if (fileInfo.exists()) {  /* if user has selected a file using Browse File System button. */
    if (!mpBreakpointTreeItem) {  /* Add Case */
      pBreakpointMarker = new BreakpointMarker(mpFileNameTextBox->text(), lineNumber, mpBreakpointsTreeModel);
      pBreakpointMarker->setEnabled(mpEnableCheckBox->isChecked());
      pBreakpointMarker->setIgnoreCount(mpIgnoreCountSpinBox->value());
      pBreakpointMarker->setCondition(mpConditionTextBox->text());
      mpBreakpointsTreeModel->insertBreakpoint(pBreakpointMarker, 0, mpBreakpointsTreeModel->getRootBreakpointTreeItem());
    } else {  /* Edit Case */
      /* find the BreakpointMarker and update its filepath and lineNumber. */
      pBreakpointMarker = mpBreakpointsTreeModel->findBreakpointMarker(mpBreakpointTreeItem->getFilePath(), mpBreakpointTreeItem->getLineNumber().toInt());
      pBreakpointMarker->setFilePath(mpFileNameTextBox->text());
      pBreakpointMarker->setLineNumber(lineNumber);
      pBreakpointMarker->setEnabled(mpEnableCheckBox->isChecked());
      pBreakpointMarker->setIgnoreCount(mpIgnoreCountSpinBox->value());
      pBreakpointMarker->setCondition(mpConditionTextBox->text());
      /* the breakpoint is file system breakpoint now so remove the mark from the previous editor and set LibraryTreeItem to 0. */
      if (mpBreakpointTreeItem->getLibraryTreeItem() && mpBreakpointTreeItem->getLibraryTreeItem()->getModelWidget()) {
        mpBreakpointTreeItem->getLibraryTreeItem()->getModelWidget()->getEditor()->getDocumentMarker()->removeMark(pBreakpointMarker);
      }
      mpBreakpointTreeItem->setLibraryTreeItem(0);
      /* update BreakpointTreeItem filePath and lineNumber. */
      mpBreakpointsTreeModel->updateBreakpoint(mpBreakpointTreeItem, mpFileNameTextBox->text(), lineNumber, mpEnableCheckBox->isChecked(),
                                               mpIgnoreCountSpinBox->value(), mpConditionTextBox->text());
    }
  } else {  /* if user has selected a class using Browse Classes button */
    LibraryWidget *pLibraryWidget = MainWindow::instance()->getLibraryWidget();
    LibraryTreeItem *pLibraryTreeItem = pLibraryWidget->getLibraryTreeModel()->findLibraryTreeItem(mpFileNameTextBox->text());
    if (pLibraryTreeItem) {
      if (!pLibraryTreeItem->isSaved()) {
        QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error),
                              GUIMessages::getMessage(GUIMessages::BREAKPOINT_INSERT_NOT_SAVED).arg(pLibraryTreeItem->getNameStructure()),
                              Helper::ok);
        return;
      } else if (pLibraryTreeItem->getLibraryType() != LibraryTreeItem::Modelica) {
        QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error),
                              GUIMessages::getMessage(GUIMessages::BREAKPOINT_INSERT_NOT_MODELICA_CLASS).arg(pLibraryTreeItem->getNameStructure()),
                              Helper::ok);
        return;
      } else if (!mpBreakpointTreeItem) { /* Add Case */
        pBreakpointMarker = new BreakpointMarker(pLibraryTreeItem->getFileName(), lineNumber, mpBreakpointsTreeModel);
        pBreakpointMarker->setEnabled(mpEnableCheckBox->isChecked());
        pBreakpointMarker->setIgnoreCount(mpIgnoreCountSpinBox->value());
        pBreakpointMarker->setCondition(mpConditionTextBox->text());
        mpBreakpointsTreeModel->insertBreakpoint(pBreakpointMarker, pLibraryTreeItem, mpBreakpointsTreeModel->getRootBreakpointTreeItem());
        if (pLibraryTreeItem->getModelWidget()) {
          pLibraryTreeItem->getModelWidget()->getEditor()->getDocumentMarker()->addMark(pBreakpointMarker, lineNumber);
        }
      } else {  /* Edit Case */
        /* find the BreakpointMarker and update its filepath and lineNumber. */
        pBreakpointMarker = mpBreakpointsTreeModel->findBreakpointMarker(mpBreakpointTreeItem->getFilePath(),
                                                                         mpBreakpointTreeItem->getLineNumber().toInt());
        // first remove the marker
        if (mpBreakpointTreeItem->getLibraryTreeItem()->getModelWidget() &&
            mpBreakpointTreeItem->getLibraryTreeItem()->getModelWidget()->getEditor()) {
          mpBreakpointTreeItem->getLibraryTreeItem()->getModelWidget()->getEditor()->getDocumentMarker()->removeMark(pBreakpointMarker);
        }
        // set new attributes for the breakpoint marker
        pBreakpointMarker->setFilePath(pLibraryTreeItem->getFileName());
        pBreakpointMarker->setLineNumber(lineNumber);
        pBreakpointMarker->setEnabled(mpEnableCheckBox->isChecked());
        pBreakpointMarker->setIgnoreCount(mpIgnoreCountSpinBox->value());
        pBreakpointMarker->setCondition(mpConditionTextBox->text());
        /* the breakpoint is not a file system breakpoint now so set LibraryTreeItem. */
        mpBreakpointTreeItem->setLibraryTreeItem(pLibraryTreeItem);
        /* update BreakpointTreeItem filePath and lineNumber. */
        mpBreakpointsTreeModel->updateBreakpoint(mpBreakpointTreeItem, pLibraryTreeItem->getFileName(), lineNumber,
                                                 mpEnableCheckBox->isChecked(), mpIgnoreCountSpinBox->value(), mpConditionTextBox->text());
        if (pLibraryTreeItem->getModelWidget()) {
          if (!pLibraryTreeItem->getModelWidget()->getEditor()) {
            pLibraryTreeItem->getModelWidget()->createModelWidgetComponents();
          }
          pLibraryTreeItem->getModelWidget()->getEditor()->getDocumentMarker()->addMark(pBreakpointMarker, lineNumber);
        }
      }
    } else {
      QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error),
                            GUIMessages::getMessage(GUIMessages::CLASS_NOT_FOUND).arg(mpFileNameTextBox->text()), Helper::ok);
      return;
    }
  }
  accept();
}