File indexing completed on 2024-05-12 05:07:58
0001 /* 0002 SPDX-FileCopyrightText: 2010-2018 Thomas Baumgart <tbaumgart@kde.org> 0003 SPDX-FileCopyrightText: 2010-2016 Cristian Oneț <onet.cristian@gmail.com> 0004 SPDX-FileCopyrightText: 2010 Alvaro Soliverez <asoliverez@gmail.com> 0005 SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KMYMONEYMVCCOMBO_H 0010 #define KMYMONEYMVCCOMBO_H 0011 0012 #include "kmm_base_widgets_export.h" 0013 0014 // ---------------------------------------------------------------------------- 0015 // QT Includes 0016 0017 // ---------------------------------------------------------------------------- 0018 // KDE Includes 0019 0020 #include <KComboBox> 0021 0022 // ---------------------------------------------------------------------------- 0023 // Project Includes 0024 0025 0026 /** 0027 * @author Cristian Onet 0028 * This class will replace the KMyMoneyCombo class when all widgets will use the MVC 0029 */ 0030 class KMyMoneyMVCComboPrivate; 0031 class KMM_BASE_WIDGETS_EXPORT KMyMoneyMVCCombo : public KComboBox 0032 { 0033 Q_OBJECT 0034 Q_DISABLE_COPY(KMyMoneyMVCCombo) 0035 Q_PROPERTY(QString selectedItem READ selectedItem WRITE setSelectedItem STORED false) 0036 0037 public: 0038 explicit KMyMoneyMVCCombo(QWidget* parent = nullptr); 0039 explicit KMyMoneyMVCCombo(bool editable, QWidget* parent = nullptr); 0040 virtual ~KMyMoneyMVCCombo(); 0041 0042 /** 0043 * @sa KLineEdit::setPlaceholderText() 0044 */ 0045 void setPlaceholderText(const QString& hint) const; 0046 0047 /** 0048 * This method returns the id of the first selected item. 0049 * 0050 * @return reference to QString containing the id. If no item 0051 * is selected the QString will be empty. 0052 */ 0053 QString selectedItem() const; 0054 0055 /** 0056 * This method selects the item with the respective @a id. 0057 * 0058 * @param id reference to QString containing the id 0059 */ 0060 void setSelectedItem(const QString& id); 0061 0062 /** 0063 * Protect an entry from selection. Protection is controlled by 0064 * the parameter @p protect. 0065 * 0066 * @param id id of item for which to modify the protection 0067 * @param protect if true, the entry specified by @p accId cannot be 0068 * selected. If false, it can be selected. 0069 * Defaults to @p true. 0070 */ 0071 void protectItem(int id, bool protect); 0072 0073 /** 0074 * Make the completion match on any substring or only 0075 * from the start of an entry. 0076 * 0077 * @param enabled @a true turns on substring match, @a false turns it off. 0078 * The default is @a false. 0079 */ 0080 void setSubstringSearch(bool enabled); 0081 0082 /** 0083 * set setSubstringSearch(enabled) of all children of widget 0084 * 0085 * @param widget a valid pointer (not 0) 0086 */ 0087 static void setSubstringSearchForChildren(QWidget *const widget, bool enabled = false); 0088 0089 /** 0090 * Reimplemented for internal reasons, no API change 0091 */ 0092 void setEditable(bool editable); 0093 0094 protected Q_SLOTS: 0095 void activated(int index); 0096 0097 protected: 0098 /** 0099 * reimplemented to support detection of new items 0100 */ 0101 void focusOutEvent(QFocusEvent*) override; 0102 0103 /** 0104 * check if the current text is contained in the internal list, if not ask the user if want to create a new item. 0105 */ 0106 virtual void checkCurrentText(); 0107 0108 /** 0109 * set the widgets text area based on the item with the given @a id. 0110 */ 0111 virtual void setCurrentTextById(const QString& id); 0112 0113 /** 0114 * Overridden for internal reasons, no API change 0115 */ 0116 void connectNotify(const QMetaMethod & signal) override; 0117 0118 /** 0119 * Overridden for internal reasons, no API change 0120 */ 0121 void disconnectNotify(const QMetaMethod & signal) override; 0122 0123 /** 0124 * overridden for internal reasons, no API change 0125 */ 0126 void setCurrentText(const QString& txt); 0127 void setCurrentText(); 0128 0129 void addEntry(const QString& newTxt, const QString& id); 0130 0131 Q_SIGNALS: 0132 void itemSelected(const QString& id); 0133 void objectCreation(bool); 0134 void createItem(const QString&, QString&); 0135 void lostFocus(); 0136 0137 protected: 0138 KMyMoneyMVCComboPrivate * const d_ptr; 0139 KMyMoneyMVCCombo(KMyMoneyMVCComboPrivate &dd, QWidget* parent = nullptr); 0140 KMyMoneyMVCCombo(KMyMoneyMVCComboPrivate &dd, bool editable, QWidget* parent = nullptr); 0141 0142 private: 0143 Q_DECLARE_PRIVATE(KMyMoneyMVCCombo) 0144 }; 0145 0146 #endif