forked from qt-creator/qt-creator
Refactoring document handling
The document handling in the qml designer was complicated source code, which was initially intended for a non creator application. To integrate new views it has to be changed and cleaned up. This is the first major step in that direction. Change-Id: Ie26f0aad7a03946d18bdb4c0759b246c5439d922 Reviewed-by: Tim Jenssen <tim.jenssen@digia.com> Reviewed-by: Alessandro Portale <alessandro.portale@digia.com>
This commit is contained in:
80
src/plugins/qmldesigner/documentmanager.cpp
Normal file
80
src/plugins/qmldesigner/documentmanager.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "documentmanager.h"
|
||||
|
||||
#include <coreplugin/designmode.h>
|
||||
#include <coreplugin/modemanager.h>
|
||||
#include <qmljseditor/qmljseditorconstants.h>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
DocumentManager::DocumentManager()
|
||||
: QObject()
|
||||
{
|
||||
}
|
||||
|
||||
DocumentManager::~DocumentManager()
|
||||
{
|
||||
foreach (const QWeakPointer<DesignDocument> &designDocument, m_designDocumentHash)
|
||||
delete designDocument.data();
|
||||
}
|
||||
|
||||
void DocumentManager::setCurrentDesignDocument(Core::IEditor *editor)
|
||||
{
|
||||
if (editor) {
|
||||
m_currentDesignDocument = m_designDocumentHash.value(editor);
|
||||
if (m_currentDesignDocument == 0) {
|
||||
m_currentDesignDocument = new DesignDocument;
|
||||
m_designDocumentHash.insert(editor, m_currentDesignDocument);
|
||||
m_currentDesignDocument->setEditor(editor);
|
||||
}
|
||||
} else {
|
||||
m_currentDesignDocument->resetToDocumentModel();
|
||||
m_currentDesignDocument.clear();
|
||||
}
|
||||
}
|
||||
|
||||
DesignDocument *DocumentManager::currentDesignDocument() const
|
||||
{
|
||||
return m_currentDesignDocument.data();
|
||||
}
|
||||
|
||||
bool DocumentManager::hasCurrentDesignDocument() const
|
||||
{
|
||||
return m_currentDesignDocument.data();
|
||||
}
|
||||
|
||||
void DocumentManager::removeEditors(QList<Core::IEditor *> editors)
|
||||
{
|
||||
foreach (Core::IEditor *editor, editors)
|
||||
delete m_designDocumentHash.take(editor).data();
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
||||
Reference in New Issue
Block a user