Commit cbfaf510 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Remove an assert when switching a tool while doing a stroke

Well, using macro for this purpose might be a bit ugly, but this is the
best thing we can do until we invent some strategy-based event handling
for the tools.

Ideally, every tool should provide a set of strategies for each of the
action. Such strategy could be registered in the tool proxy on
KisTool::activate() and deregistered on KisTool::deactivate(). But we
are on a long way till that.

BUG:328956
parent 821ee8b7
......@@ -269,7 +269,7 @@ void KisToolColorPicker::beginPrimaryAction(KoPointerEvent *event)
void KisToolColorPicker::continuePrimaryAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
QPoint pos = convertToIntPixelCoord(event);
pickColor(pos);
......@@ -279,7 +279,7 @@ void KisToolColorPicker::continuePrimaryAction(KoPointerEvent *event)
void KisToolColorPicker::endPrimaryAction(KoPointerEvent *event)
{
Q_UNUSED(event);
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
if (m_config.addPalette) {
KoColorSetEntry ent;
......
......@@ -92,7 +92,7 @@ void KisToolFill::beginPrimaryAction(KoPointerEvent *event)
void KisToolFill::endPrimaryAction(KoPointerEvent *event)
{
Q_UNUSED(event);
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
setMode(KisTool::HOVER_MODE);
......
......@@ -109,7 +109,7 @@ void KisToolGradient::continuePrimaryAction(KoPointerEvent *event)
* nested event hadler calls. Please uncomment this line
* when the tool is ported to strokes.
*/
//KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
//CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
QPointF pos = convertToPixelCoord(event);
......@@ -130,7 +130,7 @@ void KisToolGradient::continuePrimaryAction(KoPointerEvent *event)
void KisToolGradient::endPrimaryAction(KoPointerEvent *event)
{
Q_UNUSED(event);
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
setMode(KisTool::HOVER_MODE);
if (!currentNode() || currentNode()->systemLocked())
......
......@@ -121,7 +121,7 @@ void KisToolLine::beginPrimaryAction(KoPointerEvent *event)
void KisToolLine::continuePrimaryAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
// First ensure the old temp line is deleted
updatePreview();
......@@ -145,7 +145,7 @@ void KisToolLine::continuePrimaryAction(KoPointerEvent *event)
void KisToolLine::endPrimaryAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
setMode(KisTool::HOVER_MODE);
updatePreview();
......
......@@ -152,7 +152,7 @@ void KisToolMeasure::beginPrimaryAction(KoPointerEvent *event)
void KisToolMeasure::continuePrimaryAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
// Erase old temporary lines
canvas()->updateCanvas(convertToPt(boundingRect()));
......@@ -174,7 +174,7 @@ void KisToolMeasure::continuePrimaryAction(KoPointerEvent *event)
void KisToolMeasure::endPrimaryAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
Q_UNUSED(event);
setMode(KisTool::HOVER_MODE);
......
......@@ -182,7 +182,7 @@ void KisToolMove::startAction(KoPointerEvent *event, MoveToolMode mode)
void KisToolMove::continueAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
if (!m_strokeId) return;
......@@ -193,7 +193,7 @@ void KisToolMove::continueAction(KoPointerEvent *event)
void KisToolMove::endAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
setMode(KisTool::HOVER_MODE);
if (!m_strokeId) return;
......
......@@ -113,7 +113,7 @@ void KisToolSelectBrush::beginPrimaryAction(KoPointerEvent *event)
void KisToolSelectBrush::continuePrimaryAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
// this gives better performance
if(Vector2f((m_lastPoint-convertToPixelCoord(event->point)).x(), (m_lastPoint-convertToPixelCoord(event->point)).y()).norm()<m_brushRadius/6)
......@@ -133,7 +133,7 @@ void KisToolSelectBrush::continuePrimaryAction(KoPointerEvent *event)
void KisToolSelectBrush::endPrimaryAction(KoPointerEvent *event)
{
Q_UNUSED(event;)
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
setMode(KisTool::HOVER_MODE);
applyToSelection(m_selection);
......
......@@ -81,7 +81,7 @@ void KisToolSelectOutline::beginPrimaryAction(KoPointerEvent *event)
void KisToolSelectOutline::continuePrimaryAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
QPointF point = convertToPixelCoord(event);
m_paintPath->lineTo(pixelToView(point));
......@@ -92,7 +92,7 @@ void KisToolSelectOutline::continuePrimaryAction(KoPointerEvent *event)
void KisToolSelectOutline::endPrimaryAction(KoPointerEvent *event)
{
Q_UNUSED(event);
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
setMode(KisTool::HOVER_MODE);
KisCanvas2 * kisCanvas = dynamic_cast<KisCanvas2*>(canvas());
......
......@@ -227,7 +227,7 @@ void KisToolCrop::beginPrimaryAction(KoPointerEvent *event)
void KisToolCrop::continuePrimaryAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
QPointF pos = convertToPixelCoord(event);
bool needForceRatio = this->forceRatio() != bool(event->modifiers() & Qt::ShiftModifier);
......@@ -461,7 +461,7 @@ void KisToolCrop::continuePrimaryAction(KoPointerEvent *event)
void KisToolCrop::endPrimaryAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
setMode(KisTool::HOVER_MODE);
m_rectCrop = m_rectCrop.normalized();
......
......@@ -50,6 +50,14 @@
#define MOVE_CONDITION(_event, _mode) (this->mode() == (_mode))
#ifdef __GNUC__
#define WARN_WRONG_MODE(_mode) qWarning() << "Unexpected tool event has come to" << __func__ << "while being mode" << _mode << "!"
#else
#define WARN_WRONG_MODE(_mode) qWarning() << "Unexpected tool event has come while being mode" << _mode << "!"
#endif
#define CHECK_MODE_SANITY_OR_RETURN(_mode) if (mode() != _mode) { WARN_WRONG_MODE(mode()); return; }
class KActionCollection;
class KoCanvasBase;
class KoPattern;
......
......@@ -201,7 +201,7 @@ void KisToolFreehand::beginPrimaryAction(KoPointerEvent *event)
void KisToolFreehand::continuePrimaryAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
requestUpdateOutline(event->point);
......@@ -214,7 +214,7 @@ void KisToolFreehand::continuePrimaryAction(KoPointerEvent *event)
void KisToolFreehand::endPrimaryAction(KoPointerEvent *event)
{
Q_UNUSED(event);
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
endStroke();
......
......@@ -91,7 +91,7 @@ void KisToolPolylineBase::beginPrimaryAction(KoPointerEvent *event)
void KisToolPolylineBase::endPrimaryAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
setMode(KisTool::HOVER_MODE);
if(m_dragging) {
......
......@@ -61,7 +61,7 @@ void KisToolRectangleBase::beginPrimaryAction(KoPointerEvent *event)
void KisToolRectangleBase::continuePrimaryAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
QPointF pos = convertToPixelCoord(event);
......@@ -97,7 +97,7 @@ void KisToolRectangleBase::continuePrimaryAction(KoPointerEvent *event)
void KisToolRectangleBase::endPrimaryAction(KoPointerEvent *event)
{
KIS_ASSERT_RECOVER_RETURN(mode() == KisTool::PAINT_MODE);
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
setMode(KisTool::HOVER_MODE);
updateArea();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment