From 8d9710c0747a68f9938c8e7d32110f67ba64cc1e Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 23 Jan 2013 12:31:22 +0100 Subject: 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 Reviewed-by: Alessandro Portale --- src/plugins/qmldesigner/documentmanager.cpp | 80 +++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/plugins/qmldesigner/documentmanager.cpp (limited to 'src/plugins/qmldesigner/documentmanager.cpp') diff --git a/src/plugins/qmldesigner/documentmanager.cpp b/src/plugins/qmldesigner/documentmanager.cpp new file mode 100644 index 0000000000..4a7af81f42 --- /dev/null +++ b/src/plugins/qmldesigner/documentmanager.cpp @@ -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 +#include +#include + +namespace QmlDesigner { + +DocumentManager::DocumentManager() + : QObject() +{ +} + +DocumentManager::~DocumentManager() +{ + foreach (const QWeakPointer &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 editors) +{ + foreach (Core::IEditor *editor, editors) + delete m_designDocumentHash.take(editor).data(); +} + +} // namespace QmlDesigner -- cgit v1.2.1