diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2011-05-09 09:41:20 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2011-05-09 09:41:20 (GMT) |
commit | dbc9841033ba0d27048bddaa83dee24673ae2761 (patch) | |
tree | 59651fec2d17c697b66a13c8c77361a8a1036af5 /src | |
parent | f57395a27730cbf464b7f9293bcf058a0a481a98 (diff) | |
parent | 9b784789c75d59b27530bbf1d12676cc44f64f46 (diff) | |
download | Qt-dbc9841033ba0d27048bddaa83dee24673ae2761.zip Qt-dbc9841033ba0d27048bddaa83dee24673ae2761.tar.gz Qt-dbc9841033ba0d27048bddaa83dee24673ae2761.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1:
Allow different text for undo actions and items in QUndoView
Allow using not only prefixes for undo command text
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/util/qundogroup.cpp | 18 | ||||
-rw-r--r-- | src/gui/util/qundostack.cpp | 90 | ||||
-rw-r--r-- | src/gui/util/qundostack.h | 1 | ||||
-rw-r--r-- | src/gui/util/qundostack_p.h | 3 |
4 files changed, 85 insertions, 27 deletions
diff --git a/src/gui/util/qundogroup.cpp b/src/gui/util/qundogroup.cpp index 42cda74..a24ce8d 100644 --- a/src/gui/util/qundogroup.cpp +++ b/src/gui/util/qundogroup.cpp @@ -375,15 +375,18 @@ bool QUndoGroup::isClean() const for undo, if the group is empty or if none of the stacks are active, this action will be disabled. - If \a prefix is empty, the default prefix "Undo" is used. + If \a prefix is empty, the default template "Undo %1" is used instead of prefix. + Before Qt 4.8, the prefix "Undo" was used by default. \sa createRedoAction() canUndo() QUndoCommand::text() */ QAction *QUndoGroup::createUndoAction(QObject *parent, const QString &prefix) const { - QString pref = prefix.isEmpty() ? tr("Undo") : prefix; - QUndoAction *result = new QUndoAction(pref, parent); + QUndoAction *result = new QUndoAction(prefix, parent); + if (prefix.isEmpty()) + result->setTextFormat(tr("Undo %1"), tr("Undo", "Default text for undo action")); + result->setEnabled(canUndo()); result->setPrefixedText(undoText()); connect(this, SIGNAL(canUndoChanged(bool)), @@ -403,15 +406,18 @@ QAction *QUndoGroup::createUndoAction(QObject *parent, const QString &prefix) co for redo, if the group is empty or if none of the stacks are active, this action will be disabled. - If \a prefix is empty, the default prefix "Undo" is used. + If \a prefix is empty, the default template "Redo %1" is used instead of prefix. + Before Qt 4.8, the prefix "Redo" was used by default. \sa createUndoAction() canRedo() QUndoCommand::text() */ QAction *QUndoGroup::createRedoAction(QObject *parent, const QString &prefix) const { - QString pref = prefix.isEmpty() ? tr("Redo") : prefix; - QUndoAction *result = new QUndoAction(pref, parent); + QUndoAction *result = new QUndoAction(prefix, parent); + if (prefix.isEmpty()) + result->setTextFormat(tr("Redo %1"), tr("Redo", "Default text for redo action")); + result->setEnabled(canRedo()); result->setPrefixedText(redoText()); connect(this, SIGNAL(canRedoChanged(bool)), diff --git a/src/gui/util/qundostack.cpp b/src/gui/util/qundostack.cpp index 6b038ee..1dfab5d 100644 --- a/src/gui/util/qundostack.cpp +++ b/src/gui/util/qundostack.cpp @@ -114,7 +114,7 @@ QUndoCommand::QUndoCommand(const QString &text, QUndoCommand *parent) d = new QUndoCommandPrivate; if (parent != 0) parent->d->child_list.append(this); - d->text = text; + setText(text); } /*! @@ -230,10 +230,9 @@ void QUndoCommand::undo() Returns a short text string describing what this command does; for example, "insert text". - The text is used when the text properties of the stack's undo and redo - actions are updated. + The text is used for names of items in QUndoView. - \sa setText(), QUndoStack::createUndoAction(), QUndoStack::createRedoAction() + \sa actionText(), setText(), QUndoStack::createUndoAction(), QUndoStack::createRedoAction() */ QString QUndoCommand::text() const @@ -242,17 +241,47 @@ QString QUndoCommand::text() const } /*! + \since 4.8 + + Returns a short text string describing what this command does; for example, + "insert text". + + The text is used when the text properties of the stack's undo and redo + actions are updated. + + \sa text(), setText(), QUndoStack::createUndoAction(), QUndoStack::createRedoAction() +*/ + +QString QUndoCommand::actionText() const +{ + return d->actionText; +} + +/*! Sets the command's text to be the \a text specified. The specified text should be a short user-readable string describing what this command does. - \sa text() QUndoStack::createUndoAction() QUndoStack::createRedoAction() + If you need to have two different strings for text() and actionText(), separate + them with "\n" and pass into this function. Even if you do not use this feature + for English strings during development, you can still let translators use two + different strings in order to match specific languages' needs. + The described feature and the function actionText() are available since Qt 4.8. + + \sa text() actionText() QUndoStack::createUndoAction() QUndoStack::createRedoAction() */ void QUndoCommand::setText(const QString &text) { - d->text = text; + int cdpos = text.indexOf(QLatin1Char('\n')); + if (cdpos > 0) { + d->text = text.left(cdpos); + d->actionText = text.mid(cdpos + 1); + } else { + d->text = text; + d->actionText = text; + } } /*! @@ -374,11 +403,24 @@ QUndoAction::QUndoAction(const QString &prefix, QObject *parent) void QUndoAction::setPrefixedText(const QString &text) { - QString s = m_prefix; - if (!m_prefix.isEmpty() && !text.isEmpty()) - s.append(QLatin1Char(' ')); - s.append(text); - setText(s); + if (m_defaultText.isEmpty()) { + QString s = m_prefix; + if (!m_prefix.isEmpty() && !text.isEmpty()) + s.append(QLatin1Char(' ')); + s.append(text); + setText(s); + } else { + if (text.isEmpty()) + setText(m_defaultText); + else + setText(m_prefix.arg(text)); + } +} + +void QUndoAction::setTextFormat(const QString &textFormat, const QString &defaultText) +{ + m_prefix = textFormat; + m_defaultText = defaultText; } #endif // QT_NO_ACTION @@ -783,7 +825,7 @@ bool QUndoStack::canRedo() const /*! Returns the text of the command which will be undone in the next call to undo(). - \sa QUndoCommand::text() redoText() + \sa QUndoCommand::actionText() redoText() */ QString QUndoStack::undoText() const @@ -792,14 +834,14 @@ QString QUndoStack::undoText() const if (!d->macro_stack.isEmpty()) return QString(); if (d->index > 0) - return d->command_list.at(d->index - 1)->text(); + return d->command_list.at(d->index - 1)->actionText(); return QString(); } /*! Returns the text of the command which will be redone in the next call to redo(). - \sa QUndoCommand::text() undoText() + \sa QUndoCommand::actionText() undoText() */ QString QUndoStack::redoText() const @@ -808,7 +850,7 @@ QString QUndoStack::redoText() const if (!d->macro_stack.isEmpty()) return QString(); if (d->index < d->command_list.size()) - return d->command_list.at(d->index)->text(); + return d->command_list.at(d->index)->actionText(); return QString(); } @@ -822,15 +864,18 @@ QString QUndoStack::redoText() const prefixed by the specified \a prefix. If there is no command available for undo, this action will be disabled. - If \a prefix is empty, the default prefix "Undo" is used. + If \a prefix is empty, the default template "Undo %1" is used instead of prefix. + Before Qt 4.8, the prefix "Undo" was used by default. \sa createRedoAction(), canUndo(), QUndoCommand::text() */ QAction *QUndoStack::createUndoAction(QObject *parent, const QString &prefix) const { - QString pref = prefix.isEmpty() ? tr("Undo") : prefix; - QUndoAction *result = new QUndoAction(pref, parent); + QUndoAction *result = new QUndoAction(prefix, parent); + if (prefix.isEmpty()) + result->setTextFormat(tr("Undo %1"), tr("Undo", "Default text for undo action")); + result->setEnabled(canUndo()); result->setPrefixedText(undoText()); connect(this, SIGNAL(canUndoChanged(bool)), @@ -849,15 +894,18 @@ QAction *QUndoStack::createUndoAction(QObject *parent, const QString &prefix) co prefixed by the specified \a prefix. If there is no command available for redo, this action will be disabled. - If \a prefix is empty, the default prefix "Redo" is used. + If \a prefix is empty, the default template "Redo %1" is used instead of prefix. + Before Qt 4.8, the prefix "Redo" was used by default. \sa createUndoAction(), canRedo(), QUndoCommand::text() */ QAction *QUndoStack::createRedoAction(QObject *parent, const QString &prefix) const { - QString pref = prefix.isEmpty() ? tr("Redo") : prefix; - QUndoAction *result = new QUndoAction(pref, parent); + QUndoAction *result = new QUndoAction(prefix, parent); + if (prefix.isEmpty()) + result->setTextFormat(tr("Redo %1"), tr("Redo", "Default text for redo action")); + result->setEnabled(canRedo()); result->setPrefixedText(redoText()); connect(this, SIGNAL(canRedoChanged(bool)), diff --git a/src/gui/util/qundostack.h b/src/gui/util/qundostack.h index 65941b5..700996f 100644 --- a/src/gui/util/qundostack.h +++ b/src/gui/util/qundostack.h @@ -70,6 +70,7 @@ public: virtual void redo(); QString text() const; + QString actionText() const; void setText(const QString &text); virtual int id() const; diff --git a/src/gui/util/qundostack_p.h b/src/gui/util/qundostack_p.h index 3c7d0e7..a100763 100644 --- a/src/gui/util/qundostack_p.h +++ b/src/gui/util/qundostack_p.h @@ -70,6 +70,7 @@ public: QUndoCommandPrivate() : id(-1) {} QList<QUndoCommand*> child_list; QString text; + QString actionText; int id; }; @@ -98,10 +99,12 @@ class QUndoAction : public QAction Q_OBJECT public: QUndoAction(const QString &prefix, QObject *parent = 0); + void setTextFormat(const QString &textFormat, const QString &defaultText); public Q_SLOTS: void setPrefixedText(const QString &text); private: QString m_prefix; + QString m_defaultText; }; #endif // QT_NO_ACTION |