Commit 9e143a4e authored by Dmitry Kazakov's avatar Dmitry Kazakov

Implemented type-safe translations for undo actions

See documentation to a KUndo2MagicString class.

Now KUndo2Command cannot accept a usual string as the operation text().
The supplied text must pass through the kundo2_i18n() function, which
tells the developer to use (qtundo-format) which is mandatory for all the
undo-related strings (because in some languages they should be shown in
different cases in undo/redo action and in undo history, and the
translators should use Magic Split for them).
parent c2e8bf64
#! /bin/sh
$XGETTEXT_QT *.cpp *.h -o $podir/kdgantt.pot
$XGETTEXT -kkundo2_i18nc:1c,2 -kkundo2_i18ncp:1c,2,3 *.cpp *.h -o $podir/kdgantt.pot
......@@ -9,6 +9,5 @@ RCFILES=`find . -name \*.rc \
$EXTRACTRC $RCFILES >> rc.cpp
perl extracti18n.pl > i18ndata
# ignore sdk/templates since it contains templates for use a future plugins, none of the strings there will ever be seen by any user
$XGETTEXT i18ndata rc.cpp `find . -name \*.cc -o -name \*.h -o -name \*.cpp | grep -v '/tests/' | grep -v './sdk/templates'` ui/kis_aboutdata.h -o $podir/krita.pot
$XGETTEXT -kkundo2_i18nc:1c,2 -kkundo2_i18ncp:1c,2,3 -kkundo2_i18nc:1c,2 -kkundo2_i18ncp:1c,2,3 i18ndata rc.cpp `find . -name \*.cc -o -name \*.h -o -name \*.cpp | grep -v '/tests/' | grep -v './sdk/templates'` ui/kis_aboutdata.h -o $podir/krita.pot
rm -f i18ndata
......@@ -166,7 +166,7 @@ void KisFilterSelectionsBenchmark::testUsualSelections(int num)
timer.restart();
for (int i = 0; i < num; i++) {
KisTransaction transac(0, projection, 0);
KisTransaction transac(projection, 0);
m_filter->process(m_device, projection, m_selection, filterRect, m_configuration, 0);
}
avTime = double(timer.elapsed()) / num;
......@@ -189,7 +189,7 @@ void KisFilterSelectionsBenchmark::testNoSelections(int num)
timer.restart();
for (int i = 0; i < num; i++) {
KisTransaction transac(0, projection, 0);
KisTransaction transac(projection, 0);
m_filter->process(m_device, projection, 0, filterRect, m_configuration, 0);
}
avTime = double(timer.elapsed()) / num;
......@@ -244,11 +244,11 @@ void KisFilterSelectionsBenchmark::testBitBltWOSelections(int num)
for (int i = 0; i < num; i++) {
KisPaintDeviceSP cacheDevice = new KisPaintDevice(projection->colorSpace());
KisTransaction transac(0, cacheDevice, 0);
KisTransaction transac(cacheDevice, 0);
m_filter->process(m_device, projection, 0, filterRect, m_configuration, 0);
KisPainter painter(projection);
painter.beginTransaction(0);
painter.beginTransaction();
painter.setCompositeOp(projection->colorSpace()->compositeOp(COMPOSITE_ALPHA_DARKEN));
painter.bitBlt(filterRect.topLeft(), cacheDevice, filterRect);
painter.deleteTransaction();
......@@ -275,11 +275,11 @@ void KisFilterSelectionsBenchmark::testBitBltSelections(int num)
for (int i = 0; i < num; i++) {
KisPaintDeviceSP cacheDevice = new KisPaintDevice(projection->colorSpace());
KisTransaction transac(0, cacheDevice, 0);
KisTransaction transac(cacheDevice, 0);
m_filter->process(m_device, cacheDevice, 0, filterRect, m_configuration, 0);
KisPainter gc(projection);
gc.beginTransaction(0);
gc.beginTransaction();
gc.setCompositeOp(projection->colorSpace()->compositeOp(COMPOSITE_ALPHA_DARKEN));
gc.setSelection(m_selection);
gc.bitBlt(filterRect.topLeft(), cacheDevice, filterRect);
......
......@@ -83,7 +83,7 @@ void KisFloodFillBenchmark::benchmarkFlood()
fillPainter.setPaintColor( fg );
fillPainter.setBackgroundColor( bg );
fillPainter.beginTransaction(i18n("Flood Fill"));
fillPainter.beginTransaction(kundo2_noi18n("Flood Fill"));
//fillPainter.setProgress(updater->startSubtask());
fillPainter.setOpacity(OPACITY_OPAQUE_U8);
......
......@@ -66,7 +66,7 @@ void KisGradientBenchmark::benchmarkGradient()
//setupPainter(&fillPainter);
fillPainter.setGradient(kograd);
fillPainter.beginTransaction(i18n("Gradient Fill"));
fillPainter.beginTransaction(kundo2_noi18n("Gradient Fill"));
//fillPainter.setProgress(updater->startSubtask());
fillPainter.setOpacity(OPACITY_OPAQUE_U8);
......
......@@ -128,7 +128,7 @@ void KisLowMemoryBenchmark::benchmarkWideArea(const QString presetFileName,
QLineF line(rect.topLeft(), rect.topLeft() + QPointF(rect.width(), 0));
if (createTransaction) {
painter->beginTransaction("test transaction");
painter->beginTransaction();
}
KisDistanceInformation currentDistance;
......
#! /bin/sh
$XGETTEXT *.cpp -o $podir/crashhandler.pot
$XGETTEXT -kkundo2_i18nc:1c,2 -kkundo2_i18ncp:1c,2,3 *.cpp -o $podir/crashhandler.pot
......@@ -45,7 +45,7 @@ public:
const QString &filterNameAfter,
const QString &xmlAfter,
bool useGeneratorRegistry)
: KUndo2Command(i18nc("(qtundo-format)", "Change Filter")) {
: KUndo2Command(kundo2_i18n("Change Filter")) {
m_node = node;
m_filterInterface = dynamic_cast<KisNodeFilterInterface*>(node.data());
Q_ASSERT(m_filterInterface);
......
......@@ -27,7 +27,7 @@
#include "kis_pixel_selection.h"
KisDeselectGlobalSelectionCommand::KisDeselectGlobalSelectionCommand(KisImageWSP image, KUndo2Command * parent) :
KUndo2Command(i18nc("(qtundo-format)", "Deselect"), parent)
KUndo2Command(kundo2_i18n("Deselect"), parent)
, m_image(image)
{
}
......
......@@ -24,8 +24,8 @@
#include <klocale.h>
KisImageChangeLayersCommand::KisImageChangeLayersCommand(KisImageWSP image, KisNodeSP oldRootLayer, KisNodeSP newRootLayer, const QString& name)
: KisImageCommand(name, image)
KisImageChangeLayersCommand::KisImageChangeLayersCommand(KisImageWSP image, KisNodeSP oldRootLayer, KisNodeSP newRootLayer)
: KisImageCommand(kundo2_noi18n("change-layer-command"), image)
{
m_oldRootLayer = oldRootLayer;
m_newRootLayer = newRootLayer;
......
......@@ -28,7 +28,7 @@ class KisImageChangeLayersCommand : public KisImageCommand
{
public:
KisImageChangeLayersCommand(KisImageWSP image, KisNodeSP oldRootLayer, KisNodeSP newRootLayer, const QString& name);
KisImageChangeLayersCommand(KisImageWSP image, KisNodeSP oldRootLayer, KisNodeSP newRootLayer);
virtual void redo();
virtual void undo();
......
......@@ -24,7 +24,7 @@
#include "kis_layer.h"
KisImageCommand::KisImageCommand(const QString& name, KisImageWSP image, KUndo2Command *parent)
KisImageCommand::KisImageCommand(const KUndo2MagicString& name, KisImageWSP image, KUndo2Command *parent)
: KUndo2Command(name, parent)
, m_image(image)
{
......
......@@ -39,7 +39,7 @@ public:
* @param name The name that will be shown in the ui
* @param image The image the command will be working on.
*/
KisImageCommand(const QString& name, KisImageWSP image, KUndo2Command *parent = 0);
KisImageCommand(const KUndo2MagicString& name, KisImageWSP image, KUndo2Command *parent = 0);
virtual ~KisImageCommand();
protected:
......
......@@ -29,7 +29,7 @@ KisImageLayerAddCommand::KisImageLayerAddCommand(KisImageWSP image,
KisNodeSP aboveThis,
bool doRedoUpdates,
bool doUndoUpdates)
: KisImageCommand(i18nc("(qtundo-format)", "Add Layer"), image),
: KisImageCommand(kundo2_i18n("Add Layer"), image),
m_index(-1),
m_doRedoUpdates(doRedoUpdates),
m_doUndoUpdates(doUndoUpdates)
......@@ -45,7 +45,7 @@ KisImageLayerAddCommand::KisImageLayerAddCommand(KisImageWSP image,
quint32 index,
bool doRedoUpdates,
bool doUndoUpdates)
: KisImageCommand(i18nc("(qtundo-format)", "Add Layer"), image),
: KisImageCommand(kundo2_i18n("Add Layer"), image),
m_index(index),
m_doRedoUpdates(doRedoUpdates),
m_doUndoUpdates(doUndoUpdates)
......
......@@ -34,7 +34,7 @@
KisImageLayerMoveCommand::KisImageLayerMoveCommand(KisImageWSP image, KisNodeSP layer, KisNodeSP newParent, KisNodeSP newAbove)
: KisImageCommand(i18nc("(qtundo-format)", "Move Layer"), image)
: KisImageCommand(kundo2_i18n("Move Layer"), image)
{
m_layer = layer;
m_newParent = newParent;
......@@ -46,7 +46,7 @@ KisImageLayerMoveCommand::KisImageLayerMoveCommand(KisImageWSP image, KisNodeSP
}
KisImageLayerMoveCommand::KisImageLayerMoveCommand(KisImageWSP image, KisNodeSP node, KisNodeSP newParent, quint32 index)
: KisImageCommand(i18nc("(qtundo-format)", "Move Layer"), image)
: KisImageCommand(kundo2_i18n("Move Layer"), image)
{
m_layer = node;
m_newParent = newParent;
......
......@@ -24,7 +24,7 @@
KisImageLayerRemoveCommand::KisImageLayerRemoveCommand(KisImageWSP image, KisNodeSP node)
: KisImageCommand(i18nc("(qtundo-format)", "Remove Layer"), image),
: KisImageCommand(kundo2_i18n("Remove Layer"), image),
m_node(node)
{
addSubtree(image, node);
......
......@@ -44,7 +44,7 @@ struct KisImageLayerRemoveCommandImpl::Private {
};
KisImageLayerRemoveCommandImpl::KisImageLayerRemoveCommandImpl(KisImageWSP image, KisNodeSP node, KUndo2Command *parent)
: KisImageCommand(i18nc("(qtundo-format)", "Remove Layer"), image, parent),
: KisImageCommand(kundo2_i18n("Remove Layer"), image, parent),
m_d(new Private(this))
{
m_d->node = node;
......
......@@ -24,7 +24,7 @@
KisImageLockCommand::KisImageLockCommand(KisImageWSP image, bool lockImage)
: KisImageCommand("lock image", image) // Not for translation, this is only ever used inside a macro command.
: KisImageCommand(kundo2_noi18n("lock image"), image)
{
Q_UNUSED(lockImage)
}
......
......@@ -25,7 +25,7 @@
#include "kis_undo_adapter.h"
KisImageNodeLowerCommand::KisImageNodeLowerCommand(KisImageWSP image, KisNodeSP node)
: KisImageCommand(i18nc("(qtundo-format)", "Lower"), image), m_node(node)
: KisImageCommand(kundo2_i18n("Lower"), image), m_node(node)
{
}
......
......@@ -25,7 +25,7 @@
#include "kis_undo_adapter.h"
KisImageNodeRaiseCommand::KisImageNodeRaiseCommand(KisImageWSP image, KisNodeSP node)
: KisImageCommand(i18nc("(qtundo-format)", "Raise"), image), m_node(node)
: KisImageCommand(kundo2_i18n("Raise"), image), m_node(node)
{
}
......
......@@ -26,7 +26,7 @@
#include "../kis_image.h"
KisImageNodeToBottomCommand::KisImageNodeToBottomCommand(KisImageWSP image, KisNodeSP node)
: KisImageCommand(i18nc("(qtundo-format)", "Lower"), image), m_node(node)
: KisImageCommand(kundo2_i18n("Lower"), image), m_node(node)
{
m_prevParent = m_node->parent();
m_prevAbove = m_node->prevSibling();
......
......@@ -25,7 +25,7 @@
#include "kis_undo_adapter.h"
KisImageNodeToTopCommand::KisImageNodeToTopCommand(KisImageWSP image, KisNodeSP node)
: KisImageCommand(i18nc("(qtundo-format)", "Lower"), image), m_node(node)
: KisImageCommand(kundo2_i18n("Lower"), image), m_node(node)
{
m_prevParent = m_node->parent();
m_prevAbove = m_node->prevSibling();
......
......@@ -26,7 +26,7 @@
KisImageSetProjectionColorSpaceCommand::KisImageSetProjectionColorSpaceCommand(KisImageWSP image, const KoColorSpace * afterColorSpace)
: KisImageCommand(i18nc("(qtundo-format)", "Convert Image Type"), image)
: KisImageCommand(kundo2_i18n("Convert Image Type"), image)
{
m_beforeColorSpace = image->colorSpace();
m_afterColorSpace = afterColorSpace;
......
......@@ -21,7 +21,7 @@
#include "kis_layer.h"
#include "commands/kis_layer_commands.h"
KisLayerCommand::KisLayerCommand(const QString& name, KisLayerSP layer) :
KisLayerCommand::KisLayerCommand(const KUndo2MagicString& name, KisLayerSP layer) :
KUndo2Command(name), m_layer(layer)
{
}
......
......@@ -35,7 +35,7 @@ public:
* @param name The name that will be shown in the ui
* @param layer The layer the command will be working on.
*/
KisLayerCommand(const QString& name, KisLayerSP layer);
KisLayerCommand(const KUndo2MagicString& name, KisLayerSP layer);
virtual ~KisLayerCommand();
protected:
......
......@@ -39,7 +39,7 @@ KisLayerPropsCommand::KisLayerPropsCommand(KisLayerSP layer,
const QString& oldName, const QString& newName,
const QBitArray oldChannelFlags, const QBitArray newChannelFlags,
bool undoChannelFlags)
: KisLayerCommand(i18nc("(qtundo-format)", "Property Changes"), layer)
: KisLayerCommand(kundo2_i18n("Property Changes"), layer)
, m_oldName(oldName)
, m_newName(newName)
, m_oldOpacity(oldOpacity)
......
......@@ -21,7 +21,7 @@
#include "kis_node.h"
KisNodeCommand::KisNodeCommand(const QString& name, KisNodeSP node)
KisNodeCommand::KisNodeCommand(const KUndo2MagicString& name, KisNodeSP node)
: KUndo2Command(name), m_node(node)
{
}
......
......@@ -35,7 +35,7 @@ public:
* @param name The name that will be shown in the ui
* @param node The node the command will be working on.
*/
KisNodeCommand(const QString& name, KisNodeSP node);
KisNodeCommand(const KUndo2MagicString& name, KisNodeSP node);
virtual ~KisNodeCommand();
protected:
......
......@@ -25,7 +25,7 @@
KisNodeCompositeOpCommand::KisNodeCompositeOpCommand(KisNodeSP node, const QString& oldCompositeOp,
const QString& newCompositeOp) :
KisNodeCommand(i18nc("(qtundo-format)", "Composition Mode Change"), node)
KisNodeCommand(kundo2_i18n("Composition Mode Change"), node)
{
m_oldCompositeOp = oldCompositeOp;
m_newCompositeOp = newCompositeOp;
......
......@@ -23,7 +23,7 @@
KisNodeOpacityCommand::KisNodeOpacityCommand(KisNodeSP node, quint8 oldOpacity, quint8 newOpacity) :
KisNodeCommand(i18nc("(qtundo-format)", "Opacity Change"), node)
KisNodeCommand(kundo2_i18n("Opacity Change"), node)
{
m_oldOpacity = oldOpacity;
m_newOpacity = newOpacity;
......
......@@ -22,7 +22,7 @@
KisNodePropertyListCommand::KisNodePropertyListCommand(KisNodeSP node, KoDocumentSectionModel::PropertyList newPropertyList)
: KisNodeCommand(i18nc("(qtundo-format)", "Property Changes"), node),
: KisNodeCommand(kundo2_i18n("Property Changes"), node),
m_newPropertyList(newPropertyList),
m_oldPropertyList(node->sectionModelProperties())
/**
......
......@@ -27,7 +27,7 @@
#include "kis_pixel_selection.h"
KisReselectGlobalSelectionCommand::KisReselectGlobalSelectionCommand(KisImageWSP image, KUndo2Command * parent) :
KUndo2Command(i18nc("(qtundo-format)", "Reselect"), parent)
KUndo2Command(kundo2_i18n("Reselect"), parent)
, m_image(image)
{
}
......
......@@ -25,7 +25,7 @@
KisImageResizeCommand::KisImageResizeCommand(KisImageWSP image,
const QSize& newSize)
: KUndo2Command(i18nc("(qtundo-format)", "Resize Image")),
: KUndo2Command(kundo2_i18n("Resize Image")),
m_image(image)
{
// do we really need a translatable name for the command?
......
......@@ -23,7 +23,7 @@
KisImageSetResolutionCommand::KisImageSetResolutionCommand(KisImageWSP image, qreal newXRes, qreal newYRes, KUndo2Command *parent)
: KUndo2Command(i18nc("(qtundo-format)", "Set Image Resolution"), parent)
: KUndo2Command(kundo2_i18n("Set Image Resolution"), parent)
, m_image(image)
, m_newXRes(newXRes)
, m_newYRes(newYRes)
......@@ -73,7 +73,7 @@ public:
KisResetShapesCommand::KisResetShapesCommand(KisNodeSP rootNode)
: KUndo2Command("RESET_SHAPES_COMMAND"),
: KUndo2Command(kundo2_noi18n("RESET_SHAPES_COMMAND")),
m_rootNode(rootNode)
{
}
......
......@@ -37,7 +37,7 @@ class KRITAIMAGE_EXPORT KisMoveCommandCommon : public KUndo2Command
{
public:
KisMoveCommandCommon(ObjectSP object, const QPoint& oldPos, const QPoint& newPos, KUndo2Command *parent = 0)
: KUndo2Command(i18nc("(qtundo-format)", "Move"), parent),
: KUndo2Command(kundo2_i18n("Move"), parent),
m_oldPos(oldPos),
m_newPos(newPos),
m_object(object)
......
......@@ -22,7 +22,7 @@
KisProcessingCommand::KisProcessingCommand(KisProcessingVisitorSP visitor, KisNodeSP node, KUndo2Command *parent)
: KUndo2Command("processing_command", parent),
: KUndo2Command(kundo2_noi18n("processing_command"), parent),
m_visitor(visitor),
m_node(node),
m_visitorExecuted(false)
......
......@@ -24,7 +24,7 @@
#include "kis_stroke_strategy_undo_command_based.h"
KisSavedCommandBase::KisSavedCommandBase(const QString &name,
KisSavedCommandBase::KisSavedCommandBase(const KUndo2MagicString &name,
KisStrokesFacade *strokesFacade)
: KUndo2Command(name),
m_strokesFacade(strokesFacade),
......@@ -98,7 +98,7 @@ struct KisSavedMacroCommand::Private
QVector<SavedCommand> commands;
};
KisSavedMacroCommand::KisSavedMacroCommand(const QString &name,
KisSavedMacroCommand::KisSavedMacroCommand(const KUndo2MagicString &name,
KisStrokesFacade *strokesFacade)
: KisSavedCommandBase(name, strokesFacade),
m_d(new Private())
......
......@@ -30,7 +30,7 @@ class KisStrokesFacade;
class KisSavedCommandBase : public KUndo2Command
{
public:
KisSavedCommandBase(const QString &name, KisStrokesFacade *strokesFacade);
KisSavedCommandBase(const KUndo2MagicString &name, KisStrokesFacade *strokesFacade);
virtual ~KisSavedCommandBase();
void undo();
......@@ -63,7 +63,7 @@ private:
class KisSavedMacroCommand : public KisSavedCommandBase
{
public:
KisSavedMacroCommand(const QString &name, KisStrokesFacade *strokesFacade);
KisSavedMacroCommand(const KUndo2MagicString &name, KisStrokesFacade *strokesFacade);
~KisSavedMacroCommand();
void addCommand(KUndo2CommandSP command,
......
......@@ -25,7 +25,7 @@
KisUpdateCommand::KisUpdateCommand(KisNodeSP node, QRect dirtyRect,
KisUpdatesFacade *updatesFacade,
bool needsFullRefresh)
: KUndo2Command("UPDATE_COMMAND"),
: KUndo2Command(kundo2_noi18n("UPDATE_COMMAND")),
m_node(node),
m_dirtyRect(dirtyRect),
m_updatesFacade(updatesFacade),
......
......@@ -121,7 +121,7 @@ void KisFilter::process(const KisPaintDeviceSP src,
}
else {
temporary = dst->createCompositionSourceDevice(src, needRect);
transaction = new KisTransaction("", temporary);
transaction = new KisTransaction(temporary);
}
try {
......
......@@ -416,7 +416,9 @@ void KisImage::resizeImageImpl(const QRect& newRect, bool cropLayers)
{
if (newRect == bounds() && !cropLayers) return;
QString actionName = cropLayers ? i18n("Crop Image") : i18n("Resize Image");
KUndo2MagicString actionName = cropLayers ?
kundo2_i18n("Crop Image") :
kundo2_i18n("Resize Image");
KisImageSignalVector emitSignals;
emitSignals << ComplexSizeChangedSignal(newRect, newRect.size());
......@@ -450,7 +452,9 @@ void KisImage::cropImage(const QRect& newRect)
void KisImage::cropNode(KisNodeSP node, const QRect& newRect)
{
bool isLayer = dynamic_cast<KisLayer*>(node.data());
QString actionName = isLayer ? i18n("Crop Layer") : i18n("Crop Mask");
KUndo2MagicString actionName = isLayer ?
kundo2_i18n("Crop Layer") :
kundo2_i18n("Crop Mask");
KisImageSignalVector emitSignals;
emitSignals << ModifiedSignal;
......@@ -477,7 +481,9 @@ void KisImage::scaleImage(const QSize &size, qreal xres, qreal yres, KisFilterSt
if (sizeChanged) emitSignals << ComplexSizeChangedSignal(bounds(), size);
emitSignals << ModifiedSignal;
QString actionName = sizeChanged ? i18n("Scale Image") : i18n("Change Image Resolution");
KUndo2MagicString actionName = sizeChanged ?
kundo2_i18n("Scale Image") :
kundo2_i18n("Change Image Resolution");
KisProcessingApplicator::ProcessingFlags signalFlags =
(resolutionChanged || sizeChanged) ?
......@@ -524,7 +530,7 @@ void KisImage::scaleImage(const QSize &size, qreal xres, qreal yres, KisFilterSt
void KisImage::scaleNode(KisNodeSP node, qreal sx, qreal sy, KisFilterStrategy *filterStrategy)
{
QString actionName(i18n("Scale Layer"));
KUndo2MagicString actionName(kundo2_i18n("Scale Layer"));
KisImageSignalVector emitSignals;
emitSignals << ModifiedSignal;
......@@ -544,7 +550,7 @@ void KisImage::scaleNode(KisNodeSP node, qreal sx, qreal sy, KisFilterStrategy *
applicator.end();
}
void KisImage::rotateImpl(const QString &actionName,
void KisImage::rotateImpl(const KUndo2MagicString &actionName,
KisNodeSP rootNode,
bool resizeImage,
double radians)
......@@ -612,16 +618,15 @@ void KisImage::rotateImpl(const QString &actionName,
void KisImage::rotateImage(double radians)
{
// XXX i18n("Rotate Image") after 2.4
rotateImpl("Rotate Image", root(), true, radians);
rotateImpl(kundo2_i18n("Rotate Image"), root(), true, radians);
}
void KisImage::rotateNode(KisNodeSP node, double radians)
{
rotateImpl(i18n("Rotate Layer"), node, false, radians);
rotateImpl(kundo2_i18n("Rotate Layer"), node, false, radians);
}
void KisImage::shearImpl(const QString &actionName,
void KisImage::shearImpl(const KUndo2MagicString &actionName,
KisNodeSP rootNode,
bool resizeImage,
double angleX, double angleY,
......@@ -685,13 +690,13 @@ void KisImage::shearNode(KisNodeSP node, double angleX, double angleY)
{
QPointF shearOrigin = QRectF(bounds()).center();
shearImpl(i18n("Shear layer"), node, false,