Warning, file /office/kmymoney/kmymoney/widgets/register.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2006-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 REGISTER_H 0008 #define REGISTER_H 0009 0010 // ---------------------------------------------------------------------------- 0011 // QT Includes 0012 0013 // ---------------------------------------------------------------------------- 0014 // KDE Includes 0015 0016 // ---------------------------------------------------------------------------- 0017 // Project Includes 0018 0019 #include "transactioneditorcontainer.h" 0020 0021 class MyMoneyAccount; 0022 class MyMoneySplit; 0023 class MyMoneyTransaction; 0024 0025 namespace eWidgets { 0026 enum class SortField; 0027 namespace eTransaction { 0028 enum class Column; 0029 } 0030 namespace eRegister { 0031 enum class DetailColumn; 0032 } 0033 } 0034 namespace eMyMoney { 0035 namespace Account { 0036 enum class Type; 0037 } 0038 } 0039 0040 template <typename T> class QList; 0041 0042 namespace KMyMoneyRegister 0043 { 0044 class RegisterItem; 0045 class Transaction; 0046 class SelectedTransactions; 0047 0048 class RegisterPrivate; 0049 class Register : public TransactionEditorContainer 0050 { 0051 Q_OBJECT 0052 Q_DISABLE_COPY(Register) 0053 0054 friend class Transaction; 0055 friend class StdTransaction; 0056 friend class InvestTransaction; 0057 0058 public: 0059 explicit Register(QWidget* parent = nullptr); 0060 virtual ~Register(); 0061 0062 /** 0063 * add the item @a p to the register 0064 */ 0065 void addItem(RegisterItem* p); 0066 0067 /** 0068 * insert the item @a p into the register after item @a q 0069 */ 0070 void insertItemAfter(RegisterItem* p, RegisterItem* q); 0071 0072 /** 0073 * remove the item @p from the register 0074 */ 0075 void removeItem(RegisterItem* p); 0076 0077 /** 0078 * This method returns a list of pointers to all selected items 0079 * in the register 0080 * 0081 * @retval QList<RegisterItem*> 0082 */ 0083 QList<RegisterItem*> selectedItems() const; 0084 0085 /** 0086 * Construct a list of all currently selected transactions in the register. 0087 * If the current item carrying the focus (see focusItem() ) is selected 0088 * it will be the first one contained in the list. 0089 * 0090 * @param list reference to QList receiving the SelectedTransaction()'s 0091 */ 0092 void selectedTransactions(SelectedTransactions& list) const; 0093 0094 QString text(int row, int col) const; 0095 QWidget* createEditor(int row, int col, bool initFromCell) const; 0096 void setCellContentFromEditor(int row, int col); 0097 void endEdit(); 0098 0099 RegisterItem* focusItem() const; 0100 RegisterItem* anchorItem() const; 0101 0102 /** 0103 * set focus to specific item. 0104 * @return true if the item got focus 0105 */ 0106 bool setFocusItem(RegisterItem* focusItem); 0107 0108 void setAnchorItem(RegisterItem* anchorItem); 0109 0110 /** 0111 * Set focus to the first focussable item 0112 * @return true if a focussable item was found 0113 */ 0114 bool setFocusToTop(); 0115 0116 /** 0117 * Select @a item and unselect all others if @a dontChangeSelections 0118 * is @a false. If m_buttonState differs from Qt::NoButton (method is 0119 * called as a result of a mouse button press), then the setting of 0120 * @a dontChangeSelections has no effect. 0121 */ 0122 void selectItem(RegisterItem* item, bool dontChangeSelections = false); 0123 0124 /** 0125 * Clears all items in the register. All objects 0126 * added to the register will be deleted. 0127 */ 0128 void clear(); 0129 0130 void updateRegister(bool forceUpdateRowHeight = false); 0131 0132 /** 0133 * Assign all visible items an alternate background color 0134 */ 0135 void updateAlternate() const; 0136 0137 /** 0138 * make sure, we only show a single marker in a row 0139 * through hiding unused ones 0140 */ 0141 void suppressAdjacentMarkers(); 0142 0143 /** 0144 * Adjusts column @a col so that all data fits in width. 0145 */ 0146 void adjustColumn(int col); 0147 0148 /** 0149 * Convenience method to setup the register to show the columns 0150 * based on the account type of @a account. If @a showAccountColumn 0151 * is @a true then the account column is shown independent of the 0152 * account type. If @a account does not have an @a id, all columns 0153 * will be hidden. 0154 */ 0155 void setupRegister(const MyMoneyAccount& account, bool showAccountColumn = false); 0156 0157 /** 0158 * Show the columns contained in @a cols for @a account. @a account 0159 * can be left empty ( MyMoneyAccount() ) e.g. for the search dialog. 0160 */ 0161 void setupRegister(const MyMoneyAccount& account, const QList<eWidgets::eTransaction::Column>& cols); 0162 0163 void setSortOrder(const QString& order); 0164 const QList<eWidgets::SortField>& sortOrder() const; 0165 eWidgets::SortField primarySortKey() const; 0166 void sortItems(); 0167 0168 /** 0169 * This member returns the last visible column that is used by the register 0170 * after it has been setup using setupRegister(). 0171 * 0172 * @return last actively used column (base 0) 0173 */ 0174 eWidgets::eTransaction::Column lastCol() const; 0175 0176 RegisterItem* firstItem() const; 0177 RegisterItem* firstVisibleItem() const; 0178 RegisterItem* nextItem(RegisterItem*) const; 0179 RegisterItem* lastItem() const; 0180 RegisterItem* lastVisibleItem() const; 0181 RegisterItem* prevItem(RegisterItem*) const; 0182 RegisterItem* itemAtRow(int row) const; 0183 0184 void resize(int col, bool force = false); 0185 0186 void forceUpdateLists(); 0187 0188 void ensureItemVisible(RegisterItem* item); 0189 0190 void arrangeEditWidgets(QMap<QString, QWidget*>& editWidgets, Transaction* t) override; 0191 void removeEditWidgets(QMap<QString, QWidget*>& editWidgets) override; 0192 void tabOrder(QWidgetList& tabOrderWidgets, KMyMoneyRegister::Transaction* t) const override; 0193 0194 int rowHeightHint() const; 0195 0196 void clearSelection(); 0197 0198 /** 0199 * This method creates a specific transaction according to the 0200 * transaction passed in @a transaction. 0201 * 0202 * @param parent pointer to register where the created object should be added 0203 * @param transaction the transaction which should be used to create the object 0204 * @param split the split of the transaction which should be used to create the object 0205 * @param uniqueId an int that will be used to construct the id of the item 0206 * 0207 * @return pointer to created object (0 upon failure) 0208 */ 0209 static Transaction* transactionFactory(Register *parent, const MyMoneyTransaction& transaction, const MyMoneySplit& split, int uniqueId); 0210 0211 const MyMoneyAccount& account() const; 0212 0213 /** 0214 * This method creates group marker items and adds them to the register 0215 */ 0216 void addGroupMarkers(); 0217 0218 /** 0219 * This method removes all trailing group markers and in a second 0220 * run reduces all adjacent group markers to show only one. In that 0221 * case the last one will remain. 0222 */ 0223 void removeUnwantedGroupMarkers(); 0224 0225 void setLedgerLensForced(bool forced = true); 0226 bool ledgerLens() const; 0227 0228 /** 0229 * Sets the selection mode to @a mode. Supported modes are QTable::Single and 0230 * QTable::Multi. QTable::Multi is the default when the object is created. 0231 */ 0232 void setSelectionMode(SelectionMode mode); 0233 0234 /** 0235 * This method sets a hint that the register instance will be used 0236 * with a transaction editor. This information is used while the column 0237 * sizes are being auto adjusted. If a transaction editor is used then 0238 * it's possible that it will need some extra space. 0239 */ 0240 void setUsedWithEditor(bool value); 0241 0242 eWidgets::eRegister::DetailColumn getDetailsColumnType() const; 0243 void setDetailsColumnType(eWidgets::eRegister::DetailColumn detailsColumnType); 0244 0245 public Q_SLOTS: 0246 void ensureFocusItemVisible(); 0247 0248 protected: 0249 0250 void mouseReleaseEvent(QMouseEvent *e) override; 0251 void contextMenuEvent(QContextMenuEvent *e) override; 0252 0253 void unselectItems(int from = -1, int to = -1); 0254 void selectItems(int from, int to); 0255 void doSelectItems(int from, int to, bool selected); 0256 int selectedItemsCount() const; 0257 0258 bool event(QEvent*) override; 0259 void focusOutEvent(QFocusEvent*) override; 0260 void focusInEvent(QFocusEvent*) override; 0261 void keyPressEvent(QKeyEvent*) override; 0262 void resizeEvent(QResizeEvent* ev) override; 0263 0264 int rowToIndex(int row) const; 0265 void setupItemIndex(int rowCount); 0266 0267 /** 0268 * This method determines the register item that is one page 0269 * further down or up in the ledger from the previous focus item. 0270 * The height to scroll is determined by visibleHeight() 0271 * 0272 * @param key Qt::Page_Up or Qt::Page_Down depending on the direction to scroll 0273 * @param modifiers state of Qt::ShiftModifier, Qt::ControlModifier, Qt::AltModifier and 0274 * Qt::MetaModifier. 0275 */ 0276 void scrollPage(int key, Qt::KeyboardModifiers modifiers); 0277 0278 /** 0279 * This method determines the pointer to a RegisterItem 0280 * based on the item's @a id. If @a id is empty, this method 0281 * returns @a m_lastItem. 0282 * 0283 * @param id id of the item to be searched 0284 * @return pointer to RegisterItem or 0 if not found 0285 */ 0286 RegisterItem* itemById(const QString& id) const; 0287 0288 /** 0289 * Override logic and use standard QFrame behaviour 0290 */ 0291 bool focusNextPrevChild(bool next) override; 0292 0293 bool eventFilter(QObject* o, QEvent* e) override; 0294 0295 void handleItemChange(RegisterItem* old, bool shift, bool control); 0296 0297 void selectRange(RegisterItem* from, RegisterItem* to, bool invert, bool includeFirst, bool clearSel); 0298 0299 /** 0300 * Returns the minimum column width based on the data in the header and the transactions. 0301 */ 0302 int minimumColumnWidth(int col); 0303 0304 protected Q_SLOTS: 0305 void resize(); 0306 0307 void selectItem(int row, int col); 0308 void slotEnsureItemVisible(); 0309 void slotDoubleClicked(int row, int); 0310 0311 Q_SIGNALS: 0312 void transactionsSelected(const KMyMoneyRegister::SelectedTransactions& list); 0313 /** 0314 * This signal is emitted when the focus and selection changes to @p item. 0315 * 0316 * @param item pointer to transaction that received the focus and was selected 0317 */ 0318 void focusChanged(KMyMoneyRegister::Transaction* item); 0319 0320 /** 0321 * This signal is emitted when the focus changes but the selection remains 0322 * the same. This usually happens when the focus is changed using the keyboard. 0323 */ 0324 void focusChanged(); 0325 0326 /** 0327 * This signal is emitted when an @p item is about to be selected. The boolean 0328 * @p okToSelect is preset to @c true. If the @p item should not be selected 0329 * for whatever reason, the boolean @p okToSelect should be reset to @c false 0330 * by the connected slot. 0331 */ 0332 void aboutToSelectItem(KMyMoneyRegister::RegisterItem* item, bool& okToSelect); 0333 0334 void editTransaction(); 0335 0336 /** 0337 * This signal is sent out when the user clicks on the ReconcileStateColumn and 0338 * only a single transaction is selected. 0339 */ 0340 void reconcileStateColumnClicked(KMyMoneyRegister::Transaction* item); 0341 0342 /** 0343 * This signal is sent out, if an item without a transaction id has been selected. 0344 */ 0345 void emptyItemSelected(); 0346 0347 /** 0348 * This signal is sent out, if the user selects an item with the right mouse button 0349 */ 0350 void openContextMenu(); 0351 0352 /** 0353 * This signal is sent out when a new item has been added to the register 0354 */ 0355 void itemAdded(RegisterItem* item); 0356 0357 private: 0358 RegisterPrivate * const d_ptr; 0359 Q_DECLARE_PRIVATE(Register) 0360 }; 0361 0362 } // namespace 0363 0364 #endif