File indexing completed on 2024-05-12 05:07:46
0001 /* 0002 SPDX-FileCopyrightText: 2015-2019 Thomas Baumgart <tbaumgart@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef LEDGERVIEW_H 0007 #define LEDGERVIEW_H 0008 0009 // ---------------------------------------------------------------------------- 0010 // QT Includes 0011 0012 #include <QTableView> 0013 #include <QVector> 0014 0015 // ---------------------------------------------------------------------------- 0016 // KDE Includes 0017 0018 // ---------------------------------------------------------------------------- 0019 // Project Includes 0020 0021 #include "ledgerviewsettings.h" 0022 #include "mymoneyenums.h" 0023 0024 class MyMoneyAccount; 0025 class SelectedObjects; 0026 0027 namespace eMenu { 0028 enum class Menu; 0029 } 0030 0031 class LedgerView : public QTableView 0032 { 0033 Q_OBJECT 0034 public: 0035 explicit LedgerView(QWidget* parent = 0); 0036 virtual ~LedgerView(); 0037 0038 void setSingleLineDetailRole(eMyMoney::Model::Roles role); 0039 0040 /** 0041 * Returns true if the sign of the values displayed has 0042 * been inverted depending on the account type. 0043 */ 0044 bool showValuesInverted() const; 0045 0046 void setColumnsHidden(QVector<int> columns); 0047 void setColumnsShown(QVector<int> columns); 0048 0049 void setModel(QAbstractItemModel * model) override; 0050 0051 QStringList selectedJournalEntryIds() const; 0052 0053 void reselectJournalEntry(const QString& journalEntryId); 0054 0055 void selectMostRecentTransaction(); 0056 0057 void selectAllTransactions(); 0058 0059 void setColumnSelectorGroupName(const QString& groupName); 0060 0061 /** 0062 * If @a show is @c true, the payee name is shown in the 0063 * detail column if no payee column is present. This defaults 0064 * to @c true. 0065 */ 0066 void setShowPayeeInDetailColumn(bool show); 0067 0068 void editNewTransaction(); 0069 0070 QVector<eMyMoney::Model::Roles> statusRoles(const QModelIndex& idx) const; 0071 0072 /** 0073 * New transactions will be created in account referenced by @a id. 0074 */ 0075 void setAccountId(const QString& id); 0076 const QString& accountId() const; 0077 0078 QModelIndex editIndex() const; 0079 0080 /** 0081 * In case an editor is opened, make sure to fully show the 0082 * editor in the viewport. If editing is not active, this 0083 * acts as a nop. 0084 */ 0085 void showEditor(); 0086 0087 void setSortOrder(LedgerSortOrder sortOrder); 0088 0089 /** 0090 * Overridden for internal reasons 0091 */ 0092 void setFocus(); 0093 0094 public Q_SLOTS: 0095 /** 0096 * This method scrolls the ledger so that the current item is visible 0097 */ 0098 void ensureCurrentItemIsVisible(); 0099 0100 /** 0101 * Overridden for internal reasons. No change in base functionality 0102 */ 0103 void edit(const QModelIndex& index) { 0104 QTableView::edit(index); 0105 } 0106 0107 void slotSettingsChanged(); 0108 0109 /** 0110 * This resizes the section identified by @a section 0111 * if this view belongs to the same configuration group 0112 * identified by @a configGroupName. In case @a view points 0113 * to itself, the method does nothing and returns. 0114 * 0115 * @param view pointer to LedgerView object 0116 * @param configGroupName name of the configuration group that changes 0117 * @param section column index 0118 * @param oldSize the old width of the column in pixels 0119 * @param newSize the new width of the column in pixels 0120 * 0121 * @note Calls adjustDetailColumn(newSize, false) in case 0122 * the size changes but does not inform other views about the 0123 * change. 0124 */ 0125 void resizeSection(QWidget* view, const QString& configGroupName, int section, int oldSize, int newSize); 0126 0127 /** 0128 * This moves the section identified by @a section 0129 * In case @a view points to itself, the method does nothing and returns. 0130 * 0131 * @param view pointer to LedgerView object 0132 * @param section section index 0133 * @param oldIndex the old index of the column 0134 * @param newIndex the new index of the column 0135 * 0136 * @note Does not inform other views about the change. 0137 */ 0138 void moveSection(QWidget* view, int section, int oldIndex, int newIndex); 0139 0140 void reset() override; 0141 0142 void setSelectedJournalEntries(const QStringList& journalEntryIds); 0143 0144 protected: 0145 bool edit(const QModelIndex& index, EditTrigger trigger, QEvent* event) final override; 0146 void mousePressEvent(QMouseEvent* event) final override; 0147 void mouseMoveEvent(QMouseEvent* event) final override; 0148 void mouseDoubleClickEvent(QMouseEvent* event) final override; 0149 void wheelEvent(QWheelEvent *event) final override; 0150 void moveEvent(QMoveEvent *event) final override; 0151 void resizeEvent(QResizeEvent* event) final override; 0152 void paintEvent(QPaintEvent* event) final override; 0153 int sizeHintForRow(int row) const final override; 0154 int sizeHintForColumn(int row) const final override; 0155 void keyPressEvent ( QKeyEvent* event ) override; 0156 bool viewportEvent(QEvent*) override; 0157 /** 0158 * Overridden to prevent moving to the end using End or PageDown to start the editor 0159 */ 0160 QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override; 0161 0162 protected Q_SLOTS: 0163 void selectionChanged ( const QItemSelection& selected, const QItemSelection& deselected ) override; 0164 void closeEditor(QWidget* editor, QAbstractItemDelegate::EndEditHint hint) final override; 0165 void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) final override; 0166 void resizeEditorRow(); 0167 0168 /** 0169 * Adjust the detail column so that it takes the rest of the 0170 * available width. In case @a informOtherViews is @c true, 0171 * the sectionResized signal is emitted, if it is @c false 0172 * the emission will be suppressed. 0173 */ 0174 virtual void adjustDetailColumn(int newViewportWidth, bool informOtherViews); 0175 0176 void slotMoveToAccount(const QString& accountId); 0177 0178 void reselectAfterModelReset(); 0179 0180 Q_SIGNALS: 0181 void requestCustomContextMenu(eMenu::Menu type, const QPoint& pos); 0182 void transactionSelectionChanged(const SelectedObjects& selection); 0183 void transactionSelected(const QModelIndex& idx); 0184 void aboutToStartEdit(); 0185 void aboutToFinishEdit(); 0186 void sectionResized(QWidget* view, const QString& configGroupName, int section, int oldSize, int newSize); 0187 void sectionMoved(QWidget* view, int section, int oldIndex, int newIndex); 0188 void requestView(QWidget* viewWidget, const QString& accountId, const QString& journalEntryId); 0189 void settingsChanged(); 0190 void sortOrderChanged(QList<int> sortOrder); 0191 0192 void modifySortOrder(); 0193 0194 protected: 0195 class Private; 0196 Private * const d; 0197 }; 0198 #endif // LEDGERVIEW_H 0199