qt5nodeinstanceserver.cpp 4.13 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Thomas Murach's avatar
Thomas Murach committed
2
**
hjk's avatar
hjk committed
3
4
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
Thomas Murach's avatar
Thomas Murach committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Thomas Murach's avatar
Thomas Murach committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** 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.
Thomas Murach's avatar
Thomas Murach committed
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
** 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.
Thomas Murach's avatar
Thomas Murach committed
23
**
hjk's avatar
hjk committed
24
25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
Thomas Murach's avatar
Thomas Murach committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29
30
31
32

#include "qt5nodeinstanceserver.h"


33
34
#include <QQuickItem>
#include <QQuickView>
35

36
#include <designersupport.h>
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <addimportcontainer.h>
#include <createscenecommand.h>

namespace QmlDesigner {

Qt5NodeInstanceServer::Qt5NodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient)
    : NodeInstanceServer(nodeInstanceClient),
      m_designerSupport(new DesignerSupport)
{
    addImportString("import QtQuick 2.0\n");
}

Qt5NodeInstanceServer::~Qt5NodeInstanceServer()
{
51
    delete quickView();
52
53
54
55
    delete m_designerSupport;
    m_designerSupport = 0;
}

56
QQuickView *Qt5NodeInstanceServer::quickView() const
57
{
58
    return m_quickView.data();
59
60
61
62
}

void Qt5NodeInstanceServer::initializeView(const QVector<AddImportContainer> &/*importVector*/)
{
63
64
65
    Q_ASSERT(!quickView());

    m_quickView = new QQuickView;
66
    DesignerSupport::createOpenGLContext(m_quickView.data());
67
68
}

69
QQmlView *Qt5NodeInstanceServer::declarativeView() const
70
71
72
73
{
    return 0;
}

74
QQmlEngine *Qt5NodeInstanceServer::engine() const
75
{
76
77
    if (quickView())
        return quickView()->engine();
78
79
80
81
82
83
84
85
86
87

    return 0;
}

void Qt5NodeInstanceServer::resizeCanvasSizeToRootItemSize()
{
}

void Qt5NodeInstanceServer::resetAllItems()
{
88
    foreach (QQuickItem *item, allItems())
89
        DesignerSupport::resetDirty(item);
90
91
92
93
94
95
}

QList<ServerNodeInstance> Qt5NodeInstanceServer::setupScene(const CreateSceneCommand &command)
{
    setupFileUrl(command.fileUrl());
    setupImports(command.imports());
96
    setupDummyData(command.fileUrl());
97
98
99

    QList<ServerNodeInstance> instanceList = setupInstances(command);

100
    quickView()->resize(rootNodeInstance().boundingRect().size().toSize());
101
102
103
104

    return instanceList;
}

105
QList<QQuickItem*> subItems(QQuickItem *parentItem)
106
{
107
    QList<QQuickItem*> itemList;
108
109
    itemList.append(parentItem->childItems());

110
    foreach (QQuickItem *childItem, parentItem->childItems())
111
112
113
114
115
        itemList.append(subItems(childItem));

    return itemList;
}

116
QList<QQuickItem*> Qt5NodeInstanceServer::allItems() const
117
{
118
    QList<QQuickItem*> itemList;
119

120
121
122
    if (quickView()) {
        itemList.append(quickView()->rootItem());
        itemList.append(subItems(quickView()->rootItem()));
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
    }

    return itemList;
}

void Qt5NodeInstanceServer::refreshBindings()
{
    DesignerSupport::refreshExpressions(context());
}

DesignerSupport *Qt5NodeInstanceServer::designerSupport() const
{
    return m_designerSupport;
}

void Qt5NodeInstanceServer::createScene(const CreateSceneCommand &command)
{
    m_designerSupport = new DesignerSupport;
    NodeInstanceServer::createScene(command);
}

void Qt5NodeInstanceServer::clearScene(const ClearSceneCommand &command)
{
    delete m_designerSupport;
    m_designerSupport = 0;
148
    NodeInstanceServer::clearScene(command);
149
150
151
}

} // QmlDesigner