Move IEditor::createNew to IDocument::setContents

The method is for setting the contents, so it belongs to the document,
and should be named correspondingly.

Change-Id: I40363dc08f11268f530885b512e4a88e8b10d096
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Eike Ziller
2013-07-15 15:14:10 +02:00
parent 0ba2b9b37d
commit fade19a9bf
42 changed files with 194 additions and 191 deletions

View File

@@ -32,13 +32,16 @@
#include <utils/qtcassert.h>
#include <QApplication>
#include <QDesignerFormWindowInterface>
#include <QDesignerFormWindowManagerInterface>
#include <QDesignerFormEditorInterface>
#if QT_VERSION < 0x050000
# include "qt_private/qsimpleresource_p.h"
# include "qt_private/formwindowbase_p.h"
#endif
#include <QTextDocument>
#include <QUndoStack>
#include <QFileInfo>
@@ -103,6 +106,45 @@ bool FormWindowFile::save(QString *errorString, const QString &name, bool autoSa
return true;
}
bool FormWindowFile::setContents(const QByteArray &contents)
{
if (Designer::Constants::Internal::debug)
qDebug() << Q_FUNC_INFO << contents.size();
document()->setPlainText(QString());
QTC_ASSERT(m_formWindow, return false);
if (contents.isEmpty())
return false;
// If we have an override cursor, reset it over Designer loading,
// should it pop up messages about missing resources or such.
const bool hasOverrideCursor = QApplication::overrideCursor();
QCursor overrideCursor;
if (hasOverrideCursor) {
overrideCursor = QCursor(*QApplication::overrideCursor());
QApplication::restoreOverrideCursor();
}
#if QT_VERSION >= 0x050000
const bool success = m_formWindow->setContents(QString::fromUtf8(contents));
#else
m_formWindow->setContents(QString::fromUtf8(contents));
const bool success = m_formWindow->mainContainer() != 0;
#endif
if (hasOverrideCursor)
QApplication::setOverrideCursor(overrideCursor);
if (!success)
return false;
syncXmlFromFormWindow();
setShouldAutoSave(false);
return true;
}
void FormWindowFile::setFilePath(const QString &newName)
{
m_formWindow->setFileName(newName);
@@ -184,6 +226,25 @@ QDesignerFormWindowInterface *FormWindowFile::formWindow() const
return m_formWindow;
}
void FormWindowFile::syncXmlFromFormWindow()
{
document()->setPlainText(formWindowContents());
}
QString FormWindowFile::formWindowContents() const
{
#if QT_VERSION >= 0x050000 // TODO: No warnings about spacers here
QTC_ASSERT(m_formWindow, return QString());
return m_formWindow->contents();
#else
// No warnings about spacers here
const qdesigner_internal::FormWindowBase *fw =
qobject_cast<const qdesigner_internal::FormWindowBase *>(m_formWindow);
QTC_ASSERT(fw, return QString());
return fw->fileContents();
#endif
}
void FormWindowFile::slotFormWindowRemoved(QDesignerFormWindowInterface *w)
{
// Release formwindow as soon as the FormWindowManager removes