Changeset View
Changeset View
Standalone View
Standalone View
src/KPropertyEditorView.h
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project | ||
---|---|---|---|---|---|
2 | Copyright (C) 2008-2016 Jarosław Staniek <staniek@kde.org> | 2 | Copyright (C) 2008-2017 Jarosław Staniek <staniek@kde.org> | ||
3 | 3 | | |||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. | ||
8 | 8 | | |||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
Show All 26 Lines | 34 | public: | |||
37 | 37 | | |||
38 | ~KPropertyEditorView(); | 38 | ~KPropertyEditorView(); | ||
39 | 39 | | |||
40 | //! Options for changeSet(). | 40 | //! Options for changeSet(). | ||
41 | enum SetOption { | 41 | enum SetOption { | ||
42 | NoOptions = 0, | 42 | NoOptions = 0, | ||
43 | PreservePreviousSelection = 1, //!< If used, previously selected editor item | 43 | PreservePreviousSelection = 1, //!< If used, previously selected editor item | ||
44 | //!< will be kept selected. | 44 | //!< will be kept selected. | ||
45 | AlphabeticalOrder = 2, //!< Alphabetical order of properties (the default is insert-order) | 45 | AlphabeticalOrder = 2 //!< Alphabetical order of properties (the default is insert-order) | ||
46 | ExpandChildItems = 4 //!< Child property items are expanded (the default is "collapsed") | | |||
47 | }; | 46 | }; | ||
48 | Q_DECLARE_FLAGS(SetOptions, SetOption) | 47 | Q_DECLARE_FLAGS(SetOptions, SetOption) | ||
49 | 48 | | |||
50 | //! @return grid line color, defaultGridLineColor() by default | 49 | //! @return grid line color, defaultGridLineColor() by default | ||
51 | QColor gridLineColor() const; | 50 | QColor gridLineColor() const; | ||
52 | 51 | | |||
53 | //! @return default grid line color - Qt::gray | 52 | //! @return default grid line color - Qt::gray | ||
54 | static QColor defaultGridLineColor() { return Qt::gray; } | 53 | static QColor defaultGridLineColor() { return Qt::gray; } | ||
55 | 54 | | |||
56 | //! Reimplemented to suggest widget size that is based on number of property items. | 55 | //! Reimplemented to suggest widget size that is based on number of property items. | ||
57 | QSize sizeHint() const Q_DECL_OVERRIDE; | 56 | QSize sizeHint() const Q_DECL_OVERRIDE; | ||
58 | 57 | | |||
59 | //! @return the property set object that is assigned to this view or nullptr is no set | 58 | //! @return the property set object that is assigned to this view or nullptr is no set | ||
60 | //! is currently assigned. | 59 | //! is currently assigned. | ||
61 | KPropertySet* propertySet() const; | 60 | KPropertySet* propertySet() const; | ||
62 | 61 | | |||
62 | /*! @return @c true if items for parent composed properties are expanded so items for child | ||||
63 | properties are displayed. | ||||
64 | @since 3.1 */ | ||||
65 | bool childPropertyItemsExpanded() const; | ||||
66 | | ||||
67 | /*! @return value of the valueSyncEnabled flag. | ||||
68 | @since 3.1 */ | ||||
69 | bool isValueSyncEnabled() const; | ||||
70 | | ||||
71 | /*! @return @c true if the property groups should be visible. | ||||
72 | By default groups are visible. | ||||
73 | A group is visualized as a subtree displaying group caption and group icon at its root node | ||||
74 | (see KProperty::groupCaption and KProperty::groupIconName) and properties as children of this node. | ||||
75 | A property is assigned to a group while KPropertySet::addProperty() is called. | ||||
76 | | ||||
77 | @note Regardless of this flag, no groups are displayed if there is only the default group | ||||
78 | "common". | ||||
79 | | ||||
80 | When the group visibility flag is off or only the "common" group is present, all properties | ||||
81 | are displayed on the same (top) level. | ||||
82 | @since 3.1 */ | ||||
83 | bool groupsVisible() const; | ||||
84 | | ||||
85 | /*! @return @c true if group items for newly added groups are exapanded so properties for these | ||||
86 | groups are displayed. | ||||
87 | @see setGroupItemsExpanded() | ||||
88 | @since 3.1 */ | ||||
89 | bool groupItemsExpanded() const; | ||||
90 | | ||||
63 | public Q_SLOTS: | 91 | public Q_SLOTS: | ||
64 | /*! Populates the editor view with items for each property from the @ set set. | 92 | /*! Populates the editor view with items for each property from the @a set set. | ||
65 | Child items for composed properties are also created. | 93 | Child items for composed properties are also created. | ||
66 | See SetOption documentation for description of @a options options. | 94 | See SetOption documentation for description of @a options options. | ||
67 | If @a preservePreviousSelection is true, previously selected editor | 95 | If @a preservePreviousSelection is true, previously selected editor | ||
68 | item will be kept selected, if present. */ | 96 | item will be kept selected, if present. */ | ||
69 | void changeSet(KPropertySet *set, SetOptions options = NoOptions); | 97 | void changeSet(KPropertySet *set, SetOptions options = NoOptions); | ||
70 | 98 | | |||
71 | /*! Populates the editor view with items for each property from the @ set set. | 99 | /*! Populates the editor view with items for each property from the @a set set. | ||
72 | Child items for composed properties are also created. | 100 | Child items for composed properties are also created. | ||
73 | If @a propertyToSelect is provided, item for this property name | 101 | If @a propertyToSelect is provided, item for this property name | ||
74 | will be selected, if present. */ | 102 | will be selected, if present. */ | ||
75 | void changeSet(KPropertySet *set, const QByteArray& propertyToSelect, SetOptions options = NoOptions); | 103 | void changeSet(KPropertySet *set, const QByteArray& propertyToSelect, SetOptions options = NoOptions); | ||
76 | 104 | | |||
77 | /*! If @a enable is true (the default), property values are automatically synced as | 105 | /*! If @a set is @c true (the default), items for parent composed properties are expanded | ||
78 | soon as editor contents change (e.g. every time the user types a character) | 106 | so items for child properties are displayed. | ||
79 | and the values are written back to the assigned property set. | 107 | If @a set is @c false, the items are collapsed. | ||
80 | If @a enable is false, property set is updated only when selection within | 108 | @note Appearance of the existing child items is not altered. This method can be typically called | ||
81 | the property editor or user presses Enter/Return key. | 109 | before a changeSet() call or before adding properties. | ||
82 | Each property can overwrite this setting by changing its own autoSync flag. | 110 | @note Expansion of group items is not affected by this method. Use setGroupItemsExpanded() | ||
83 | */ | 111 | to control expansion of group items. | ||
84 | void setAutoSync(bool enable); | 112 | @note To expand all items use expandAll(). To collapse all items use collapseAll(). | ||
113 | @since 3.1 */ | ||||
114 | void setChildPropertyItemsExpanded(bool set); | ||||
85 | 115 | | |||
86 | /*! @return value of autoSync flag. */ | 116 | /*! If @a set is @c true (the default), property values are automatically synchronized as | ||
87 | bool isAutoSync() const; | 117 | soon as editor contents change (e.g. every time the user types a character) | ||
118 | and the values are saved back to the assigned property set. | ||||
119 | If @a enable is false, property set is updated only when selection within the property editor | ||||
120 | or user presses Enter/Return key. | ||||
121 | Each property can override this policy by changing its own valueSyncPolicy flag. | ||||
122 | @see KProperty::setValueSyncPolicy() | ||||
123 | @since 3.1 */ | ||||
124 | void setValueSyncEnabled(bool set); | ||||
88 | 125 | | |||
89 | /*! Accepts the changes made to the current editor item (if any) | 126 | /*! Accepts the changes made to the current editor item (if any) | ||
90 | (as if the user had pressed Enter key). */ | 127 | (as if the user had pressed Enter key). */ | ||
91 | void acceptInput(); | 128 | void acceptInput(); | ||
92 | 129 | | |||
93 | //! Sets color of grid lines. Use invalid color QColor() to hide grid lines. | 130 | //! Sets color of grid lines. Use invalid color QColor() to hide grid lines. | ||
94 | void setGridLineColor(const QColor& color); | 131 | void setGridLineColor(const QColor& color); | ||
95 | 132 | | |||
133 | /*! Shows the property groups if @a set is @c true. | ||||
134 | @see groupsVisible() | ||||
135 | @since 3.1 */ | ||||
136 | void setGroupsVisible(bool set); | ||||
137 | | ||||
138 | /*! If @a set is @c true (the default), group items for newly added groups are exapanded | ||||
139 | so properties for these groups are displayed. | ||||
140 | If @a set is @c false, the items are collapsed. | ||||
141 | @note Appearance of the existing group items is not altered. This method can be typically called | ||||
142 | before a changeSet() call or before adding properties. | ||||
143 | @note Expansion of child items for composed properties is not affected by this method. | ||||
144 | Use setChildPropertyItemsExpanded() to control expansion child items for composed properties. | ||||
145 | @note To expand all items use expandAll(). To collapse all items use collapseAll(). | ||||
146 | @since 3.1 */ | ||||
147 | void setGroupItemsExpanded(bool set); | ||||
148 | | ||||
96 | Q_SIGNALS: | 149 | Q_SIGNALS: | ||
97 | /*! Emitted when current property set has been changed. May be 0. */ | 150 | /*! Emitted when current property set has been changed. May be 0. */ | ||
98 | void propertySetChanged(KPropertySet *set); | 151 | void propertySetChanged(KPropertySet *set); | ||
99 | 152 | | |||
100 | protected: | 153 | protected: | ||
101 | virtual bool viewportEvent( QEvent * event ); | 154 | virtual bool viewportEvent( QEvent * event ); | ||
102 | 155 | | |||
103 | protected Q_SLOTS: | 156 | protected Q_SLOTS: | ||
Show All 15 Lines | |||||
119 | 172 | | |||
120 | void slotPropertyReset(KPropertySet& set, KProperty& property); | 173 | void slotPropertyReset(KPropertySet& set, KProperty& property); | ||
121 | 174 | | |||
122 | private: | 175 | private: | ||
123 | /*! Used by changeSet(). */ | 176 | /*! Used by changeSet(). */ | ||
124 | void changeSetInternal(KPropertySet *set, SetOptions options, const QByteArray& propertyToSelect); | 177 | void changeSetInternal(KPropertySet *set, SetOptions options, const QByteArray& propertyToSelect); | ||
125 | virtual bool edit( const QModelIndex & index, EditTrigger trigger, QEvent * event ); | 178 | virtual bool edit( const QModelIndex & index, EditTrigger trigger, QEvent * event ); | ||
126 | virtual void drawBranches( QPainter * painter, const QRect & rect, const QModelIndex & index ) const; | 179 | virtual void drawBranches( QPainter * painter, const QRect & rect, const QModelIndex & index ) const; | ||
180 | | ||||
181 | //! Reimplemented to draw group header text by hand. | ||||
182 | void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; | ||||
183 | | ||||
127 | virtual void mousePressEvent( QMouseEvent * event ); | 184 | virtual void mousePressEvent( QMouseEvent * event ); | ||
128 | 185 | | |||
129 | //! @return true if @a x is within the area of the revert button for @a index index. | 186 | //! @return true if @a x is within the area of the revert button for @a index index. | ||
130 | bool withinRevertButtonArea( int x, const QModelIndex& index ) const; | 187 | bool withinRevertButtonArea( int x, const QModelIndex& index ) const; | ||
131 | 188 | | |||
132 | //! @return area of revert button, if it is displayed for @a index index. | 189 | //! @return area of revert button, if it is displayed for @a index index. | ||
133 | //! Otherwise invalid QRect is returned. | 190 | //! Otherwise invalid QRect is returned. | ||
134 | QRect revertButtonArea( const QModelIndex& index ) const; | 191 | QRect revertButtonArea( const QModelIndex& index ) const; | ||
Show All 14 Lines |