95void QUndoGroup::addStack(QUndoStack *stack)
99 if (d->stack_list.contains(stack))
101 d->stack_list.append(stack);
103 if (QUndoGroup *other = stack->d_func()->group)
104 other->removeStack(stack);
105 stack->d_func()->group =
this;
152void QUndoGroup::setActiveStack(QUndoStack *stack)
155 if (d->active == stack)
158 if (d->active !=
nullptr) {
159 disconnect(d->active, SIGNAL(canUndoChanged(
bool)),
160 this, SIGNAL(canUndoChanged(
bool)));
161 disconnect(d->active, SIGNAL(undoTextChanged(QString)),
162 this, SIGNAL(undoTextChanged(QString)));
163 disconnect(d->active, SIGNAL(canRedoChanged(
bool)),
164 this, SIGNAL(canRedoChanged(
bool)));
165 disconnect(d->active, SIGNAL(redoTextChanged(QString)),
166 this, SIGNAL(redoTextChanged(QString)));
167 disconnect(d->active, SIGNAL(indexChanged(
int)),
168 this, SIGNAL(indexChanged(
int)));
169 disconnect(d->active, SIGNAL(cleanChanged(
bool)),
170 this, SIGNAL(cleanChanged(
bool)));
175 if (d->active ==
nullptr) {
176 emit canUndoChanged(
false);
177 emit undoTextChanged(QString());
178 emit canRedoChanged(
false);
179 emit redoTextChanged(QString());
180 emit cleanChanged(
true);
181 emit indexChanged(0);
183 connect(d->active, SIGNAL(canUndoChanged(
bool)),
184 this, SIGNAL(canUndoChanged(
bool)));
185 connect(d->active, SIGNAL(undoTextChanged(QString)),
186 this, SIGNAL(undoTextChanged(QString)));
187 connect(d->active, SIGNAL(canRedoChanged(
bool)),
188 this, SIGNAL(canRedoChanged(
bool)));
189 connect(d->active, SIGNAL(redoTextChanged(QString)),
190 this, SIGNAL(redoTextChanged(QString)));
191 connect(d->active, SIGNAL(indexChanged(
int)),
192 this, SIGNAL(indexChanged(
int)));
193 connect(d->active, SIGNAL(cleanChanged(
bool)),
194 this, SIGNAL(cleanChanged(
bool)));
195 emit canUndoChanged(d->active->canUndo());
196 emit undoTextChanged(d->active->undoText());
197 emit canRedoChanged(d->active->canRedo());
198 emit redoTextChanged(d->active->redoText());
199 emit cleanChanged(d->active->isClean());
200 emit indexChanged(d->active->index());
203 emit activeStackChanged(d->active);
238QAction *QUndoGroup::createUndoAction(QObject *parent,
const QString &prefix)
const
240 QAction *action =
new QAction(parent);
241 action->setEnabled(canUndo());
243 QString effectivePrefix = prefix;
245 if (prefix.isEmpty()) {
246 effectivePrefix = tr(
"Undo %1");
247 defaultText = tr(
"Undo",
"Default text for undo action");
250 QUndoStackPrivate::setPrefixedText(action, effectivePrefix, defaultText, undoText());
252 connect(
this, &QUndoGroup::canUndoChanged, action, &QAction::setEnabled);
253 connect(
this, &QUndoGroup::undoTextChanged, action, [=](
const QString &text) {
254 QUndoStackPrivate::setPrefixedText(action, effectivePrefix, defaultText, text);
256 connect(action, &QAction::triggered,
this, &QUndoGroup::undo);
276QAction *QUndoGroup::createRedoAction(QObject *parent,
const QString &prefix)
const
278 QAction *action =
new QAction(parent);
279 action->setEnabled(canRedo());
281 QString effectivePrefix = prefix;
283 if (prefix.isEmpty()) {
284 effectivePrefix = tr(
"Redo %1");
285 defaultText = tr(
"Redo",
"Default text for redo action");
288 QUndoStackPrivate::setPrefixedText(action, effectivePrefix, defaultText, redoText());
290 connect(
this, &QUndoGroup::canRedoChanged, action, &QAction::setEnabled);
291 connect(
this, &QUndoGroup::redoTextChanged, action, [=](
const QString &text) {
292 QUndoStackPrivate::setPrefixedText(action, effectivePrefix, defaultText, text);
294 connect(action, &QAction::triggered,
this, &QUndoGroup::redo);