viewmanager.cpp 7.68 KB
Newer Older
Marco Bubke's avatar
Marco Bubke committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "viewmanager.h"

#include "designdocument.h"
#include "componentaction.h"
#include "itemlibrarywidget.h"
#include "designmodewidget.h"
#include "formeditorwidget.h"
#include "toolbox.h"
#include "designeractionmanager.h"

#include <qmldesigner/qmldesignerplugin.h>

#include <utils/crumblepath.h>
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtversionmanager.h>
#include <qtsupport/qtsupportconstants.h>

namespace QmlDesigner {

ViewManager::ViewManager()
{
    //QObject::connect(&m_nodeInstanceView, SIGNAL(qmlPuppetCrashed()), designModeWidget, SLOT(qmlPuppetCrashed()));
    //QObject::connect(m_formEditorView.crumblePath(), SIGNAL(elementClicked(QVariant)), designModeWidget, SLOT(onCrumblePathElementClicked(QVariant)));
    m_formEditorView.formEditorWidget()->toolBox()->addLeftSideAction(m_componentView.action()); // ugly hack
}

27
28
29
30
31
32
ViewManager::~ViewManager()
{
    foreach (const QWeakPointer<AbstractView> &view, m_additionalViews)
        delete view.data();
}

Marco Bubke's avatar
Marco Bubke committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
DesignDocument *ViewManager::currentDesignDocument() const
{
    return QmlDesignerPlugin::instance()->documentManager().currentDesignDocument();
}

QString ViewManager::pathToQt() const
{
    QtSupport::BaseQtVersion *activeQtVersion = QtSupport::QtVersionManager::instance()->version(currentDesignDocument()->qtVersionId());
    if (activeQtVersion && (activeQtVersion->qtVersion() >= QtSupport::QtVersionNumber(4, 7, 1))
            && (activeQtVersion->type() == QLatin1String(QtSupport::Constants::DESKTOPQT)
                || activeQtVersion->type() == QLatin1String(QtSupport::Constants::SIMULATORQT)))
        return activeQtVersion->qmakeProperty("QT_INSTALL_DATA");

    return QString();
}

void ViewManager::attachNodeInstanceView()
{
    setNodeInstanceViewQtPath(pathToQt());
    currentModel()->setNodeInstanceView(&m_nodeInstanceView);
}

void ViewManager::attachRewriterView(TextModifier *textModifier)
{
    if (currentDesignDocument()->rewriterView()) {
        currentDesignDocument()->rewriterView()->setTextModifier(textModifier);
        currentDesignDocument()->rewriterView()->reactivateTextMofifierChangeSignals();
        currentModel()->setRewriterView(currentDesignDocument()->rewriterView());
    }
}

void ViewManager::detachRewriterView()
{
    if (currentDesignDocument()->rewriterView()) {
        currentDesignDocument()->rewriterView()->deactivateTextMofifierChangeSignals();
        currentModel()->setRewriterView(0);
    }
}

void ViewManager::switchStateEditorViewToBaseState()
{
    if (m_statesEditorView.isAttached()) {
        m_savedState = m_statesEditorView.currentState();
        m_statesEditorView.setCurrentState(m_statesEditorView.baseState());
    }
}

void ViewManager::switchStateEditorViewToSavedState()
{
    if (m_savedState.isValid() && m_statesEditorView.isAttached())
        m_statesEditorView.setCurrentState(m_savedState);
}

void ViewManager::resetPropertyEditorView()
{
    m_propertyEditorView.resetView();
}

Marco Bubke's avatar
Marco Bubke committed
91
void ViewManager::registerFormEditorTool(AbstractFormEditorTool *tool)
92
93
94
95
{
    m_formEditorView.registerTool(tool);
}

96
97
98
99
100
void ViewManager::registerView(AbstractView *view)
{
    m_additionalViews.append(view);
}

Marco Bubke's avatar
Marco Bubke committed
101
102
103
void ViewManager::detachViewsExceptRewriterAndComponetView()
{
    switchStateEditorViewToBaseState();
104
    detachAdditionalViews();
Marco Bubke's avatar
Marco Bubke committed
105
106
107
108
109
110
111
    currentModel()->detachView(DesignerActionManager::view());
    currentModel()->detachView(&m_formEditorView);
    currentModel()->detachView(&m_navigatorView);
    currentModel()->detachView(&m_itemLibraryView);
    currentModel()->detachView(&m_statesEditorView);
    currentModel()->detachView(&m_propertyEditorView);
    currentModel()->setNodeInstanceView(0);
112
113
114
115

    static bool enableViewLogger = !qgetenv("QTC_ENABLE_QMLDESIGNER_LOGGER").isEmpty();
    if (enableViewLogger)
        currentModel()->detachView(&m_viewLogger);
Marco Bubke's avatar
Marco Bubke committed
116
117
118
119
120
121
122
123
}

void ViewManager::attachItemLibraryView()
{
    setItemLibraryViewResourcePath(QFileInfo(currentDesignDocument()->fileName()).absolutePath());
    currentModel()->attachView(&m_itemLibraryView);
}

124
125
126
127
128
129
130
131
132
133
134
135
void ViewManager::attachAdditionalViews()
{
    foreach (const QWeakPointer<AbstractView> &view, m_additionalViews)
        currentModel()->attachView(view.data());
}

void ViewManager::detachAdditionalViews()
{
    foreach (const QWeakPointer<AbstractView> &view, m_additionalViews)
        currentModel()->detachView(view.data());
}

Marco Bubke's avatar
Marco Bubke committed
136
137
138
void ViewManager::attachComponentView()
{
    documentModel()->attachView(&m_componentView);
139
    QObject::connect(m_componentView.action(), SIGNAL(currentComponentChanged(ModelNode)), currentDesignDocument(), SLOT(changeToSubComponent(ModelNode)));
Marco Bubke's avatar
Marco Bubke committed
140
141
142
143
}

void ViewManager::detachComponentView()
{
144
    QObject::disconnect(m_componentView.action(), SIGNAL(currentComponentChanged(ModelNode)), currentDesignDocument(), SLOT(changeToSubComponent(ModelNode)));
Marco Bubke's avatar
Marco Bubke committed
145
146
147
148
149
    documentModel()->detachView(&m_componentView);
}

void ViewManager::attachViewsExceptRewriterAndComponetView()
{
150
151
152
153
    static bool enableViewLogger = !qgetenv("QTC_ENABLE_QMLDESIGNER_LOGGER").isEmpty();
    if (enableViewLogger)
        currentModel()->attachView(&m_viewLogger);

Marco Bubke's avatar
Marco Bubke committed
154
155
156
157
158
159
160
    attachNodeInstanceView();
    currentModel()->attachView(&m_formEditorView);
    currentModel()->attachView(&m_navigatorView);
    attachItemLibraryView();
    currentModel()->attachView(&m_statesEditorView);
    currentModel()->attachView(&m_propertyEditorView);
    currentModel()->attachView(DesignerActionManager::view());
161
    attachAdditionalViews();
Marco Bubke's avatar
Marco Bubke committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
    switchStateEditorViewToSavedState();
}

void ViewManager::setItemLibraryViewResourcePath(const QString &resourcePath)
{
    m_itemLibraryView.setResourcePath(resourcePath);
}

void ViewManager::setComponentNode(const ModelNode &componentNode)
{
    m_componentView.setComponentNode(componentNode);
}

void ViewManager::setNodeInstanceViewQtPath(const QString &qtPath)
{
    m_nodeInstanceView.setPathToQt(qtPath);
}

180
static bool widgetInfoLessThan(const WidgetInfo &firstWidgetInfo, const WidgetInfo &secondWidgetInfo)
Marco Bubke's avatar
Marco Bubke committed
181
{
182
    return firstWidgetInfo.placementPriority < secondWidgetInfo.placementPriority;
Marco Bubke's avatar
Marco Bubke committed
183
184
}

185
QList<WidgetInfo> ViewManager::widgetInfos()
Marco Bubke's avatar
Marco Bubke committed
186
{
187
    QList<WidgetInfo> widgetInfoList;
Marco Bubke's avatar
Marco Bubke committed
188

189
190
191
192
193
194
195
196
197
198
199
200
201
202
    widgetInfoList.append(m_formEditorView.widgetInfo());
    widgetInfoList.append(m_itemLibraryView.widgetInfo());
    widgetInfoList.append(m_navigatorView.widgetInfo());
    widgetInfoList.append(m_propertyEditorView.widgetInfo());
    widgetInfoList.append(m_statesEditorView.widgetInfo());

    foreach (const QWeakPointer<AbstractView> &abstractView, m_additionalViews) {
        if (abstractView && abstractView->hasWidget())
            widgetInfoList.append(abstractView->widgetInfo());
    }

    qSort(widgetInfoList.begin(), widgetInfoList.end(), widgetInfoLessThan);

    return widgetInfoList;
Marco Bubke's avatar
Marco Bubke committed
203
204
}

205
void ViewManager::disableWidgets()
Marco Bubke's avatar
Marco Bubke committed
206
{
207
208
    foreach (const WidgetInfo &widgetInfo, widgetInfos())
        widgetInfo.widget->setEnabled(false);
Marco Bubke's avatar
Marco Bubke committed
209
210
}

211
void ViewManager::enableWidgets()
Marco Bubke's avatar
Marco Bubke committed
212
{
213
214
    foreach (const WidgetInfo &widgetInfo, widgetInfos())
        widgetInfo.widget->setEnabled(true);
Marco Bubke's avatar
Marco Bubke committed
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
}

void ViewManager::pushFileOnCrambleBar(const QString &fileName)
{
    m_formEditorView.formEditorWidget()->formEditorCrumbleBar()->pushFile(fileName);
}

void ViewManager::pushInFileComponentOnCrambleBar(const QString &componentId)

{
    m_formEditorView.formEditorWidget()->formEditorCrumbleBar()->pushInFileComponent(componentId);
}

void ViewManager::nextFileIsCalledInternally()
{
    m_formEditorView.formEditorWidget()->formEditorCrumbleBar()->nextFileIsCalledInternally();
}

233
234
235
236
237
 QmlModelView *ViewManager::qmlModelView()
 {
     return &m_formEditorView;
 }

Marco Bubke's avatar
Marco Bubke committed
238
239
240
241
242
243
244
245
246
247
248
Model *ViewManager::currentModel() const
{
    return currentDesignDocument()->currentModel();
}

Model *ViewManager::documentModel() const
{
    return currentDesignDocument()->documentModel();
}

} // namespace QmlDesigner