File indexing completed on 2024-05-19 16:14:57
0001 /* 0002 SPDX-FileCopyrightText: 2008-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 KMYMONEYSPLITTABLE_H 0008 #define KMYMONEYSPLITTABLE_H 0009 0010 // ---------------------------------------------------------------------------- 0011 // QT Includes 0012 0013 #include <QTableWidget> 0014 0015 // ---------------------------------------------------------------------------- 0016 // KDE Includes 0017 0018 // ---------------------------------------------------------------------------- 0019 // Project Includes 0020 0021 class KMyMoneyCategory; 0022 class MyMoneyMoney; 0023 class MyMoneySplit; 0024 class MyMoneyTransaction; 0025 class MyMoneyAccount; 0026 class KTagContainer; 0027 0028 template <class Key, class Value> class QMap; 0029 0030 /** 0031 * @author Thomas Baumgart 0032 */ 0033 class KMyMoneySplitTablePrivate; 0034 class KMyMoneySplitTable : public QTableWidget 0035 { 0036 Q_OBJECT 0037 Q_DISABLE_COPY(KMyMoneySplitTable) 0038 public: 0039 explicit KMyMoneySplitTable(QWidget *parent = nullptr); 0040 ~KMyMoneySplitTable(); 0041 0042 /** 0043 * This method is used to load the widget with the information about 0044 * the transaction @p t. The split referencing the account @p acc is 0045 * not shown in the widget. 0046 * 0047 * @param t reference to transaction to be shown/modified 0048 * @param s reference to split that is to be hidden 0049 * @param acc reference to account 0050 */ 0051 void setTransaction(const MyMoneyTransaction& t, const MyMoneySplit& s, const MyMoneyAccount& acc); 0052 0053 /** 0054 * This method is used to retrieve the transaction from the widget. 0055 */ 0056 MyMoneyTransaction transaction() const; 0057 0058 /** 0059 * Returns a list of MyMoneySplit objects. It contains all but the one 0060 * referencing the account passed in setTransaction(). 0061 * 0062 * @param t reference to transaction 0063 * @return list of splits 0064 */ 0065 QList<MyMoneySplit> getSplits(const MyMoneyTransaction& t) const; 0066 0067 void setup(const QMap<QString, MyMoneyMoney>& priceInfo, int precision); 0068 0069 int currentRow() const; 0070 0071 /** 0072 * Setting @a readOnly to @c true forces the object into readonly mode. 0073 * It does not allow to modify any information. 0074 */ 0075 void setReadOnlyMode(bool readOnly); 0076 0077 protected: 0078 void mousePressEvent(QMouseEvent* e) override; 0079 void mouseReleaseEvent(QMouseEvent* e) override; 0080 void mouseDoubleClickEvent(QMouseEvent* e) override; 0081 bool eventFilter(QObject *o, QEvent *e) override; 0082 0083 void resizeEvent(QResizeEvent*) override; 0084 KMyMoneyCategory* createEditWidgets(bool setFocus); 0085 void destroyEditWidgets(); 0086 void destroyEditWidget(int r, int c); 0087 0088 /** 0089 * This method handles the focus of the keyboard. When in edit mode 0090 * (m_editCategory widget is visible) the keyboard focus is handled 0091 * according to the widgets that are referenced in m_tabOrderWidgets. 0092 * If not in edit mode, the base class functionality is provided. 0093 * 0094 * @param next true if forward-tab, false if backward-tab was 0095 * pressed by the user 0096 */ 0097 bool focusNextPrevChild(bool next) override; 0098 void addToTabOrder(QWidget* w); 0099 0100 void updateTransactionTableSize(); 0101 0102 /** 0103 * This method returns the current state of the inline editing mode 0104 * 0105 * @return true if inline edit mode is on, false otherwise 0106 */ 0107 bool isEditMode() const; 0108 0109 /** 0110 * This method returns true if the currently edited split is valid 0111 * and can be entered. 0112 * 0113 * @return true if the split can be entered, false otherwise 0114 */ 0115 bool isEditSplitValid() const; 0116 0117 void endEdit(bool keyboardDriven, bool setFocusToNextRow = true); 0118 0119 public Q_SLOTS: 0120 /** No descriptions */ 0121 virtual void setRowCount(int r); 0122 0123 void selectRow(int row); 0124 0125 void slotStartEdit(); 0126 void slotEndEdit(); 0127 void slotEndEditKeyboard(); 0128 void slotDeleteSplit(); 0129 void slotCancelEdit(); 0130 void slotDuplicateSplit(); 0131 0132 protected Q_SLOTS: 0133 /// move the focus to the selected @p row. 0134 void slotSetFocus(const QModelIndex& index); 0135 void slotSetFocus(const QModelIndex& index, int button); 0136 0137 /** 0138 * Calling this slot refills the widget with the data 0139 * passed in the argument @p t. 0140 * 0141 * @param t reference to transaction data 0142 */ 0143 void slotUpdateData(const MyMoneyTransaction& t); 0144 0145 void slotLoadEditWidgets(); 0146 0147 Q_SIGNALS: 0148 /** 0149 * This signal is emitted whenever the widget goes into edit mode. 0150 */ 0151 void editStarted(); 0152 0153 /** 0154 * This signal is emitted whenever the widget ends edit mode. 0155 */ 0156 void editFinished(); 0157 0158 /** 0159 * This signal is emitted whenever the return key is pressed 0160 * and the widget is not in edit mode. 0161 */ 0162 void escapePressed(); 0163 0164 /** 0165 * This signal is emitted whenever the return key is pressed 0166 * and the widget is not in edit mode. 0167 */ 0168 void returnPressed(); 0169 0170 /** 0171 * This signal is emitted whenever the transaction data has been changed 0172 * 0173 * @param t modified transaction data 0174 */ 0175 void transactionChanged(const MyMoneyTransaction& t); 0176 0177 /** 0178 * This signal is sent out, when a new category needs to be created 0179 * @sa KMyMoneyCombo::createItem() 0180 * 0181 * @param txt The name of the category to be created 0182 * @param id A connected slot should store the id of the created object in this variable 0183 */ 0184 void createCategory(const QString& txt, QString& id); 0185 0186 /** 0187 * This signal is sent out, when a new tag needs to be created 0188 * @sa KMyMoneyCombo::createItem() 0189 * 0190 * @param txt The name of the tag to be created 0191 * @param id A connected slot should store the id of the created object in this variable 0192 */ 0193 void createTag(const QString& txt, QString& id); 0194 0195 /** 0196 * Signal is emitted, if any of the widgets enters (@a state equals @a true) 0197 * or leaves (@a state equals @a false) object creation mode. 0198 * 0199 * @param state Enter (@a true) or leave (@a false) object creation 0200 */ 0201 void objectCreation(bool state); 0202 0203 private: 0204 KMyMoneySplitTablePrivate * const d_ptr; 0205 Q_DECLARE_PRIVATE(KMyMoneySplitTable) 0206 }; 0207 0208 #endif