56 lines
3.0 KiB
C++
56 lines
3.0 KiB
C++
#include "plugins/tkrShapePluginStore.h"
|
|
#include "ShapeBuildContract.h"
|
|
|
|
#include <QCoreApplication>
|
|
#include <QDir>
|
|
#include <QJsonArray>
|
|
#include <QJsonObject>
|
|
|
|
namespace TikzRefinery {
|
|
|
|
tkrShapePluginStore::tkrShapePluginStore(const QString &strModulePath)
|
|
: m_loader(strModulePath.isEmpty()
|
|
? QDir(QCoreApplication::applicationDirPath()).filePath(QStringLiteral("shape-plugins/tkr_rectangle"))
|
|
: strModulePath)
|
|
{
|
|
const QJsonObject root = m_loader.metaData();
|
|
const QJsonObject metadata = root.value(QStringLiteral("MetaData")).toObject();
|
|
const QJsonArray operations = metadata.value(QStringLiteral("operations")).toArray();
|
|
if (root.value(QStringLiteral("IID")).toString() != QString::fromLatin1(TKR_SHAPE_PROVIDER_IID)
|
|
|| metadata.value(QStringLiteral("id")).toString() != QStringLiteral("org.tikzrefinery.rectangle")
|
|
|| metadata.value(QStringLiteral("name")).toString().isEmpty()
|
|
|| metadata.value(QStringLiteral("version")).toString().isEmpty()
|
|
|| metadata.value(QStringLiteral("role")).toString() != QStringLiteral("shape")
|
|
|| metadata.value(QStringLiteral("apiVersion")).toInt() != ShapeApi::iApiVersion
|
|
|| metadata.value(QStringLiteral("shapeType")).toString() != ShapeApi::strRectangleType
|
|
|| metadata.value(QStringLiteral("geometrySchemaVersion")).toInt() != ShapeApi::iRectangleSchemaVersion
|
|
|| metadata.value(QStringLiteral("parameterSchemaVersion")).toInt() != ShapeApi::iParameterSchemaVersion
|
|
|| metadata.value(QStringLiteral("buildKey")).toString() != QString::fromLatin1(ShapeBuildContract::pBuildKey)
|
|
|| !operations.contains(ShapeApi::strMoveOperation) || !operations.contains(ShapeApi::strResizeOperation)) {
|
|
m_result = {false, QStringLiteral("Rectangle plugin missing or incompatible (API, schema, operations or toolchain). %1")
|
|
.arg(m_loader.fileName())};
|
|
return;
|
|
}
|
|
m_pProvider = qobject_cast<tkrShapeProvider *>(m_loader.instance());
|
|
if (!m_pProvider) {
|
|
m_result = {false, QStringLiteral("Rectangle plugin could not load: %1").arg(m_loader.errorString())};
|
|
return;
|
|
}
|
|
m_strName = metadata.value(QStringLiteral("name")).toString();
|
|
m_strVersion = metadata.value(QStringLiteral("version")).toString();
|
|
m_strRuntimeIdentity = QUuid::createUuid().toString(QUuid::WithoutBraces);
|
|
m_result = {true, QStringLiteral("Loaded %1 %2").arg(m_strName, m_strVersion)};
|
|
}
|
|
|
|
const tkrShapeProvider *tkrShapePluginStore::provider() const { return m_pProvider; }
|
|
const OperationResult &tkrShapePluginStore::loadResult() const { return m_result; }
|
|
const QString &tkrShapePluginStore::runtimeIdentity() const { return m_strRuntimeIdentity; }
|
|
QString tkrShapePluginStore::modulePath() const { return m_loader.fileName(); }
|
|
QString tkrShapePluginStore::description() const
|
|
{
|
|
return m_result.bSucceeded ? QStringLiteral("%1 %2\n%3\nInstance: %4")
|
|
.arg(m_strName, m_strVersion, modulePath(), m_strRuntimeIdentity) : m_result.strMessage;
|
|
}
|
|
|
|
} // namespace TikzRefinery
|