void MainWindow::openFileToWorkspace(const QString &xmlFileName, bool clear) { // Open file QFile xmlFile(xmlFileName); if (!xmlFile.open(QIODevice::ReadOnly)) { // Display error message QMessageBox msgBox(this); msgBox.setText(QString(tr("Couldn't open file to read content: %1.") ).arg(xmlFileName)); msgBox.exec(); return; } // Read content QByteArray content = xmlFile.readAll(); QString xml(content); xmlFile.close(); // Set XML to Workspace setXml(xml, clear); // Set XML file name if (clear) { setXmlFileName(xmlFileName); } }
void MainWindow::actionDocumentRedo() { // If already in first change, return if (documentHistory.length() < 2) return; if (documentHistoryStep >= documentHistory.length() - 1) return; documentHistoryStep++; sourceChanging = true; // Prevent adding this change to the history setXml(documentHistory[documentHistoryStep], true); }
void MainWindow::actionDocumentUndo() { // If no history, return if (documentHistory.length() < 2) return; if (documentHistoryStep == -1) { // First undo, get previous document documentHistoryStep = documentHistory.length() - 2; } else { // If already in first change, return if (documentHistoryStep == 0) return; documentHistoryStep--; } sourceChanging = true; // Prevent adding this change to the history setXml(documentHistory[documentHistoryStep], true); }
bool CodingWidget::loadFile(QString xmlFilename) { qDebug() << "CodingWidget::loadFile(QString xmlFilename)"; QFile xmlFile(xmlFilename); if (!xmlFile.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::warning(this, tr("MDI"), tr("Cannot read file %1:\n%2.") .arg(xmlFilename) .arg(xmlFile.errorString())); return false; } xmlFile.setObjectName(xmlFilename); codingElementCount = 0; codingElementSize = 0; QApplication::setOverrideCursor(Qt::WaitCursor); reader = new CodingReader(); reader->read(&xmlFile, this); xmlFile.reset(); // XML QTextStream inXml(&xmlFile); setXml(inXml.readAll()); // XSD QFile xsdFile(getXsdFilename()); qDebug() << "getXsdFilename()): " << getXsdFilename(); if (!xsdFile.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::warning(this, tr("MDI"), tr("Cannot read file %1:\n%2.") .arg(getXsdFilename()) .arg(xsdFile.errorString())); return false; } QTextStream inXsd(&xsdFile); setXsd(inXsd.readAll()); QApplication::restoreOverrideCursor(); return true; }