Seamly2D
Code documentation
vpropertyformview.cpp
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vpropertyformview.cpp
4  ** @author hedgeware <internal(at)hedgeware.net>
5  ** @date
6  **
7  ** @brief
8  ** @copyright
9  ** All rights reserved. This program and the accompanying materials
10  ** are made available under the terms of the GNU Lesser General Public License
11  ** (LGPL) version 2.1 which accompanies this distribution, and is available at
12  ** http://www.gnu.org/licenses/lgpl-2.1.html
13  **
14  ** This library is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  ** Lesser General Public License for more details.
18  **
19  *************************************************************************/
20 
21 #include "vpropertyformview.h"
22 
23 #include <QList>
24 #include <Qt>
25 
26 #include "vpropertyformview_p.h"
27 #include "vpropertyformwidget_p.h"
28 #include "vpropertymodel.h"
29 #include "vpropertyset.h"
30 
33 {
34  //
35 }
36 
39 {
40  setModel(model);
41 }
42 
45 {
46  setPropertySet(property_set);
47 }
48 
50 {
51  // Nothing to do
52 }
53 
55 {
57 
58  // Go through all sub widgets and connect
59  connectPropertyFormWidget(this);
60 }
61 
63 {
64  // Remove old model or set
65  removeModelAndSet();
66 
67  // Set model
68  static_cast<VPropertyFormViewPrivate*>(d_ptr)->Model = model;
69  if (model)
70  {
71  // Set the property list
72  if (model->getPropertySet())
73  {
74  d_ptr->Properties = model->getPropertySet()->getRootProperties();
75  }
76 
77  // Connect signals // todo: more signals neccesary!!!
78  connect(model, &VPropertyModel::destroyed, this, &VPropertyFormView::modelDestroyed);
79  connect(model, &VPropertyModel::rowsInserted, this, &VPropertyFormView::rowsInserted);
80  connect(model, &VPropertyModel::modelReset, this, &VPropertyFormView::modelReset);
81  connect(model, &VPropertyModel::rowsRemoved, this, &VPropertyFormView::rowsRemoved);
82  }
83 
84  // Build the widget
85  updatePropertyList();
86 }
87 
89 {
90  // Remove old model or set
91  removeModelAndSet();
92 
93  // Set property set
94  static_cast<VPropertyFormViewPrivate*>(d_ptr)->PropertySet = property_set;
95  if (property_set)
96  {
97  // Set the property list
98  d_ptr->Properties = property_set->getRootProperties();
99  }
100 
101  // Build the widget
102  updatePropertyList();
103 }
104 
105 void VPE::VPropertyFormView::rowsRemoved(const QModelIndex &parent, int start, int end)
106 {
107  // todo: Only rebuild the neccessary parts
108  Q_UNUSED(parent)
109  Q_UNUSED(start)
110  Q_UNUSED(end)
111  updatePropertyList();
112 }
113 
114 void VPE::VPropertyFormView::rowsInserted(const QModelIndex &parent, int start, int end) //-V524
115 {
116  // todo: Only rebuild the neccessary parts
117  Q_UNUSED(parent)
118  Q_UNUSED(start)
119  Q_UNUSED(end)
120  updatePropertyList();
121 }
122 
124 {
125  updatePropertyList();
126 }
127 
129 {
130  removeModelAndSet();
131  updatePropertyList();
132 }
133 
134 void VPE::VPropertyFormView::dataChanged(const QModelIndex &top_left, const QModelIndex &bottom_right)
135 {
136  Q_UNUSED(top_left)
137  Q_UNUSED(bottom_right)
138  if (static_cast<VPropertyFormViewPrivate*>(d_ptr)->IgnoreDataChangedSignal)
139  {
140  return;
141  }
142  // todo: handle data changes
143 }
144 
146 {
147  VPropertyModel *tmpModel = static_cast<VPropertyFormViewPrivate*>(d_ptr)->Model;
148 
149  if (tmpModel && d_ptr->UpdateEditors)
150  {
151  static_cast<VPropertyFormViewPrivate*>(d_ptr)->IgnoreDataChangedSignal = true;
152  tmpModel->onDataChangedByModel(property);
153  static_cast<VPropertyFormViewPrivate*>(d_ptr)->IgnoreDataChangedSignal = false;
154  }
155 }
156 
157 void VPE::VPropertyFormView::showEvent(QShowEvent *event)
158 {
159  Q_UNUSED(event)
160  if (static_cast<VPropertyFormViewPrivate*>(d_ptr)->NeedsRebuild)
161  {
162  build();
163  }
164  static_cast<VPropertyFormViewPrivate*>(d_ptr)->NeedsRebuild = false;
165 }
166 
168 {
169  VPropertyModel *tmpModel = static_cast<VPropertyFormViewPrivate*>(d_ptr)->Model;
170  VPropertySet *tmpSet = static_cast<VPropertyFormViewPrivate*>(d_ptr)->PropertySet;
171 
172  if (tmpModel && tmpModel->getPropertySet())
173  {
174  d_ptr->Properties = tmpModel->getPropertySet()->getRootProperties();
175  }
176  else if (tmpSet)
177  {
178  d_ptr->Properties = tmpSet->getRootProperties();
179  }
180  else
181  d_ptr->Properties.clear();
182 
183  if (isVisible())
184  {
185  build();
186  }
187  else
188  static_cast<VPropertyFormViewPrivate*>(d_ptr)->NeedsRebuild = true;
189 }
190 
192 {
193  if (static_cast<VPropertyFormViewPrivate*>(d_ptr)->Model)
194  {
195  disconnect(static_cast<VPropertyFormViewPrivate*>(d_ptr)->Model, nullptr, this, nullptr);
196  static_cast<VPropertyFormViewPrivate*>(d_ptr)->Model = nullptr;
197  }
198 
199  static_cast<VPropertyFormViewPrivate*>(d_ptr)->NeedsRebuild = true;
200  d_ptr->Properties.clear();
201  static_cast<VPropertyFormViewPrivate*>(d_ptr)->PropertySet = nullptr;
202 }
203 
205 {
206  if (!widget)
207  {
208  return;
209  }
210 
212  Qt::UniqueConnection);
214 
215  foreach(VPropertyFormWidget *tmpEditorWidget, tmpList)
216  {
217  connectPropertyFormWidget(tmpEditorWidget);
218  }
219 }
void rowsInserted(const QModelIndex &parent, int start, int end)
Called when a new row is being inserted into the model.
virtual ~VPropertyFormView() Q_DECL_OVERRIDE
Destructor.
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
void dataSubmitted(VProperty *property)
Updates the model when data was submitted by the view.
virtual void connectPropertyFormWidget(VPropertyFormWidget *widget)
Function to handle newly created VPropertyWidgets.
void setModel(VPropertyModel *model)
Set the source model. Leads to the rebuild of the form.
void modelDestroyed()
Called, when the model gets destroyed.
void rowsRemoved(const QModelIndex &parent, int start, int end)
Called when a row gets removed in the model.
void dataChanged(const QModelIndex &top_left, const QModelIndex &bottom_right)
Called when data in the model gets changed.
void removeModelAndSet()
Removes the model and property set if they were set.
virtual void build() Q_DECL_OVERRIDE
Rebuilds the whole form.
void modelReset()
Called when the model is being reset.
VPropertyFormView(QWidget *parent=nullptr)
Constructor.
void setPropertySet(VPropertySet *property_set)
Set the property set to use. Note that if using a property set directly, adding and removing properti...
void updatePropertyList()
Rebuilds the widegt only if it is visible.
QList< VProperty * > Properties
The root property to use.
Class that displays the sub properties of a property using a form layout.
void propertyDataSubmitted(VProperty *property)
Emitted whenever a property data changes.
QList< VPropertyFormWidget * > getChildPropertyFormWidgets() const
Returns a list of all child property form widgets (note that indirect children will not be in the lis...
virtual void build()
Rebuilds the whole form.
This is the base model for managing all the properties and passing them to the view.
void onDataChangedByModel(VProperty *property)
This function causes the views to update the property.
virtual const VPropertySet * getPropertySet() const
Returns a const pointer to the property set managed by this model. If you want to manipulate the prop...
VPropertySet is a simple class for managing a set of properties. If you don't need all the Model-func...
Definition: vpropertyset.h:48
const QList< VProperty * > & getRootProperties() const
Returns a const reference to the list of root properties.