qtbuttonpropertybrowser.h
Go to the documentation of this file.
1 /****************************************************************************
2  **
3  ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4  ** All rights reserved.
5  **
6  ** Contact: Nokia Corporation (qt-info@nokia.com)
7  **
8  ** This file is part of a Qt Solutions component.
9  **
10  ** You may use this file under the terms of the BSD license as follows:
11  **
12  ** "Redistribution and use in source and binary forms, with or without
13  ** modification, are permitted provided that the following conditions are
14  ** met:
15  ** * Redistributions of source code must retain the above copyright
16  ** notice, this list of conditions and the following disclaimer.
17  ** * Redistributions in binary form must reproduce the above copyright
18  ** notice, this list of conditions and the following disclaimer in
19  ** the documentation and/or other materials provided with the
20  ** distribution.
21  ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22  ** the names of its contributors may be used to endorse or promote
23  ** products derived from this software without specific prior written
24  ** permission.
25  **
26  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37  **
38  ****************************************************************************/
39 
40 #pragma GCC system_header
41 
42 #ifndef QTBUTTONPROPERTYBROWSER_H
43 #define QTBUTTONPROPERTYBROWSER_H
44 
45 #include <QtGui/QToolButton>
46 #include <QtGui/QLabel>
47 #include <QtGui/QGridLayout>
48 
49 #include "qtpropertybrowser.h"
50 
51 #if QT_VERSION >= 0x040400
52 QT_BEGIN_NAMESPACE
53 #endif
54 
56 
59 {
60  Q_OBJECT
61  public:
62 
63  explicit QtButtonPropertyBrowser(QWidget *parent = 0);
65 
66  void setExpanded(QtBrowserItem *item, bool expanded);
67  bool isExpanded(QtBrowserItem *item) const;
68 
69  Q_SIGNALS:
70 
71  void collapsed(QtBrowserItem *item);
72  void expanded(QtBrowserItem *item);
73 
74  protected:
75  virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem);
76  virtual void itemRemoved(QtBrowserItem *item);
77  virtual void itemChanged(QtBrowserItem *item);
78 
79  private:
80 
82  Q_DECLARE_PRIVATE(QtButtonPropertyBrowser)
83  Q_DISABLE_COPY(QtButtonPropertyBrowser)
84  Q_PRIVATE_SLOT(d_func(), void slotUpdate())
85  Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed())
86  Q_PRIVATE_SLOT(d_func(), void slotToggled(bool))
87 };
88 
90 {
92  Q_DECLARE_PUBLIC(QtButtonPropertyBrowser)
93  public:
95  : q_ptr(NULL), m_mainLayout(NULL)
96  {}
97  void init(QWidget *parent);
98 
99  void propertyInserted(QtBrowserItem *index, QtBrowserItem *afterIndex);
100  void propertyRemoved(QtBrowserItem *index);
101  void propertyChanged(QtBrowserItem *index);
102  QWidget *createEditor(QtProperty *property, QWidget *parent) const
103  { return q_ptr->createEditor(property, parent); }
104 
105  void slotEditorDestroyed();
106  void slotUpdate();
107  void slotToggled(bool checked);
108 
109  struct WidgetItem
110  {
111  WidgetItem() : widget(0), label(0), widgetLabel(0),
112  button(0), container(0), layout(0), /*line(0), */parent(0),
113  expanded(false) { }
114  QWidget *widget; // can be null
115  QLabel *label; // main label with property name
116 
117  QLabel *widgetLabel;
118  QToolButton *button; // expandable button for items with children
119 
120  QWidget *container;
121  QGridLayout *layout; // layout in container
122  WidgetItem *parent;
123  QList<WidgetItem *> children;
124  bool expanded;
125  };
126  private:
127  void updateLater();
128  void updateItem(WidgetItem *item);
129  void insertRow(QGridLayout *layout, int row) const;
130  void removeRow(QGridLayout *layout, int row) const;
131  int gridRow(WidgetItem *item) const;
132  int gridSpan(WidgetItem *item) const;
133  void setExpanded(WidgetItem *item, bool expanded);
134  QToolButton *createButton(QWidget *panret = 0) const;
135 
136  QMap<QtBrowserItem *, WidgetItem *> m_indexToItem;
137  QMap<WidgetItem *, QtBrowserItem *> m_itemToIndex;
138  QMap<QWidget *, WidgetItem *> m_widgetToItem;
139  QMap<QObject *, WidgetItem *> m_buttonToItem;
140  QGridLayout *m_mainLayout;
141  QList<WidgetItem *> m_children;
142  QList<WidgetItem *> m_recreateQueue;
143 };
144 #if QT_VERSION >= 0x040400
145 QT_END_NAMESPACE
146 #endif
147 
148 #endif
Definition: qtpropertybrowser.h:384
virtual void itemChanged(QtBrowserItem *item)=0
Definition: qtpropertybrowser.h:311
Definition: qtbuttonpropertybrowser.h:89
virtual void itemRemoved(QtBrowserItem *item)=0
Definition: qtbuttonpropertybrowser.h:57
#define NULL
Definition: CommonTypes.hh:30
virtual QWidget * createEditor(QtProperty *property, QWidget *parent)
#define QT_QTPROPERTYBROWSER_EXPORT
Definition: qtpropertybrowser.h:68
virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem)=0
Definition: qtpropertybrowser.h:77