Commit 10966945 authored by Marco Bubke's avatar Marco Bubke Committed by Thomas Hartmann
Browse files

QmlDesigner: Use ScopedPointer instead of raw pointer



Change-Id: I2fb52fdb01c287fa1a4090b639f26521a3aabc6d
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent f185097b
......@@ -97,7 +97,7 @@ DesignDocument::DesignDocument(QObject *parent) :
QObject(parent),
m_documentModel(Model::create("QtQuick.Item", 1, 0)),
m_inFileComponentModel(Model::create("QtQuick.Item", 1, 0)),
m_currentModel(m_documentModel),
m_currentModel(m_documentModel.data()),
m_subComponentManager(new SubComponentManager(m_documentModel.data(), this)),
m_rewriterView (new RewriterView(RewriterView::Amend, m_documentModel.data())),
m_documentLoaded(false),
......@@ -108,13 +108,6 @@ DesignDocument::DesignDocument(QObject *parent) :
DesignDocument::~DesignDocument()
{
delete m_documentModel.data();
delete m_inFileComponentModel.data();
delete rewriterView();
delete m_inFileComponentTextModifier.data();
delete m_documentTextModifier.data();
}
Model *DesignDocument::currentModel() const
......@@ -132,7 +125,7 @@ void DesignDocument::changeToDocumentModel()
viewManager().detachRewriterView();
viewManager().detachViewsExceptRewriterAndComponetView();
m_currentModel = m_documentModel;
m_currentModel = m_documentModel.data();
viewManager().attachRewriterView(m_documentTextModifier.data());
viewManager().attachViewsExceptRewriterAndComponetView();
......@@ -143,7 +136,7 @@ void DesignDocument::changeToInFileComponentModel()
viewManager().detachRewriterView();
viewManager().detachViewsExceptRewriterAndComponetView();
m_currentModel = m_inFileComponentModel;
m_currentModel = m_inFileComponentModel.data();
viewManager().attachRewriterView(m_inFileComponentTextModifier.data());
viewManager().attachViewsExceptRewriterAndComponetView();
......@@ -208,12 +201,11 @@ bool DesignDocument::loadInFileComponent(const ModelNode &componentNode)
return false;
if (!componentNode.isRootNode()) {
Q_ASSERT(m_currentModel == m_documentModel);
//change to subcomponent model
if (m_inFileComponentTextModifier)
delete m_inFileComponentTextModifier.data();
m_inFileComponentTextModifier = createComponentTextModifier(m_documentTextModifier.data(), rewriterView(), componentText, componentNode);
m_inFileComponentTextModifier.reset(createComponentTextModifier(m_documentTextModifier.data(), rewriterView(), componentText, componentNode));
changeToInFileComponentModel();
}
......@@ -286,7 +278,7 @@ bool DesignDocument::isDocumentLoaded() const
void DesignDocument::resetToDocumentModel()
{
m_currentModel = m_documentModel;
m_currentModel = m_documentModel.data();
m_rewriterView->setTextModifier(m_documentTextModifier.data());
}
......@@ -301,9 +293,9 @@ void DesignDocument::loadDocument(QPlainTextEdit *edit)
connect(edit, SIGNAL(modificationChanged(bool)),
this, SIGNAL(dirtyStateChanged(bool)));
m_documentTextModifier = new BaseTextEditModifier(dynamic_cast<TextEditor::BaseTextEditorWidget*>(plainTextEdit()));
m_documentTextModifier.reset(new BaseTextEditModifier(dynamic_cast<TextEditor::BaseTextEditorWidget*>(plainTextEdit())));
m_inFileComponentTextModifier.clear();
m_inFileComponentTextModifier.reset();
//masterModel = Model::create(textModifier, searchPath, errors);
......@@ -314,11 +306,6 @@ void DesignDocument::loadDocument(QPlainTextEdit *edit)
m_documentLoaded = true;
}
static const QString fileNameOfCurrentDocument()
{
return QmlDesignerPlugin::instance()->documentManager().currentDesignDocument()->textEditor()->document()->fileName();
}
void DesignDocument::changeCurrentModelTo(const ModelNode &node)
{
if (QmlDesignerPlugin::instance()->currentDesignDocument() != this)
......@@ -334,18 +321,15 @@ void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
QWeakPointer<Model> oldModel = m_currentModel;
Q_ASSERT(oldModel.data());
if (m_currentModel == m_inFileComponentModel) {
if (m_currentModel.data() == m_inFileComponentModel.data()) {
changeToDocumentModel();
}
bool subComponentLoaded = loadInFileComponent(componentNode);
if (subComponentLoaded) {
Q_ASSERT(m_documentModel);
Q_ASSERT(m_currentModel);
if (subComponentLoaded)
activateCurrentModel(m_inFileComponentTextModifier.data());
}
if (!componentNode.id().isEmpty())
QmlDesignerPlugin::instance()->viewManager().pushInFileComponentOnCrambleBar(componentNode.id());
}
......
......@@ -144,16 +144,16 @@ private: // functions
QmlModelView *qmlModelView();
private: // variables
QWeakPointer<QStackedWidget> m_stackedWidget;
QWeakPointer<Model> m_documentModel;
QWeakPointer<Model> m_inFileComponentModel;
QScopedPointer<QStackedWidget> m_stackedWidget;
QScopedPointer<Model> m_documentModel;
QScopedPointer<Model> m_inFileComponentModel;
QWeakPointer<Model> m_currentModel;
QWeakPointer<Core::IEditor> m_textEditor;
QWeakPointer<BaseTextEditModifier> m_documentTextModifier;
QWeakPointer<ComponentTextModifier> m_inFileComponentTextModifier;
QWeakPointer<SubComponentManager> m_subComponentManager;
QScopedPointer<BaseTextEditModifier> m_documentTextModifier;
QScopedPointer<ComponentTextModifier> m_inFileComponentTextModifier;
QScopedPointer<SubComponentManager> m_subComponentManager;
QWeakPointer<RewriterView> m_rewriterView;
QScopedPointer<RewriterView> m_rewriterView;
bool m_documentLoaded;
int m_qtVersionId;
......
......@@ -183,8 +183,6 @@ void DocumentWarningWidget::goToError()
DesignModeWidget::DesignModeWidget(QWidget *parent) :
QWidget(parent),
m_mainSplitter(0),
m_leftSideBar(0),
m_rightSideBar(0),
m_isDisabled(false),
m_showSidebars(true),
m_initStatus(NotInitialized),
......@@ -196,6 +194,10 @@ DesignModeWidget::DesignModeWidget(QWidget *parent) :
m_outputPanePlaceholder = new StyledOutputpanePlaceHolder(Core::DesignMode::instance(), m_outputPlaceholderSplitter);
}
DesignModeWidget::~DesignModeWidget()
{
}
void DesignModeWidget::restoreDefaultView()
{
QSettings *settings = Core::ICore::settings();
......@@ -407,11 +409,11 @@ void DesignModeWidget::setup()
m_sideBarItems << openDocumentsItem;
}
m_leftSideBar = new Core::SideBar(m_sideBarItems, QList<Core::SideBarItem*>() << navigatorItem << libraryItem);
m_rightSideBar = new Core::SideBar(m_sideBarItems, QList<Core::SideBarItem*>() << propertiesItem);
m_leftSideBar.reset(new Core::SideBar(m_sideBarItems, QList<Core::SideBarItem*>() << navigatorItem << libraryItem));
m_rightSideBar.reset(new Core::SideBar(m_sideBarItems, QList<Core::SideBarItem*>() << propertiesItem));
connect(m_leftSideBar, SIGNAL(availableItemsChanged()), SLOT(updateAvailableSidebarItemsRight()));
connect(m_rightSideBar, SIGNAL(availableItemsChanged()), SLOT(updateAvailableSidebarItemsLeft()));
connect(m_leftSideBar.data(), SIGNAL(availableItemsChanged()), SLOT(updateAvailableSidebarItemsRight()));
connect(m_rightSideBar.data(), SIGNAL(availableItemsChanged()), SLOT(updateAvailableSidebarItemsLeft()));
connect(Core::ICore::instance(), SIGNAL(coreAboutToClose()),
this, SLOT(deleteSidebarWidgets()));
......@@ -429,9 +431,9 @@ void DesignModeWidget::setup()
QWidget *centerWidget = createCenterWidget();
// m_mainSplitter area:
m_mainSplitter->addWidget(m_leftSideBar);
m_mainSplitter->addWidget(m_leftSideBar.data());
m_mainSplitter->addWidget(centerWidget);
m_mainSplitter->addWidget(m_rightSideBar);
m_mainSplitter->addWidget(m_rightSideBar.data());
// Finishing touches:
m_mainSplitter->setStretchFactor(1, 1);
......@@ -468,10 +470,8 @@ void DesignModeWidget::updateAvailableSidebarItemsLeft()
void DesignModeWidget::deleteSidebarWidgets()
{
delete m_leftSideBar;
delete m_rightSideBar;
m_leftSideBar = 0;
m_rightSideBar = 0;
m_leftSideBar.reset();
m_rightSideBar.reset();
}
void DesignModeWidget::qmlPuppetCrashed()
......
......@@ -52,6 +52,7 @@
#include <QToolBar>
#include <QComboBox>
#include <QLabel>
#include <QScopedPointer>
QT_BEGIN_NAMESPACE
class QStackedWidget;
......@@ -104,6 +105,7 @@ class DesignModeWidget : public QWidget
public:
explicit DesignModeWidget(QWidget *parent = 0);
~DesignModeWidget();
void showEditor(Core::IEditor *editor);
void closeEditors(const QList<Core::IEditor*> editors);
QString contextHelpId() const;
......@@ -157,8 +159,8 @@ private: // functions
private: // variables
QSplitter *m_mainSplitter;
Core::SideBar *m_leftSideBar;
Core::SideBar *m_rightSideBar;
QScopedPointer<Core::SideBar> m_leftSideBar;
QScopedPointer<Core::SideBar> m_rightSideBar;
Core::EditorToolBar *m_toolBar;
Core::OutputPanePlaceHolder *m_outputPanePlaceholder;
Core::MiniSplitter *m_outputPlaceholderSplitter;
......
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