Designer: Move "open" implementation to document.

This avoids that reloading needs to call back to the editor, and is in
preparation to a complete move of "open" to the document.

Change-Id: Ic24ecf7612c311055276e81edb080ab855590df9
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
This commit is contained in:
Eike Ziller
2015-05-28 16:43:34 +02:00
parent 08d94196fb
commit 832aa7851c
4 changed files with 40 additions and 53 deletions

View File

@@ -36,6 +36,7 @@
#include <utils/qtcassert.h>
#include <QApplication>
#include <QBuffer>
#include <QDesignerFormWindowInterface>
#include <QDesignerFormWindowManagerInterface>
#include <QDesignerFormEditorInterface>
@@ -71,6 +72,41 @@ FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *pare
m_resourceHandler, SLOT(updateResources()));
}
bool FormWindowFile::open(QString *errorString, const QString &fileName, const QString &realFileName)
{
if (Designer::Constants::Internal::debug)
qDebug() << "FormWindowFile::open" << fileName;
QDesignerFormWindowInterface *form = formWindow();
QTC_ASSERT(form, return false);
if (fileName.isEmpty())
return true;
const QFileInfo fi(fileName);
const QString absfileName = fi.absoluteFilePath();
QString contents;
if (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);
syncXmlFromFormWindow();
setFilePath(Utils::FileName::fromString(absfileName));
setShouldAutoSave(false);
resourceHandler()->updateResources(true);
return true;
}
bool FormWindowFile::save(QString *errorString, const QString &name, bool autoSave)
{
const FileName actualName = name.isEmpty() ? filePath() : FileName::fromString(name);
@@ -175,8 +211,7 @@ bool FormWindowFile::reload(QString *errorString, ReloadFlag flag, ChangeType ty
emit changed();
} else {
emit aboutToReload();
emit reloadRequested(errorString, filePath().toString());
const bool success = errorString->isEmpty();
const bool success = open(errorString, filePath().toString(), filePath().toString());
emit reloadFinished(success);
return success;
}