propertyeditor.h 5.75 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
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.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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
con's avatar
con 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 33

#ifndef QmlPropertyView_h
#define QmlPropertyView_h

#include <qmlmodelview.h>
34
#include <declarativewidgetview.h>
35
#include <QHash>
36
#include <QDeclarativePropertyMap>
37
#include <QStackedWidget>
38
#include <QTimer>
39 40

#include "qmlanchorbindingproxy.h"
41 42
#include "designerpropertymap.h"
#include "propertyeditorvalue.h"
43
#include "propertyeditorcontextobject.h"
44

45
QT_BEGIN_NAMESPACE
46 47
class QShortcut;
class QStackedWidget;
48
class QTimer;
49
QT_END_NAMESPACE
50

51 52
class PropertyEditorValue;

53 54
namespace QmlDesigner {

55
class PropertyEditorTransaction;
56 57
class CollapseButton;
class StackedWidget;
58

59 60 61 62 63 64
class PropertyEditor: public QmlModelView
{
    Q_OBJECT

    class NodeType {
    public:
65
        NodeType(PropertyEditor *propertyEditor);
66 67
        ~NodeType();

68
        void setup(const QmlObjectNode &fxObjectNode, const QString &stateName, const QUrl &qmlSpecificsFile, PropertyEditor *propertyEditor);
69 70
        void initialSetup(const TypeName &typeName, const QUrl &qmlSpecificsFile, PropertyEditor *propertyEditor);
        void setValue(const QmlObjectNode &fxObjectNode, const PropertyName &name, const QVariant &value);
71

72
        DeclarativeWidgetView *m_view;
73
        Internal::QmlAnchorBindingProxy m_backendAnchorBinding;
74
        DesignerPropertyMap<PropertyEditorValue> m_backendValuesPropertyMap;
75
        QScopedPointer<PropertyEditorTransaction> m_propertyEditorTransaction;
76
        QScopedPointer<PropertyEditorValue> m_dummyPropertyEditorValue;
77
        QScopedPointer<PropertyEditorContextObject> m_contextObject;
78 79 80 81 82 83 84 85
    };

public:
    PropertyEditor(QWidget *parent = 0);
    ~PropertyEditor();

    void setQmlDir(const QString &qmlDirPath);

86
    QWidget *widget();
87 88
    bool hasWidget() const;
    WidgetInfo widgetInfo();
89 90

    void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
91 92
                              const QList<ModelNode> &lastSelectedNodeList) QTC_OVERRIDE;
    void nodeAboutToBeRemoved(const ModelNode &removedNode) QTC_OVERRIDE;
93

94
    void propertiesRemoved(const QList<AbstractProperty>& propertyList) QTC_OVERRIDE;
95

96
    void modelAttached(Model *model) QTC_OVERRIDE;
97

98
    void modelAboutToBeDetached(Model *model) QTC_OVERRIDE;
99 100 101

    ModelState modelState() const;

102 103
    void variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange) QTC_OVERRIDE;
    void bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange) QTC_OVERRIDE;
104

105
    void instanceInformationsChange(const QMultiHash<ModelNode, InformationName> &informationChangeHash) QTC_OVERRIDE;
106

107 108
    void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId) QTC_OVERRIDE;
    void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList) QTC_OVERRIDE;
109

110
    void resetView();
111 112
    void actualStateChanged(const ModelNode &node) QTC_OVERRIDE;
    void instancePropertyChange(const QList<QPair<ModelNode, PropertyName> > &propertyList) QTC_OVERRIDE;
113

114 115
protected:
    void timerEvent(QTimerEvent *event);
116 117
    void setupPane(const TypeName &typeName);
    void setValue(const QmlObjectNode &fxObjectNode, const PropertyName &name, const QVariant &value);
118 119 120 121 122

private slots:
    void reloadQml();
    void changeValue(const QString &name);
    void changeExpression(const QString &name);
123
    void updateSize();
124
    void setupPanes();
125 126 127 128

private: //functions
    QString qmlFileName(const NodeMetaInfo &nodeInfo) const;
    QUrl fileToUrl(const QString &filePath) const;
129
    QString fileFromUrl(const QUrl &url) const;
130
    QUrl qmlForNode(const ModelNode &modelNode, TypeName &className) const;
131
    QString locateQmlFile(const NodeMetaInfo &info, const QString &relativePath) const;
132 133 134 135 136 137 138 139 140 141
    void select(const ModelNode& node);

    void delayedResetView();


private: //variables
    ModelNode m_selectedNode;
    QWidget *m_parent;
    QShortcut *m_updateShortcut;
    int m_timerId;
142
    StackedWidget* m_stackedWidget;
143 144 145
    QString m_qmlDir;
    QHash<QString, NodeType *> m_typeHash;
    NodeType *m_currentType;
146
    bool m_locked;
147
    bool m_setupCompleted;
148
    QTimer *m_singleShotTimer;
149 150
};

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

class StackedWidget : public QStackedWidget
{
Q_OBJECT

public:
    StackedWidget(QWidget *parent = 0) : QStackedWidget(parent) {}

signals:
    void resized();
protected:
    void resizeEvent(QResizeEvent * event)
    {
        QStackedWidget::resizeEvent(event);
        emit resized();
    }
};
168 169 170
}

#endif // QmlPropertyView_h