Commit 776c5993 authored by Friedemann Kleint's avatar Friedemann Kleint

Designer: Fix a crash when open() fails.

editorsClosed() is not emitted when open fails and thus
the file was not removed from FormEditorStack.
Add a connection from destroy to ensure the editor is removed.

Happens when loading a session whose files no longer exists.

Task-number: QTCREATORBUG-4266
Reviewed-by: dt
parent b38a256e
......@@ -35,6 +35,8 @@
#include "formeditorw.h"
#include "formeditorstack.h"
#include <coreplugin/editormanager/ieditor.h>
#include <utils/qtcassert.h>
#include <QtGui/QVBoxLayout>
......@@ -109,9 +111,9 @@ void EditorWidget::add(const EditorData &d)
m_stack->add(d);
}
bool EditorWidget::removeFormWindowEditor(Core::IEditor *xmlEditor)
void EditorWidget::removeFormWindowEditor(Core::IEditor *xmlEditor)
{
return m_stack->removeFormWindowEditor(xmlEditor);
m_stack->removeFormWindowEditor(xmlEditor);
}
bool EditorWidget::setVisibleEditor(Core::IEditor *xmlEditor)
......
......@@ -68,7 +68,7 @@ public:
// Form editor stack API
void add(const EditorData &d);
bool removeFormWindowEditor(Core::IEditor *xmlEditor);
void removeFormWindowEditor(Core::IEditor *xmlEditor);
bool setVisibleEditor(Core::IEditor *xmlEditor);
SharedTools::WidgetHost *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const;
SharedTools::WidgetHost *formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const;
......
......@@ -78,12 +78,17 @@ void FormEditorStack::add(const EditorData &data)
m_formEditors.append(data);
addWidget(data.widgetHost);
// Editors are normally removed by listening to EditorManager::editorsClosed.
// However, in the case opening a file fails, EditorManager just deletes the editor, which
// is caught by the destroyed() signal.
connect(data.formWindowEditor, SIGNAL(destroyed(QObject*)),
this, SLOT(removeFormWindowEditor(QObject*)));
connect(data.widgetHost, SIGNAL(formWindowSizeChanged(int,int)),
this, SLOT(formSizeChanged(int,int)));
if (Designer::Constants::Internal::debug)
qDebug() << "FormEditorStack::add" << data.widgetHost;
qDebug() << "FormEditorStack::add" << data.widgetHost << m_formEditors.size();
// Since we have 1 pixel splitters we enforce no frame
// on the content widget
......@@ -91,7 +96,7 @@ void FormEditorStack::add(const EditorData &data)
frame->setFrameStyle(QFrame::NoFrame);
}
int FormEditorStack::indexOf(const QDesignerFormWindowInterface *fw) const
int FormEditorStack::indexOfFormWindow(const QDesignerFormWindowInterface *fw) const
{
const int count = m_formEditors.size();
for(int i = 0; i < count; ++i)
......@@ -100,7 +105,7 @@ int FormEditorStack::indexOf(const QDesignerFormWindowInterface *fw) const
return -1;
}
int FormEditorStack::indexOf(const Core::IEditor *xmlEditor) const
int FormEditorStack::indexOfFormEditor(const QObject *xmlEditor) const
{
const int count = m_formEditors.size();
for(int i = 0; i < count; ++i)
......@@ -113,7 +118,7 @@ EditorData FormEditorStack::activeEditor() const
{
// Should actually be in sync with current index.
if (QDesignerFormWindowInterface *afw = m_designerCore->formWindowManager()->activeFormWindow()) {
const int index = indexOf(afw);
const int index = indexOfFormWindow(afw);
if (index >= 0)
return m_formEditors.at(index);
}
......@@ -122,28 +127,28 @@ EditorData FormEditorStack::activeEditor() const
SharedTools::WidgetHost *FormEditorStack::formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const
{
const int i = indexOf(fw);
const int i = indexOfFormWindow(fw);
return i != -1 ? m_formEditors[i].widgetHost : static_cast<SharedTools::WidgetHost *>(0);
}
bool FormEditorStack::removeFormWindowEditor(Core::IEditor *xmlEditor)
void FormEditorStack::removeFormWindowEditor(QObject *xmlEditor)
{
const int i = indexOfFormEditor(xmlEditor);
if (Designer::Constants::Internal::debug)
qDebug() << "FormEditorStack::removeFormWindowEditor" << xmlEditor;
const int i = indexOf(xmlEditor);
if (i == -1) // Fail silently as this is invoked for all editors.
return false;
qDebug() << "FormEditorStack::removeFormWindowEditor" << xmlEditor << i << " of " << m_formEditors.size() ;
if (i == -1) // Fail silently as this is invoked for all editors from EditorManager
return; // and editor deletion signal.
removeWidget(m_formEditors[i].widgetHost);
m_formEditors[i].widgetHost->deleteLater();
m_formEditors.removeAt(i);
return true;
}
bool FormEditorStack::setVisibleEditor(Core::IEditor *xmlEditor)
{
if (Designer::Constants::Internal::debug)
qDebug() << "FormEditorStack::setVisibleEditor" << xmlEditor;
const int i = indexOf(xmlEditor);
const int i = indexOfFormEditor(xmlEditor);
QTC_ASSERT(i != -1, return false);
if (i != currentIndex())
......@@ -177,7 +182,7 @@ void FormEditorStack::formSizeChanged(int w, int h)
SharedTools::WidgetHost *FormEditorStack::formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const
{
const int i = indexOf(xmlEditor);
const int i = indexOfFormEditor(xmlEditor);
return i != -1 ? m_formEditors.at(i).widgetHost : static_cast<SharedTools::WidgetHost *>(0);
}
......
......@@ -66,7 +66,6 @@ public:
explicit FormEditorStack(QWidget *parent = 0);
void add(const EditorData &d);
bool removeFormWindowEditor(Core::IEditor *xmlEditor);
bool setVisibleEditor(Core::IEditor *xmlEditor);
SharedTools::WidgetHost *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const;
......@@ -74,14 +73,17 @@ public:
EditorData activeEditor() const;
public slots:
void removeFormWindowEditor(QObject *);
private slots:
void updateFormWindowSelectionHandles();
void modeAboutToChange(Core::IMode *);
void formSizeChanged(int w, int h);
private:
inline int indexOf(const QDesignerFormWindowInterface *) const;
inline int indexOf(const Core::IEditor *xmlEditor) const;
inline int indexOfFormWindow(const QDesignerFormWindowInterface *) const;
inline int indexOfFormEditor(const QObject *xmlEditor) const;
QList<EditorData> m_formEditors;
QDesignerFormEditorInterface *m_designerCore;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment