1 /*
2  *  Copyright (c) 2011 Dmitry Kazakov <dimula73@gmail.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef __KIS_PROCESSING_VISITOR_H
20 #define __KIS_PROCESSING_VISITOR_H
21 
22 #include "kritaimage_export.h"
23 #include "kis_shared.h"
24 
25 #include <QMutex>
26 
27 class KisNode;
28 class KoUpdater;
29 class KoProgressUpdater;
30 class KisUndoAdapter;
31 class KisPaintLayer;
32 class KisGroupLayer;
33 class KisAdjustmentLayer;
34 class KisExternalLayer;
35 class KisCloneLayer;
36 class KisFilterMask;
37 class KisTransformMask;
38 class KisTransparencyMask;
39 class KisSelectionMask;
40 class KisGeneratorLayer;
41 class KisColorizeMask;
42 class KUndo2Command;
43 
44 /**
45  * A visitor that processes a single layer; it does not recurse into the
46  * layer's children. Classes inheriting KisProcessingVisitor must not
47  * emit signals or ask the image to update the projection.
48  */
49 class KRITAIMAGE_EXPORT KisProcessingVisitor : public KisShared
50 {
51 public:
52     virtual ~KisProcessingVisitor();
53 
54     virtual void visit(KisNode *node, KisUndoAdapter *undoAdapter) = 0;
55     virtual void visit(KisPaintLayer *layer, KisUndoAdapter *undoAdapter) = 0;
56     virtual void visit(KisGroupLayer *layer, KisUndoAdapter *undoAdapter) = 0;
57     virtual void visit(KisAdjustmentLayer *layer, KisUndoAdapter *undoAdapter) = 0;
58     virtual void visit(KisExternalLayer *layer, KisUndoAdapter *undoAdapter) = 0;
59     virtual void visit(KisGeneratorLayer *layer, KisUndoAdapter *undoAdapter) = 0;
60     virtual void visit(KisCloneLayer *layer, KisUndoAdapter *undoAdapter) = 0;
61     virtual void visit(KisFilterMask *mask, KisUndoAdapter *undoAdapter) = 0;
62     virtual void visit(KisTransformMask *mask, KisUndoAdapter *undoAdapter) = 0;
63     virtual void visit(KisTransparencyMask *mask, KisUndoAdapter *undoAdapter) = 0;
64     virtual void visit(KisColorizeMask *mask, KisUndoAdapter *undoAdapter) = 0;
65     virtual void visit(KisSelectionMask *mask, KisUndoAdapter *undoAdapter) = 0;
66 
67     /**
68      * Create a command that initializes the processing visitor before running
69      * on all the layers. The command is executed sequentially, non-exclusively
70      * on the image by applicator.
71      */
72     virtual KUndo2Command* createInitCommand();
73 
74 public:
75     class KRITAIMAGE_EXPORT ProgressHelper {
76     public:
77         ProgressHelper(const KisNode *node);
78         ~ProgressHelper();
79 
80         KoUpdater* updater() const;
81     private:
82         KoProgressUpdater *m_progressUpdater;
83         mutable QMutex m_progressMutex;
84     };
85 };
86 
87 #endif /* __KIS_PROCESSING_VISITOR_H */
88