File indexing completed on 2024-05-12 16:44:07

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 REGISTERITEM_H
0008 #define REGISTERITEM_H
0009 
0010 // ----------------------------------------------------------------------------
0011 // QT Includes
0012 
0013 #include <qglobal.h>
0014 #include <QString>
0015 
0016 // ----------------------------------------------------------------------------
0017 // KDE Includes
0018 
0019 // ----------------------------------------------------------------------------
0020 // Project Includes
0021 
0022 class QDate;
0023 class QPainter;
0024 class QPoint;
0025 class QRect;
0026 class QStyleOptionViewItem;
0027 class QModelIndex;
0028 
0029 class MyMoneyMoney;
0030 
0031 namespace eMyMoney {
0032 namespace Split {
0033 enum class State;
0034 }
0035 }
0036 namespace eWidgets {
0037 namespace eRegister {
0038 enum class CashFlowDirection;
0039 }
0040 }
0041 
0042 namespace KMyMoneyRegister
0043 {
0044 struct RegisterFilter;
0045 class Register;
0046 
0047 /**
0048 * @author Thomas Baumgart
0049 */
0050 class RegisterItemPrivate;
0051 class RegisterItem
0052 {
0053     Q_DISABLE_COPY(RegisterItem)
0054 
0055 public:
0056     explicit RegisterItem(Register* getParent);
0057     virtual ~RegisterItem();
0058 
0059     virtual const char* className() = 0;
0060 
0061     virtual bool isSelectable() const = 0;
0062     virtual bool isSelected() const;
0063     virtual void setSelected(bool /* selected*/);
0064 
0065     virtual bool canHaveFocus() const = 0;
0066     virtual bool hasFocus() const;
0067     virtual bool hasEditorOpen() const;
0068 
0069     virtual void setFocus(bool /*focus*/, bool updateLens = true);
0070 
0071     virtual bool isErroneous() const = 0;
0072 
0073     // helper functions used for sorting
0074     virtual QDate sortPostDate() const;
0075     virtual int sortSamePostDate() const = 0;
0076     virtual QDate sortEntryDate() const;
0077     virtual const QString& sortPayee() const;
0078     virtual MyMoneyMoney sortValue() const;
0079     virtual QString sortNumber() const;
0080     virtual const QString& sortEntryOrder() const;
0081     virtual eWidgets::eRegister::CashFlowDirection sortType() const;
0082     virtual const QString& sortCategory() const;
0083     virtual eMyMoney::Split::State sortReconcileState() const;
0084     virtual const QString sortSecurity() const;
0085 
0086     /**
0087     * This method sets the row offset of the item in the register
0088     * to row.
0089     *
0090     * @param row row offset
0091     *
0092     * @note The row offset is based on QTable rows, not register
0093     * items.
0094     */
0095     virtual void setStartRow(int row);
0096     int startRow() const;
0097     virtual int rowHeightHint() const;
0098 
0099     /**
0100     * This method modifies the number of rows required to display this item
0101     * in a Register.
0102     * It calls Register::forceUpdateLists() when the number differs.
0103     */
0104     virtual void setNumRowsRegister(int rows);
0105 
0106     /**
0107     * This method modifies the number of rows required to display this item
0108     * in a Form.
0109     */
0110     virtual void setNumRowsForm(int rows);
0111 
0112     /**
0113     * This method returns the number of rows required to display this item
0114     * in a Register
0115     */
0116     virtual int numRowsRegister() const;
0117 
0118     /**
0119     * This method returns the number of rows required to display this item
0120     * in a Form
0121     */
0122     virtual int numRowsForm() const;
0123     virtual int numColsForm() const;
0124 
0125     /**
0126     * This method sets up the register item to be shown in normal (@p alternate = @p false)
0127     * or alternate (@p alternate = @p true) background.
0128     *
0129     * @param alternate selects normal or alternate background
0130     */
0131     virtual void setAlternate(bool alternate);
0132 
0133     virtual void paintRegisterCell(QPainter *painter, QStyleOptionViewItem &option, const QModelIndex &index) = 0;
0134     virtual void paintFormCell(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) = 0;
0135 
0136     virtual QString id() const;
0137 
0138     /**
0139     * Sets the parent of this item to be the register @p parent
0140     *
0141     * @param parent pointer to register
0142     */
0143     void setParent(Register* getParent);
0144 
0145     /**
0146     * This member returns a pointer to the parent object
0147     *
0148     * @retval pointer to Register
0149     */
0150     Register* getParent() const;
0151 
0152     void setNeedResize();
0153 
0154     bool isVisible() const;
0155 
0156     /**
0157     * Marks the item visible depending on @a visible and
0158     * updates the underlying register object
0159     */
0160     virtual void setVisible(bool visible);
0161 
0162     /**
0163     * Marks the item visible depending on @a visible but
0164     * does not update the underlying register object. Returns
0165     * true, if visibility has changed.
0166     */
0167     virtual bool markVisible(bool visible);
0168 
0169     void setNextItem(RegisterItem* p);
0170     void setPrevItem(RegisterItem* p);
0171     RegisterItem* nextItem() const;
0172     RegisterItem* prevItem() const;
0173 
0174     virtual bool matches(const RegisterFilter&) const = 0;
0175 
0176     /**
0177     * Checks if the mouse hovered over an area that has a tooltip associated with it.
0178     * The mouse position is given in relative coordinates to the @a startRow and the
0179     * @a row and @a col of the item are also passed as relative values.
0180     *
0181     * If a tooltip shall be shown, this method presets the rectangle @a r with the
0182     * area in register coordinates and @a msg with the string that will be passed
0183     * to QToolTip::tip. @a true is returned in this case.
0184     *
0185     * If no tooltip is available, @a false will be returned.
0186     */
0187     virtual bool maybeTip(const QPoint& /* relpos */, int /* row */, int /* col */, QRect& /* r */, QString& /* msg */);
0188 
0189 protected:
0190     RegisterItemPrivate * const d_ptr;
0191     RegisterItem(RegisterItemPrivate &dd, Register *parent);
0192 
0193 private:
0194     Q_DECLARE_PRIVATE(RegisterItem)
0195 };
0196 } // namespace
0197 
0198 #endif