1 /****************************************************************************
2 
3  Copyright (C) 2002-2014 Gilles Debunne. All rights reserved.
4 
5  This file is part of the QGLViewer library version 2.7.2.
6 
7  http://www.libqglviewer.com - contact@libqglviewer.com
8 
9  This file may be used under the terms of the GNU General Public License
10  versions 2.0 or 3.0 as published by the Free Software Foundation and
11  appearing in the LICENSE file included in the packaging of this file.
12  In addition, as a special exception, Gilles Debunne gives you certain
13  additional rights, described in the file GPL_EXCEPTION in this package.
14 
15  libQGLViewer uses dual licensing. Commercial/proprietary software must
16  purchase a libQGLViewer Commercial License.
17 
18  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 
21 *****************************************************************************/
22 
23 #include "undo.h"
24 #include <qstring.h>
25 
clear()26 void Undo::clear() {
27   index_ = 0;
28   maxIndex_ = 0;
29   state_.clear();
30 }
31 
addState(const QString & s)32 void Undo::addState(const QString &s) {
33   if (index_ < int(state_.size()))
34     state_[index_] = s;
35   else
36     state_.append(s);
37 
38   index_++;
39   maxIndex_ = index_;
40 }
41 
undoState()42 QString Undo::undoState() {
43   if (index_ > 1) {
44     index_--;
45     return state_[index_ - 1];
46   } else
47     return QString();
48 }
49 
redoState()50 QString Undo::redoState() {
51   if (index_ < maxIndex_) {
52     index_++;
53     return state_[index_ - 1];
54   } else
55     return QString();
56 }
57 
operator <<(std::ostream & out,const Undo & u)58 std::ostream &operator<<(std::ostream &out, const Undo &u) {
59   out << std::endl << u.index_ << ' ' << u.maxIndex_ << std::endl;
60 
61   for (int i = 0; i < u.maxIndex_; ++i)
62 #if QT_VERSION < 0x040000
63     out << u.state_[i].ascii() << std::endl;
64 #else
65     out << u.state_[i].toLatin1().constData() << std::endl;
66 #endif
67 
68   return out;
69 }
70 
operator >>(std::istream & in,Undo & u)71 std::istream &operator>>(std::istream &in, Undo &u) {
72   u.state_.clear();
73   u.index_ = u.maxIndex_ = 0;
74   in >> u.index_ >> u.maxIndex_;
75 
76   char str[10000];
77   for (int i = 0; i < u.maxIndex_; ++i) {
78     in >> str;
79     u.state_.append(str);
80   }
81 
82   return in;
83 }
84