1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the Qt Designer of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 21 ** included in the packaging of this file. Please review the following 22 ** information to ensure the GNU General Public License requirements will 23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 24 ** 25 ** $QT_END_LICENSE$ 26 ** 27 ****************************************************************************/ 28 29 #ifndef ITEMLISTEDITOR_H 30 #define ITEMLISTEDITOR_H 31 32 #include "ui_itemlisteditor.h" 33 34 #include <QtWidgets/qdialog.h> 35 36 QT_BEGIN_NAMESPACE 37 38 class QDesignerFormWindowInterface; 39 class QtProperty; 40 class QtVariantProperty; 41 class QtTreePropertyBrowser; 42 class QSplitter; 43 class QVBoxLayout; 44 45 namespace qdesigner_internal { 46 47 class DesignerIconCache; 48 class DesignerPropertyManager; 49 class DesignerEditorFactory; 50 51 // Utility class that ensures a bool is true while in scope. 52 // Courtesy of QBoolBlocker in qobject_p.h 53 class BoolBlocker 54 { 55 public: BoolBlocker(bool & b)56 inline BoolBlocker(bool &b):block(b), reset(b){block = true;} ~BoolBlocker()57 inline ~BoolBlocker(){block = reset; } 58 private: 59 bool █ 60 bool reset; 61 }; 62 63 class AbstractItemEditor: public QWidget 64 { 65 Q_OBJECT 66 67 public: 68 explicit AbstractItemEditor(QDesignerFormWindowInterface *form, QWidget *parent); 69 ~AbstractItemEditor(); 70 iconCache()71 DesignerIconCache *iconCache() const { return m_iconCache; } 72 73 struct PropertyDefinition { 74 int role; 75 int type; 76 int (*typeFunc)(); 77 const char *name; 78 }; 79 80 public slots: 81 void cacheReloaded(); 82 83 private slots: 84 void propertyChanged(QtProperty *property); 85 void resetProperty(QtProperty *property); 86 87 protected: 88 virtual int defaultItemFlags() const = 0; 89 void setupProperties(PropertyDefinition *propDefs); 90 void setupObject(QWidget *object); 91 void setupEditor(QWidget *object, PropertyDefinition *propDefs); 92 void injectPropertyBrowser(QWidget *parent, QWidget *widget); 93 void updateBrowser(); 94 virtual void setItemData(int role, const QVariant &v) = 0; 95 virtual QVariant getItemData(int role) const = 0; 96 97 DesignerIconCache *m_iconCache; 98 DesignerPropertyManager *m_propertyManager; 99 DesignerEditorFactory *m_editorFactory; 100 QSplitter *m_propertySplitter = nullptr; 101 QtTreePropertyBrowser *m_propertyBrowser; 102 QList<QtVariantProperty*> m_properties; 103 QList<QtVariantProperty*> m_rootProperties; 104 QHash<QtVariantProperty*, int> m_propertyToRole; 105 bool m_updatingBrowser = false; 106 }; 107 108 class ItemListEditor: public AbstractItemEditor 109 { 110 Q_OBJECT 111 112 public: 113 explicit ItemListEditor(QDesignerFormWindowInterface *form, QWidget *parent); 114 115 void setupEditor(QWidget *object, PropertyDefinition *propDefs); listWidget()116 QListWidget *listWidget() const { return ui.listWidget; } setNewItemText(const QString & tpl)117 void setNewItemText(const QString &tpl) { m_newItemText = tpl; } newItemText()118 QString newItemText() const { return m_newItemText; } 119 void setCurrentIndex(int idx); 120 121 signals: 122 void indexChanged(int idx); 123 void itemChanged(int idx, int role, const QVariant &v); 124 void itemInserted(int idx); 125 void itemDeleted(int idx); 126 void itemMovedUp(int idx); 127 void itemMovedDown(int idx); 128 129 private slots: 130 void on_newListItemButton_clicked(); 131 void on_deleteListItemButton_clicked(); 132 void on_moveListItemUpButton_clicked(); 133 void on_moveListItemDownButton_clicked(); 134 void on_listWidget_currentRowChanged(); 135 void on_listWidget_itemChanged(QListWidgetItem * item); 136 void togglePropertyBrowser(); 137 void cacheReloaded(); 138 139 protected: 140 void setItemData(int role, const QVariant &v) override; 141 QVariant getItemData(int role) const override; 142 int defaultItemFlags() const override; 143 144 private: 145 void setPropertyBrowserVisible(bool v); 146 void updateEditor(); 147 Ui::ItemListEditor ui; 148 bool m_updating; 149 QString m_newItemText; 150 }; 151 152 } // namespace qdesigner_internal 153 154 QT_END_NAMESPACE 155 156 #endif // ITEMLISTEDITOR_H 157