72 lines
1.9 KiB
C++
72 lines
1.9 KiB
C++
|
|
// src/canvas/PluginItemFactory.cpp
|
||
|
|
#include "diagramCavas/include/graphicsItem/pluginItemFactory.h"
|
||
|
|
#include "include/graphicsItem/pluginItemWrapper.h"
|
||
|
|
#include "pluginManager/include/pluginManager.h"
|
||
|
|
#include <QDebug>
|
||
|
|
|
||
|
|
PluginItemFactory* PluginItemFactory::instance()
|
||
|
|
{
|
||
|
|
static PluginItemFactory instance;
|
||
|
|
return &instance;
|
||
|
|
}
|
||
|
|
|
||
|
|
PluginItemFactory::PluginItemFactory(QObject *parent)
|
||
|
|
: QObject(parent)
|
||
|
|
, d(new Private)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
void PluginItemFactory::setPluginManager(PluginManager *manager)
|
||
|
|
{
|
||
|
|
d->pluginManager = manager;
|
||
|
|
}
|
||
|
|
|
||
|
|
GraphicsFunctionModelItem* PluginItemFactory::createItem(const QString &shapeId,
|
||
|
|
QGraphicsItem *parent)
|
||
|
|
{
|
||
|
|
if (!d->pluginManager) {
|
||
|
|
qWarning() << "PluginManager not set";
|
||
|
|
emit creationFailed(shapeId, "PluginManager not set");
|
||
|
|
return nullptr;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 1. 通过插件管理器创建原始插件项
|
||
|
|
ICanvasItem *pluginItem = d->pluginManager->createItem(shapeId);
|
||
|
|
if (!pluginItem) {
|
||
|
|
qWarning() << "Failed to create plugin item:" << shapeId;
|
||
|
|
emit creationFailed(shapeId, "Plugin item creation failed");
|
||
|
|
return nullptr;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 2. 创建包装器
|
||
|
|
GraphicsFunctionModelItem *item = createItemFromPlugin(pluginItem, parent);
|
||
|
|
|
||
|
|
if (item) {
|
||
|
|
emit itemCreated(item);
|
||
|
|
}
|
||
|
|
|
||
|
|
return item;
|
||
|
|
}
|
||
|
|
|
||
|
|
GraphicsFunctionModelItem* PluginItemFactory::createItemFromPlugin(
|
||
|
|
ICanvasItem *pluginItem, QGraphicsItem *parent)
|
||
|
|
{
|
||
|
|
if (!pluginItem) {
|
||
|
|
return nullptr;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 创建包装器
|
||
|
|
PluginItemWrapper *wrapper = new PluginItemWrapper(pluginItem, parent);
|
||
|
|
|
||
|
|
if (!wrapper) {
|
||
|
|
qWarning() << "PluginItemFactory: Failed to create wrapper";
|
||
|
|
return nullptr;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 设置基本属性
|
||
|
|
wrapper->setItemType(GIT_PluginItem);
|
||
|
|
wrapper->setName(pluginItem->displayName());
|
||
|
|
|
||
|
|
return wrapper;
|
||
|
|
}
|