File indexing completed on 2024-05-05 17:18:50
0001 /*************************************************************************** 0002 * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr 0003 * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 ***************************************************************************/ 0006 #ifndef SKGOBJECTMODEL_H 0007 #define SKGOBJECTMODEL_H 0008 /** @file 0009 * This file defines classes SKGObjectModel. 0010 * 0011 * @author Stephane MANKOWSKI / Guillaume DE BURE 0012 */ 0013 #include <qcolor.h> 0014 #include <qfont.h> 0015 0016 #include "skgbankgui_export.h" 0017 #include "skgdocumentbank.h" 0018 #include "skgobjectbase.h" 0019 #include "skgobjectmodelbase.h" 0020 0021 /** 0022 * The Table model managing SKGObjectBase 0023 */ 0024 class SKGBANKGUI_EXPORT SKGObjectModel : public SKGObjectModelBase 0025 { 0026 Q_OBJECT 0027 public: 0028 /** 0029 * Default constructor 0030 * @param iDocument the document where to search 0031 * @param iTable the table where to search 0032 * @param iWhereClause the where clause 0033 * @param iParent parent QT object 0034 * @param iParentAttribute the attribute to find the parent of an object clause to find children 0035 * @param iResetOnCreation to reset data during creation 0036 */ 0037 explicit SKGObjectModel(SKGDocumentBank* iDocument, 0038 const QString& iTable, 0039 const QString& iWhereClause, 0040 QWidget* iParent, 0041 const QString& iParentAttribute = QString(), 0042 bool iResetOnCreation = true); 0043 0044 /** 0045 * Destructor 0046 */ 0047 ~SKGObjectModel() override; 0048 0049 /** 0050 * Returns the data stored under the given role for the item referred to by the index. 0051 * @param iIndex the index 0052 * @param iRole the role 0053 * @return the returned value 0054 */ 0055 QVariant computeData(const QModelIndex& iIndex, int iRole = Qt::DisplayRole) const override; 0056 0057 /** 0058 * Sets the role data for the item at index to value. Returns true if successful; otherwise returns false. 0059 * @param iIndex index of the object 0060 * @param iValue value 0061 * @param iRole role 0062 * @return 0063 */ 0064 bool setData(const QModelIndex& iIndex, const QVariant& iValue, int iRole = Qt::EditRole) override; 0065 0066 /** 0067 * Returns the data for the given role and section in the header with the specified orientation. 0068 * @param section the section 0069 * @param orientation the orientation 0070 * @param role the role 0071 * @return the header data 0072 */ 0073 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0074 0075 /** 0076 * Returns the item flags for the given index. 0077 * @param iIndex index of the object 0078 * @return flags of the given index 0079 */ 0080 Qt::ItemFlags flags(const QModelIndex& iIndex) const override; 0081 0082 /** 0083 * Returns the actions supported by the data in this model. 0084 * @return Qt::DropActions 0085 */ 0086 Qt::DropActions supportedDragActions() const override; 0087 0088 /** 0089 * Returns the actions supported by the data in this model. 0090 * @return Qt::DropActions 0091 */ 0092 Qt::DropActions supportedDropActions() const override; 0093 0094 /** 0095 * Handles the data supplied by a drag and drop transaction that ended with the given action. 0096 * Returns true if the data and action can be handled by the model; otherwise returns false. 0097 * Although the specified row, column and parent indicate the location of an item in the model where the transaction ended, 0098 *it is the responsibility of the view to provide a suitable location for where the data should be inserted. 0099 * @param iData mime data 0100 * @param iAction action 0101 * @param iRow row 0102 * @param iColumn column 0103 * @param iParent parent 0104 * @return true if the dropping was successful otherwise false. 0105 */ 0106 bool dropMimeData(const QMimeData* iData, 0107 Qt::DropAction iAction, 0108 int iRow, int iColumn, 0109 const QModelIndex& iParent) override; 0110 0111 protected: 0112 /** 0113 * Get the attribute value for grouping 0114 * @param iObject the object 0115 * @param iAttribute the attribute name 0116 * @return the value of the attribute 0117 */ 0118 QString getAttributeForGrouping(const SKGObjectBase& iObject, const QString& iAttribute) const override; 0119 0120 /** 0121 * Get the string of an amount 0122 * @param iValue the value 0123 * @return the string 0124 */ 0125 QString formatMoney(double iValue) const override; 0126 0127 protected Q_SLOTS: 0128 /** 0129 * This method is called by refresh to build the cache (to improve performance) 0130 */ 0131 void buidCache() override; 0132 0133 /** 0134 * data are modified 0135 * @param iTableName table name 0136 * @param iIdTransaction the id of the transaction for direct modifications of the table (update of modify objects is enough) 0137 *or 0 in case of modifications by impact (full table must be refreshed) 0138 */ 0139 void dataModified(const QString& iTableName, int iIdTransaction) override; 0140 0141 private: 0142 Q_DISABLE_COPY(SKGObjectModel) 0143 0144 SKGServices::SKGUnitInfo m_cacheUnit; 0145 bool m_operationTable; 0146 bool m_recurrentoperationTable; 0147 bool m_trackerTable; 0148 bool m_accountTable; 0149 bool m_unitTable; 0150 bool m_unitvalueTable; 0151 bool m_suboperationTable; 0152 bool m_categoryTable; 0153 bool m_ruleTable; 0154 bool m_interestTable; 0155 bool m_interestResultTable; 0156 bool m_payeeTable; 0157 bool m_budgetTable; 0158 bool m_budgetRuleTable; 0159 0160 QVariant m_fontDisabledScheduleColor; 0161 QVariant m_fontFutureOperationsColor; 0162 QVariant m_fontNotValidatedOperationsColor; 0163 QVariant m_fontSubOperationsColor; 0164 0165 QVariant m_iconTransfer; 0166 QVariant m_iconGroup; 0167 QVariant m_iconSplit; 0168 QVariant m_iconMuchMore; 0169 QVariant m_iconMuchLess; 0170 QVariant m_iconMore; 0171 QVariant m_iconLess; 0172 QVariant m_iconClosed; 0173 QVariant m_iconImported; 0174 QVariant m_iconImportedChecked; 0175 QVariant m_iconRecurrent; 0176 QVariant m_iconRecurrentMaster; 0177 QVariant m_iconFavorite; 0178 QVariant m_iconCategory; 0179 QVariant m_iconCategoryPlus; 0180 QVariant m_iconCategoryMoins; 0181 QVariant m_iconSearch; 0182 QVariant m_iconUpdate; 0183 QVariant m_iconAlarm; 0184 QVariant m_iconTemplate; 0185 0186 QVariant m_iconGreen; 0187 QVariant m_iconRed; 0188 QVariant m_iconAnber; 0189 }; 0190 0191 #endif