Commit 70134c1e authored by Sven Langkamp's avatar Sven Langkamp

Fix for unsetting the canvas

REVIEW:108725
BUG:314029
parent bd3c3a51
......@@ -342,8 +342,8 @@ void FlipbookDockerDock::selectImage(const QModelIndex &index)
QList<KoCanvasObserverBase*> canvasObservers = m_canvas->view()->shell()->canvasObservers();
foreach (KoCanvasObserverBase *canvasObserver, canvasObservers) {
if (canvasObserver != this) {
canvasObserver->unsetCanvas();
canvasObserver->setCanvas(m_canvas);
canvasObserver->unsetObservedCanvas();
canvasObserver->setObservedCanvas(m_canvas);
}
}
......
......@@ -197,7 +197,7 @@ void KoCanvasControllerWidget::Private::activate()
foreach(KoCanvasObserverBase *docker, observerProvider->canvasObservers()) {
KoCanvasObserverBase *observer = dynamic_cast<KoCanvasObserverBase*>(docker);
if (observer) {
observer->setCanvas(q->canvas());
observer->setObservedCanvas(q->canvas());
}
}
lastActivatedCanvas = q->canvas();
......@@ -216,8 +216,8 @@ void KoCanvasControllerWidget::Private::unsetCanvas()
}
foreach(KoCanvasObserverBase *docker, observerProvider->canvasObservers()) {
KoCanvasObserverBase *observer = dynamic_cast<KoCanvasObserverBase*>(docker);
if (observer) {
observer->unsetCanvas();
if (observer && observer->observedCanvas() == q->canvas()) {
observer->unsetObservedCanvas();
}
}
}
......
......@@ -19,10 +19,36 @@
#include "KoCanvasObserverBase.h"
KoCanvasObserverBase::KoCanvasObserverBase()
class KoCanvasObserverBasePrivate
{
public:
KoCanvasObserverBasePrivate() : canvas(0) {}
~KoCanvasObserverBasePrivate() {}
KoCanvasBase* canvas;
};
KoCanvasObserverBase::KoCanvasObserverBase() : d(new KoCanvasObserverBasePrivate)
{
}
KoCanvasObserverBase::~KoCanvasObserverBase()
{
}
void KoCanvasObserverBase::setObservedCanvas(KoCanvasBase* canvas)
{
d->canvas = canvas;
setCanvas(canvas);
}
void KoCanvasObserverBase::unsetObservedCanvas()
{
d->canvas = 0;
unsetCanvas();
}
KoCanvasBase* KoCanvasObserverBase::observedCanvas()
{
return d->canvas;
}
......@@ -21,6 +21,7 @@
#define KOCANVASOBSERVERBASE_H
class KoCanvasBase;
class KoCanvasObserverBasePrivate;
#include "flake_export.h"
......@@ -36,6 +37,23 @@ public:
KoCanvasObserverBase();
virtual ~KoCanvasObserverBase();
/**
* set observed canvas
* @param canvas canvas to observe
*/
void setObservedCanvas(KoCanvasBase *canvas);
/**
* notify the observer that canvas is gone
*/
void unsetObservedCanvas();
/**
* the currently observed canvas
* @return observed canvas, can be 0
*/
KoCanvasBase* observedCanvas();
protected:
/**
* re-implement this method in your canvas observer. It will be called
* whenever a canvas becomes active. Note that you are responsible for
......@@ -54,6 +72,8 @@ public:
*/
virtual void unsetCanvas() = 0;
private:
KoCanvasObserverBasePrivate * const d;
};
#endif // KOCANVASOBSERVERBASE_H
......@@ -51,7 +51,6 @@ class KoModeBox::Private
public:
Private(KoCanvasController *c)
: canvas(c->canvas())
, canvasReset(false)
, activeId(-1)
, iconTextFitted(true)
, fittingIterations(0)
......@@ -59,7 +58,6 @@ public:
}
KoCanvasBase *canvas;
bool canvasReset;
QList<KoToolButton> buttons; // buttons maintained by toolmanager
QList<KoToolButton> addedButtons; //buttons in the order added to QToolBox
QMap<int, QWidget *> addedWidgets;
......@@ -383,8 +381,6 @@ void KoModeBox::setCanvas(KoCanvasBase *canvas)
this, SLOT(setOptionWidgets(const QList<QWidget *> &)));
}
d->canvasReset = d->canvas != 0;
d->canvas = canvas;
ccwidget = dynamic_cast<KoCanvasControllerWidget *>(d->canvas->canvasController());
......@@ -395,9 +391,7 @@ void KoModeBox::setCanvas(KoCanvasBase *canvas)
void KoModeBox::unsetCanvas()
{
if (!d->canvasReset) {
d->canvas = 0;
}
d->canvas = 0;
}
void KoModeBox::toolAdded(const KoToolButton &button, KoCanvasController *canvas)
......
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