Beispiel #1
0
/*!
 * \brief ModelicaEditor::getClassNames
 * Uses the OMC parseString API to check the class names inside the Modelica Text
 * \param errorString
 * \return QStringList a list of class names
 * \sa ModelWidget::modelicaEditorTextChanged()
 */
QStringList ModelicaEditor::getClassNames(QString *errorString)
{
  OMCProxy *pOMCProxy = mpMainWindow->getOMCProxy();
  QStringList classNames;
  LibraryTreeItem *pLibraryTreeItem = mpModelWidget->getLibraryTreeItem();
  if (mpPlainTextEdit->toPlainText().isEmpty()) {
    *errorString = tr("Start and End modifiers are different");
    return QStringList();
  } else {
    QString modelicaText = mpPlainTextEdit->toPlainText();
    QString stringToParse = modelicaText;
    if (!modelicaText.startsWith("within")) {
      stringToParse = QString("within %1;%2").arg(pLibraryTreeItem->parent()->getNameStructure()).arg(modelicaText);
    }
    classNames = pOMCProxy->parseString(stringToParse, pLibraryTreeItem->getFileName());
  }
  // if user is defining multiple top level classes.
  if (classNames.size() > 1) {
    *errorString = QString(GUIMessages::getMessage(GUIMessages::MULTIPLE_TOP_LEVEL_CLASSES)).arg(pLibraryTreeItem->getNameStructure())
        .arg(classNames.join(","));
    return QStringList();
  }
  bool existModel = false;
  QStringList existingmodelsList;
  // check if the class already exists
  foreach(QString className, classNames) {
    if (pLibraryTreeItem->getNameStructure().compare(className) != 0) {
      if (mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem(className)) {
        existingmodelsList.append(className);
        existModel = true;
      }
    }
  }
  // check if existModel is true
  if (existModel) {
    *errorString = QString(GUIMessages::getMessage(GUIMessages::REDEFINING_EXISTING_CLASSES)).arg(existingmodelsList.join(",")).append("\n")
        .append(GUIMessages::getMessage(GUIMessages::DELETE_AND_LOAD).arg(""));
    return QStringList();
  }
  return classNames;
}
Beispiel #2
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);
    }
  }
}
Beispiel #3
0
/*!
  Adds the error message.\n
  Moves to the most recent error message in the view.
  */
void MessagesWidget::addGUIMessage(MessageItem messageItem)
{
  // move the cursor down before adding message.
  QTextCursor textCursor = mpMessagesTextBrowser->textCursor();
  textCursor.movePosition(QTextCursor::End);
  mpMessagesTextBrowser->setTextCursor(textCursor);
  // set the CSS class depending on message type
  QString messageCSSClass;
  switch (messageItem.getErrorType()) {
    case StringHandler::Warning:
      messageCSSClass = "warning";
      break;
    case StringHandler::OMError:
      messageCSSClass = "error";
      break;
    case StringHandler::Notification:
    default:
      messageCSSClass = "notification";
      break;
  }
  QString linkFormat = QString("[%1: %2]: <a href=\"omeditmessagesbrowser:///%3?lineNumber=%4\">%5</a>");
  QString errorMessage;
  QString message;
  if(messageItem.getMessageItemType()== MessageItem::Modelica) {
    // if message already have tags then just use it.
    if (Qt::mightBeRichText(messageItem.getMessage())) {
      message = messageItem.getMessage();
    } else {
      message = Qt::convertFromPlainText(messageItem.getMessage()).remove("<p>").remove("</p>");
    }
  } else if(messageItem.getMessageItemType()== MessageItem::TLM) {
    message = messageItem.getMessage().remove("<p>");
  }
  if (messageItem.getFileName().isEmpty()) { // if custom error message
    errorMessage = message;
  } else if (messageItem.getMessageItemType()== MessageItem::TLM ||
             mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem(messageItem.getFileName())) {
    // If the class is only loaded in AST via loadString then create link for the error message.
    errorMessage = linkFormat.arg(messageItem.getFileName())
        .arg(messageItem.getLocation())
        .arg(messageItem.getFileName())
        .arg(messageItem.getLineStart())
        .arg(message);
  } else {
    // Find the class name using the file name and line number.
    LibraryTreeItem *pLibraryTreeItem;
    pLibraryTreeItem = mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->getLibraryTreeItemFromFile(messageItem.getFileName(),
                                                                                                           messageItem.getLineStart().toInt());
    if (pLibraryTreeItem) {
      errorMessage = linkFormat.arg(pLibraryTreeItem->getNameStructure())
          .arg(messageItem.getLocation())
          .arg(pLibraryTreeItem->getNameStructure())
          .arg(messageItem.getLineStart())
          .arg(message);
    } else {
      // otherwise display filename to user where error occurred.
      errorMessage = QString("[%1: %2]: %3")
          .arg(messageItem.getFileName())
          .arg(messageItem.getLocation())
          .arg(message);
    }
  }
  QString errorString = QString("<div class=\"%1\">"
                                "<b>[%2] %3 %4 %5</b><br>"
                                "%6"
                                "</div><br>")
      .arg(messageCSSClass)
      .arg(QString::number(mMessageNumber))
      .arg(QTime::currentTime().toString())
      .arg(StringHandler::getErrorKindString(messageItem.getErrorKind()))
      .arg(StringHandler::getErrorTypeDisplayString(messageItem.getErrorType()))
      .arg(errorMessage);
  mpMessagesTextBrowser->insertHtml(errorString);
  mMessageNumber++;
  // move the cursor down after adding message.
  textCursor.movePosition(QTextCursor::End);
  mpMessagesTextBrowser->setTextCursor(textCursor);
  emit MessageAdded();
}
Beispiel #4
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();
}