bool FormWindowEditor::open(QString *errorString, const QString &fileName, const QString &realFileName) { if (Designer::Constants::Internal::debug) qDebug() << "FormWindowEditor::open" << fileName; auto document = qobject_cast<FormWindowFile *>(textDocument()); QDesignerFormWindowInterface *form = document->formWindow(); QTC_ASSERT(form, return false); if (fileName.isEmpty()) return true; const QFileInfo fi(fileName); const QString absfileName = fi.absoluteFilePath(); QString contents; if (document->read(absfileName, &contents, errorString) != Utils::TextFileFormat::ReadSuccess) return false; form->setFileName(absfileName); const QByteArray contentsBA = contents.toUtf8(); QBuffer str; str.setData(contentsBA); str.open(QIODevice::ReadOnly); if (!form->setContents(&str, errorString)) return false; form->setDirty(fileName != realFileName); document->syncXmlFromFormWindow(); document->setFilePath(absfileName); document->setShouldAutoSave(false); document->resourceHandler()->updateResources(true); return true; }
bool FormWindowEditor::open(QString *errorString, const QString &fileName, const QString &realFileName) { if (Designer::Constants::Internal::debug) qDebug() << "FormWindowEditor::open" << fileName; QDesignerFormWindowInterface *form = d->m_file.formWindow(); QTC_ASSERT(form, return false); if (fileName.isEmpty()) { setDisplayName(tr("untitled")); return true; } const QFileInfo fi(fileName); const QString absfileName = fi.absoluteFilePath(); QString contents; if (d->m_file.read(absfileName, &contents, errorString) != Utils::TextFileFormat::ReadSuccess) return false; form->setFileName(absfileName); #if QT_VERSION >= 0x050000 const QByteArray contentsBA = contents.toUtf8(); QBuffer str; str.setData(contentsBA); str.open(QIODevice::ReadOnly); if (!form->setContents(&str, errorString)) return false; #else form->setContents(contents); if (!form->mainContainer()) return false; #endif form->setDirty(fileName != realFileName); syncXmlEditor(contents); setDisplayName(fi.fileName()); d->m_file.setFileName(absfileName); d->m_file.setShouldAutoSave(false); if (Internal::ResourceHandler *rh = form->findChild<Designer::Internal::ResourceHandler*>()) rh->updateResources(); emit changed(); return true; }
bool FormWindowEditor::open(const QString &fileName) { if (Designer::Constants::Internal::debug) qDebug() << "FormWindowEditor::open" << fileName; QDesignerFormWindowInterface *form = d->m_file.formWindow(); QTC_ASSERT(form, return false); if (fileName.isEmpty()) { setDisplayName(tr("untitled")); return true; } const QFileInfo fi(fileName); const QString absfileName = fi.absoluteFilePath(); QFile file(absfileName); if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) return false; form->setFileName(absfileName); const QString contents = QString::fromUtf8(file.readAll()); form->setContents(contents); file.close(); if (!form->mainContainer()) return false; form->setDirty(false); syncXmlEditor(contents); setDisplayName(fi.fileName()); d->m_file.setFileName(absfileName); if (Internal::ResourceHandler *rh = qFindChild<Designer::Internal::ResourceHandler*>(form)) rh->updateResources(); emit changed(); return true; }