Changeset View
Changeset View
Standalone View
Standalone View
commands/tools/selection/text/kpToolTextDeleteCommand.cpp
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | |||||
54 | } | 54 | } | ||
55 | 55 | | |||
56 | 56 | | |||
57 | // public | 57 | // public | ||
58 | void kpToolTextDeleteCommand::addDelete () | 58 | void kpToolTextDeleteCommand::addDelete () | ||
59 | { | 59 | { | ||
60 | QList <QString> textLines = textSelection ()->textLines (); | 60 | QList <QString> textLines = textSelection ()->textLines (); | ||
61 | 61 | | |||
62 | if (m_col < (int) textLines [m_row].length ()) | 62 | if (m_col < static_cast<int> (textLines [m_row].length ())) | ||
63 | { | 63 | { | ||
64 | m_deletedText.prepend (textLines [m_row][m_col]); | 64 | m_deletedText.prepend (textLines [m_row][m_col]); | ||
65 | 65 | | |||
66 | textLines [m_row] = textLines [m_row].left (m_col) + | 66 | textLines [m_row] = textLines [m_row].left (m_col) + | ||
67 | textLines [m_row].mid (m_col + 1); | 67 | textLines [m_row].mid (m_col + 1); | ||
68 | } | 68 | } | ||
69 | else | 69 | else | ||
70 | { | 70 | { | ||
71 | if (m_row < (int) textLines.size () - 1) | 71 | if (m_row < static_cast<int> (textLines.size () - 1)) | ||
72 | { | 72 | { | ||
73 | m_deletedText.prepend ('\n'); | 73 | m_deletedText.prepend ('\n'); | ||
74 | 74 | | |||
75 | textLines [m_row] += textLines [m_row + 1]; | 75 | textLines [m_row] += textLines [m_row + 1]; | ||
76 | textLines.erase (textLines.begin () + m_row + 1); | 76 | textLines.erase (textLines.begin () + m_row + 1); | ||
77 | } | 77 | } | ||
78 | } | 78 | } | ||
79 | 79 | | |||
80 | textSelection ()->setTextLines (textLines); | 80 | textSelection ()->setTextLines (textLines); | ||
81 | 81 | | |||
82 | viewManager ()->setTextCursorPosition (m_row, m_col); | 82 | viewManager ()->setTextCursorPosition (m_row, m_col); | ||
83 | 83 | | |||
84 | m_numDeletes++; | 84 | m_numDeletes++; | ||
85 | } | 85 | } | ||
86 | 86 | | |||
87 | 87 | | |||
88 | // public virtual [base kpCommand] | 88 | // public virtual [base kpCommand] | ||
89 | kpCommandSize::SizeType kpToolTextDeleteCommand::size () const | 89 | kpCommandSize::SizeType kpToolTextDeleteCommand::size () const | ||
90 | { | 90 | { | ||
91 | return (kpCommandSize::SizeType) m_deletedText.length () * sizeof (QChar); | 91 | return static_cast<kpCommandSize::SizeType> | ||
92 | (static_cast<unsigned int> (m_deletedText.length ()) * sizeof (QChar)); | ||||
92 | } | 93 | } | ||
93 | 94 | | |||
94 | 95 | | |||
95 | // public virtual [base kpCommand] | 96 | // public virtual [base kpCommand] | ||
96 | void kpToolTextDeleteCommand::execute () | 97 | void kpToolTextDeleteCommand::execute () | ||
97 | { | 98 | { | ||
98 | viewManager ()->setTextCursorPosition (m_row, m_col); | 99 | viewManager ()->setTextCursorPosition (m_row, m_col); | ||
99 | 100 | | |||
100 | m_deletedText.clear (); | 101 | m_deletedText.clear (); | ||
101 | int oldNumDeletes = m_numDeletes; | 102 | int oldNumDeletes = m_numDeletes; | ||
102 | m_numDeletes = 0; | 103 | m_numDeletes = 0; | ||
103 | 104 | | |||
104 | for (int i = 0; i < oldNumDeletes; i++) | 105 | for (int i = 0; i < oldNumDeletes; i++) | ||
105 | addDelete (); | 106 | addDelete (); | ||
106 | } | 107 | } | ||
107 | 108 | | |||
108 | // public virtual [base kpCommand] | 109 | // public virtual [base kpCommand] | ||
109 | void kpToolTextDeleteCommand::unexecute () | 110 | void kpToolTextDeleteCommand::unexecute () | ||
110 | { | 111 | { | ||
111 | viewManager ()->setTextCursorPosition (m_row, m_col); | 112 | viewManager ()->setTextCursorPosition (m_row, m_col); | ||
112 | 113 | | |||
113 | QList <QString> textLines = textSelection ()->textLines (); | 114 | QList <QString> textLines = textSelection ()->textLines (); | ||
114 | 115 | | |||
115 | for (int i = 0; i < (int) m_deletedText.length (); i++) | 116 | for (int i = 0; i < static_cast<int> (m_deletedText.length ()); i++) | ||
116 | { | 117 | { | ||
117 | if (m_deletedText [i] == '\n') | 118 | if (m_deletedText [i] == '\n') | ||
118 | { | 119 | { | ||
119 | const QString rightHalf = textLines [m_row].mid (m_col); | 120 | const QString rightHalf = textLines [m_row].mid (m_col); | ||
120 | 121 | | |||
121 | textLines [m_row].truncate (m_col); | 122 | textLines [m_row].truncate (m_col); | ||
122 | textLines.insert (textLines.begin () + m_row + 1, rightHalf); | 123 | textLines.insert (textLines.begin () + m_row + 1, rightHalf); | ||
123 | } | 124 | } | ||
Show All 16 Lines |