Commit e85fceaa authored by patrick pereira's avatar patrick pereira 🏃

abstractpluginmodel: Run clang-format

Signed-off-by: patrick pereira's avatarPatrick José Pereira <patrickelectric@gmail.com>
parent 20c63030
......@@ -21,8 +21,8 @@
#include "abstractpluginmodel.h"
#include "debug.h"
#include <KPluginLoader>
#include <KPluginFactory>
#include <KPluginLoader>
#include <QCoreApplication>
#include <QMetaEnum>
......@@ -38,9 +38,10 @@ public:
QVector<KPluginMetaData> plugins;
// This is QMap so `AbstractPluginModel::loadedPlugins` returns a stable sort.
QMap<QString, QObject*> loadedPlugins;
QMap<QString, QObject *> loadedPlugins;
void loadPluginByService(const QString &serviceType);
void loadPluginByService(const QString& serviceType);
private:
AbstractPluginModel *m_q;
};
......@@ -51,12 +52,10 @@ AbstractPluginModel::Private::Private(AbstractPluginModel *q)
}
AbstractPluginModel::Private::~Private() = default;
AbstractPluginModel::AbstractPluginModel(QObject *parent)
: QAbstractListModel(parent)
, d(new AbstractPluginModel::Private(this))
: QAbstractListModel(parent)
, d(new AbstractPluginModel::Private(this))
{
}
AbstractPluginModel::~AbstractPluginModel()
......@@ -65,35 +64,32 @@ AbstractPluginModel::~AbstractPluginModel()
delete d;
}
void AbstractPluginModel::Private::loadPluginByService(const QString& serviceType)
void AbstractPluginModel::Private::loadPluginByService(const QString &serviceType)
{
auto filterLambda = [serviceType](const KPluginMetaData &metaData) -> bool { return metaData.serviceTypes().contains(serviceType); };
const QString lowercaseMetadata = serviceType.toLower();
// Look for plugins in a relative path, covers the case when the application is
// not installed in the system.
const QString possiblePluginPath = QCoreApplication::applicationDirPath()
+ QStringLiteral("/../lib/plugins/%1").arg(lowercaseMetadata);
const QString possiblePluginPath = QCoreApplication::applicationDirPath() + QStringLiteral("/../lib/plugins/%1").arg(lowercaseMetadata);
plugins = KPluginLoader::findPlugins(possiblePluginPath, filterLambda);
plugins += KPluginLoader::findPlugins(lowercaseMetadata, filterLambda);
// Unload plugins that apparently got uninstalled at runtime.
for (const QString &id : loadedPlugins.keys()) {
const bool found = std::any_of(plugins.constBegin(), plugins.constEnd(),
[id](const auto &md) { return md.pluginId() == id; });
const bool found = std::any_of(plugins.constBegin(), plugins.constEnd(), [id](const auto &md) { return md.pluginId() == id; });
if (!found) {
loadedPlugins.take(id)->deleteLater();
}
}
}
void AbstractPluginModel::loadPluginByService(const QString& serviceType)
void AbstractPluginModel::loadPluginByService(const QString &serviceType)
{
d->loadPluginByService(serviceType);
}
bool AbstractPluginModel::loadPluginByIndex(int row)
{
const KPluginMetaData &md = d->plugins.at(row);
......@@ -128,7 +124,6 @@ bool AbstractPluginModel::loadPluginByIndex(int row)
return true;
}
bool AbstractPluginModel::loadPluginById(const QString &id)
{
for (int i = 0; i < d->plugins.count(); ++i) {
......@@ -213,10 +208,9 @@ KPluginMetaData AbstractPluginModel::metadataAt(int row) const
return d->plugins.at(row);
}
QObject * AbstractPluginModel::pluginForId(const QString& id) const
QObject *AbstractPluginModel::pluginForId(const QString &id) const
{
return d->loadedPlugins.value(id, nullptr);
}
}
......@@ -20,27 +20,29 @@
#pragma once
#include <QAbstractListModel>
#include <KPluginMetaData>
#include <KPluginFactory>
#include <KPluginMetaData>
#include <QAbstractListModel>
#include "kirogicore_export.h"
namespace Kirogi {
namespace Kirogi
{
/* This class is the base class of different models for plugins in Kirogi
*/
class KIROGI_EXPORT AbstractPluginModel : public QAbstractListModel {
Q_OBJECT
*/
class KIROGI_EXPORT AbstractPluginModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit AbstractPluginModel(QObject *parent = nullptr);
~AbstractPluginModel() override;
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override final;
QObject *pluginForId(const QString& id) const;
QObject *pluginForId(const QString &id) const;
KPluginMetaData metadataAt(int row) const;
void loadPluginByService(const QString& serviceType);
void loadPluginByService(const QString &serviceType);
Q_INVOKABLE bool loadPluginByIndex(int idx);
Q_INVOKABLE bool loadPluginById(const QString &id);
......
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