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

kdevplatform/language/codegen: use Q_DECLARE_PRIVATE/Q_D to forward constness to d

parent b70de6dd
......@@ -65,8 +65,10 @@ public:
ApplyChangesWidget::ApplyChangesWidget(QWidget* parent)
: QDialog(parent)
, d(new ApplyChangesWidgetPrivate(this))
, d_ptr(new ApplyChangesWidgetPrivate(this))
{
Q_D(ApplyChangesWidget);
setSizeGripEnabled(true);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
......@@ -97,21 +99,29 @@ ApplyChangesWidget::~ApplyChangesWidget() = default;
bool ApplyChangesWidget::hasDocuments() const
{
Q_D(const ApplyChangesWidget);
return d->m_editParts.size() > 0;
}
KTextEditor::Document* ApplyChangesWidget::document() const
{
return qobject_cast<KTextEditor::Document*>(d->m_editParts[d->m_index]);
Q_D(const ApplyChangesWidget);
return qobject_cast<KTextEditor::Document*>(d->m_editParts.value(d->m_index));
}
void ApplyChangesWidget::setInformation(const QString& info)
{
Q_D(ApplyChangesWidget);
d->m_info->setText(info);
}
void ApplyChangesWidget::addDocuments(const IndexedString& original)
{
Q_D(ApplyChangesWidget);
int idx = d->m_files.indexOf(original);
if (idx < 0) {
QWidget* w = new QWidget;
......@@ -127,6 +137,8 @@ void ApplyChangesWidget::addDocuments(const IndexedString& original)
bool ApplyChangesWidget::applyAllChanges()
{
Q_D(ApplyChangesWidget);
/// @todo implement safeguard in case a file saving fails
bool ret = true;
......@@ -188,12 +200,16 @@ void ApplyChangesWidgetPrivate::createEditPart(const IndexedString& file)
void ApplyChangesWidget::indexChanged(int newIndex)
{
Q_D(ApplyChangesWidget);
Q_ASSERT(newIndex != -1);
d->m_index = newIndex;
}
void ApplyChangesWidget::updateDiffView(int index)
{
Q_D(ApplyChangesWidget);
d->m_index = index == -1 ? d->m_index : index;
}
}
......@@ -29,6 +29,7 @@ class Document;
namespace KDevelop {
class IndexedString;
class ApplyChangesWidgetPrivate;
class KDEVPLATFORMLANGUAGE_EXPORT ApplyChangesWidget
: public QDialog
......@@ -60,7 +61,8 @@ public Q_SLOTS:
void indexChanged(int);
private:
const QScopedPointer<class ApplyChangesWidgetPrivate> d;
const QScopedPointer<class ApplyChangesWidgetPrivate> d_ptr;
Q_DECLARE_PRIVATE(ApplyChangesWidget)
};
}
......
......@@ -38,7 +38,7 @@ ArchiveTemplateLoader* ArchiveTemplateLoader::self()
}
ArchiveTemplateLoader::ArchiveTemplateLoader()
: d(new ArchiveTemplateLoaderPrivate)
: d_ptr(new ArchiveTemplateLoaderPrivate)
{
}
......@@ -46,16 +46,22 @@ ArchiveTemplateLoader::~ArchiveTemplateLoader() = default;
void ArchiveTemplateLoader::addLocation(ArchiveTemplateLocation* location)
{
Q_D(ArchiveTemplateLoader);
d->locations.append(location);
}
void ArchiveTemplateLoader::removeLocation(ArchiveTemplateLocation* location)
{
Q_D(ArchiveTemplateLoader);
d->locations.removeOne(location);
}
bool ArchiveTemplateLoader::canLoadTemplate(const QString& name) const
{
Q_D(const ArchiveTemplateLoader);
return std::any_of(d->locations.constBegin(), d->locations.constEnd(), [&](ArchiveTemplateLocation* location) {
return (location->hasTemplate(name));
});
......@@ -63,6 +69,8 @@ bool ArchiveTemplateLoader::canLoadTemplate(const QString& name) const
Grantlee::Template ArchiveTemplateLoader::loadByName(const QString& name, const Grantlee::Engine* engine) const
{
Q_D(const ArchiveTemplateLoader);
for (ArchiveTemplateLocation* location : qAsConst(d->locations)) {
if (location->hasTemplate(name)) {
return engine->newTemplate(location->templateContents(name), name);
......
......@@ -25,6 +25,7 @@
class KArchiveDirectory;
namespace KDevelop {
class ArchiveTemplateLocation;
class ArchiveTemplateLoaderPrivate;
class ArchiveTemplateLoader
: public Grantlee::AbstractTemplateLoader
......@@ -46,7 +47,8 @@ private:
Q_DISABLE_COPY(ArchiveTemplateLoader)
ArchiveTemplateLoader();
const QScopedPointer<class ArchiveTemplateLoaderPrivate> d;
const QScopedPointer<class ArchiveTemplateLoaderPrivate> d_ptr;
Q_DECLARE_PRIVATE(ArchiveTemplateLoader)
};
/**
......
......@@ -33,11 +33,11 @@
#include <debug.h>
namespace KDevelop {
class CodeGeneratorPrivate
class CodeGeneratorBasePrivate
{
public:
CodeGeneratorPrivate() : autoGen(false)
CodeGeneratorBasePrivate() : autoGen(false)
, context(0) {}
QMap<IndexedString, DUChainChangeSet*> duchainChanges;
......@@ -50,7 +50,7 @@ public:
};
CodeGeneratorBase::CodeGeneratorBase()
: d(new CodeGeneratorPrivate)
: d_ptr(new CodeGeneratorBasePrivate)
{
}
......@@ -61,6 +61,8 @@ CodeGeneratorBase::~CodeGeneratorBase()
void CodeGeneratorBase::autoGenerate(DUContext* context, const KDevelop::DocumentRange* range)
{
Q_D(CodeGeneratorBase);
d->autoGen = true;
d->context = context;
d->range = *range;
......@@ -68,6 +70,8 @@ void CodeGeneratorBase::autoGenerate(DUContext* context, const KDevelop::Documen
void CodeGeneratorBase::addChangeSet(DUChainChangeSet* duchainChange)
{
Q_D(CodeGeneratorBase);
IndexedString file = duchainChange->topDuContext().data()->url();
QMap<IndexedString, DUChainChangeSet*>::iterator it = d->duchainChanges.find(file);
......@@ -82,31 +86,43 @@ void CodeGeneratorBase::addChangeSet(DUChainChangeSet* duchainChange)
void CodeGeneratorBase::addChangeSet(DocumentChangeSet& docChangeSet)
{
Q_D(CodeGeneratorBase);
d->documentChanges << docChangeSet;
}
DocumentChangeSet& CodeGeneratorBase::documentChangeSet()
{
Q_D(CodeGeneratorBase);
return d->documentChanges;
}
const QString& CodeGeneratorBase::errorText() const
{
Q_D(const CodeGeneratorBase);
return d->error;
}
bool CodeGeneratorBase::autoGeneration() const
{
Q_D(const CodeGeneratorBase);
return d->autoGen;
}
void CodeGeneratorBase::setErrorText(const QString& errorText)
{
Q_D(CodeGeneratorBase);
d->error = errorText;
}
void CodeGeneratorBase::clearChangeSets()
{
Q_D(CodeGeneratorBase);
qCDebug(LANGUAGE) << "Cleaning up all the changesets registered by the generator";
qDeleteAll(d->duchainChanges);
......@@ -117,6 +133,8 @@ void CodeGeneratorBase::clearChangeSets()
bool CodeGeneratorBase::execute()
{
Q_D(CodeGeneratorBase);
qCDebug(LANGUAGE) << "Checking Preconditions for the codegenerator";
//Shouldn't there be a method in iDocument to get a DocumentRange as well?
......@@ -198,6 +216,8 @@ bool CodeGeneratorBase::execute()
bool CodeGeneratorBase::displayChanges()
{
Q_D(CodeGeneratorBase);
DocumentChangeSet::ChangeResult result = d->documentChanges.applyAllToTemp();
if (!result) {
setErrorText(result.m_failureReason);
......
......@@ -32,6 +32,7 @@ class DUContext;
class DUChainChangeSet;
class DocumentChangeSet;
class DocumentRange;
class CodeGeneratorBasePrivate;
/**
* \short Base class for generic code generators
......@@ -137,7 +138,8 @@ private:
bool displayChanges();
private:
const QScopedPointer<class CodeGeneratorPrivate> d;
const QScopedPointer<class CodeGeneratorBasePrivate> d_ptr;
Q_DECLARE_PRIVATE(CodeGeneratorBase)
};
/**
......
......@@ -130,8 +130,10 @@ static QString printRange(const KTextEditor::Range& r)
}
DocumentChangeSet::DocumentChangeSet()
: d(new DocumentChangeSetPrivate)
: d_ptr(new DocumentChangeSetPrivate)
{
Q_D(DocumentChangeSet);
d->replacePolicy = StopOnFailedChange;
d->formatPolicy = AutoFormatChanges;
d->updatePolicy = SimpleUpdate;
......@@ -139,13 +141,13 @@ DocumentChangeSet::DocumentChangeSet()
}
DocumentChangeSet::DocumentChangeSet(const DocumentChangeSet& rhs)
: d(new DocumentChangeSetPrivate(*rhs.d))
: d_ptr(new DocumentChangeSetPrivate(*rhs.d_ptr))
{
}
DocumentChangeSet& DocumentChangeSet::operator=(const DocumentChangeSet& rhs)
{
*d = *rhs.d;
*d_ptr = *rhs.d_ptr;
return *this;
}
......@@ -153,17 +155,23 @@ DocumentChangeSet::~DocumentChangeSet() = default;
DocumentChangeSet::ChangeResult DocumentChangeSet::addChange(const DocumentChange& change)
{
Q_D(DocumentChangeSet);
return d->addChange(DocumentChangePointer(new DocumentChange(change)));
}
DocumentChangeSet::ChangeResult DocumentChangeSet::addChange(const DocumentChangePointer& change)
{
Q_D(DocumentChangeSet);
return d->addChange(change);
}
DocumentChangeSet::ChangeResult DocumentChangeSet::addDocumentRenameChange(const IndexedString& oldFile,
const IndexedString& newname)
{
Q_D(DocumentChangeSet);
d->documentsRename.insert(oldFile, newname);
return DocumentChangeSet::ChangeResult::successfulResult();
}
......@@ -176,26 +184,36 @@ DocumentChangeSet::ChangeResult DocumentChangeSetPrivate::addChange(const Docume
void DocumentChangeSet::setReplacementPolicy(DocumentChangeSet::ReplacementPolicy policy)
{
Q_D(DocumentChangeSet);
d->replacePolicy = policy;
}
void DocumentChangeSet::setFormatPolicy(DocumentChangeSet::FormatPolicy policy)
{
Q_D(DocumentChangeSet);
d->formatPolicy = policy;
}
void DocumentChangeSet::setUpdateHandling(DocumentChangeSet::DUChainUpdateHandling policy)
{
Q_D(DocumentChangeSet);
d->updatePolicy = policy;
}
void DocumentChangeSet::setActivationPolicy(DocumentChangeSet::ActivationPolicy policy)
{
Q_D(DocumentChangeSet);
d->activationPolicy = policy;
}
DocumentChangeSet::ChangeResult DocumentChangeSet::applyAllChanges()
{
Q_D(DocumentChangeSet);
QUrl oldActiveDoc;
if (IDocument* activeDoc = ICore::self()->documentController()->activeDocument()) {
oldActiveDoc = activeDoc->url();
......
......@@ -29,6 +29,8 @@
#include <QUrl>
namespace KDevelop {
class DocumentChangeSetPrivate;
class KDEVPLATFORMLANGUAGE_EXPORT DocumentChange
: public QSharedData
{
......@@ -147,7 +149,8 @@ private:
ChangeResult applyAllChanges();
private:
const QScopedPointer<class DocumentChangeSetPrivate> d;
const QScopedPointer<class DocumentChangeSetPrivate> d_ptr;
Q_DECLARE_PRIVATE(DocumentChangeSet)
};
}
......
......@@ -45,11 +45,11 @@ public:
QString descriptionFileName;
QStringList searchLocations;
ConfigOption readEntry(const QDomElement& element, TemplateRenderer* renderer);
ConfigOption readEntry(const QDomElement& element, TemplateRenderer* renderer) const;
};
ConfigOption SourceFileTemplatePrivate::readEntry(const QDomElement& element,
TemplateRenderer* renderer)
TemplateRenderer* renderer) const
{
ConfigOption entry;
......@@ -109,53 +109,65 @@ ConfigOption SourceFileTemplatePrivate::readEntry(const QDomElement& element,
}
SourceFileTemplate::SourceFileTemplate (const QString& templateDescription)
: d(new KDevelop::SourceFileTemplatePrivate)
: d_ptr(new KDevelop::SourceFileTemplatePrivate)
{
Q_D(SourceFileTemplate);
d->archive = nullptr;
setTemplateDescription(templateDescription);
}
SourceFileTemplate::SourceFileTemplate()
: d(new KDevelop::SourceFileTemplatePrivate)
: d_ptr(new KDevelop::SourceFileTemplatePrivate)
{
Q_D(SourceFileTemplate);
d->archive = nullptr;
}
SourceFileTemplate::SourceFileTemplate (const SourceFileTemplate& other)
: d(new KDevelop::SourceFileTemplatePrivate)
: d_ptr(new KDevelop::SourceFileTemplatePrivate)
{
Q_D(SourceFileTemplate);
d->archive = nullptr;
*this = other;
}
SourceFileTemplate::~SourceFileTemplate()
{
Q_D(SourceFileTemplate);
delete d->archive;
}
SourceFileTemplate& SourceFileTemplate::operator=(const SourceFileTemplate& other)
{
if (other.d == d) {
Q_D(SourceFileTemplate);
if (other.d_ptr == d_ptr) {
return *this;
}
delete d->archive;
if (other.d->archive) {
if (other.d->archive->fileName().endsWith(QLatin1String(".zip"))) {
d->archive = new KZip(other.d->archive->fileName());
if (other.d_ptr->archive) {
if (other.d_ptr->archive->fileName().endsWith(QLatin1String(".zip"))) {
d->archive = new KZip(other.d_ptr->archive->fileName());
} else {
d->archive = new KTar(other.d->archive->fileName());
d->archive = new KTar(other.d_ptr->archive->fileName());
}
d->archive->open(QIODevice::ReadOnly);
} else {
d->archive = nullptr;
}
d->descriptionFileName = other.d->descriptionFileName;
d->descriptionFileName = other.d_ptr->descriptionFileName;
return *this;
}
void SourceFileTemplate::setTemplateDescription(const QString& templateDescription)
{
Q_D(SourceFileTemplate);
delete d->archive;
d->descriptionFileName = templateDescription;
......@@ -196,11 +208,15 @@ void SourceFileTemplate::setTemplateDescription(const QString& templateDescripti
bool SourceFileTemplate::isValid() const
{
Q_D(const SourceFileTemplate);
return d->archive;
}
QString SourceFileTemplate::name() const
{
Q_D(const SourceFileTemplate);
KConfig templateConfig(d->descriptionFileName);
KConfigGroup cg(&templateConfig, "General");
return cg.readEntry("Name");
......@@ -208,6 +224,8 @@ QString SourceFileTemplate::name() const
QString SourceFileTemplate::type() const
{
Q_D(const SourceFileTemplate);
KConfig templateConfig(d->descriptionFileName);
KConfigGroup cg(&templateConfig, "General");
return cg.readEntry("Type", QString());
......@@ -215,6 +233,8 @@ QString SourceFileTemplate::type() const
QString SourceFileTemplate::languageName() const
{
Q_D(const SourceFileTemplate);
KConfig templateConfig(d->descriptionFileName);
KConfigGroup cg(&templateConfig, "General");
return cg.readEntry("Language", QString());
......@@ -222,6 +242,8 @@ QString SourceFileTemplate::languageName() const
QStringList SourceFileTemplate::category() const
{
Q_D(const SourceFileTemplate);
KConfig templateConfig(d->descriptionFileName);
KConfigGroup cg(&templateConfig, "General");
return cg.readEntry("Category", QStringList());
......@@ -229,6 +251,8 @@ QStringList SourceFileTemplate::category() const
QStringList SourceFileTemplate::defaultBaseClasses() const
{
Q_D(const SourceFileTemplate);
KConfig templateConfig(d->descriptionFileName);
KConfigGroup cg(&templateConfig, "General");
return cg.readEntry("BaseClasses", QStringList());
......@@ -236,12 +260,16 @@ QStringList SourceFileTemplate::defaultBaseClasses() const
const KArchiveDirectory* SourceFileTemplate::directory() const
{
Q_D(const SourceFileTemplate);
Q_ASSERT(isValid());
return d->archive->directory();
}
QVector<SourceFileTemplate::OutputFile> SourceFileTemplate::outputFiles() const
{
Q_D(const SourceFileTemplate);
QVector<SourceFileTemplate::OutputFile> outputFiles;
KConfig templateConfig(d->descriptionFileName);
......@@ -266,6 +294,8 @@ QVector<SourceFileTemplate::OutputFile> SourceFileTemplate::outputFiles() const
bool SourceFileTemplate::hasCustomOptions() const
{
Q_D(const SourceFileTemplate);
Q_ASSERT(isValid());
KConfig templateConfig(d->descriptionFileName);
......@@ -278,6 +308,8 @@ bool SourceFileTemplate::hasCustomOptions() const
QVector<SourceFileTemplate::ConfigOptionGroup> SourceFileTemplate::customOptions(TemplateRenderer* renderer) const
{
Q_D(const SourceFileTemplate);
Q_ASSERT(isValid());
KConfig templateConfig(d->descriptionFileName);
......@@ -332,6 +364,8 @@ QVector<SourceFileTemplate::ConfigOptionGroup> SourceFileTemplate::customOptions
void SourceFileTemplate::addAdditionalSearchLocation(const QString& location)
{
Q_D(SourceFileTemplate);
if (!d->searchLocations.contains(location))
d->searchLocations.append(location);
}
......@@ -33,6 +33,7 @@ class KArchiveDirectory;
namespace KDevelop {
class TemplateRenderer;
class SourceFileTemplatePrivate;
/**
* Represents a source file template archive
......@@ -326,7 +327,8 @@ public:
void addAdditionalSearchLocation(const QString& location);
private:
const QScopedPointer<class SourceFileTemplatePrivate> d;
const QScopedPointer<class SourceFileTemplatePrivate> d_ptr;
Q_DECLARE_PRIVATE(SourceFileTemplate)
};
}
......
......@@ -54,14 +54,16 @@ class KDevelop::TemplateClassGeneratorPrivate
public:
SourceFileTemplate fileTemplate;
QUrl baseUrl;
TemplateRenderer renderer;
// changes state when rendering
mutable TemplateRenderer renderer;
QString name;
QString identifier;
QStringList namespaces;
QString license;
QHash<QString, QUrl> fileUrls;
// lazily estimated
mutable QHash<QString, QUrl> fileUrls;
QHash<QString, KTextEditor::Cursor> filePositions;
ClassDescription description;
......@@ -96,8 +98,10 @@ void TemplateClassGeneratorPrivate::fetchSuperClasses(const DeclarationPointer&
}
TemplateClassGenerator::TemplateClassGenerator(const QUrl& baseUrl)
: d(new TemplateClassGeneratorPrivate)
: d_ptr(new TemplateClassGeneratorPrivate)
{
Q_D(TemplateClassGenerator);
Q_ASSERT(QFileInfo(baseUrl.toLocalFile()).isDir()); // assume folder
d->baseUrl = baseUrl;
......@@ -108,17 +112,23 @@ TemplateClassGenerator::~TemplateClassGenerator() = default;
void TemplateClassGenerator::setTemplateDescription(const SourceFileTemplate& fileTemplate)
{
Q_D(TemplateClassGenerator);
d->fileTemplate = fileTemplate;
Q_ASSERT(fileTemplate.isValid());
}
DocumentChangeSet TemplateClassGenerator::generate()
{
Q_D(TemplateClassGenerator);