Krita Source Code Documentation
Loading...
Searching...
No Matches
SvgTextInsertCommand Class Reference

#include <SvgTextInsertCommand.h>

+ Inheritance diagram for SvgTextInsertCommand:

Public Member Functions

int id () const override
 
bool mergeWith (const KUndo2Command *other) override
 
void redo () override
 
 SvgTextInsertCommand (KoSvgTextShape *shape, int pos, int anchor, QString text, KUndo2Command *parent=0)
 
void undo () override
 
 ~SvgTextInsertCommand () override=default
 
- Public Member Functions inherited from KUndo2Command
QString actionText () const
 
virtual bool canAnnihilateWith (const KUndo2Command *other) const
 
const KUndo2Commandchild (int index) const
 
int childCount () const
 
virtual QTime endTime () const
 
KUndo2CommandExtraDataextraData () const
 
bool hasParent () const
 
virtual bool isMerged () const
 
 KUndo2Command (const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 KUndo2Command (KUndo2Command *parent=0)
 
virtual QVector< KUndo2Command * > mergeCommandsVector () const
 
virtual void redoMergedCommands ()
 
void setEndTime ()
 
virtual void setEndTime (const QTime &time)
 
void setExtraData (KUndo2CommandExtraData *data)
 
void setText (const KUndo2MagicString &text)
 
void setTime ()
 
virtual void setTime (const QTime &time)
 
virtual void setTimedID (int timedID)
 
KUndo2MagicString text () const
 
virtual QTime time () const
 
virtual int timedId () const
 
virtual bool timedMergeWith (KUndo2Command *other)
 
virtual void undoMergedCommands ()
 
virtual ~KUndo2Command ()
 

Private Attributes

int m_anchor
 
int m_pos
 
KoSvgTextShapem_shape
 
QString m_text
 
KoSvgTextShapeMementoSP m_textData
 

Detailed Description

Definition at line 13 of file SvgTextInsertCommand.h.

Constructor & Destructor Documentation

◆ SvgTextInsertCommand()

SvgTextInsertCommand::SvgTextInsertCommand ( KoSvgTextShape * shape,
int pos,
int anchor,
QString text,
KUndo2Command * parent = 0 )

Definition at line 13 of file SvgTextInsertCommand.cpp.

14 : KUndo2Command(parent)
15 , m_shape(shape)
16 , m_pos(pos)
17 , m_anchor(anchor)
18 , m_text(text)
19{
20 setText(kundo2_i18n("Insert Text"));
21
22 QRegExp exp;
23 // This replaces...
24 // - carriage return
25 // - linefeed-carriage return
26 // - carriage return-linefeed
27 // - line separator
28 // - paragraph separator
29 // - vertical tab/line tab
30 // with a single linefeed to avoid them from being added to the textShape.
31 exp.setPattern("[\\r|\\r\\n|\\x2029|\\x2028\\x000b]");
32
33#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
34 text.replace(exp, "\n");
35#else
36 exp.replaceIn(text, "\n");
37#endif
38 m_text = text;
39}
void setText(const KUndo2MagicString &text)
KUndo2MagicString text() const
KUndo2Command(KUndo2Command *parent=0)
KUndo2MagicString kundo2_i18n(const char *text)

References kundo2_i18n(), m_text, KUndo2Command::setText(), and KUndo2Command::text().

◆ ~SvgTextInsertCommand()

SvgTextInsertCommand::~SvgTextInsertCommand ( )
overridedefault

Member Function Documentation

◆ id()

int SvgTextInsertCommand::id ( ) const
overridevirtual

Returns the ID of this command.

A command ID is used in command compression. It must be an integer unique to this command's class, or -1 if the command doesn't support compression.

If the command supports compression this function must be overridden in the derived class to return the correct ID. The base implementation returns -1.

KUndo2QStack::push() will only try to merge two commands if they have the same ID, and the ID is not -1.

See also
mergeWith(), KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 64 of file SvgTextInsertCommand.cpp.

References KisCommandUtils::SvgInsertTextCommand.

◆ mergeWith()

bool SvgTextInsertCommand::mergeWith ( const KUndo2Command * command)
overridevirtual

Attempts to merge this command with command. Returns true on success; otherwise returns false.

If this function returns true, calling this command's redo() must have the same effect as redoing both this command and command. Similarly, calling this command's undo() must have the same effect as undoing command and this command.

KUndo2QStack will only try to merge two commands if they have the same id, and the id is not -1.

The default implementation returns false.

See also
id() KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 69 of file SvgTextInsertCommand.cpp.

70{
71 const SvgTextInsertCommand *command = dynamic_cast<const SvgTextInsertCommand*>(other);
72
73
74 if (!command || command->m_shape != m_shape) {
75 return false;
76 }
77 int oldIndex = m_shape->indexForPos(m_pos);
78 int otherOldIndex = m_shape->indexForPos(command->m_pos);
79 if (oldIndex + m_text.size() != otherOldIndex) {
80 return false;
81 }
82
83 m_text += command->m_text;
84 return true;
85}
int indexForPos(int pos) const
indexForPos get the string index for a given cursor position.

References KoSvgTextShape::indexForPos(), m_pos, m_shape, and m_text.

◆ redo()

void SvgTextInsertCommand::redo ( )
overridevirtual

Applies a change to the document. This function must be implemented in the derived class. Calling KUndo2QStack::push(), KUndo2QStack::undo() or KUndo2QStack::redo() from this function leads to undefined behavior.

The default implementation calls redo() on all child commands.

See also
undo()

Reimplemented from KUndo2Command.

Definition at line 41 of file SvgTextInsertCommand.cpp.

42{
43 QRectF updateRect = m_shape->boundingRect();
44 // Index defaults to -1 when there's no text in the shape.
45 int oldIndex = qMax(0, m_shape->indexForPos(m_pos));
46
51
52 int pos = m_shape->posForIndex(oldIndex + m_text.size(), false, false);
54
55}
virtual void updateAbsolute(const QRectF &rect) const
Definition KoShape.cpp:616
void notifyCursorPosChanged(int pos, int anchor)
Notify that the cursor position has changed.
KoSvgTextShapeMementoSP getMemento()
Get a memento holding the current textdata and layout info.
QRectF boundingRect() const override
Get the bounding box of the shape.
void cleanUp()
Cleans up the internal text data. Used by undo commands.
int posForIndex(int index, bool firstIndex=false, bool skipSynthetic=false) const
posForIndex Get the cursor position for a given index in a string.
bool insertText(int pos, QString text)
insertText Insert a text somewhere in the KoTextShape.
KoSvgTextShapeMementoSP m_textData

References KoSvgTextShape::boundingRect(), KoSvgTextShape::cleanUp(), KoSvgTextShape::getMemento(), KoSvgTextShape::indexForPos(), KoSvgTextShape::insertText(), m_pos, m_shape, m_text, m_textData, KoSvgTextShape::notifyCursorPosChanged(), KoSvgTextShape::posForIndex(), and KoShape::updateAbsolute().

◆ undo()

void SvgTextInsertCommand::undo ( )
overridevirtual

Reverts a change to the document. After undo() is called, the state of the document should be the same as before redo() was called. This function must be implemented in the derived class. Calling KUndo2QStack::push(), KUndo2QStack::undo() or KUndo2QStack::redo() from this function leads to undefined behavior.

The default implementation calls undo() on all child commands in reverse order.

See also
redo()

Reimplemented from KUndo2Command.

Definition at line 57 of file SvgTextInsertCommand.cpp.

58{
59 QRectF updateRect = m_shape->boundingRect();
62}
void setMemento(const KoSvgTextShapeMementoSP memento)
Set the text data and layout info, reset listening cursors to 0.

References KoSvgTextShape::boundingRect(), m_anchor, m_pos, m_shape, m_textData, KoSvgTextShape::setMemento(), and KoShape::updateAbsolute().

Member Data Documentation

◆ m_anchor

int SvgTextInsertCommand::m_anchor
private

Definition at line 30 of file SvgTextInsertCommand.h.

◆ m_pos

int SvgTextInsertCommand::m_pos
private

Definition at line 29 of file SvgTextInsertCommand.h.

◆ m_shape

KoSvgTextShape* SvgTextInsertCommand::m_shape
private

Definition at line 27 of file SvgTextInsertCommand.h.

◆ m_text

QString SvgTextInsertCommand::m_text
private

Definition at line 31 of file SvgTextInsertCommand.h.

◆ m_textData

KoSvgTextShapeMementoSP SvgTextInsertCommand::m_textData
private

Definition at line 32 of file SvgTextInsertCommand.h.


The documentation for this class was generated from the following files: