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