Esempio n. 1
0
static Score::FileError doValidate(const QString& name, QIODevice* dev)
      {
      QTime t;
      t.start();

      // initialize the schema
      ValidatorMessageHandler messageHandler;
      QXmlSchema schema;
      schema.setMessageHandler(&messageHandler);
      if (!initMusicXmlSchema(schema))
            return Score::FileError::FILE_BAD_FORMAT;  // appropriate error message has been printed by initMusicXmlSchema

      // validate the data
      QXmlSchemaValidator validator(schema);
      bool valid = validator.validate(dev, QUrl::fromLocalFile(name));
      qDebug("Validation time elapsed: %d ms", t.elapsed());

      if (valid)
            qDebug("importMusicXml() file '%s' is a valid MusicXML file", qPrintable(name));
      else {
            qDebug("importMusicXml() file '%s' is not a valid MusicXML file", qPrintable(name));
            MScore::lastError = QObject::tr("File '%1' is not a valid MusicXML file").arg(name);
            if (MScore::noGui)
                  return Score::FileError::FILE_NO_ERROR;   // might as well try anyhow in converter mode
            if (musicXMLValidationErrorDialog(MScore::lastError, messageHandler.getErrors()) != QMessageBox::Yes)
                  return Score::FileError::FILE_USER_ABORT;
            }

      // return OK
      return Score::FileError::FILE_NO_ERROR;
      }
Esempio n. 2
0
void XmlEditWidgetPrivate::showValidationResults(const QString xmlAsText, ValidatorMessageHandler &validator)
{
    Element *element = NULL ;
    QDomDocument document;
    if(document.setContent(xmlAsText)) {
        FindNodeWithLocationInfo info;
        findDomNodeScan(document, document, validator.line(), validator.column(), info);
        QList<int> errorPath;
        if(!info.matchedNode.isNull()) {
            errorPath = makeDomNodePath(info.matchedNode);
        } else if(!info.lastKnownNode.isNull()) {
            errorPath = makeDomNodePath(info.lastKnownNode);
        }
        if(!errorPath.isEmpty()) {
            Element *selectedElement = regola->findElementByArray(errorPath);
            p->setCurrentItem(selectedElement);
        }
    }
    QString htmlTextError = tr("Line:%1, Col:%2 :%3")
                            .arg(validator.line())
                            .arg(validator.column())
                            .arg(validator.descriptionInPlainText());

    emit p->schemaValidationError(htmlTextError, element);
}
ValidationResults::ValidationResults(const QString text, ValidatorMessageHandler &validator, QWidget *parent) :
    QDialog(parent),
    _validator(validator)
{
    init();
    textBrowser->setText(text);
    TextEditUtils::gotoPos(textBrowser, validator.column(), validator.line());
    TextEditUtils::hiliteCurrentPos(textBrowser);
    error->setText(QString(tr("Line:%1, Col:%2 :%3"))
                   .arg(validator.line())
                   .arg(validator.column())
                   .arg(validator.description()));
}