| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/util/qundostack.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | QUndoCommand::QUndoCommand(const QString &text, QUndoCommand *parent) | - | ||||||||||||||||||
| 6 | { | - | ||||||||||||||||||
| 7 | d = new QUndoCommandPrivate; | - | ||||||||||||||||||
| 8 | if (parent != 0
| 0 | ||||||||||||||||||
| 9 | parent->d->child_list.append(this); never executed: parent->d->child_list.append(this); | 0 | ||||||||||||||||||
| 10 | setText(text); | - | ||||||||||||||||||
| 11 | } never executed: end of block | 0 | ||||||||||||||||||
| 12 | QUndoCommand::QUndoCommand(QUndoCommand *parent) | - | ||||||||||||||||||
| 13 | { | - | ||||||||||||||||||
| 14 | d = new QUndoCommandPrivate; | - | ||||||||||||||||||
| 15 | if (parent != 0
| 0 | ||||||||||||||||||
| 16 | parent->d->child_list.append(this); never executed: parent->d->child_list.append(this); | 0 | ||||||||||||||||||
| 17 | } never executed: end of block | 0 | ||||||||||||||||||
| 18 | - | |||||||||||||||||||
| 19 | - | |||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 | - | |||||||||||||||||||
| 22 | - | |||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | - | |||||||||||||||||||
| 25 | QUndoCommand::~QUndoCommand() | - | ||||||||||||||||||
| 26 | { | - | ||||||||||||||||||
| 27 | qDeleteAll(d->child_list); | - | ||||||||||||||||||
| 28 | delete d; | - | ||||||||||||||||||
| 29 | } never executed: end of block | 0 | ||||||||||||||||||
| 30 | int QUndoCommand::id() const | - | ||||||||||||||||||
| 31 | { | - | ||||||||||||||||||
| 32 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 33 | } | - | ||||||||||||||||||
| 34 | bool QUndoCommand::mergeWith(const QUndoCommand *command) | - | ||||||||||||||||||
| 35 | { | - | ||||||||||||||||||
| 36 | (void)command;; | - | ||||||||||||||||||
| 37 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 38 | } | - | ||||||||||||||||||
| 39 | void QUndoCommand::redo() | - | ||||||||||||||||||
| 40 | { | - | ||||||||||||||||||
| 41 | for (int i = 0; i < d->child_list.size()
| 0 | ||||||||||||||||||
| 42 | d->child_list.at(i)->redo(); never executed: d->child_list.at(i)->redo(); | 0 | ||||||||||||||||||
| 43 | } never executed: end of block | 0 | ||||||||||||||||||
| 44 | void QUndoCommand::undo() | - | ||||||||||||||||||
| 45 | { | - | ||||||||||||||||||
| 46 | for (int i = d->child_list.size() - 1; i >= 0
| 0 | ||||||||||||||||||
| 47 | d->child_list.at(i)->undo(); never executed: d->child_list.at(i)->undo(); | 0 | ||||||||||||||||||
| 48 | } never executed: end of block | 0 | ||||||||||||||||||
| 49 | QString QUndoCommand::text() const | - | ||||||||||||||||||
| 50 | { | - | ||||||||||||||||||
| 51 | return never executed: d->text;return d->text;never executed: return d->text; | 0 | ||||||||||||||||||
| 52 | } | - | ||||||||||||||||||
| 53 | QString QUndoCommand::actionText() const | - | ||||||||||||||||||
| 54 | { | - | ||||||||||||||||||
| 55 | return never executed: d->actionText;return d->actionText;never executed: return d->actionText; | 0 | ||||||||||||||||||
| 56 | } | - | ||||||||||||||||||
| 57 | void QUndoCommand::setText(const QString &text) | - | ||||||||||||||||||
| 58 | { | - | ||||||||||||||||||
| 59 | int cdpos = text.indexOf(QLatin1Char('\n')); | - | ||||||||||||||||||
| 60 | if (cdpos > 0
| 0 | ||||||||||||||||||
| 61 | d->text = text.left(cdpos); | - | ||||||||||||||||||
| 62 | d->actionText = text.mid(cdpos + 1); | - | ||||||||||||||||||
| 63 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 64 | d->text = text; | - | ||||||||||||||||||
| 65 | d->actionText = text; | - | ||||||||||||||||||
| 66 | } never executed: end of block | 0 | ||||||||||||||||||
| 67 | } | - | ||||||||||||||||||
| 68 | int QUndoCommand::childCount() const | - | ||||||||||||||||||
| 69 | { | - | ||||||||||||||||||
| 70 | return never executed: d->child_list.count();return d->child_list.count();never executed: return d->child_list.count(); | 0 | ||||||||||||||||||
| 71 | } | - | ||||||||||||||||||
| 72 | const QUndoCommand *QUndoCommand::child(int index) const | - | ||||||||||||||||||
| 73 | { | - | ||||||||||||||||||
| 74 | if (index < 0
| 0 | ||||||||||||||||||
| 75 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 76 | return never executed: d->child_list.at(index);return d->child_list.at(index);never executed: return d->child_list.at(index); | 0 | ||||||||||||||||||
| 77 | } | - | ||||||||||||||||||
| 78 | QUndoAction::QUndoAction(const QString &prefix, QObject *parent) | - | ||||||||||||||||||
| 79 | : QAction(parent) | - | ||||||||||||||||||
| 80 | { | - | ||||||||||||||||||
| 81 | m_prefix = prefix; | - | ||||||||||||||||||
| 82 | } never executed: end of block | 0 | ||||||||||||||||||
| 83 | - | |||||||||||||||||||
| 84 | void QUndoAction::setPrefixedText(const QString &text) | - | ||||||||||||||||||
| 85 | { | - | ||||||||||||||||||
| 86 | if (m_defaultText.isEmpty()
| 0 | ||||||||||||||||||
| 87 | QString s = m_prefix; | - | ||||||||||||||||||
| 88 | if (!m_prefix.isEmpty()
| 0 | ||||||||||||||||||
| 89 | s.append(QLatin1Char(' ')); never executed: s.append(QLatin1Char(' ')); | 0 | ||||||||||||||||||
| 90 | s.append(text); | - | ||||||||||||||||||
| 91 | setText(s); | - | ||||||||||||||||||
| 92 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 93 | if (text.isEmpty()
| 0 | ||||||||||||||||||
| 94 | setText(m_defaultText); never executed: setText(m_defaultText); | 0 | ||||||||||||||||||
| 95 | else | - | ||||||||||||||||||
| 96 | setText(m_prefix.arg(text)); never executed: setText(m_prefix.arg(text)); | 0 | ||||||||||||||||||
| 97 | } | - | ||||||||||||||||||
| 98 | } | - | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | void QUndoAction::setTextFormat(const QString &textFormat, const QString &defaultText) | - | ||||||||||||||||||
| 101 | { | - | ||||||||||||||||||
| 102 | m_prefix = textFormat; | - | ||||||||||||||||||
| 103 | m_defaultText = defaultText; | - | ||||||||||||||||||
| 104 | } never executed: end of block | 0 | ||||||||||||||||||
| 105 | void QUndoStackPrivate::setIndex(int idx, bool clean) | - | ||||||||||||||||||
| 106 | { | - | ||||||||||||||||||
| 107 | QUndoStack * const q = q_func(); | - | ||||||||||||||||||
| 108 | - | |||||||||||||||||||
| 109 | bool was_clean = index == clean_index; | - | ||||||||||||||||||
| 110 | - | |||||||||||||||||||
| 111 | if (idx != index
| 0 | ||||||||||||||||||
| 112 | index = idx; | - | ||||||||||||||||||
| 113 | q->indexChanged(index); | - | ||||||||||||||||||
| 114 | q->canUndoChanged(q->canUndo()); | - | ||||||||||||||||||
| 115 | q->undoTextChanged(q->undoText()); | - | ||||||||||||||||||
| 116 | q->canRedoChanged(q->canRedo()); | - | ||||||||||||||||||
| 117 | q->redoTextChanged(q->redoText()); | - | ||||||||||||||||||
| 118 | } never executed: end of block | 0 | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | if (clean
| 0 | ||||||||||||||||||
| 121 | clean_index = index; never executed: clean_index = index; | 0 | ||||||||||||||||||
| 122 | - | |||||||||||||||||||
| 123 | bool is_clean = index == clean_index; | - | ||||||||||||||||||
| 124 | if (is_clean != was_clean
| 0 | ||||||||||||||||||
| 125 | q->cleanChanged(is_clean); never executed: q->cleanChanged(is_clean); | 0 | ||||||||||||||||||
| 126 | } never executed: end of block | 0 | ||||||||||||||||||
| 127 | bool QUndoStackPrivate::checkUndoLimit() | - | ||||||||||||||||||
| 128 | { | - | ||||||||||||||||||
| 129 | if (undo_limit <= 0
| 0 | ||||||||||||||||||
| 130 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | int del_count = command_list.count() - undo_limit; | - | ||||||||||||||||||
| 133 | - | |||||||||||||||||||
| 134 | for (int i = 0; i < del_count
| 0 | ||||||||||||||||||
| 135 | delete command_list.takeFirst(); never executed: delete command_list.takeFirst(); | 0 | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | index -= del_count; | - | ||||||||||||||||||
| 138 | if (clean_index != -1
| 0 | ||||||||||||||||||
| 139 | if (clean_index < del_count
| 0 | ||||||||||||||||||
| 140 | clean_index = -1; never executed: clean_index = -1; | 0 | ||||||||||||||||||
| 141 | else | - | ||||||||||||||||||
| 142 | clean_index -= del_count; never executed: clean_index -= del_count; | 0 | ||||||||||||||||||
| 143 | } | - | ||||||||||||||||||
| 144 | - | |||||||||||||||||||
| 145 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 146 | } | - | ||||||||||||||||||
| 147 | QUndoStack::QUndoStack(QObject *parent) | - | ||||||||||||||||||
| 148 | : QObject(*(new QUndoStackPrivate), parent) | - | ||||||||||||||||||
| 149 | { | - | ||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | if (QUndoGroup *group = qobject_cast<QUndoGroup*>(parent)
| 0 | ||||||||||||||||||
| 152 | group->addStack(this); never executed: group->addStack(this); | 0 | ||||||||||||||||||
| 153 | - | |||||||||||||||||||
| 154 | } never executed: end of block | 0 | ||||||||||||||||||
| 155 | QUndoStack::~QUndoStack() | - | ||||||||||||||||||
| 156 | { | - | ||||||||||||||||||
| 157 | - | |||||||||||||||||||
| 158 | QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 159 | if (d->group != 0
| 0 | ||||||||||||||||||
| 160 | d->group->removeStack(this); never executed: d->group->removeStack(this); | 0 | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | clear(); | - | ||||||||||||||||||
| 163 | } never executed: end of block | 0 | ||||||||||||||||||
| 164 | void QUndoStack::clear() | - | ||||||||||||||||||
| 165 | { | - | ||||||||||||||||||
| 166 | QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | if (d->command_list.isEmpty()
| 0 | ||||||||||||||||||
| 169 | return; never executed: return; | 0 | ||||||||||||||||||
| 170 | - | |||||||||||||||||||
| 171 | bool was_clean = isClean(); | - | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | d->macro_stack.clear(); | - | ||||||||||||||||||
| 174 | qDeleteAll(d->command_list); | - | ||||||||||||||||||
| 175 | d->command_list.clear(); | - | ||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | d->index = 0; | - | ||||||||||||||||||
| 178 | d->clean_index = 0; | - | ||||||||||||||||||
| 179 | - | |||||||||||||||||||
| 180 | indexChanged(0); | - | ||||||||||||||||||
| 181 | canUndoChanged(false); | - | ||||||||||||||||||
| 182 | undoTextChanged(QString()); | - | ||||||||||||||||||
| 183 | canRedoChanged(false); | - | ||||||||||||||||||
| 184 | redoTextChanged(QString()); | - | ||||||||||||||||||
| 185 | - | |||||||||||||||||||
| 186 | if (!was_clean
| 0 | ||||||||||||||||||
| 187 | cleanChanged(true); never executed: cleanChanged(true); | 0 | ||||||||||||||||||
| 188 | } never executed: end of block | 0 | ||||||||||||||||||
| 189 | void QUndoStack::push(QUndoCommand *cmd) | - | ||||||||||||||||||
| 190 | { | - | ||||||||||||||||||
| 191 | QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 192 | cmd->redo(); | - | ||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | bool macro = !d->macro_stack.isEmpty(); | - | ||||||||||||||||||
| 195 | - | |||||||||||||||||||
| 196 | QUndoCommand *cur = 0; | - | ||||||||||||||||||
| 197 | if (macro
| 0 | ||||||||||||||||||
| 198 | QUndoCommand *macro_cmd = d->macro_stack.last(); | - | ||||||||||||||||||
| 199 | if (!macro_cmd->d->child_list.isEmpty()
| 0 | ||||||||||||||||||
| 200 | cur = macro_cmd->d->child_list.last(); never executed: cur = macro_cmd->d->child_list.last(); | 0 | ||||||||||||||||||
| 201 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 202 | if (d->index > 0
| 0 | ||||||||||||||||||
| 203 | cur = d->command_list.at(d->index - 1); never executed: cur = d->command_list.at(d->index - 1); | 0 | ||||||||||||||||||
| 204 | while (d->index < d->command_list.size()
| 0 | ||||||||||||||||||
| 205 | delete d->command_list.takeLast(); never executed: delete d->command_list.takeLast(); | 0 | ||||||||||||||||||
| 206 | if (d->clean_index > d->index
| 0 | ||||||||||||||||||
| 207 | d->clean_index = -1; never executed: d->clean_index = -1; | 0 | ||||||||||||||||||
| 208 | } never executed: end of block | 0 | ||||||||||||||||||
| 209 | - | |||||||||||||||||||
| 210 | bool try_merge = cur != 0
| 0 | ||||||||||||||||||
| 211 | && cur->id() != -1
| 0 | ||||||||||||||||||
| 212 | && cur->id() == cmd->id()
| 0 | ||||||||||||||||||
| 213 | && (macro
| 0 | ||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | if (try_merge
| 0 | ||||||||||||||||||
| 216 | delete cmd; | - | ||||||||||||||||||
| 217 | if (!macro
| 0 | ||||||||||||||||||
| 218 | indexChanged(d->index); | - | ||||||||||||||||||
| 219 | canUndoChanged(canUndo()); | - | ||||||||||||||||||
| 220 | undoTextChanged(undoText()); | - | ||||||||||||||||||
| 221 | canRedoChanged(canRedo()); | - | ||||||||||||||||||
| 222 | redoTextChanged(redoText()); | - | ||||||||||||||||||
| 223 | } never executed: end of block | 0 | ||||||||||||||||||
| 224 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 225 | if (macro
| 0 | ||||||||||||||||||
| 226 | d->macro_stack.last()->d->child_list.append(cmd); | - | ||||||||||||||||||
| 227 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 228 | d->command_list.append(cmd); | - | ||||||||||||||||||
| 229 | d->checkUndoLimit(); | - | ||||||||||||||||||
| 230 | d->setIndex(d->index + 1, false); | - | ||||||||||||||||||
| 231 | } never executed: end of block | 0 | ||||||||||||||||||
| 232 | } | - | ||||||||||||||||||
| 233 | } | - | ||||||||||||||||||
| 234 | void QUndoStack::setClean() | - | ||||||||||||||||||
| 235 | { | - | ||||||||||||||||||
| 236 | QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 237 | if (!d->macro_stack.isEmpty()
| 0 | ||||||||||||||||||
| 238 | QMessageLogger(__FILE__, 639, __PRETTY_FUNCTION__).warning("QUndoStack::setClean(): cannot set clean in the middle of a macro"); | - | ||||||||||||||||||
| 239 | return; never executed: return; | 0 | ||||||||||||||||||
| 240 | } | - | ||||||||||||||||||
| 241 | - | |||||||||||||||||||
| 242 | d->setIndex(d->index, true); | - | ||||||||||||||||||
| 243 | } never executed: end of block | 0 | ||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | - | |||||||||||||||||||
| 247 | - | |||||||||||||||||||
| 248 | - | |||||||||||||||||||
| 249 | - | |||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | bool QUndoStack::isClean() const | - | ||||||||||||||||||
| 252 | { | - | ||||||||||||||||||
| 253 | const QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 254 | if (!d->macro_stack.isEmpty()
| 0 | ||||||||||||||||||
| 255 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 256 | return never executed: d->clean_index == d->index;return d->clean_index == d->index;never executed: return d->clean_index == d->index; | 0 | ||||||||||||||||||
| 257 | } | - | ||||||||||||||||||
| 258 | int QUndoStack::cleanIndex() const | - | ||||||||||||||||||
| 259 | { | - | ||||||||||||||||||
| 260 | const QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 261 | return never executed: d->clean_index;return d->clean_index;never executed: return d->clean_index; | 0 | ||||||||||||||||||
| 262 | } | - | ||||||||||||||||||
| 263 | void QUndoStack::undo() | - | ||||||||||||||||||
| 264 | { | - | ||||||||||||||||||
| 265 | QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 266 | if (d->index == 0
| 0 | ||||||||||||||||||
| 267 | return; never executed: return; | 0 | ||||||||||||||||||
| 268 | - | |||||||||||||||||||
| 269 | if (!d->macro_stack.isEmpty()
| 0 | ||||||||||||||||||
| 270 | QMessageLogger(__FILE__, 694, __PRETTY_FUNCTION__).warning("QUndoStack::undo(): cannot undo in the middle of a macro"); | - | ||||||||||||||||||
| 271 | return; never executed: return; | 0 | ||||||||||||||||||
| 272 | } | - | ||||||||||||||||||
| 273 | - | |||||||||||||||||||
| 274 | int idx = d->index - 1; | - | ||||||||||||||||||
| 275 | d->command_list.at(idx)->undo(); | - | ||||||||||||||||||
| 276 | d->setIndex(idx, false); | - | ||||||||||||||||||
| 277 | } never executed: end of block | 0 | ||||||||||||||||||
| 278 | void QUndoStack::redo() | - | ||||||||||||||||||
| 279 | { | - | ||||||||||||||||||
| 280 | QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 281 | if (d->index == d->command_list.size()
| 0 | ||||||||||||||||||
| 282 | return; never executed: return; | 0 | ||||||||||||||||||
| 283 | - | |||||||||||||||||||
| 284 | if (!d->macro_stack.isEmpty()
| 0 | ||||||||||||||||||
| 285 | QMessageLogger(__FILE__, 720, __PRETTY_FUNCTION__).warning("QUndoStack::redo(): cannot redo in the middle of a macro"); | - | ||||||||||||||||||
| 286 | return; never executed: return; | 0 | ||||||||||||||||||
| 287 | } | - | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | d->command_list.at(d->index)->redo(); | - | ||||||||||||||||||
| 290 | d->setIndex(d->index + 1, false); | - | ||||||||||||||||||
| 291 | } never executed: end of block | 0 | ||||||||||||||||||
| 292 | int QUndoStack::count() const | - | ||||||||||||||||||
| 293 | { | - | ||||||||||||||||||
| 294 | const QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 295 | return never executed: d->command_list.size();return d->command_list.size();never executed: return d->command_list.size(); | 0 | ||||||||||||||||||
| 296 | } | - | ||||||||||||||||||
| 297 | int QUndoStack::index() const | - | ||||||||||||||||||
| 298 | { | - | ||||||||||||||||||
| 299 | const QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 300 | return never executed: d->index;return d->index;never executed: return d->index; | 0 | ||||||||||||||||||
| 301 | } | - | ||||||||||||||||||
| 302 | void QUndoStack::setIndex(int idx) | - | ||||||||||||||||||
| 303 | { | - | ||||||||||||||||||
| 304 | QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 305 | if (!d->macro_stack.isEmpty()
| 0 | ||||||||||||||||||
| 306 | QMessageLogger(__FILE__, 767, __PRETTY_FUNCTION__).warning("QUndoStack::setIndex(): cannot set index in the middle of a macro"); | - | ||||||||||||||||||
| 307 | return; never executed: return; | 0 | ||||||||||||||||||
| 308 | } | - | ||||||||||||||||||
| 309 | - | |||||||||||||||||||
| 310 | if (idx < 0
| 0 | ||||||||||||||||||
| 311 | idx = 0; never executed: idx = 0; | 0 | ||||||||||||||||||
| 312 | else if (idx > d->command_list.size()
| 0 | ||||||||||||||||||
| 313 | idx = d->command_list.size(); never executed: idx = d->command_list.size(); | 0 | ||||||||||||||||||
| 314 | - | |||||||||||||||||||
| 315 | int i = d->index; | - | ||||||||||||||||||
| 316 | while (i < idx
| 0 | ||||||||||||||||||
| 317 | d->command_list.at(i++)->redo(); never executed: d->command_list.at(i++)->redo(); | 0 | ||||||||||||||||||
| 318 | while (i > idx
| 0 | ||||||||||||||||||
| 319 | d->command_list.at(--i)->undo(); never executed: d->command_list.at(--i)->undo(); | 0 | ||||||||||||||||||
| 320 | - | |||||||||||||||||||
| 321 | d->setIndex(idx, false); | - | ||||||||||||||||||
| 322 | } never executed: end of block | 0 | ||||||||||||||||||
| 323 | bool QUndoStack::canUndo() const | - | ||||||||||||||||||
| 324 | { | - | ||||||||||||||||||
| 325 | const QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 326 | if (!d->macro_stack.isEmpty()
| 0 | ||||||||||||||||||
| 327 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 328 | return never executed: d->index > 0;return d->index > 0;never executed: return d->index > 0; | 0 | ||||||||||||||||||
| 329 | } | - | ||||||||||||||||||
| 330 | bool QUndoStack::canRedo() const | - | ||||||||||||||||||
| 331 | { | - | ||||||||||||||||||
| 332 | const QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 333 | if (!d->macro_stack.isEmpty()
| 0 | ||||||||||||||||||
| 334 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 335 | return never executed: d->index < d->command_list.size();return d->index < d->command_list.size();never executed: return d->index < d->command_list.size(); | 0 | ||||||||||||||||||
| 336 | } | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | - | |||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | - | |||||||||||||||||||
| 341 | - | |||||||||||||||||||
| 342 | - | |||||||||||||||||||
| 343 | - | |||||||||||||||||||
| 344 | QString QUndoStack::undoText() const | - | ||||||||||||||||||
| 345 | { | - | ||||||||||||||||||
| 346 | const QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 347 | if (!d->macro_stack.isEmpty()
| 0 | ||||||||||||||||||
| 348 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 349 | if (d->index > 0
| 0 | ||||||||||||||||||
| 350 | return never executed: d->command_list.at(d->index - 1)->actionText();return d->command_list.at(d->index - 1)->actionText();never executed: return d->command_list.at(d->index - 1)->actionText(); | 0 | ||||||||||||||||||
| 351 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 352 | } | - | ||||||||||||||||||
| 353 | - | |||||||||||||||||||
| 354 | - | |||||||||||||||||||
| 355 | - | |||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | - | |||||||||||||||||||
| 358 | - | |||||||||||||||||||
| 359 | - | |||||||||||||||||||
| 360 | QString QUndoStack::redoText() const | - | ||||||||||||||||||
| 361 | { | - | ||||||||||||||||||
| 362 | const QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 363 | if (!d->macro_stack.isEmpty()
| 0 | ||||||||||||||||||
| 364 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 365 | if (d->index < d->command_list.size()
| 0 | ||||||||||||||||||
| 366 | return never executed: d->command_list.at(d->index)->actionText();return d->command_list.at(d->index)->actionText();never executed: return d->command_list.at(d->index)->actionText(); | 0 | ||||||||||||||||||
| 367 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 368 | } | - | ||||||||||||||||||
| 369 | QAction *QUndoStack::createUndoAction(QObject *parent, const QString &prefix) const | - | ||||||||||||||||||
| 370 | { | - | ||||||||||||||||||
| 371 | QUndoAction *result = new QUndoAction(prefix, parent); | - | ||||||||||||||||||
| 372 | if (prefix.isEmpty()
| 0 | ||||||||||||||||||
| 373 | result->setTextFormat(tr("Undo %1"), tr("Undo", "Default text for undo action")); never executed: result->setTextFormat(tr("Undo %1"), tr("Undo", "Default text for undo action")); | 0 | ||||||||||||||||||
| 374 | - | |||||||||||||||||||
| 375 | result->setEnabled(canUndo()); | - | ||||||||||||||||||
| 376 | result->setPrefixedText(undoText()); | - | ||||||||||||||||||
| 377 | connect(this, qFlagLocation("2""canUndoChanged(bool)" "\0" __FILE__ ":" "879"), | - | ||||||||||||||||||
| 378 | result, qFlagLocation("1""setEnabled(bool)" "\0" __FILE__ ":" "880")); | - | ||||||||||||||||||
| 379 | connect(this, qFlagLocation("2""undoTextChanged(QString)" "\0" __FILE__ ":" "881"), | - | ||||||||||||||||||
| 380 | result, qFlagLocation("1""setPrefixedText(QString)" "\0" __FILE__ ":" "882")); | - | ||||||||||||||||||
| 381 | connect(result, qFlagLocation("2""triggered()" "\0" __FILE__ ":" "883"), this, qFlagLocation("1""undo()" "\0" __FILE__ ":" "883")); | - | ||||||||||||||||||
| 382 | return never executed: result;return result;never executed: return result; | 0 | ||||||||||||||||||
| 383 | } | - | ||||||||||||||||||
| 384 | QAction *QUndoStack::createRedoAction(QObject *parent, const QString &prefix) const | - | ||||||||||||||||||
| 385 | { | - | ||||||||||||||||||
| 386 | QUndoAction *result = new QUndoAction(prefix, parent); | - | ||||||||||||||||||
| 387 | if (prefix.isEmpty()
| 0 | ||||||||||||||||||
| 388 | result->setTextFormat(tr("Redo %1"), tr("Redo", "Default text for redo action")); never executed: result->setTextFormat(tr("Redo %1"), tr("Redo", "Default text for redo action")); | 0 | ||||||||||||||||||
| 389 | - | |||||||||||||||||||
| 390 | result->setEnabled(canRedo()); | - | ||||||||||||||||||
| 391 | result->setPrefixedText(redoText()); | - | ||||||||||||||||||
| 392 | connect(this, qFlagLocation("2""canRedoChanged(bool)" "\0" __FILE__ ":" "909"), | - | ||||||||||||||||||
| 393 | result, qFlagLocation("1""setEnabled(bool)" "\0" __FILE__ ":" "910")); | - | ||||||||||||||||||
| 394 | connect(this, qFlagLocation("2""redoTextChanged(QString)" "\0" __FILE__ ":" "911"), | - | ||||||||||||||||||
| 395 | result, qFlagLocation("1""setPrefixedText(QString)" "\0" __FILE__ ":" "912")); | - | ||||||||||||||||||
| 396 | connect(result, qFlagLocation("2""triggered()" "\0" __FILE__ ":" "913"), this, qFlagLocation("1""redo()" "\0" __FILE__ ":" "913")); | - | ||||||||||||||||||
| 397 | return never executed: result;return result;never executed: return result; | 0 | ||||||||||||||||||
| 398 | } | - | ||||||||||||||||||
| 399 | void QUndoStack::beginMacro(const QString &text) | - | ||||||||||||||||||
| 400 | { | - | ||||||||||||||||||
| 401 | QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 402 | QUndoCommand *cmd = new QUndoCommand(); | - | ||||||||||||||||||
| 403 | cmd->setText(text); | - | ||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | if (d->macro_stack.isEmpty()
| 0 | ||||||||||||||||||
| 406 | while (d->index < d->command_list.size()
| 0 | ||||||||||||||||||
| 407 | delete d->command_list.takeLast(); never executed: delete d->command_list.takeLast(); | 0 | ||||||||||||||||||
| 408 | if (d->clean_index > d->index
| 0 | ||||||||||||||||||
| 409 | d->clean_index = -1; never executed: d->clean_index = -1; | 0 | ||||||||||||||||||
| 410 | d->command_list.append(cmd); | - | ||||||||||||||||||
| 411 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 412 | d->macro_stack.last()->d->child_list.append(cmd); | - | ||||||||||||||||||
| 413 | } never executed: end of block | 0 | ||||||||||||||||||
| 414 | d->macro_stack.append(cmd); | - | ||||||||||||||||||
| 415 | - | |||||||||||||||||||
| 416 | if (d->macro_stack.count() == 1
| 0 | ||||||||||||||||||
| 417 | canUndoChanged(false); | - | ||||||||||||||||||
| 418 | undoTextChanged(QString()); | - | ||||||||||||||||||
| 419 | canRedoChanged(false); | - | ||||||||||||||||||
| 420 | redoTextChanged(QString()); | - | ||||||||||||||||||
| 421 | } never executed: end of block | 0 | ||||||||||||||||||
| 422 | } never executed: end of block | 0 | ||||||||||||||||||
| 423 | void QUndoStack::endMacro() | - | ||||||||||||||||||
| 424 | { | - | ||||||||||||||||||
| 425 | QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 426 | if (d->macro_stack.isEmpty()
| 0 | ||||||||||||||||||
| 427 | QMessageLogger(__FILE__, 987, __PRETTY_FUNCTION__).warning("QUndoStack::endMacro(): no matching beginMacro()"); | - | ||||||||||||||||||
| 428 | return; never executed: return; | 0 | ||||||||||||||||||
| 429 | } | - | ||||||||||||||||||
| 430 | - | |||||||||||||||||||
| 431 | d->macro_stack.removeLast(); | - | ||||||||||||||||||
| 432 | - | |||||||||||||||||||
| 433 | if (d->macro_stack.isEmpty()
| 0 | ||||||||||||||||||
| 434 | d->checkUndoLimit(); | - | ||||||||||||||||||
| 435 | d->setIndex(d->index + 1, false); | - | ||||||||||||||||||
| 436 | } never executed: end of block | 0 | ||||||||||||||||||
| 437 | } never executed: end of block | 0 | ||||||||||||||||||
| 438 | const QUndoCommand *QUndoStack::command(int index) const | - | ||||||||||||||||||
| 439 | { | - | ||||||||||||||||||
| 440 | const QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 441 | - | |||||||||||||||||||
| 442 | if (index < 0
| 0 | ||||||||||||||||||
| 443 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 444 | return never executed: d->command_list.at(index);return d->command_list.at(index);never executed: return d->command_list.at(index); | 0 | ||||||||||||||||||
| 445 | } | - | ||||||||||||||||||
| 446 | - | |||||||||||||||||||
| 447 | - | |||||||||||||||||||
| 448 | - | |||||||||||||||||||
| 449 | - | |||||||||||||||||||
| 450 | - | |||||||||||||||||||
| 451 | - | |||||||||||||||||||
| 452 | - | |||||||||||||||||||
| 453 | QString QUndoStack::text(int idx) const | - | ||||||||||||||||||
| 454 | { | - | ||||||||||||||||||
| 455 | const QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 456 | - | |||||||||||||||||||
| 457 | if (idx < 0
| 0 | ||||||||||||||||||
| 458 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 459 | return never executed: d->command_list.at(idx)->text();return d->command_list.at(idx)->text();never executed: return d->command_list.at(idx)->text(); | 0 | ||||||||||||||||||
| 460 | } | - | ||||||||||||||||||
| 461 | void QUndoStack::setUndoLimit(int limit) | - | ||||||||||||||||||
| 462 | { | - | ||||||||||||||||||
| 463 | QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 464 | - | |||||||||||||||||||
| 465 | if (!d->command_list.isEmpty()
| 0 | ||||||||||||||||||
| 466 | QMessageLogger(__FILE__, 1055, __PRETTY_FUNCTION__).warning("QUndoStack::setUndoLimit(): an undo limit can only be set when the stack is empty"); | - | ||||||||||||||||||
| 467 | return; never executed: return; | 0 | ||||||||||||||||||
| 468 | } | - | ||||||||||||||||||
| 469 | - | |||||||||||||||||||
| 470 | if (limit == d->undo_limit
| 0 | ||||||||||||||||||
| 471 | return; never executed: return; | 0 | ||||||||||||||||||
| 472 | d->undo_limit = limit; | - | ||||||||||||||||||
| 473 | d->checkUndoLimit(); | - | ||||||||||||||||||
| 474 | } never executed: end of block | 0 | ||||||||||||||||||
| 475 | - | |||||||||||||||||||
| 476 | int QUndoStack::undoLimit() const | - | ||||||||||||||||||
| 477 | { | - | ||||||||||||||||||
| 478 | const QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 479 | - | |||||||||||||||||||
| 480 | return never executed: d->undo_limit;return d->undo_limit;never executed: return d->undo_limit; | 0 | ||||||||||||||||||
| 481 | } | - | ||||||||||||||||||
| 482 | void QUndoStack::setActive(bool active) | - | ||||||||||||||||||
| 483 | { | - | ||||||||||||||||||
| 484 | - | |||||||||||||||||||
| 485 | - | |||||||||||||||||||
| 486 | - | |||||||||||||||||||
| 487 | QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 488 | - | |||||||||||||||||||
| 489 | if (d->group != 0
| 0 | ||||||||||||||||||
| 490 | if (active
| 0 | ||||||||||||||||||
| 491 | d->group->setActiveStack(this); never executed: d->group->setActiveStack(this); | 0 | ||||||||||||||||||
| 492 | else if (d->group->activeStack() == this
| 0 | ||||||||||||||||||
| 493 | d->group->setActiveStack(0); never executed: d->group->setActiveStack(0); | 0 | ||||||||||||||||||
| 494 | } never executed: end of block | 0 | ||||||||||||||||||
| 495 | - | |||||||||||||||||||
| 496 | } never executed: end of block | 0 | ||||||||||||||||||
| 497 | - | |||||||||||||||||||
| 498 | bool QUndoStack::isActive() const | - | ||||||||||||||||||
| 499 | { | - | ||||||||||||||||||
| 500 | - | |||||||||||||||||||
| 501 | - | |||||||||||||||||||
| 502 | - | |||||||||||||||||||
| 503 | const QUndoStackPrivate * const d = d_func(); | - | ||||||||||||||||||
| 504 | return never executed: d->group == 0return d->group == 0 || d->group->activeStack() == this;
never executed: return d->group == 0 || d->group->activeStack() == this; | 0 | ||||||||||||||||||
| 505 | - | |||||||||||||||||||
| 506 | } | - | ||||||||||||||||||
| 507 | - | |||||||||||||||||||
| 508 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |