summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlexander Potashev <aspotashev@gmail.com>2011-05-09 08:39:18 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2011-05-09 09:07:37 (GMT)
commit9b784789c75d59b27530bbf1d12676cc44f64f46 (patch)
treea62ad80fcea987721381ad8aab9e5d442524946c /tests
parent213c25ad24e4f3b0a44f82f23d34746cd294f8d6 (diff)
downloadQt-9b784789c75d59b27530bbf1d12676cc44f64f46.zip
Qt-9b784789c75d59b27530bbf1d12676cc44f64f46.tar.gz
Qt-9b784789c75d59b27530bbf1d12676cc44f64f46.tar.bz2
Allow different text for undo actions and items in QUndoView
Now the texts used for undo actions and for items in QUndoView can be set separately. This introduces an extended format of text that can be passed to QUndoCommand::setText or QUndoCommand constructor. The action text can now contain two strings separated by a "\n". The first string (that goes before "\n") is then returned by QUndoCommand::text() and used as name of item in QUndoView. The second string (that goes after "\n") is returned by QUndoCommand::actionText() and used when the text properties of the undo and redo actions are updated. If the text passed to QUndoCommand does not contain "\n", everything works as before, and both QUndoCommand::text() and QUndoCommand::actionText() return the same string. Even though action text in English usually does not need different forms for undo actions and QUndoView item, translators can employ this new command text format, for example to adjust the grammatical case used in command text to match the context of "Undo %1"/"Redo %1". Merge-request: 2610 Reviewed-by: ossi
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qundostack/tst_qundostack.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/auto/qundostack/tst_qundostack.cpp b/tests/auto/qundostack/tst_qundostack.cpp
index bcab43d..5aea0a1 100644
--- a/tests/auto/qundostack/tst_qundostack.cpp
+++ b/tests/auto/qundostack/tst_qundostack.cpp
@@ -101,6 +101,16 @@ private:
QString m_text;
};
+class IdleCommand : public QUndoCommand
+{
+public:
+ IdleCommand(QUndoCommand *parent = 0);
+ ~IdleCommand();
+
+ virtual void undo();
+ virtual void redo();
+};
+
InsertCommand::InsertCommand(QString *str, int idx, const QString &text,
QUndoCommand *parent)
: QUndoCommand(parent)
@@ -201,6 +211,26 @@ bool AppendCommand::mergeWith(const QUndoCommand *other)
return true;
}
+IdleCommand::IdleCommand(QUndoCommand *parent)
+ : QUndoCommand(parent)
+{
+ // "idle-item" goes to QUndoStack::{redo,undo}Text
+ // "idle-action" goes to all other places (e.g. QUndoView)
+ setText("idle-item\nidle-action");
+}
+
+IdleCommand::~IdleCommand()
+{
+}
+
+void IdleCommand::redo()
+{
+}
+
+void IdleCommand::undo()
+{
+}
+
/******************************************************************************
** tst_QUndoStack
*/
@@ -221,6 +251,7 @@ private slots:
void compression();
void undoLimit();
void commandTextFormat();
+ void separateUndoText();
};
tst_QUndoStack::tst_QUndoStack()
@@ -2970,6 +3001,34 @@ void tst_QUndoStack::commandTextFormat()
qApp->removeTranslator(&translator);
}
+void tst_QUndoStack::separateUndoText()
+{
+ QUndoStack stack;
+ QAction *undo_action = stack.createUndoAction(0);
+ QAction *redo_action = stack.createRedoAction(0);
+
+ QUndoCommand *command1 = new IdleCommand();
+ QUndoCommand *command2 = new IdleCommand();
+ stack.push(command1);
+ stack.push(command2);
+ stack.undo();
+
+ QCOMPARE(undo_action->text(), QString("Undo idle-action"));
+ QCOMPARE(redo_action->text(), QString("Redo idle-action"));
+ QCOMPARE(command1->actionText(), QString("idle-action"));
+
+ QCOMPARE(command1->text(), QString("idle-item"));
+ QCOMPARE(stack.text(0), QString("idle-item"));
+
+ command1->setText("idle");
+ QCOMPARE(command1->actionText(), QString("idle"));
+ QCOMPARE(command1->text(), QString("idle"));
+
+ command1->setText("idle-item\nidle-action");
+ QCOMPARE(command1->actionText(), QString("idle-action"));
+ QCOMPARE(command1->text(), QString("idle-item"));
+}
+
QTEST_MAIN(tst_QUndoStack)
#include "tst_qundostack.moc"