Seamly2D
Code documentation
vwidgetproperty.cpp
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vwidgetproperty.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 "vwidgetproperty.h"
22 
23 #include <QPointer>
24 #include <QVariant>
25 #include <QWidget>
26 
27 #include "../vwidgetproperty_p.h"
28 #include "vemptyproperty.h"
29 #include "../vproperty.h"
30 
31 VPE::VWidgetProperty::VWidgetProperty(const QString& name, QWidget* widget)
32  : VEmptyProperty(new VWidgetPropertyPrivate(name, QVariant::Invalid, widget))
33 {
34 }
35 
37 {
38  //
39 }
40 
42 {
43  return static_cast<VWidgetPropertyPrivate*>(d_ptr)->Widget.data();
44 }
45 
46 void VPE::VWidgetProperty::setWidget(QWidget* widget)
47 {
48  VWidgetPropertyPrivate* tmpDPtr = static_cast<VWidgetPropertyPrivate*>(d_ptr);
49  QWidget* tmpOldWidget = tmpDPtr->Widget.data();
50  if (tmpOldWidget)
51  {
52  tmpOldWidget->deleteLater();
53  }
54 
55  tmpDPtr->Widget = widget;
56 }
57 
58 
60 {
61  return "widget";
62 }
63 
64 VPE::VProperty* VPE::VWidgetProperty::clone(bool include_children, VProperty* container) const
65 {
66  /* todo: This is a tricky one to clone... don't know what would be the best way to do so... Maybe serialize the
67  * widget somehow?
68  */
69  return VProperty::clone(include_children, container ? container : new VWidgetProperty(getName()));
70 }
virtual Q_REQUIRED_RESULT VProperty * clone(bool include_children=true, VProperty *container=nullptr) const
Clones this property.
Definition: vproperty.cpp:372
QPointer< QWidget > Widget
The widget to show.
This property holds a QWidget and displays it, if the view supports that. If not, it will behave like...
virtual Q_REQUIRED_RESULT VProperty * clone(bool include_children=true, VProperty *container=nullptr) const Q_DECL_OVERRIDE
Clones this property.
virtual ~VWidgetProperty() Q_DECL_OVERRIDE
The destructor.
QWidget * getWidget() const
Returns the widget held by this property.
void setWidget(QWidget *widget)
Sets the widget for this property. If there is already an old one, it will be deleted.
VWidgetProperty(const QString &name, QWidget *widget=nullptr)
Constructor.
virtual QString type() const Q_DECL_OVERRIDE
Returns a string containing the type of the property.