1 #pragma once
2 
3 #ifndef EXPRESSIONREFERENCEMANAGER_H
4 #define EXPRESSIONREFERENCEMANAGER_H
5 
6 #include "tparamchange.h"
7 #include "toonzqt/treemodel.h"
8 #include "toonzqt/functiontreeviewer.h"
9 #include "toonz/txsheetcolumnchange.h"
10 #include "toonz/tstageobjectid.h"
11 #include "toonz/expressionreferencemonitor.h"
12 #include <QObject>
13 #include <QMap>
14 #include <QSet>
15 #include <QList>
16 
17 class TDoubleParam;
18 class TFx;
19 
20 class ExpressionReferenceManager : public QObject,
21                                    public TXsheetColumnChangeObserver,
22                                    public TParamObserver {  // singleton
23   Q_OBJECT
24 
25   FunctionTreeModel* m_model;
26   // block to run onChange() due to keyframe change caused by itself
27   bool m_blockParamChange;
28 
29   ExpressionReferenceMonitor* currentMonitor();
30 
31   QMap<TDoubleParam*, ExpressionReferenceMonitorInfo>& info(
32       TXsheet* xsh = nullptr);
33 
34   ExpressionReferenceMonitorInfo& touchInfo(TDoubleParam* param,
35                                             TXsheet* xsh = nullptr);
36 
37   ExpressionReferenceManager();
38 
39   void checkRef(TreeModel::Item* item, TXsheet* xsh = nullptr);
40   FunctionTreeModel::Channel* findChannel(TDoubleParam* param,
41                                           TreeModel::Item* item);
42 
43   void gatherParams(TreeModel::Item* item, QList<TDoubleParam*>&);
44   bool refreshParamsRef(TDoubleParam* curve, TXsheet* xsh = nullptr);
45 
46   void replaceExpressionTexts(
47       TDoubleParam* curve, const std::map<std::string, std::string> replaceMap,
48       TXsheet* xsh = nullptr);
49 
50   bool doCheckReferenceDeletion(
51       const QSet<int>& columnIdsToBeDeleted, const QSet<TFx*>& fxsToBeDeleted,
52       const QList<TStageObjectId>& objectIdsToBeDeleted,
53       const QList<TStageObjectId>& objIdsToBeDuplicated,
54       bool checkInvert = false);
55 
56 public:
57   static ExpressionReferenceManager* instance();
58   void onChange(const TXsheetColumnChange&) override;
59   void onFxAdded(const std::vector<TFx*>&) override;
60   void onStageObjectAdded(const TStageObjectId) override;
61   bool isIgnored(TDoubleParam*) override;
62 
63   void onChange(const TParamChange&) override;
64 
65   void init();
66 
67   bool checkReferenceDeletion(const QSet<int>& columnIdsToBeDeleted,
68                               const QSet<TFx*>& fxsToBeDeleted,
69                               const QList<TStageObjectId>& objIdsToBeDuplicated,
70                               bool checkInvert);
71   bool checkReferenceDeletion(
72       const QList<TStageObjectId>& objectIdsToBeDeleted);
73   bool checkExplode(TXsheet* childXsh, int index, bool removeColumn,
74                     bool columnsOnly);
75 
76   void transferReference(TXsheet* fromXsh, TXsheet* toXsh,
77                          const QMap<TStageObjectId, TStageObjectId>& idTable,
78                          const QMap<TFx*, TFx*>& fxTable);
79 
80   bool askIfParamIsIgnoredOnSave(bool saveSubXsheet);
81 
82 protected slots:
83   void onSceneSwitched();
84   void onXsheetSwitched();
85   void onXsheetChanged();
86   void onPreferenceChanged(const QString& prefName);
87 };
88 
89 #endif