Commit 03af69ef authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

Unnest the pimpl classes

NO_CHANGELOG
parent 14040459
......@@ -14,7 +14,7 @@
// sndfile
#include <sndfile.hh>
class Q_DECL_HIDDEN KgSound::Private
class KgSoundPrivate
{
public:
KgSound::PlaybackType m_type;
......@@ -24,14 +24,14 @@ class Q_DECL_HIDDEN KgSound::Private
bool m_valid;
ALuint m_buffer;
Private() : m_type(KgSound::AmbientPlayback), m_volume(1.0), m_valid(false), m_buffer(AL_NONE) {}
KgSoundPrivate() : m_type(KgSound::AmbientPlayback), m_volume(1.0), m_valid(false), m_buffer(AL_NONE) {}
};
//BEGIN KgSound
KgSound::KgSound(const QString& file, QObject* parent)
: QObject(parent)
, d(new Private)
, d(new KgSoundPrivate)
{
VirtualFileQt fileInterface(file);
if (!fileInterface.open()) {
......@@ -102,7 +102,6 @@ KgSound::~KgSound()
KgOpenALRuntime::instance()->m_soundsEvents.remove(this);
alDeleteBuffers(1, &d->m_buffer);
}
delete d;
}
bool KgSound::isValid() const
......
......@@ -12,6 +12,8 @@
// Qt
#include <QObject>
#include <QPointF>
// Std
#include <memory>
class PlaybackEvent;
......@@ -133,8 +135,7 @@ class KDEGAMES_EXPORT KgSound : public QObject
void volumeChanged(qreal volume);
private:
friend class KgPlaybackEvent;
class Private;
Private* const d;
std::unique_ptr<class KgSoundPrivate> const d;
};
#endif // KGSOUND_H
......@@ -32,7 +32,7 @@
Q_LOGGING_CATEGORY(GAMES_HIGHSCORE, "org.kde.games.highscore", QtWarningMsg)
class Q_DECL_HIDDEN KHighscore::KHighscorePrivate
class KHighscorePrivate
{
public:
KHighscorePrivate() {}
......@@ -176,7 +176,6 @@ void KHighscore::writeAndUnlock()
KHighscore::~KHighscore()
{
writeAndUnlock();
delete d;
}
KConfig* KHighscore::config() const
......
......@@ -14,6 +14,8 @@
// Qt
#include <QObject>
#include <QLoggingCategory>
// Std
#include <memory>
class KConfig;
......@@ -285,8 +287,7 @@ class KDEGAMES_EXPORT KHighscore : public QObject
void init(bool forceLocal);
private:
class KHighscorePrivate;
KHighscorePrivate* const d;
std::unique_ptr<class KHighscorePrivate> const d;
};
Q_DECLARE_LOGGING_CATEGORY(GAMES_HIGHSCORE)
......
......@@ -36,7 +36,7 @@
typedef QList<KScoreDialog::FieldInfo> GroupScores; ///<The list of scores in a group
class Q_DECL_HIDDEN KScoreDialog::KScoreDialogPrivate
class KScoreDialogPrivate
{
public:
//QList<FieldInfo*> scores;
......@@ -134,8 +134,6 @@ KScoreDialog::KScoreDialog(int fields, QWidget *parent)
KScoreDialog::~KScoreDialog()
{
delete d->highscoreObject;
delete d;
}
#if KDEGAMES_BUILD_DEPRECATED_SINCE(4, 1)
......@@ -199,7 +197,7 @@ void KScoreDialog::setConfigGroupWeights(const QMap<int, QByteArray>& weights)
d->configGroupWeights = weights;
}
QString KScoreDialog::KScoreDialogPrivate::findTranslatedGroupName(const QByteArray& name)
QString KScoreDialogPrivate::findTranslatedGroupName(const QByteArray& name)
{
const QString lookupResult = translatedGroupNames.value(name);
//If it wasn't found then just try i18n( to see if it happens to be in the database
......@@ -226,7 +224,7 @@ void KScoreDialog::hideField(int field)
/*
Create the widgets and layouts etc. for the dialog
*/
void KScoreDialog::KScoreDialogPrivate::setupDialog()
void KScoreDialogPrivate::setupDialog()
{
nrCols = 1;
for(int field = 1; field < fields; field = field * 2)
......@@ -251,7 +249,7 @@ void KScoreDialog::KScoreDialogPrivate::setupDialog()
}
}
void KScoreDialog::KScoreDialogPrivate::setupGroup(const QByteArray& groupKey)
void KScoreDialogPrivate::setupGroup(const QByteArray& groupKey)
{
if (hiddenGroups.contains(groupKey))
return;
......@@ -285,7 +283,7 @@ void KScoreDialog::KScoreDialogPrivate::setupGroup(const QByteArray& groupKey)
{
layout->addItem( new QSpacerItem( 50, 0 ), 0, col[field] );
label = new QLabel(header[field], widget);
layout->addWidget(label, 3, col[field], field <= Name ? Qt::AlignLeft : Qt::AlignRight);
layout->addWidget(label, 3, col[field], field <= KScoreDialog::Name ? Qt::AlignLeft : Qt::AlignRight);
label->setFont(bold);
}
}
......@@ -301,18 +299,17 @@ void KScoreDialog::KScoreDialogPrivate::setupGroup(const QByteArray& groupKey)
label = new QLabel(i18nc("Enumeration (#1, #2 ...) of the highscore entries", "#%1", num), widget);
labels[groupKey].insert((i-1)*nrCols + 0, label); //Fill up column zero
layout->addWidget(label, i+4, 0);
if (fields & Name) //If we have a Name field
if (fields & KScoreDialog::Name) //If we have a Name field
{
QStackedWidget *localStack = new QStackedWidget(widget);
stack[groupKey].insert(i-1, localStack);
layout->addWidget(localStack, i+4, col[Name]);
layout->addWidget(localStack, i+4, col[KScoreDialog::Name]);
label = new QLabel(localStack);
labels[groupKey].insert((i-1)*nrCols + col[Name], label);
labels[groupKey].insert((i-1)*nrCols + col[KScoreDialog::Name], label);
localStack->addWidget(label);
localStack->setCurrentWidget(label);
}
for(int field = Name * 2; field < fields; field = field * 2)
{
for (int field = KScoreDialog::Name * 2; field < fields; field = field * 2) {
if ( (fields & field) && !(hiddenFields & field ) ) //Maybe disable for Name?
{
label = new QLabel(widget);
......@@ -326,7 +323,7 @@ void KScoreDialog::KScoreDialogPrivate::setupGroup(const QByteArray& groupKey)
/*
Fill the dialog with the correct data
*/
void KScoreDialog::KScoreDialogPrivate::aboutToShow()
void KScoreDialogPrivate::aboutToShow()
{
if (!loaded)
loadScores();
......@@ -383,14 +380,14 @@ void KScoreDialog::KScoreDialogPrivate::aboutToShow()
//qCDebug(GAMES_HIGHSCORE) << "groupName:" << groupName << "id:" << i-1;
FieldInfo score = scores[groupKey].at(i-1);
KScoreDialog::FieldInfo score = scores[groupKey].at(i-1);
label = labels[groupKey].at((i-1)*nrCols + 0); //crash! FIXME
if ( (i == latest.second) && (groupKey == latest.first) )
label->setFont(bold);
else
label->setFont(normal);
if (fields & Name)
if (fields & KScoreDialog::Name)
{
if ( (newName.second == i) && (groupKey == newName.first) )
{
......@@ -400,20 +397,20 @@ void KScoreDialog::KScoreDialogPrivate::aboutToShow()
localStack->addWidget(edit);
localStack->setCurrentWidget(edit);
edit->setFocus();
connect(edit, &KLineEdit::returnPressed, q, &KScoreDialog::slotGotReturn);
QObject::connect(edit, &KLineEdit::returnPressed, q, &KScoreDialog::slotGotReturn);
}
else
{
label = labels[groupKey].at((i-1)*nrCols + col[Name]);
label = labels[groupKey].at((i-1)*nrCols + col[KScoreDialog::Name]);
if ( (i == latest.second) && (groupKey == latest.first) )
label->setFont(bold);
else
label->setFont(normal);
label->setText(score[Name]);
label->setText(score[KScoreDialog::Name]);
}
}
for(int field = Name * 2; field < fields; field = field * 2)
for(int field = KScoreDialog::Name * 2; field < fields; field = field * 2)
{
if ( (fields & field) && !(hiddenFields & field ) )
{
......@@ -437,7 +434,7 @@ void KScoreDialog::KScoreDialogPrivate::aboutToShow()
q->setFixedSize(q->minimumSizeHint()); //NOTE Remove this line to make dialog resizable
}
void KScoreDialog::KScoreDialogPrivate::loadScores()
void KScoreDialogPrivate::loadScores()
{
scores.clear();
......@@ -463,7 +460,7 @@ void KScoreDialog::KScoreDialogPrivate::loadScores()
for (int i = 1; i <= 10; ++i)
{
FieldInfo score;
KScoreDialog::FieldInfo score;
for(int field = 1; field < fields; field = field * 2)
{
if (fields & field)
......@@ -477,7 +474,7 @@ void KScoreDialog::KScoreDialogPrivate::loadScores()
highscoreObject->setHighscoreGroup(QLatin1String( tempCurrentGroup )); //reset to the user-set group name
const auto groupKeys = scores.keys();
for (const QByteArray &groupKey : groupKeys) {
if( (scores[groupKey][0].value(Score)==QLatin1String( "-" )) && (scores.size() > 1) && (latest.first != groupKey) )
if( (scores[groupKey][0].value(KScoreDialog::Score)==QLatin1String( "-" )) && (scores.size() > 1) && (latest.first != groupKey) )
{
qCDebug(GAMES_HIGHSCORE) << "Removing group " << groupKey << " since it's unused.";
scores.remove(groupKey);
......@@ -486,7 +483,7 @@ void KScoreDialog::KScoreDialogPrivate::loadScores()
loaded = true;
}
void KScoreDialog::KScoreDialogPrivate::saveScores()
void KScoreDialogPrivate::saveScores()
{
highscoreObject->setHighscoreGroup(QLatin1String( configGroup ));
......@@ -494,7 +491,7 @@ void KScoreDialog::KScoreDialogPrivate::saveScores()
for (int i = 1; i <= 10; ++i)
{
FieldInfo score = scores[configGroup].at(i-1);
KScoreDialog::FieldInfo score = scores[configGroup].at(i-1);
for(int field = 1; field < fields; field = field * 2)
{
if (fields & field)
......
......@@ -16,6 +16,8 @@
#include <QFlags>
#include <QDialogButtonBox>
#include <QDialog>
// Std
#include <memory>
class KgDifficulty;
......@@ -262,8 +264,8 @@ class KDEGAMES_EXPORT KScoreDialog : public QDialog
void keyPressEvent(QKeyEvent *ev) override;
private:
class KScoreDialogPrivate;
KScoreDialogPrivate* const d;
friend class KScoreDialogPrivate;
std::unique_ptr<class KScoreDialogPrivate> const d;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(KScoreDialog::AddScoreFlags)
......
......@@ -28,25 +28,27 @@
//BEGIN KgDifficultyLevel
class Q_DECL_HIDDEN KgDifficultyLevel::Private
class KgDifficultyLevelPrivate
{
public:
bool m_isDefault;
int m_hardness;
StandardLevel m_level;
KgDifficultyLevel::StandardLevel m_level;
QByteArray m_key;
QString m_title;
Private(int hardness, const QByteArray& key, const QString& title, StandardLevel level, bool isDefault);
static Private* fromStandardLevel(StandardLevel level, bool isDefault);
KgDifficultyLevelPrivate(int hardness, const QByteArray& key, const QString& title,
KgDifficultyLevel::StandardLevel level, bool isDefault);
static KgDifficultyLevelPrivate* fromStandardLevel(KgDifficultyLevel::StandardLevel level, bool isDefault);
};
KgDifficultyLevel::KgDifficultyLevel(int hardness, const QByteArray& key, const QString& title, bool isDefault)
: d(new Private(hardness, key, title, Custom, isDefault))
: d(new KgDifficultyLevelPrivate(hardness, key, title, Custom, isDefault))
{
}
KgDifficultyLevel::Private::Private(int hardness, const QByteArray& key, const QString& title, StandardLevel level, bool isDefault)
KgDifficultyLevelPrivate::KgDifficultyLevelPrivate(int hardness, const QByteArray& key, const QString& title,
KgDifficultyLevel::StandardLevel level, bool isDefault)
: m_isDefault(isDefault)
, m_hardness(hardness)
, m_level(level)
......@@ -56,13 +58,13 @@ KgDifficultyLevel::Private::Private(int hardness, const QByteArray& key, const Q
}
KgDifficultyLevel::KgDifficultyLevel(StandardLevel level, bool isDefault)
: d(Private::fromStandardLevel(level, isDefault))
: d(KgDifficultyLevelPrivate::fromStandardLevel(level, isDefault))
{
}
KgDifficultyLevel::Private* KgDifficultyLevel::Private::fromStandardLevel(KgDifficultyLevel::StandardLevel level, bool isDefault)
KgDifficultyLevelPrivate* KgDifficultyLevelPrivate::fromStandardLevel(KgDifficultyLevel::StandardLevel level, bool isDefault)
{
Q_ASSERT_X(level != Custom,
Q_ASSERT_X(level != KgDifficultyLevel::Custom,
"KgDifficultyLevel(StandardLevel) constructor",
"Custom level not allowed here"
);
......@@ -70,40 +72,37 @@ KgDifficultyLevel::Private* KgDifficultyLevel::Private::fromStandardLevel(KgDiff
QPair<QByteArray, QString> data;
switch (level)
{
case RidiculouslyEasy:
case KgDifficultyLevel::RidiculouslyEasy:
data = qMakePair(QByteArray("Ridiculously Easy"), i18nc("Game difficulty level 1 out of 8", "Ridiculously Easy"));
break;
case VeryEasy:
case KgDifficultyLevel::VeryEasy:
data = qMakePair(QByteArray("Very Easy"), i18nc("Game difficulty level 2 out of 8", "Very Easy"));
break;
case Easy:
case KgDifficultyLevel::Easy:
data = qMakePair(QByteArray("Easy"), i18nc("Game difficulty level 3 out of 8", "Easy"));
break;
case Medium:
case KgDifficultyLevel::Medium:
data = qMakePair(QByteArray("Medium"), i18nc("Game difficulty level 4 out of 8", "Medium"));
break;
case Hard:
case KgDifficultyLevel::Hard:
data = qMakePair(QByteArray("Hard"), i18nc("Game difficulty level 5 out of 8", "Hard"));
break;
case VeryHard:
case KgDifficultyLevel::VeryHard:
data = qMakePair(QByteArray("Very Hard"), i18nc("Game difficulty level 6 out of 8", "Very Hard"));
break;
case ExtremelyHard:
case KgDifficultyLevel::ExtremelyHard:
data = qMakePair(QByteArray("Extremely Hard"), i18nc("Game difficulty level 7 out of 8", "Extremely Hard"));
break;
case Impossible:
case KgDifficultyLevel::Impossible:
data = qMakePair(QByteArray("Impossible"), i18nc("Game difficulty level 8 out of 8", "Impossible"));
break;
case Custom:
case KgDifficultyLevel::Custom:
return nullptr;
}
return new KgDifficultyLevel::Private(level, data.first, data.second, level, isDefault);
return new KgDifficultyLevelPrivate(level, data.first, data.second, level, isDefault);
}
KgDifficultyLevel::~KgDifficultyLevel()
{
delete d;
}
KgDifficultyLevel::~KgDifficultyLevel() = default;
bool KgDifficultyLevel::isDefault() const
{
......@@ -133,14 +132,14 @@ KgDifficultyLevel::StandardLevel KgDifficultyLevel::standardLevel() const
//END KgDifficultyLevel
//BEGIN KgDifficulty
class Q_DECL_HIDDEN KgDifficulty::Private
class KgDifficultyPrivate
{
public:
QList<const KgDifficultyLevel*> m_levels;
const KgDifficultyLevel* m_currentLevel;
bool m_editable, m_gameRunning;
Private() : m_currentLevel(nullptr), m_editable(true), m_gameRunning(false) {}
KgDifficultyPrivate() : m_currentLevel(nullptr), m_editable(true), m_gameRunning(false) {}
};
static void saveLevel()
......@@ -154,7 +153,7 @@ static void saveLevel()
KgDifficulty::KgDifficulty(QObject* parent)
: QObject(parent)
, d(new Private)
, d(new KgDifficultyPrivate)
{
qRegisterMetaType<const KgDifficultyLevel*>();
qAddPostRoutine(saveLevel);
......
......@@ -14,6 +14,8 @@
// Qt
#include <QMetaType>
#include <QObject>
// Std
#include <memory>
/**
* @class KgDifficultyLevel kgdifficulty.h <KgDifficultyLevel>
......@@ -64,8 +66,7 @@ class KDEGAMES_EXPORT KgDifficultyLevel : public QObject
/// KgDifficultyLevel::Custom for custom levels
StandardLevel standardLevel() const;
private:
class Private;
Private* const d;
std::unique_ptr<class KgDifficultyLevelPrivate> const d;
};
/**
......@@ -157,8 +158,7 @@ class KDEGAMES_EXPORT KgDifficulty : public QObject
///confirmation before the new difficulty level is selected.
void select(const KgDifficultyLevel* level);
private:
class Private;
Private* const d;
std::unique_ptr<class KgDifficultyPrivate> const d;
};
Q_DECLARE_METATYPE(const KgDifficultyLevel*)
......
......@@ -16,30 +16,27 @@
Q_LOGGING_CATEGORY(GAMES_LIB, "org.kde.games.lib", QtWarningMsg)
class Q_DECL_HIDDEN KgTheme::Private
class KgThemePrivate
{
public:
const QByteArray m_identifier;
QString m_name, m_description, m_author, m_authorEmail, m_graphicsPath, m_previewPath;
QMap<QString, QString> m_customData;
Private(const QByteArray& id) : m_identifier(id) {}
KgThemePrivate(const QByteArray& id) : m_identifier(id) {}
static QStringList s_configGroupNames;
};
/*static*/ QStringList KgTheme::Private::s_configGroupNames;
/*static*/ QStringList KgThemePrivate::s_configGroupNames;
KgTheme::KgTheme(const QByteArray& identifier, QObject* parent)
: QObject(parent)
, d(new Private(identifier))
, d(new KgThemePrivate(identifier))
{
}
KgTheme::~KgTheme()
{
delete d;
}
KgTheme::~KgTheme() = default;
QByteArray KgTheme::identifier() const
{
......@@ -91,14 +88,14 @@ bool KgTheme::readFromDesktopFile(const QString& path_)
}
}
//default group name
if (Private::s_configGroupNames.isEmpty())
if (KgThemePrivate::s_configGroupNames.isEmpty())
{
Private::s_configGroupNames << QStringLiteral("KGameTheme");
KgThemePrivate::s_configGroupNames << QStringLiteral("KGameTheme");
}
//open file, look for a known config group
KConfig config(path, KConfig::SimpleConfig);
KConfigGroup group;
for (const QString& groupName : qAsConst(Private::s_configGroupNames)) {
for (const QString& groupName : qAsConst(KgThemePrivate::s_configGroupNames)) {
if (config.hasGroup(groupName))
{
group = config.group(groupName);
......
......@@ -14,6 +14,8 @@
#include <QObject>
#include <QLoggingCategory>
#include <QPixmap>
// Std
#include <memory>
/**
* @class KgTheme kgtheme.h <KgTheme>
......@@ -127,8 +129,7 @@ class KDEGAMES_EXPORT KgTheme : public QObject
///complain about properties without NOTIFY signals, even readonly ones.
void readOnlyProperty();
private:
class Private;
Private* const d;
std::unique_ptr<class KgThemePrivate> const d;
};
Q_DECLARE_METATYPE(const KgTheme*)
......
......@@ -16,7 +16,7 @@
#include <QStandardPaths>
#include <QGuiApplication>
class Q_DECL_HIDDEN KgThemeProvider::Private
class KgThemeProviderPrivate
{
public:
KgThemeProvider *q;
......@@ -35,7 +35,13 @@ class Q_DECL_HIDDEN KgThemeProvider::Private
//this disables the addTheme() lock during rediscoverThemes()
bool m_inRediscover;
Private(KgThemeProvider *parent, const QByteArray& key) : q(parent), m_configKey(key), m_currentTheme(nullptr), m_defaultTheme(nullptr), m_inRediscover(false) {}
KgThemeProviderPrivate(KgThemeProvider *parent, const QByteArray& key)
: q(parent)
, m_configKey(key)
, m_currentTheme(nullptr)
, m_defaultTheme(nullptr)
, m_inRediscover(false)
{}
void updateThemeName()
{
......@@ -45,7 +51,7 @@ class Q_DECL_HIDDEN KgThemeProvider::Private
KgThemeProvider::KgThemeProvider(const QByteArray& configKey, QObject* parent)
: QObject(parent)
, d(new Private(this, configKey))
, d(new KgThemeProviderPrivate(this, configKey))
{
qRegisterMetaType<const KgTheme*>();
qRegisterMetaType<KgThemeProvider*>();
......@@ -71,7 +77,6 @@ KgThemeProvider::~KgThemeProvider()
{
delete const_cast<KgTheme*>(d->m_themes.takeFirst());
}
delete d;
}
}
......
......@@ -16,6 +16,8 @@
#include <QQmlContext>
#include <QDir>
#include <QPointer>
// Std
#include <memory>
/**
* @class KgThemeProvider kgthemeprovider.h <KgThemeProvider>
......@@ -130,8 +132,7 @@ class KDEGAMES_EXPORT KgThemeProvider : public QObject
///this instance.
void setCurrentTheme(const KgTheme* theme);
private:
class Private;
Private* const d;
std::unique_ptr<class KgThemeProviderPrivate> const d;
};
Q_DECLARE_METATYPE(KgThemeProvider*)
......
......@@ -33,18 +33,23 @@ namespace Metrics
//BEGIN KgThemeSelector
class Q_DECL_HIDDEN KgThemeSelector::Private
class KgThemeSelectorPrivate
{
public:
KgThemeSelector* q;
KgThemeProvider* m_provider;
Options m_options;
KgThemeSelector::Options m_options;
QListWidget* m_list;
QPushButton* m_knsButton;
void fillList();
Private(KgThemeProvider* provider, Options options, KgThemeSelector* q) : q(q), m_provider(provider), m_options(options), m_knsButton(nullptr) {}
KgThemeSelectorPrivate(KgThemeProvider* provider, KgThemeSelector::Options options, KgThemeSelector* q)
: q(q)
, m_provider(provider)
, m_options(options)
, m_knsButton(nullptr)
{}
void _k_updateListSelection(const KgTheme* theme);
void _k_updateProviderSelection();
......@@ -53,7 +58,7 @@ class Q_DECL_HIDDEN KgThemeSelector::Private
KgThemeSelector::KgThemeSelector(KgThemeProvider* provider, Options options, QWidget* parent)
: QWidget(parent)
, d(new Private(provider, options, this))
, d(new KgThemeSelectorPrivate(provider, options, this))
{
d->m_list = new QListWidget(this);
d->m_list->setSelectionMode(QAbstractItemView::SingleSelection);
......@@ -86,12 +91,9 @@ KgThemeSelector::KgThemeSelector(KgThemeProvider* provider, Options options, QWi
}
KgThemeSelector::~KgThemeSelector()
{
delete d;
}
KgThemeSelector::~KgThemeSelector() = default;
void KgThemeSelector::Private::fillList()
void KgThemeSelectorPrivate::fillList()
{
m_list->clear();
const auto themes = m_provider->themes();
......@@ -107,7 +109,7 @@ void KgThemeSelector::Private::fillList()
_k_updateListSelection(m_provider->currentTheme());
}
void KgThemeSelector::Private::_k_updateListSelection(const KgTheme* theme)