1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
/****************************************************************************
**
** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
**
** This file is part of the Edyuk project <http://edyuk.org>
**
** This file may be used under the terms of the GNU General Public License
** version 3 as published by the Free Software Foundation and appearing in the
** file GPL.txt included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#ifndef _QDOCUMENT_COMMAND_H_
#define _QDOCUMENT_COMMAND_H_
#include "qce-config.h"
/*!
\file qdocumentcommand.h
\brief Definition of the QDocumentCommand class
*/
#include "modifiedQObject.h"
#include <QUndoCommand>
#include "qdocument.h"
class QDocumentLine;
class QDocumentLineHandle;
class QDocumentCursorHandle;
class QCE_EXPORT QDocumentCommand : public QUndoCommand
{
public:
enum Command
{
None,
Insert,
Erase,
Replace,
Custom
};
struct TextCommandData
{
QString begin, end;
int lineNumber, startOffset, endOffset;
QList<QDocumentLineHandle*> handles;
};
QDocumentCommand(Command c, QDocument *d, QDocumentCommand *p = 0);
virtual ~QDocumentCommand();
virtual int id() const;
virtual bool mergeWith(const QUndoCommand *command);
virtual void redo();
virtual void undo();
bool isSilent() const;
void setSilent(bool y);
bool keepAnchor() const;
void setKeepAnchor(bool y);
void setTargetCursor(QDocumentCursorHandle *h);
void setRedoOffset(int off);
void setUndoOffset(int off);
virtual QStringList debugRepresentation() const;
protected:
bool m_state, m_first;
QDocument *m_doc;
int m_redoOffset, m_undoOffset;
void markRedone(QDocumentLineHandle *h, bool firstTime);
void markUndone(QDocumentLineHandle *h);
void updateTarget(int l, int offset);
void insertText(int line, int pos, const QString& s);
void removeText(int line, int pos, int length);
void insertLines(int after, const QList<QDocumentLineHandle*>& l);
void removeLines(int after, int n);
void updateCursorsOnInsertion(int line, int column, int prefixLength, int numLines, int suffixLength);
void updateCursorsOnDeletion(int line, int column, int prefixLength, int numLines, int suffixLength);
private:
bool m_silent;
bool m_keepAnchor;
Command m_command;
QDocumentCursorHandle *m_cursor;
};
Q_DECLARE_TYPEINFO(QDocumentCommand::TextCommandData, Q_MOVABLE_TYPE);
class QCE_EXPORT QDocumentInsertCommand : public QDocumentCommand
{
public:
QDocumentInsertCommand( int l, int offset,
const QString& text,
QDocument *doc,
QDocumentCommand *p = 0);
virtual ~QDocumentInsertCommand();
virtual bool mergeWith(const QUndoCommand *command);
virtual void redo();
virtual void undo();
virtual QStringList debugRepresentation() const;
private:
TextCommandData m_data;
};
class QCE_EXPORT QDocumentEraseCommand : public QDocumentCommand
{
public:
QDocumentEraseCommand( int bl, int bo,
int el, int eo,
QDocument *doc,
QDocumentCommand *p = 0);
virtual ~QDocumentEraseCommand();
virtual bool mergeWith(const QUndoCommand *command);
virtual void redo();
virtual void undo();
virtual QStringList debugRepresentation() const;
private:
TextCommandData m_data;
bool m_mergedLines;
};
class QCE_EXPORT QDocumentCommandBlock : public QDocumentCommand
{
public:
QDocumentCommandBlock(QDocument *d);
virtual ~QDocumentCommandBlock();
virtual void redo();
virtual void undo();
void setWeakLock(bool l);
bool isWeakLocked() const;
virtual void addCommand(QDocumentCommand *c);
virtual void removeCommand(QDocumentCommand *c);
virtual QStringList debugRepresentation() const;
private:
bool m_weakLocked;
QList<QDocumentCommand*> m_commands;
};
class QCE_EXPORT QDocumentChangeMetaDataCommand: public QDocumentCommand{
public:
QDocumentChangeMetaDataCommand(QDocument *d, QTextCodec* newCodec);
QDocumentChangeMetaDataCommand(QDocument *d, QDocument::LineEnding newLineEnding);
virtual void redo();
virtual void undo();
virtual QStringList debugRepresentation() const;
private:
void init(QTextCodec* newCodec, QDocument::LineEnding newLineEnding);
QTextCodec *newCodec, *oldCodec;
QDocument::LineEnding newLineEnding, oldLineEnding;
};
#endif
|