Commit 1dfd78a9 authored by Christian Kamm's avatar Christian Kamm
Browse files

Indenters: Fix dangling pointer when project settings are deleted.

Task-number: QTCREATORBUG-5390
Change-Id: I68517955a86fbb2ded53f6235a7fe27793e2b2c8
Reviewed-on: http://codereview.qt.nokia.com/1481

Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent f7b2dd95
...@@ -50,6 +50,8 @@ using namespace CppTools; ...@@ -50,6 +50,8 @@ using namespace CppTools;
CppQtStyleIndenter::CppQtStyleIndenter() CppQtStyleIndenter::CppQtStyleIndenter()
: m_cppCodeStylePreferences(0) : m_cppCodeStylePreferences(0)
{ {
// Just for safety. setCodeStylePreferences should be called when the editor the
// indenter belongs to gets initialized.
m_cppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStylePreferences(); m_cppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStylePreferences();
} }
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "codeassistant.h" #include "codeassistant.h"
#include "defaultassistinterface.h" #include "defaultassistinterface.h"
#include "convenience.h" #include "convenience.h"
#include "texteditorsettings.h"
#include <aggregation/aggregate.h> #include <aggregation/aggregate.h>
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
...@@ -4335,12 +4336,16 @@ void BaseTextEditorWidget::setTabPreferences(TabPreferences *tabPreferences) ...@@ -4335,12 +4336,16 @@ void BaseTextEditorWidget::setTabPreferences(TabPreferences *tabPreferences)
{ {
if (d->m_tabPreferences) { if (d->m_tabPreferences) {
disconnect(d->m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)), disconnect(d->m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
this, SLOT(setTabSettings(TextEditor::TabSettings))); this, SLOT(setTabSettings(TextEditor::TabSettings)));
disconnect(d->m_tabPreferences, SIGNAL(destroyed()),
this, SLOT(onTabPreferencesDestroyed()));
} }
d->m_tabPreferences = tabPreferences; d->m_tabPreferences = tabPreferences;
if (d->m_tabPreferences) { if (d->m_tabPreferences) {
connect(d->m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)), connect(d->m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
this, SLOT(setTabSettings(TextEditor::TabSettings))); this, SLOT(setTabSettings(TextEditor::TabSettings)));
connect(d->m_tabPreferences, SIGNAL(destroyed()),
this, SLOT(onTabPreferencesDestroyed()));
setTabSettings(d->m_tabPreferences->currentSettings()); setTabSettings(d->m_tabPreferences->currentSettings());
} }
} }
...@@ -4351,15 +4356,37 @@ void BaseTextEditorWidget::setCodeStylePreferences(IFallbackPreferences *prefere ...@@ -4351,15 +4356,37 @@ void BaseTextEditorWidget::setCodeStylePreferences(IFallbackPreferences *prefere
if (d->m_codeStylePreferences) { if (d->m_codeStylePreferences) {
disconnect(d->m_codeStylePreferences, SIGNAL(currentValueChanged(QVariant)), disconnect(d->m_codeStylePreferences, SIGNAL(currentValueChanged(QVariant)),
this, SLOT(slotCodeStyleSettingsChanged(QVariant))); this, SLOT(slotCodeStyleSettingsChanged(QVariant)));
disconnect(d->m_codeStylePreferences, SIGNAL(destroyed()),
this, SLOT(onCodeStylePreferencesDestroyed()));
} }
d->m_codeStylePreferences = preferences; d->m_codeStylePreferences = preferences;
if (d->m_codeStylePreferences) { if (d->m_codeStylePreferences) {
connect(d->m_codeStylePreferences, SIGNAL(currentValueChanged(QVariant)), connect(d->m_codeStylePreferences, SIGNAL(currentValueChanged(QVariant)),
this, SLOT(slotCodeStyleSettingsChanged(QVariant))); this, SLOT(slotCodeStyleSettingsChanged(QVariant)));
connect(d->m_codeStylePreferences, SIGNAL(destroyed()),
this, SLOT(onCodeStylePreferencesDestroyed()));
slotCodeStyleSettingsChanged(d->m_codeStylePreferences->currentValue()); slotCodeStyleSettingsChanged(d->m_codeStylePreferences->currentValue());
} }
} }
void BaseTextEditorWidget::onTabPreferencesDestroyed()
{
if (sender() != d->m_tabPreferences)
return;
// avoid failing disconnects, m_tabPreferences has already been reduced to QObject
d->m_tabPreferences = 0;
setTabPreferences(TextEditorSettings::instance()->tabPreferences(languageSettingsId()));
}
void BaseTextEditorWidget::onCodeStylePreferencesDestroyed()
{
if (sender() != d->m_codeStylePreferences)
return;
// avoid failing disconnects, m_codeStylePreferences has already been reduced to QObject
d->m_codeStylePreferences = 0;
setCodeStylePreferences(TextEditorSettings::instance()->codeStylePreferences(languageSettingsId()));
}
void BaseTextEditorWidget::slotCodeStyleSettingsChanged(const QVariant &) void BaseTextEditorWidget::slotCodeStyleSettingsChanged(const QVariant &)
{ {
......
...@@ -355,6 +355,8 @@ private slots: ...@@ -355,6 +355,8 @@ private slots:
bool inFindScope(const QTextCursor &cursor); bool inFindScope(const QTextCursor &cursor);
bool inFindScope(int selectionStart, int selectionEnd); bool inFindScope(int selectionStart, int selectionEnd);
void inSnippetMode(bool *active); void inSnippetMode(bool *active);
void onTabPreferencesDestroyed();
void onCodeStylePreferencesDestroyed();
private: private:
Internal::BaseTextEditorPrivate *d; Internal::BaseTextEditorPrivate *d;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "indenter.h" #include "indenter.h"
#include "basetexteditor.h" #include "basetexteditor.h"
#include "tabsettings.h" #include "tabsettings.h"
#include "ifallbackpreferences.h"
using namespace TextEditor; using namespace TextEditor;
......
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