labplot  2.8.2
About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.
  Fossies Dox: labplot-2.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

commandtemplates.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : commandtemplates.h
3  Project : LabPlot
4  Description : Undo/Redo command templates
5  --------------------------------------------------------------------
6  Copyright : (C) 2009 Tilman Benkert (thzs@gmx.net)
7  Copyright : (C) 2017 by Alexander Semke (alexander.semke@web.de)
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  * This program is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU General Public License for more details. *
21  * *
22  * You should have received a copy of the GNU General Public License *
23  * along with this program; if not, write to the Free Software *
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
25  * Boston, MA 02110-1301 USA *
26  * *
27  ***************************************************************************/
28 
29 #ifndef COMMANDTEMPLATES_H
30 #define COMMANDTEMPLATES_H
31 
32 #include <QUndoCommand>
33 
34 #include <KLocalizedString>
35 
36 template <class target_class, typename value_type>
37 class StandardSetterCmd : public QUndoCommand {
38 public:
39  StandardSetterCmd(target_class* target, value_type target_class::* field, value_type newValue, const KLocalizedString& description) // use ki18n("%1: ...")
40  : m_target(target), m_field(field), m_otherValue(newValue) {
41  setText(description.subs(m_target->name()).toString());
42  }
43 
44  virtual void initialize() {};
45  virtual void finalize() {};
46 
47  void redo() override {
48  initialize();
49  value_type tmp = *m_target.*m_field;
51  m_otherValue = tmp;
52  finalize();
53  }
54 
55  void undo() override { redo(); }
56 
57 protected:
58  target_class* m_target;
59  value_type target_class::*m_field;
60  value_type m_otherValue;
61 };
62 
63 template <class target_class, typename value_type>
64 class StandardMacroSetterCmd : public QUndoCommand {
65 public:
66  StandardMacroSetterCmd(target_class* target, value_type target_class::*field, value_type newValue, const KLocalizedString& description) // use ki18n("%1: ...")
67  : m_target(target), m_field(field), m_otherValue(newValue) {
68  setText(description.subs(m_target->name()).toString());
69  }
70 
71  virtual void initialize() {};
72  virtual void finalize() {};
73  virtual void finalizeUndo() {};
74 
75  void redo() override {
76  initialize();
77  value_type tmp = *m_target.*m_field;
79  m_otherValue = tmp;
80  finalize();
81  }
82 
83  //call finalizeUndo() at the end where only the signal is emitted
84  //and no actual finalize-method is called that can potentially
85  //cause new entries on the undo-stack
86  void undo() override {
87  initialize();
88  value_type tmp = *m_target.*m_field;
90  m_otherValue = tmp;
91  finalizeUndo();
92  }
93 
94 protected:
95  target_class* m_target;
96  value_type target_class::*m_field;
97  value_type m_otherValue;
98 };
99 
100 template <class target_class, typename value_type>
101 class StandardSwapMethodSetterCmd : public QUndoCommand {
102 public:
103  StandardSwapMethodSetterCmd(target_class* target, value_type (target_class::*method)(value_type), value_type newValue, const KLocalizedString& description) // use ki18n("%1: ...")
104  : m_target(target), m_method(method), m_otherValue(newValue) {
105  setText(description.subs(m_target->name()).toString());
106  }
107 
108  virtual void initialize() {};
109  virtual void finalize() {};
110 
111  void redo() override {
112  initialize();
114  finalize();
115  }
116 
117  void undo() override { redo(); }
118 
119 protected:
120  target_class* m_target;
121  value_type (target_class::*m_method)(value_type);
122  value_type m_otherValue;
123 };
124 
125 #endif
StandardMacroSetterCmd(target_class *target, value_type target_class::*field, value_type newValue, const KLocalizedString &description)
value_type target_class::* m_field
virtual void finalizeUndo()
virtual void initialize()
Template for simple setter undo commands.
virtual void initialize()
void undo() override
StandardSetterCmd(target_class *target, value_type target_class::*field, value_type newValue, const KLocalizedString &description)
value_type m_otherValue
value_type target_class::* m_field
virtual void finalize()
void redo() override
target_class * m_target
Template for setter undo commands which require a function call.
StandardSwapMethodSetterCmd(target_class *target, value_type(target_class::*method)(value_type), value_type newValue, const KLocalizedString &description)
value_type(target_class::* m_method)(value_type)