kcmplugin: Do not use d-ptr for trivial members that are fully qualified

Also, make this for the most part header only, because it is just a utility class.
We could make this entirely header only, but it is not worth it.
This commit is contained in:
Alexander Lohnau 2023-08-12 13:56:19 +02:00 committed by Albert Vaca Cintora
parent 473589cd32
commit b70de1eb21
4 changed files with 24 additions and 45 deletions

View file

@ -21,13 +21,15 @@ struct KdeConnectPluginConfigPrivate {
QDBusMessage m_signal;
};
KdeConnectPluginConfig::KdeConnectPluginConfig()
: d(new KdeConnectPluginConfigPrivate())
KdeConnectPluginConfig::KdeConnectPluginConfig(QObject *parent)
: QObject(parent)
, d(new KdeConnectPluginConfigPrivate())
{
}
KdeConnectPluginConfig::KdeConnectPluginConfig(const QString &deviceId, const QString &pluginName)
: d(new KdeConnectPluginConfigPrivate())
KdeConnectPluginConfig::KdeConnectPluginConfig(const QString &deviceId, const QString &pluginName, QObject *parent)
: QObject(parent)
, d(new KdeConnectPluginConfigPrivate())
{
d->m_configDir = KdeConnectConfig::instance().pluginConfigDir(deviceId, pluginName);
QDir().mkpath(d->m_configDir.path());

View file

@ -25,8 +25,8 @@ class KDECONNECTCORE_EXPORT KdeConnectPluginConfig : public QObject
Q_PROPERTY(QString pluginName READ pluginName WRITE setPluginName NOTIFY configChanged)
public:
KdeConnectPluginConfig();
KdeConnectPluginConfig(const QString &deviceId, const QString &pluginName);
explicit KdeConnectPluginConfig(QObject *parent = nullptr);
explicit KdeConnectPluginConfig(const QString &deviceId, const QString &pluginName, QObject *parent = nullptr);
~KdeConnectPluginConfig() override;
/**

View file

@ -6,42 +6,17 @@
#include "kdeconnectpluginkcm.h"
struct KdeConnectPluginKcmPrivate {
QString m_deviceId;
QString m_pluginName;
KdeConnectPluginConfig *m_config = nullptr;
};
KdeConnectPluginKcm::KdeConnectPluginKcm(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
#if QT_VERSION_MAJOR < 6
: KCModule(qobject_cast<QWidget *>(parent), args)
#else
: KCModule(parent)
#endif
, d(new KdeConnectPluginKcmPrivate())
, m_deviceId(args.at(0).toString())
// The plugin name is the KCMs ID with the postfix removed
, m_config(new KdeConnectPluginConfig(m_deviceId, args.at(1).toString().remove(QLatin1String("_config")), this))
{
Q_ASSERT(data.isValid()); // Even if we have empty metadata, it should be valid!
d->m_deviceId = args.at(0).toString();
const static QRegularExpression removeConfigPostfix(QStringLiteral("_config$"));
d->m_pluginName = data.pluginId().remove(removeConfigPostfix);
// The parent of the config should be the plugin itself
d->m_config = new KdeConnectPluginConfig(d->m_deviceId, d->m_pluginName);
}
KdeConnectPluginKcm::~KdeConnectPluginKcm()
{
delete d->m_config;
}
KdeConnectPluginConfig *KdeConnectPluginKcm::config() const
{
return d->m_config;
}
QString KdeConnectPluginKcm::deviceId() const
{
return d->m_deviceId;
}
#include "moc_kdeconnectpluginkcm.cpp"

View file

@ -4,8 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#ifndef KDECONNECTPLUGINKCM_H
#define KDECONNECTPLUGINKCM_H
#pragma once
#include <KCModule>
#include <KPluginMetaData> // Not in KCModule header of older KF5 versions
@ -14,8 +13,6 @@
#include "core/kdeconnectpluginconfig.h"
#include "kdeconnectpluginkcm_export.h"
struct KdeConnectPluginKcmPrivate;
/**
* Inheriting your plugin's KCM from this class gets you a easy way to share
* configuration values between the KCM and the plugin.
@ -25,18 +22,23 @@ class KDECONNECTPLUGINKCM_EXPORT KdeConnectPluginKcm : public KCModule
Q_OBJECT
public:
KdeConnectPluginKcm(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
~KdeConnectPluginKcm() override;
explicit KdeConnectPluginKcm(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
/**
* The device this kcm is instantiated for
*/
QString deviceId() const;
QString deviceId() const
{
return m_deviceId;
}
/**
* The object where to save the config, so the plugin can access it
*/
KdeConnectPluginConfig *config() const;
KdeConnectPluginConfig *config() const
{
return m_config;
}
#if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 105, 0)
QWidget *widget()
@ -46,7 +48,7 @@ public:
#endif
private:
QScopedPointer<KdeConnectPluginKcmPrivate> d;
const QString m_deviceId;
const QString m_pluginName;
KdeConnectPluginConfig *const m_config;
};
#endif