Commit b338b71e authored by Boudewijn Rempt's avatar Boudewijn Rempt

Remove the canCreateTool from KisToolFactoryBase

canCreateTool dates back to when we loaded all plugins and had to have
a way to hide the tools an app didn't need. We have a plugin blacklist
now, so that's not necessary anymore.

And this method was the only reason we had to pass a canvas to the
toolbox docker factory, which means we couldn't create a toolbox unless
we've got a canvas.
parent ac2cd76e
......@@ -387,7 +387,7 @@ KisView2::KisView2(KoPart *part, KisDoc2 * doc, QWidget * parent)
action->setShortcut(QKeySequence(), KAction::ActiveShortcut);
}
KoToolBoxFactory toolBoxFactory(m_d->canvasController);
KoToolBoxFactory toolBoxFactory;
mainWindow()->createDockWidget(&toolBoxFactory);
connect(canvasController, SIGNAL(toolOptionWidgetsChanged(QList<QWidget*>)),
......
......@@ -116,8 +116,3 @@ void KoToolFactoryBase::setShortcut(const KShortcut & shortcut)
{
d->shortcut = shortcut;
}
bool KoToolFactoryBase::canCreateTool(KoCanvasBase *) const
{
return true;
}
......@@ -66,18 +66,9 @@ public:
* @param canvas the canvas that the new tool will work on. Should be passed
* to the constructor of the tool.
* @return a new KoToolBase instance, or zero if the tool doesn't want to show up.
* @see canCreateTool()
*/
virtual KoToolBase *createTool(KoCanvasBase *canvas) = 0;
/**
* Returns true if this factory will create a tool instance when called with the same canvas in createTool()
* The default implementation returns true.
* @param canvas the canvas that the new tool will work on. Should be passed
* to the constructor of the tool.
*/
virtual bool canCreateTool(KoCanvasBase *canvas) const;
/**
* return the id for the tool this factory creates.
* @return the id for the tool this factory creates.
......
......@@ -725,14 +725,12 @@ KoToolManager::~KoToolManager()
delete d;
}
QList<KoToolButton> KoToolManager::createToolList(KoCanvasBase *canvas) const
QList<KoToolButton> KoToolManager::createToolList() const
{
QList<KoToolButton> answer;
foreach(ToolHelper *tool, d->tools) {
if (tool->id() == KoCreateShapesTool_ID)
continue; // don't show this one.
if (!tool->canCreateTool(canvas))
continue;
KoToolButton button;
button.button = tool->createButton();
button.section = tool->toolType();
......@@ -974,7 +972,7 @@ void KoToolManager::addDeferredToolFactory(KoToolFactoryBase *toolFactory)
}
// Then create a button for the toolbox for this canvas
if (tool->id() == KoCreateShapesTool_ID || !tool->canCreateTool(controller->canvas())) {
if (tool->id() == KoCreateShapesTool_ID) {
continue;
}
......@@ -1004,11 +1002,6 @@ QPair<QString, KoToolBase*> KoToolManager::createTools(KoCanvasController *contr
return QPair<QString, KoToolBase*>(tool->id(), origHash.value(tool->id()));
}
if (!tool->canCreateTool(controller->canvas())) {
kDebug(30006) << "Skipping the creation of tool" << tool->id();
return QPair<QString, KoToolBase*>(QString(), 0);
}
kDebug(30006) << "Creating tool" << tool->id() << ". Activated on:" << tool->activationShapeId() << ", prio:" << tool->priority();
KoToolBase *tl = tool->createTool(controller->canvas());
......
......@@ -182,7 +182,7 @@ public:
* @returns a list of Buttons.
* This is a factory method for buttons and meta information on the button to better display the button.
*/
QList<KoToolButton> createToolList(KoCanvasBase *canvas) const;
QList<KoToolButton> createToolList() const;
/// Request tool activation for the given canvas controller
void requestToolActivation(KoCanvasController *controller);
......
......@@ -65,8 +65,6 @@ QString ToolHelper::toolTip() const
KoToolBase *ToolHelper::createTool(KoCanvasBase *canvas) const
{
if (! canCreateTool(canvas))
return 0;
KoToolBase *tool = m_toolFactory->createTool(canvas);
tool->setToolId(id());
return tool;
......@@ -87,11 +85,6 @@ KShortcut ToolHelper::shortcut() const
return m_toolFactory->shortcut();
}
bool ToolHelper::canCreateTool(KoCanvasBase *canvas) const
{
return m_toolFactory->canCreateTool(canvas);
}
// ************ Connector **********
Connector::Connector(KoShapeManager *parent)
: QObject(parent),
......
......@@ -129,8 +129,6 @@ public:
}
/// wrapper around KoToolFactoryBase::shortcut()
KShortcut shortcut() const;
/// returns true if the factory will create a tool, false if it decided to not create one in createTool().
bool canCreateTool(KoCanvasBase *canvas) const;
signals:
/// emitted when one of the generated buttons was pressed.
......
......@@ -324,7 +324,7 @@ void KoPAView::initGUI(KoPAFlags flags)
}
} else {
if (mw) {
KoToolBoxFactory toolBoxFactory(d->canvasController);
KoToolBoxFactory toolBoxFactory;
mw->createDockWidget( &toolBoxFactory );
connect(canvasController, SIGNAL(toolOptionWidgetsChanged(const QList<QWidget *> &)),
mw->dockerManager(), SLOT(newOptionWidgets(const QList<QWidget *> &) ));
......
......@@ -50,9 +50,3 @@ KoToolBase * KoPABackgroundToolFactory::createTool(KoCanvasBase *canvas)
setToolTip(toolTip);
return new KoPABackgroundTool(canvas);
}
bool KoPABackgroundToolFactory::canCreateTool(KoCanvasBase *canvas) const
{
KoPACanvas *paCanvas = dynamic_cast<KoPACanvas *>(canvas);
return paCanvas != 0; // we only work in KoPACanvas
}
......@@ -31,8 +31,6 @@ public:
virtual ~KoPABackgroundToolFactory();
///reimplemented from KoToolFactoryBase
virtual KoToolBase * createTool( KoCanvasBase *canvas );
///reimplemented from KoToolFactoryBase
virtual bool canCreateTool( KoCanvasBase *canvas ) const;
};
#endif //KOPABACKGROUNDTOOLFACTORY_H
......@@ -29,7 +29,7 @@ K_PLUGIN_FACTORY(PluginFactory, registerPlugin<Plugin>();)
K_EXPORT_PLUGIN(PluginFactory("kopageapplication-backgroundtool"))
Plugin::Plugin( QObject* parent, const QVariantList& )
: QObject( parent )
: QObject( parent )
{
KoToolRegistry::instance()->add( new KoPABackgroundToolFactory() );
}
......
......@@ -149,7 +149,7 @@ KoModeBox::KoModeBox(KoCanvasControllerWidget *canvas, const QString &appName)
d->layout->setContentsMargins(0,0,0,0);
setLayout(d->layout);
foreach(const KoToolButton &button, KoToolManager::instance()->createToolList(canvas->canvas())) {
foreach(const KoToolButton &button, KoToolManager::instance()->createToolList()) {
addButton(button);
}
......
......@@ -35,10 +35,10 @@
class KoToolBox::Private
{
public:
Private(KoCanvasController *c)
Private()
: layout(0)
, buttonGroup(0)
, canvas(c->canvas())
, canvas(0)
, floating(false)
{
}
......@@ -60,8 +60,8 @@ void KoToolBox::Private::addSection(Section *section, const QString &name)
sections.insert(name, section);
}
KoToolBox::KoToolBox(KoCanvasController *canvas)
: d( new Private(canvas))
KoToolBox::KoToolBox()
: d(new Private)
{
d->layout = new KoToolBoxLayout(this);
// add defaults
......@@ -70,14 +70,13 @@ KoToolBox::KoToolBox(KoCanvasController *canvas)
d->buttonGroup = new QButtonGroup(this);
setLayout(d->layout);
foreach(const KoToolButton & button,
KoToolManager::instance()->createToolList(canvas->canvas())) {
foreach(const KoToolButton & button, KoToolManager::instance()->createToolList()) {
addButton(button.button, button.section, button.priority, button.buttonGroupId);
d->visibilityCodes.insert(button.button, button.visibilityCode);
}
// Update visibility of buttons
setButtonsVisible(canvas, QList<QString>());
setButtonsVisible(QList<QString>());
connect(KoToolManager::instance(), SIGNAL(changedTool(KoCanvasController*, int)),
this, SLOT(setActiveTool(KoCanvasController*, int)));
......@@ -140,12 +139,8 @@ void KoToolBox::setActiveTool(KoCanvasController *canvas, int id)
}
}
void KoToolBox::setButtonsVisible(const KoCanvasController *canvas, const QList<QString> &codes)
void KoToolBox::setButtonsVisible(const QList<QString> &codes)
{
if (canvas->canvas() != d->canvas) {
return;
}
foreach(QToolButton *button, d->visibilityCodes.keys()) {
QString code = d->visibilityCodes.value(button);
......@@ -259,6 +254,6 @@ void KoToolBox::toolAdded(const KoToolButton &button, KoCanvasController *canvas
if (canvas->canvas() == d->canvas) {
addButton(button.button, button.section, button.priority, button.buttonGroupId);
d->visibilityCodes.insert(button.button, button.visibilityCode);
setButtonsVisible(canvas, QList<QString>());
setButtonsVisible(QList<QString>());
}
}
......@@ -21,20 +21,12 @@
#include "KoToolBox_p.h"
#include "KoToolBoxDocker_p.h"
class KoToolBoxFactory::Private {
public:
KoCanvasController *canvasController;
};
KoToolBoxFactory::KoToolBoxFactory(KoCanvasController *canvasController)
: d( new Private())
KoToolBoxFactory::KoToolBoxFactory()
{
d->canvasController = canvasController;
}
KoToolBoxFactory::~KoToolBoxFactory() {
delete d;
}
QString KoToolBoxFactory::id() const
......@@ -49,7 +41,7 @@ KoDockFactoryBase::DockPosition KoToolBoxFactory::defaultDockPosition() const
QDockWidget* KoToolBoxFactory::createDockWidget()
{
KoToolBox *box = new KoToolBox(d->canvasController);
KoToolBox *box = new KoToolBox();
KoToolBoxDocker *docker = new KoToolBoxDocker(box);
docker->setObjectName(QLatin1String("ToolBox"));
......
......@@ -36,17 +36,13 @@ class KoCanvasController;
class KOMAIN_EXPORT KoToolBoxFactory : public KoDockFactoryBase
{
public:
explicit KoToolBoxFactory(KoCanvasController *canvasController);
explicit KoToolBoxFactory();
~KoToolBoxFactory();
virtual QString id() const;
KoDockFactoryBase::DockPosition defaultDockPosition() const;
QDockWidget* createDockWidget();
virtual bool isCollapsable() const { return false; }
private:
class Private;
Private * const d;
};
#endif
......@@ -52,7 +52,7 @@ class KoToolBox : public QWidget {
Q_OBJECT
public:
/// constructor
explicit KoToolBox(KoCanvasController *canvas);
explicit KoToolBox();
~KoToolBox();
/**
......@@ -87,7 +87,7 @@ public slots:
* @param canvas the currently active canvas.
* @param codes a list of all the codes to show.
*/
void setButtonsVisible(const KoCanvasController *canvas, const QList<QString> &codes);
void setButtonsVisible(const QList<QString> &codes);
/// set the canvas this docker should listen to for changes.
void setCanvas(KoCanvasBase *canvas);
......
......@@ -44,9 +44,3 @@ KoToolBase * ReferencesToolFactory::createTool(KoCanvasBase *canvas)
{
return new ReferencesTool(canvas);
}
bool ReferencesToolFactory::canCreateTool(KoCanvasBase* canvas) const
{
Q_UNUSED(canvas);
return true;
}
......@@ -30,8 +30,6 @@ public:
~ReferencesToolFactory();
KoToolBase * createTool(KoCanvasBase *canvas);
virtual bool canCreateTool(KoCanvasBase* canvas) const;
};
#endif
......@@ -49,12 +49,3 @@ KoToolBase *ReviewToolFactory::createTool(KoCanvasBase *canvas)
{
return new ReviewTool(canvas);
}
bool ReviewToolFactory::canCreateTool(KoCanvasBase* canvas) const
{
Q_UNUSED(canvas);
//if (canvas->shapeController()->resourceManager() && canvas->shapeController()->resourceManager()->hasResource(KoText::ChangeTracker))
// return true;
//return false;
return true;
}
......@@ -30,8 +30,6 @@ public:
~ReviewToolFactory();
KoToolBase * createTool(KoCanvasBase *canvas);
virtual bool canCreateTool(KoCanvasBase* canvas) const;
};
#endif
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