1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #pragma once
27 
28 #include <modelnode.h>
29 #include <bindingproperty.h>
30 #include <variantproperty.h>
31 
32 #include <QStandardItemModel>
33 
34 namespace QmlDesigner {
35 
36 namespace Internal {
37 
38 class ConnectionView;
39 
40 class DynamicPropertiesModel : public QStandardItemModel
41 {
42     Q_OBJECT
43 
44 public:
45     enum ColumnRoles {
46         TargetModelNodeRow = 0,
47         PropertyNameRow = 1,
48         PropertyTypeRow = 2,
49         PropertyValueRow = 3
50     };
51     DynamicPropertiesModel(ConnectionView *parent = nullptr);
52     void bindingPropertyChanged(const BindingProperty &bindingProperty);
53     void variantPropertyChanged(const VariantProperty &variantProperty);
54     void bindingRemoved(const BindingProperty &bindingProperty);
55     void selectionChanged(const QList<ModelNode> &selectedNodes);
56 
57     ConnectionView *connectionView() const;
58     AbstractProperty abstractPropertyForRow(int rowNumber) const;
59     BindingProperty bindingPropertyForRow(int rowNumber) const;
60     VariantProperty variantPropertyForRow(int rowNumber) const;
61     QStringList possibleTargetProperties(const BindingProperty &bindingProperty) const;
62     QStringList possibleSourceProperties(const BindingProperty &bindingProperty) const;
63     void deleteDynamicPropertyByRow(int rowNumber);
64 
65     void updateDisplayRoleFromVariant(int row, int columns, const QVariant &variant);
66     void addDynamicPropertyForCurrentNode();
67     void resetModel();
68 
69     BindingProperty replaceVariantWithBinding(const PropertyName &name, bool copyValue = false);
70     void resetProperty(const PropertyName &name);
71 
72 protected:
73     void addProperty(const QVariant &propertyValue,
74                      const QString &propertyType,
75                      const AbstractProperty &abstractProperty);
76     void addBindingProperty(const BindingProperty &property);
77     void addVariantProperty(const VariantProperty &property);
78     void updateBindingProperty(int rowNumber);
79     void updateVariantProperty(int rowNumber);
80     void addModelNode(const ModelNode &modelNode);
81     void updateValue(int row);
82     void updatePropertyName(int rowNumber);
83     void updatePropertyType(int rowNumber);
84     ModelNode getNodeByIdOrParent(const QString &id, const ModelNode &targetNode) const;
85     void updateCustomData(QStandardItem *item, const AbstractProperty &property);
86     void updateCustomData(int row, const AbstractProperty &property);
87     int findRowForBindingProperty(const BindingProperty &bindingProperty) const;
88     int findRowForVariantProperty(const VariantProperty &variantProperty) const;
89 
90     bool getExpressionStrings(const BindingProperty &bindingProperty, QString *sourceNode, QString *sourceProperty);
91 
92     void updateDisplayRole(int row, int columns, const QString &string);
93 
94 private:
95     void handleDataChanged(const QModelIndex &topLeft, const QModelIndex& bottomRight);
96     void handleException();
97 
98 private:
99     ConnectionView *m_connectionView;
100     bool m_lock = false;
101     bool m_handleDataChanged = false;
102     QString m_exceptionError;
103 
104 };
105 
106 } // namespace Internal
107 } // namespace QmlDesigner
108