1 /**************************************************************************** 2 ** 3 ** DQt - D bindings for the Qt Toolkit 4 ** 5 ** GNU Lesser General Public License Usage 6 ** This file may be used under the terms of the GNU Lesser 7 ** General Public License version 3 as published by the Free Software 8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 9 ** packaging of this file. Please review the following information to 10 ** ensure the GNU Lesser General Public License version 3 requirements 11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 12 ** 13 ****************************************************************************/ 14 module qt.widgets.combobox; 15 extern(C++): 16 17 import qt.config; 18 import qt.core.abstractitemmodel; 19 import qt.core.coreevent; 20 import qt.core.namespace; 21 import qt.core.size; 22 import qt.core.string; 23 import qt.core.stringlist; 24 import qt.core.variant; 25 import qt.gui.event; 26 import qt.gui.icon; 27 import qt.helpers; 28 import qt.widgets.abstractitemdelegate; 29 import qt.widgets.abstractitemview; 30 import qt.widgets.completer; 31 import qt.widgets.lineedit; 32 import qt.widgets.styleoption; 33 import qt.widgets.widget; 34 version(QT_NO_VALIDATOR){}else 35 import qt.gui.validator; 36 37 /+ QT_REQUIRE_CONFIG(combobox); 38 39 40 class QAbstractItemView; 41 class QLineEdit; +/ 42 extern(C++, class) struct QComboBoxPrivate; 43 /+ class QCompleter; +/ 44 45 class /+ Q_WIDGETS_EXPORT +/ QComboBox : QWidget 46 { 47 mixin(Q_OBJECT); 48 49 /+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable) 50 Q_PROPERTY(int count READ count) 51 Q_PROPERTY(QString currentText READ currentText WRITE setCurrentText NOTIFY currentTextChanged USER true) 52 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) 53 Q_PROPERTY(QVariant currentData READ currentData) 54 Q_PROPERTY(int maxVisibleItems READ maxVisibleItems WRITE setMaxVisibleItems) 55 Q_PROPERTY(int maxCount READ maxCount WRITE setMaxCount) 56 Q_PROPERTY(InsertPolicy insertPolicy READ insertPolicy WRITE setInsertPolicy) 57 Q_PROPERTY(SizeAdjustPolicy sizeAdjustPolicy READ sizeAdjustPolicy WRITE setSizeAdjustPolicy) 58 Q_PROPERTY(int minimumContentsLength READ minimumContentsLength WRITE setMinimumContentsLength) 59 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) 60 Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText) 61 62 #if QT_CONFIG(completer) 63 #if QT_DEPRECATED_SINCE(5, 13) 64 Q_PROPERTY(bool autoCompletion READ autoCompletion WRITE setAutoCompletion DESIGNABLE false) 65 Q_PROPERTY(Qt::CaseSensitivity autoCompletionCaseSensitivity READ autoCompletionCaseSensitivity WRITE setAutoCompletionCaseSensitivity DESIGNABLE false) 66 #endif 67 #endif // QT_CONFIG(completer) 68 69 Q_PROPERTY(bool duplicatesEnabled READ duplicatesEnabled WRITE setDuplicatesEnabled) 70 Q_PROPERTY(bool frame READ hasFrame WRITE setFrame) 71 Q_PROPERTY(int modelColumn READ modelColumn WRITE setModelColumn) +/ 72 73 public: 74 /+ explicit +/this(QWidget parent = null); 75 ~this(); 76 77 final int maxVisibleItems() const; 78 final void setMaxVisibleItems(int maxItems); 79 80 final int count() const; 81 final void setMaxCount(int max); 82 final int maxCount() const; 83 84 /+ #if QT_CONFIG(completer) 85 #if QT_DEPRECATED_SINCE(5, 13) +/ 86 /+ QT_DEPRECATED_X("Use completer() instead.") +/ 87 final bool autoCompletion() const; 88 /+ QT_DEPRECATED_X("Use setCompleter() instead.") +/ 89 final void setAutoCompletion(bool enable); 90 /+ QT_DEPRECATED_X("Use completer()->caseSensitivity() instead.") +/ 91 final /+ Qt:: +/qt.core.namespace.CaseSensitivity autoCompletionCaseSensitivity() const; 92 /+ QT_DEPRECATED_X("Use completer()->setCaseSensitivity() instead.") +/ 93 final void setAutoCompletionCaseSensitivity(/+ Qt:: +/qt.core.namespace.CaseSensitivity sensitivity); 94 /+ #endif 95 #endif +/ 96 97 final bool duplicatesEnabled() const; 98 final void setDuplicatesEnabled(bool enable); 99 100 final void setFrame(bool); 101 final bool hasFrame() const; 102 103 /+ pragma(inline, true) final int findText(ref const(QString) text, 104 /+ Qt:: +/qt.core.namespace.MatchFlags flags = static_cast!(/+ Qt:: +/qt.core.namespace.MatchFlags)(/+ Qt:: +/qt.core.namespace.MatchFlag.MatchExactly|/+ Qt:: +/qt.core.namespace.MatchFlag.MatchCaseSensitive)) const 105 { return findData(text, /+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole, flags); } 106 final int findData(ref const(QVariant) data, int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.UserRole, 107 /+ Qt:: +/qt.core.namespace.MatchFlags flags = static_cast!(/+ Qt:: +/qt.core.namespace.MatchFlags)(/+ Qt:: +/qt.core.namespace.MatchFlag.MatchExactly|/+ Qt:: +/qt.core.namespace.MatchFlag.MatchCaseSensitive)) const; 108 +/ 109 enum InsertPolicy { 110 NoInsert, 111 InsertAtTop, 112 InsertAtCurrent, 113 InsertAtBottom, 114 InsertAfterCurrent, 115 InsertBeforeCurrent, 116 InsertAlphabetically 117 } 118 /+ Q_ENUM(InsertPolicy) +/ 119 120 final InsertPolicy insertPolicy() const; 121 final void setInsertPolicy(InsertPolicy policy); 122 123 enum SizeAdjustPolicy { 124 AdjustToContents, 125 AdjustToContentsOnFirstShow, 126 /+ #if QT_DEPRECATED_SINCE(5, 15) +/ 127 AdjustToMinimumContentsLength /+ Q_DECL_ENUMERATOR_DEPRECATED_X( 128 "Use AdjustToContents or AdjustToContentsOnFirstShow") +/, // ### Qt 6: remove 129 /+ #endif +/ 130 AdjustToMinimumContentsLengthWithIcon = SizeAdjustPolicy.AdjustToContentsOnFirstShow + 2 131 } 132 /+ Q_ENUM(SizeAdjustPolicy) +/ 133 134 final SizeAdjustPolicy sizeAdjustPolicy() const; 135 final void setSizeAdjustPolicy(SizeAdjustPolicy policy); 136 final int minimumContentsLength() const; 137 final void setMinimumContentsLength(int characters); 138 final QSize iconSize() const; 139 final void setIconSize(ref const(QSize) size); 140 141 final void setPlaceholderText(ref const(QString) placeholderText); 142 final QString placeholderText() const; 143 144 final bool isEditable() const; 145 final void setEditable(bool editable); 146 final void setLineEdit(QLineEdit edit); 147 final QLineEdit lineEdit() const; 148 /+ #ifndef QT_NO_VALIDATOR +/ 149 version(QT_NO_VALIDATOR){}else 150 { 151 final void setValidator(const(QValidator) v); 152 final const(QValidator) validator() const; 153 } 154 /+ #endif 155 156 #if QT_CONFIG(completer) +/ 157 final void setCompleter(QCompleter c); 158 final QCompleter completer() const; 159 /+ #endif +/ 160 161 final QAbstractItemDelegate itemDelegate() const; 162 final void setItemDelegate(QAbstractItemDelegate delegate_); 163 164 final QAbstractItemModel model() const; 165 final void setModel(QAbstractItemModel model); 166 167 final QModelIndex rootModelIndex() const; 168 final void setRootModelIndex(ref const(QModelIndex) index); 169 170 final int modelColumn() const; 171 final void setModelColumn(int visibleColumn); 172 173 final int currentIndex() const; 174 final QString currentText() const; 175 final QVariant currentData(int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.UserRole) const; 176 177 final QString itemText(int index) const; 178 final QIcon itemIcon(int index) const; 179 final QVariant itemData(int index, int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.UserRole) const; 180 181 pragma(inline, true) final void addItem(ref const(QString) atext, ref const(QVariant) auserData = globalInitVar!QVariant) 182 { insertItem(count(), atext, auserData); } 183 pragma(inline, true) final void addItem(const(QString) atext, const(QVariant) auserData = globalInitVar!QVariant) 184 { insertItem(count(), atext, auserData); } 185 pragma(inline, true) final void addItem(ref const(QIcon) aicon, ref const(QString) atext, 186 ref const(QVariant) auserData = globalInitVar!QVariant) 187 { insertItem(count(), aicon, atext, auserData); } 188 pragma(inline, true) final void addItems(ref const(QStringList) texts) 189 { insertItems(count(), texts); } 190 191 pragma(inline, true) final void insertItem(int aindex, ref const(QString) atext, ref const(QVariant) auserData = globalInitVar!QVariant) 192 { auto tmp = QIcon(); insertItem(aindex, tmp, atext, auserData); } 193 final void insertItem(int index, ref const(QIcon) icon, ref const(QString) text, 194 ref const(QVariant) userData = globalInitVar!QVariant); 195 final void insertItems(int index, ref const(QStringList) texts); 196 final void insertSeparator(int index); 197 198 final void removeItem(int index); 199 200 final void setItemText(int index, ref const(QString) text); 201 final void setItemText(int index, const QString s){setItemText(index, s);} 202 final void setItemIcon(int index, ref const(QIcon) icon); 203 final void setItemData(int index, ref const(QVariant) value, int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.UserRole); 204 205 final QAbstractItemView view() const; 206 final void setView(QAbstractItemView itemView); 207 208 override QSize sizeHint() const; 209 override QSize minimumSizeHint() const; 210 211 /+ virtual +/ void showPopup(); 212 /+ virtual +/ void hidePopup(); 213 214 override bool event(QEvent event); 215 override QVariant inputMethodQuery(/+ Qt:: +/qt.core.namespace.InputMethodQuery) const; 216 @QInvokable final QVariant inputMethodQuery(/+ Qt:: +/qt.core.namespace.InputMethodQuery query, ref const(QVariant) argument) const; 217 218 public /+ Q_SLOTS +/: 219 @QSlot final void clear(); 220 @QSlot final void clearEditText(); 221 @QSlot final void setEditText(ref const(QString) text); 222 @QSlot final void setCurrentIndex(int index); 223 @QSlot final void setCurrentText(ref const(QString) text); 224 225 /+ Q_SIGNALS +/public: 226 @QSignal final void editTextChanged(ref const(QString) ); 227 @QSignal final void activated(int index); 228 @QSignal final void textActivated(ref const(QString) ); 229 @QSignal final void highlighted(int index); 230 @QSignal final void textHighlighted(ref const(QString) ); 231 @QSignal final void currentIndexChanged(int index); 232 /+ #if QT_DEPRECATED_SINCE(5, 15) +/ 233 /+ QT_DEPRECATED_VERSION_X_5_15( 234 "Use currentIndexChanged(int) instead, and get the text using itemText(index)") +/ 235 @QSignal final void currentIndexChanged(ref const(QString) ); 236 /+ #endif +/ 237 @QSignal final void currentTextChanged(ref const(QString) ); 238 /+ #if QT_DEPRECATED_SINCE(5, 15) +/ 239 /+ QT_DEPRECATED_VERSION_X(5, 15, "Use textActivated() instead") +/ 240 @QSignal final void activated(ref const(QString) ); 241 /+ QT_DEPRECATED_VERSION_X(5, 15, "Use textHighlighted() instead") +/ 242 @QSignal final void highlighted(ref const(QString) ); 243 /+ #endif +/ 244 245 protected: 246 override void focusInEvent(QFocusEvent e); 247 override void focusOutEvent(QFocusEvent e); 248 override void changeEvent(QEvent e); 249 override void resizeEvent(QResizeEvent e); 250 override void paintEvent(QPaintEvent e); 251 override void showEvent(QShowEvent e); 252 override void hideEvent(QHideEvent e); 253 override void mousePressEvent(QMouseEvent e); 254 override void mouseReleaseEvent(QMouseEvent e); 255 override void keyPressEvent(QKeyEvent e); 256 override void keyReleaseEvent(QKeyEvent e); 257 /+ #if QT_CONFIG(wheelevent) +/ 258 override void wheelEvent(QWheelEvent e); 259 /+ #endif 260 #ifndef QT_NO_CONTEXTMENU +/ 261 version(QT_NO_CONTEXTMENU){}else 262 { 263 override void contextMenuEvent(QContextMenuEvent e); 264 } 265 /+ #endif +/ // QT_NO_CONTEXTMENU 266 override void inputMethodEvent(QInputMethodEvent ); 267 final void initStyleOption(QStyleOptionComboBox* option) const; 268 269 270 protected: 271 this(ref QComboBoxPrivate , QWidget ); 272 273 private: 274 /+ Q_DECLARE_PRIVATE(QComboBox) +/ 275 /+ Q_DISABLE_COPY(QComboBox) +/ 276 /+ Q_PRIVATE_SLOT(d_func(), void _q_itemSelected(const QModelIndex &item)) 277 Q_PRIVATE_SLOT(d_func(), void _q_emitHighlighted(const QModelIndex &)) 278 Q_PRIVATE_SLOT(d_func(), void _q_emitCurrentIndexChanged(const QModelIndex &index)) 279 Q_PRIVATE_SLOT(d_func(), void _q_editingFinished()) 280 Q_PRIVATE_SLOT(d_func(), void _q_returnPressed()) 281 Q_PRIVATE_SLOT(d_func(), void _q_resetButton()) 282 Q_PRIVATE_SLOT(d_func(), void _q_dataChanged(const QModelIndex &, const QModelIndex &)) 283 Q_PRIVATE_SLOT(d_func(), void _q_updateIndexBeforeChange()) 284 Q_PRIVATE_SLOT(d_func(), void _q_rowsInserted(const QModelIndex & parent, int start, int end)) 285 Q_PRIVATE_SLOT(d_func(), void _q_rowsRemoved(const QModelIndex & parent, int start, int end)) 286 Q_PRIVATE_SLOT(d_func(), void _q_modelDestroyed()) 287 Q_PRIVATE_SLOT(d_func(), void _q_modelReset()) 288 #if QT_CONFIG(completer) 289 Q_PRIVATE_SLOT(d_func(), void _q_completerActivated(const QModelIndex &index)) 290 #endif +/ 291 } 292