Computer Assisted Medical Intervention Tool Kit version 6.0
 
Loading...
Searching...
No Matches
qtpropertybrowser.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
41#ifndef QTPROPERTYBROWSER_H
42#define QTPROPERTYBROWSER_H
43
44#include <QtWidgets/QWidget>
45#include <QSet>
46#include <QtWidgets/QLineEdit>
47
48#if QT_VERSION >= 0x040400
49QT_BEGIN_NAMESPACE
50#endif
51
52#if defined(_WIN32)
53# if defined(COMPILE_QTPROPERTYBROWSER)
54# define QT_QTPROPERTYBROWSER_EXPORT __declspec(dllexport)
55# else
56# define QT_QTPROPERTYBROWSER_EXPORT __declspec(dllimport)
57# endif
58#else
59#define QT_QTPROPERTYBROWSER_EXPORT
60#endif
61
62typedef QLineEdit::EchoMode EchoMode;
63
66
105public:
106 virtual ~QtProperty();
107
108 QList<QtProperty*> subProperties() const;
109
110 QtAbstractPropertyManager* propertyManager() const;
111
112 QString toolTip() const;
113 QString statusTip() const;
114 QString whatsThis() const;
115 QString propertyName() const;
116 bool isEnabled() const;
117 bool isModified() const;
118
119 bool hasValue() const;
120 QIcon valueIcon() const;
121 QString valueText() const;
122 QString displayText() const;
123
124 void setToolTip(const QString& text);
125 void setStatusTip(const QString& text);
126 void setWhatsThis(const QString& text);
127 void setPropertyName(const QString& text);
128 void setEnabled(bool enable);
129 void setModified(bool modified);
130
131 void addSubProperty(QtProperty* property);
132 void insertSubProperty(QtProperty* property, QtProperty* afterProperty);
133 void removeSubProperty(QtProperty* property);
134protected:
135 explicit QtProperty(QtAbstractPropertyManager* manager);
136 void propertyChanged();
137private:
139 QtPropertyPrivate* d_ptr;
140};
141
143
145 Q_OBJECT
146public:
147
148 explicit QtAbstractPropertyManager(QObject* parent = nullptr);
150
151 QSet<QtProperty*> properties() const;
152 void clear() const;
153
154 QtProperty* addProperty(const QString& name = QString());
155Q_SIGNALS:
156
158 QtProperty* parent, QtProperty* after);
160 void propertyRemoved(QtProperty* property, QtProperty* parent);
162protected:
163 virtual bool hasValue(const QtProperty* property) const;
164 virtual QIcon valueIcon(const QtProperty* property) const;
165 virtual QString valueText(const QtProperty* property) const;
166 virtual QString displayText(const QtProperty* property) const;
167 virtual EchoMode echoMode(const QtProperty*) const;
168 virtual void initializeProperty(QtProperty* property) = 0;
169 virtual void uninitializeProperty(QtProperty* property);
170 virtual QtProperty* createProperty();
171private:
172 friend class QtProperty;
174 Q_DECLARE_PRIVATE(QtAbstractPropertyManager)
175#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
176 Q_DISABLE_COPY_MOVE(QtAbstractPropertyManager)
177#else
178 Q_DISABLE_COPY(QtAbstractPropertyManager)
179#endif
180};
181
183 Q_OBJECT
184public:
185 virtual QWidget* createEditor(QtProperty* property, QWidget* parent) = 0;
186protected:
187 explicit QtAbstractEditorFactoryBase(QObject* parent = nullptr)
188 : QObject(parent) {}
189
190 virtual void breakConnection(QtAbstractPropertyManager* manager) = 0;
191protected Q_SLOTS:
192 virtual void managerDestroyed(QObject* manager) = 0;
193
195};
196
197template <class PropertyManager>
199public:
200 explicit QtAbstractEditorFactory(QObject* parent) : QtAbstractEditorFactoryBase(parent) {}
201 QWidget* createEditor(QtProperty* property, QWidget* parent) override {
202 QSetIterator<PropertyManager*> it(m_managers);
203 while (it.hasNext()) {
204 PropertyManager* manager = it.next();
205 if (manager == property->propertyManager()) {
206 return createEditor(manager, property, parent);
207 }
208 }
209 return nullptr;
210 }
211 void addPropertyManager(PropertyManager* manager) {
212 if (m_managers.contains(manager)) {
213 return;
214 }
215 m_managers.insert(manager);
216 connectPropertyManager(manager);
217 connect(manager, SIGNAL(destroyed(QObject*)),
218 this, SLOT(managerDestroyed(QObject*)));
219 }
220 void removePropertyManager(PropertyManager* manager) {
221 if (!m_managers.contains(manager)) {
222 return;
223 }
224 disconnect(manager, SIGNAL(destroyed(QObject*)),
225 this, SLOT(managerDestroyed(QObject*)));
227 m_managers.remove(manager);
228 }
229 QSet<PropertyManager*> propertyManagers() const {
230 return m_managers;
231 }
232 PropertyManager* propertyManager(QtProperty* property) const {
233 QtAbstractPropertyManager* manager = property->propertyManager();
234 QSetIterator<PropertyManager*> itManager(m_managers);
235 while (itManager.hasNext()) {
236 PropertyManager* m = itManager.next();
237 if (m == manager) {
238 return m;
239 }
240 }
241 return 0;
242 }
243protected:
244 virtual void connectPropertyManager(PropertyManager* manager) = 0;
245 virtual QWidget* createEditor(PropertyManager* manager, QtProperty* property,
246 QWidget* parent) = 0;
247 virtual void disconnectPropertyManager(PropertyManager* manager) = 0;
248 void managerDestroyed(QObject* manager) override {
249 QSetIterator<PropertyManager*> it(m_managers);
250 while (it.hasNext()) {
251 PropertyManager* m = it.next();
252 if (m == manager) {
253 m_managers.remove(m);
254 return;
255 }
256 }
257 }
258private:
259 void breakConnection(QtAbstractPropertyManager* manager) override {
260 QSetIterator<PropertyManager*> it(m_managers);
261 while (it.hasNext()) {
262 PropertyManager* m = it.next();
263 if (m == manager) {
265 return;
266 }
267 }
268 }
269private:
270 QSet<PropertyManager*> m_managers;
272};
273
276
278public:
279 QtProperty* property() const;
280 QtBrowserItem* parent() const;
281 QList<QtBrowserItem*> children() const;
282 QtAbstractPropertyBrowser* browser() const;
283private:
284 explicit QtBrowserItem(QtAbstractPropertyBrowser* browser, QtProperty* property, QtBrowserItem* parent);
288};
289
291
293 Q_OBJECT
294public:
295
296 explicit QtAbstractPropertyBrowser(QWidget* parent = nullptr);
298
299 QList<QtProperty*> properties() const;
300 QList<QtBrowserItem*> items(QtProperty* property) const;
301 QtBrowserItem* topLevelItem(QtProperty* property) const;
302 QList<QtBrowserItem*> topLevelItems() const;
303 void clear();
304
305 template <class PropertyManager>
306 void setFactoryForManager(PropertyManager* manager,
308 QtAbstractPropertyManager* abstractManager = manager;
309 QtAbstractEditorFactoryBase* abstractFactory = factory;
310
311 if (addFactory(abstractManager, abstractFactory)) {
312 factory->addPropertyManager(manager);
313 }
314 }
315
316 void unsetFactoryForManager(QtAbstractPropertyManager* manager);
317
318 QtBrowserItem* currentItem() const;
319 void setCurrentItem(QtBrowserItem*);
320
321Q_SIGNALS:
323
324public Q_SLOTS:
325
326 QtBrowserItem* addProperty(QtProperty* property);
327 QtBrowserItem* insertProperty(QtProperty* property, QtProperty* afterProperty);
328 void removeProperty(QtProperty* property);
329
330protected:
331
332 virtual void itemInserted(QtBrowserItem* item, QtBrowserItem* afterItem) = 0;
333 virtual void itemRemoved(QtBrowserItem* item) = 0;
334 // can be tooltip, statustip, whatsthis, name, icon, text.
335 virtual void itemChanged(QtBrowserItem* item) = 0;
336
337 virtual QWidget* createEditor(QtProperty* property, QWidget* parent);
338private:
339
340 bool addFactory(QtAbstractPropertyManager* abstractManager,
341 QtAbstractEditorFactoryBase* abstractFactory);
342
344 Q_DECLARE_PRIVATE(QtAbstractPropertyBrowser)
345#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
346 Q_DISABLE_COPY_MOVE(QtAbstractPropertyBrowser)
347#else
348 Q_DISABLE_COPY(QtAbstractPropertyBrowser)
349#endif
350 Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty*,
352 Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty*,
353 QtProperty*))
354 Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty*))
355 Q_PRIVATE_SLOT(d_func(), void slotPropertyDataChanged(QtProperty*))
356
357};
358
359#if QT_VERSION >= 0x040400
360QT_END_NAMESPACE
361#endif
362
363#endif // QTPROPERTYBROWSER_H
Definition PersistenceManager.h:30
The QtAbstractEditorFactoryBase provides an interface for editor factories.
Definition qtpropertybrowser.h:182
virtual void breakConnection(QtAbstractPropertyManager *manager)=0
virtual void managerDestroyed(QObject *manager)=0
QtAbstractEditorFactoryBase(QObject *parent=nullptr)
Definition qtpropertybrowser.h:187
virtual QWidget * createEditor(QtProperty *property, QWidget *parent)=0
The QtAbstractEditorFactory is the base template class for editor factories.
Definition qtpropertybrowser.h:198
void removePropertyManager(PropertyManager *manager)
Definition qtpropertybrowser.h:220
virtual QWidget * createEditor(PropertyManager *manager, QtProperty *property, QWidget *parent)=0
QtAbstractEditorFactory(QObject *parent)
Definition qtpropertybrowser.h:200
virtual void disconnectPropertyManager(PropertyManager *manager)=0
QWidget * createEditor(QtProperty *property, QWidget *parent) override
Definition qtpropertybrowser.h:201
friend class QtAbstractPropertyEditor
Definition qtpropertybrowser.h:271
PropertyManager * propertyManager(QtProperty *property) const
Definition qtpropertybrowser.h:232
virtual void connectPropertyManager(PropertyManager *manager)=0
QSet< PropertyManager * > propertyManagers() const
Definition qtpropertybrowser.h:229
void managerDestroyed(QObject *manager) override
Definition qtpropertybrowser.h:248
void addPropertyManager(PropertyManager *manager)
Definition qtpropertybrowser.h:211
Definition qtpropertybrowser.cpp:1182
QtAbstractPropertyBrowser provides a base class for implementing property browsers.
Definition qtpropertybrowser.h:292
virtual void itemChanged(QtBrowserItem *item)=0
virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem)=0
void currentItemChanged(QtBrowserItem *)
void setFactoryForManager(PropertyManager *manager, QtAbstractEditorFactory< PropertyManager > *factory)
Definition qtpropertybrowser.h:306
virtual void itemRemoved(QtBrowserItem *item)=0
Definition qtpropertybrowser.cpp:76
The QtAbstractPropertyManager provides an interface for property managers.
Definition qtpropertybrowser.h:144
void propertyDestroyed(QtProperty *property)
void propertyInserted(QtProperty *property, QtProperty *parent, QtProperty *after)
void propertyChanged(QtProperty *property)
virtual void initializeProperty(QtProperty *property)=0
void propertyRemoved(QtProperty *property, QtProperty *parent)
Definition qtpropertybrowser.cpp:1062
The QtBrowserItem class represents a property in a property browser instance.
Definition qtpropertybrowser.h:277
Definition qtpropertybrowser.cpp:55
The QtProperty class encapsulates an instance of a property.
Definition qtpropertybrowser.h:104
QtAbstractPropertyManager * propertyManager() const
Definition qtpropertybrowser.cpp:187
#define QT_QTPROPERTYBROWSER_EXPORT
Definition qtpropertybrowser.h:59
QLineEdit::EchoMode EchoMode
Definition qtpropertybrowser.h:62