File indexing completed on 2024-05-12 05:06:06

0001 /*
0002  *    SPDX-FileCopyrightText: 2022 Thomas Baumgart <tbaumgart@kde.org>
0003  *    SPDX-License-Identifier: GPL-2.0-or-later
0004  */
0005 
0006 #ifndef ACCOUNTCREATOR_H
0007 #define ACCOUNTCREATOR_H
0008 
0009 #include "kmm_base_dialogs_export.h"
0010 
0011 // ----------------------------------------------------------------------------
0012 // QT Includes
0013 
0014 #include <QObject>
0015 
0016 // ----------------------------------------------------------------------------
0017 // KDE Headers
0018 
0019 // ----------------------------------------------------------------------------
0020 // Project Includes
0021 
0022 #include "mymoneyenums.h"
0023 
0024 class QAbstractButton;
0025 class KMyMoneyAccountCombo;
0026 
0027 /**
0028  * This class implements the creation of a new category
0029  * based on the data provided through a KMyMoneyAccountCombo.
0030  * It can be called within a focusOut event handler to check
0031  * if the text contained in the combobox refers to an existing
0032  * item or needs to create a new one.
0033  *
0034  * If the category is created, the data in the combo box will
0035  * be updated and the focus is moved to the next widget.
0036  * If it is not created, the text will be removed in the
0037  * lineedit of the combobox and the focus remains in the
0038  * combobox.
0039  *
0040  * Since any editor buttons (enter, cancel, etc.) also issue
0041  * a focusOut event on the combobox, they need to be added
0042  * to this object using the @c addButton() method so that the
0043  * creation does not trigger when one of the buttons is
0044  * pressed.
0045  *
0046  * Use @c setComboBox() to identify the combobox to be used.
0047  * Using @c setAccountType() the preferred account type can
0048  * be set. This is useful when an amout is already known and
0049  * one can determine if the account type shall be expense or
0050  * income.
0051  *
0052  * Calling @c createCategory() will start the creation process
0053  * delayed by at least 150ms and returns immediately. This period
0054  * is extended in case one of the buttons added using @c addButton()
0055  * is still pressed. In case the object is destroyed before the
0056  * waiting period elapses, the creation will not be triggered.
0057  * Once the creation is processed, the object destroys itself.
0058  */
0059 class KMM_BASE_DIALOGS_EXPORT AccountCreator : public QObject
0060 {
0061     Q_OBJECT
0062 public:
0063     explicit AccountCreator(QObject* parent);
0064 
0065     void addButton(QAbstractButton* button);
0066     void setComboBox(KMyMoneyAccountCombo* cb);
0067     void setAccountType(eMyMoney::Account::Type type);
0068 
0069 public Q_SLOTS:
0070     void createAccount();
0071 
0072 private:
0073     QList<QAbstractButton*> m_buttons;
0074     KMyMoneyAccountCombo* m_comboBox;
0075     eMyMoney::Account::Type m_accountType;
0076 };
0077 
0078 #endif // ACCOUNTCREATOR_H