File indexing completed on 2024-05-19 05:08:28
0001 /* 0002 SPDX-FileCopyrightText: 2019 Thomas Baumgart <tbaumgart@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef TRANSACTIONEDITORBASE_H 0007 #define TRANSACTIONEDITORBASE_H 0008 0009 // ---------------------------------------------------------------------------- 0010 // QT Includes 0011 0012 #include <QWidget> 0013 0014 // ---------------------------------------------------------------------------- 0015 // Project Includes 0016 0017 #include "mymoneyenums.h" 0018 #include "mymoneysplit.h" 0019 0020 class CreditDebitEdit; 0021 class KMyMoneyAccountCombo; 0022 class MyMoneyTransaction; 0023 class QAbstractButton; 0024 class QAbstractItemModel; 0025 class QComboBox; 0026 class KTagContainer; 0027 class SplitModel; 0028 class WidgetHintFrameCollection; 0029 0030 class TransactionEditorBase : public QWidget 0031 { 0032 Q_OBJECT 0033 0034 public: 0035 explicit TransactionEditorBase(QWidget* parent = 0, const QString& accountId = QString()); 0036 virtual ~TransactionEditorBase(); 0037 0038 /** 0039 * This method returns true if the user pressed the enter button. 0040 * It remains false, in case the user pressed the cancel button. 0041 */ 0042 virtual bool accepted() const; 0043 virtual void loadTransaction(const QModelIndex& index) = 0; 0044 virtual QStringList saveTransaction(const QStringList& selectedJournalEntries) = 0; 0045 virtual void setAmountPlaceHolderText(const QAbstractItemModel* model); 0046 0047 /** 0048 * Inform the editor about the selected journal entries so that 0049 * it can check if the editor can handle the selection. 0050 * The default implementation does nothing and returns @c true. 0051 * 0052 * In case it cannot handle the selection, the method returns 0053 * @c false, the errorMessage() should return the reason why it 0054 * cannot do so. 0055 */ 0056 virtual bool setSelectedJournalEntryIds(const QStringList& selectedJournalEntryIds); 0057 0058 /** 0059 * Returns the reason in case setSelectedJournalEntryIds() returned 0060 * with @c false. The default implementation returns an empty string. 0061 */ 0062 virtual QString errorMessage() const; 0063 0064 virtual void setReadOnly(bool readOnly); 0065 bool isReadOnly() const; 0066 0067 QWidget* focusFrame() const; 0068 0069 /** 0070 * This method is used to embed the transaction editor in other dialogs 0071 * e.g. KEditScheduleDlg. If the editor does not have a WidgetHintFrameCollection 0072 * then @c nullptr is returned. This is the default implementation. 0073 */ 0074 virtual WidgetHintFrameCollection* widgetHintFrameCollection() const; 0075 0076 void setVisible(bool visible) override; 0077 0078 public Q_SLOTS: 0079 virtual void slotSettingsChanged() 0080 { 0081 } 0082 0083 protected: 0084 void keyPressEvent(QKeyEvent* e) override; 0085 bool focusNextPrevChild(bool next) override; 0086 void setCancelButton(QAbstractButton* button); 0087 void setEnterButton(QAbstractButton* button); 0088 QStringList tabOrder(const QString& name, const QStringList& defaultTabOrder) const; 0089 void setupTabOrder(const QStringList& tabOrder); 0090 void storeTabOrder(const QString& name, const QStringList& tabOrder); 0091 virtual bool isTransactionDataValid() const = 0; 0092 0093 /** 0094 * Check a category with the name entered into the 0095 * lineedit of @a comboBox needs to be created 0096 */ 0097 bool needCreateCategory(KMyMoneyAccountCombo* comboBox) const; 0098 0099 /** 0100 * Create a category/account based on the name provided 0101 * in @a comboBox and the @a type. 0102 * 0103 * @note This starts the creation editor and returns immediately 0104 */ 0105 void createCategory(KMyMoneyAccountCombo* comboBox, eMyMoney::Account::Type type); 0106 0107 /** 0108 * Return type depending on the amount entered into the @a valueWidget 0109 */ 0110 eMyMoney::Account::Type defaultCategoryType(CreditDebitEdit* valueWidget) const; 0111 0112 /** 0113 * Check if a payee with the name entered into the 0114 * lineedit of @a comboBox needs to be created 0115 * 0116 * @note As a side effect: sets combobox's completer case 0117 * sensitivity to @c Qt::CaseSensitive 0118 */ 0119 bool needCreatePayee(QComboBox* comboBox) const; 0120 0121 /** 0122 * Create a payee based on the name provided 0123 * in @a comboBox. 0124 * 0125 * @note This starts the creation editor and returns immediately 0126 */ 0127 void createPayee(QComboBox* comboBox); 0128 0129 /** 0130 * Check if a tag with the name entered into the 0131 * lineedit of @a comboBox needs to be created 0132 * 0133 * @note As a side effect: sets combobox's completer case 0134 * sensitivity to @c Qt::CaseSensitive 0135 */ 0136 bool needCreateTag(QComboBox* comboBox) const; 0137 0138 /** 0139 * Create a tag based on the name provided 0140 * in the combobox of @a tagContainer. 0141 * 0142 * @note This starts the creation editor and returns immediately 0143 */ 0144 void createTag(KTagContainer* tagContainer); 0145 0146 protected Q_SLOTS: 0147 virtual void reject(); 0148 virtual void acceptEdit(); 0149 0150 Q_SIGNALS: 0151 void done(); 0152 void editorLayoutChanged(); 0153 0154 private: 0155 class Private; 0156 QScopedPointer<Private> const d; 0157 }; 0158 0159 #endif // TRANSACTIONEDITORBASE_H 0160