File indexing completed on 2024-05-12 16:44:07
0001 /* 0002 SPDX-FileCopyrightText: 2007-2018 Thomas Baumgart <tbaumgart@kde.org> 0003 SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef REGISTERSEARCHLINE_H 0008 #define REGISTERSEARCHLINE_H 0009 0010 // ---------------------------------------------------------------------------- 0011 // QT Includes 0012 0013 // ---------------------------------------------------------------------------- 0014 // KDE Includes 0015 0016 #include <KLineEdit> 0017 0018 // ---------------------------------------------------------------------------- 0019 // Project Includes 0020 0021 namespace KMyMoneyRegister { 0022 class Register; 0023 class RegisterItem; 0024 } 0025 0026 namespace KMyMoneyRegister 0027 { 0028 0029 /** 0030 * This class makes it easy to add a search line for filtering the items 0031 * in a register based on simple text. Inspired by the idea of the kdelibs 0032 * class KListViewSearchLine. 0033 * 0034 * @author Thomas Baumgart 0035 */ 0036 class RegisterSearchLine : public KLineEdit 0037 { 0038 Q_OBJECT 0039 public: 0040 /** 0041 * Constructs a RegisterSearchLine with @a reg being the register to be 0042 * filtered. 0043 * 0044 * If @a reg is null then the widget will be disabled until a register 0045 * is set with setRegister(). 0046 */ 0047 explicit RegisterSearchLine(QWidget* parent = nullptr, Register* reg = 0); 0048 0049 /** 0050 * Destroys the object 0051 */ 0052 ~RegisterSearchLine(); 0053 0054 /** 0055 * Sets the KMyMoneyRegister that is filtered by this search line. 0056 * If @a reg is null then the widget will be disabled. 0057 * 0058 * @see KMyMoneyRegister() 0059 */ 0060 void setRegister(Register* reg); 0061 0062 public Q_SLOTS: 0063 virtual void updateSearch(const QString& s = QString()); 0064 0065 protected Q_SLOTS: 0066 void queueSearch(const QString& search); 0067 void activateSearch(); 0068 void slotStatusChanged(int); 0069 0070 private Q_SLOTS: 0071 void itemAdded(RegisterItem* item) const; 0072 void registerDestroyed(); 0073 0074 private: 0075 void init(Register* reg); 0076 0077 private: 0078 class RegisterSearchLinePrivate; 0079 RegisterSearchLinePrivate* const d; 0080 }; 0081 0082 /** 0083 * Creates a widget containing a RegisterSearchLine, a label with the text 0084 * "Search" and a button to clear the search. Modelled after KListViewSearchLineWidget. 0085 * 0086 * @author Thomas Baumgart 0087 */ 0088 class RegisterSearchLineWidget : public QWidget 0089 { 0090 Q_OBJECT 0091 public: 0092 /** 0093 * Creates a RegisterSearchLineWidget for @a reg with @a parent as the 0094 * parent and with @a name. 0095 */ 0096 explicit RegisterSearchLineWidget(Register* reg = 0, QWidget* parent = nullptr); 0097 0098 /** 0099 * Destroys the object 0100 */ 0101 ~RegisterSearchLineWidget(); 0102 0103 /** 0104 * Returns a pointer to the searchline 0105 */ 0106 RegisterSearchLine* searchLine() const; 0107 0108 /** 0109 * Creates the search line. This can be useful to reimplement in cases where 0110 * a RegisterSearchLine subclass is used. 0111 */ 0112 virtual RegisterSearchLine* createSearchLine(Register* reg); 0113 0114 protected Q_SLOTS: 0115 /** 0116 * Creates the widgets inside of the widget. This is called from the 0117 * constructor via a single shot timer so that it it guaranteed to run 0118 * after construction is complete. This makes it suitable for overriding in 0119 * subclasses. 0120 */ 0121 virtual void createWidgets(); 0122 0123 private: 0124 class RegisterSearchLineWidgetPrivate; 0125 RegisterSearchLineWidgetPrivate* const d; 0126 }; 0127 0128 } // namespace 0129 0130 #endif