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

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

parent c36e88bc
......@@ -60,8 +60,10 @@ public:
RenameAction::RenameAction(const Identifier& oldDeclarationName, const QString& newDeclarationName,
const QVector<RevisionedFileRanges>& oldDeclarationUses)
: d(new RenameActionPrivate)
: d_ptr(new RenameActionPrivate)
{
Q_D(RenameAction);
d->m_oldDeclarationName = oldDeclarationName;
d->m_newDeclarationName = newDeclarationName.trimmed();
d->m_oldDeclarationUses = oldDeclarationUses;
......@@ -73,21 +75,29 @@ RenameAction::~RenameAction()
QString RenameAction::description() const
{
Q_D(const RenameAction);
return i18n("Rename \"%1\" to \"%2\"", d->m_oldDeclarationName.toString(), d->m_newDeclarationName);
}
QString RenameAction::newDeclarationName() const
{
Q_D(const RenameAction);
return d->m_newDeclarationName;
}
QString RenameAction::oldDeclarationName() const
{
Q_D(const RenameAction);
return d->m_oldDeclarationName.toString();
}
void RenameAction::execute()
{
Q_D(RenameAction);
DocumentChangeSet changes;
for (const RevisionedFileRanges& ranges : qAsConst(d->m_oldDeclarationUses)) {
......
......@@ -27,6 +27,7 @@
namespace KDevelop {
class Identifier;
class RenameActionPrivate;
/**
* A HACK to circumvent the bad RangeInRevision API without rewriting everything.
......@@ -65,7 +66,8 @@ public:
QString oldDeclarationName() const;
private:
const QScopedPointer<class RenameActionPrivate> d;
const QScopedPointer<class RenameActionPrivate> d_ptr;
Q_DECLARE_PRIVATE(RenameAction)
};
}
......
......@@ -105,7 +105,7 @@ public:
RenameAssistant::RenameAssistant(ILanguageSupport* supportedLanguage)
: StaticAssistant(supportedLanguage)
, d(new RenameAssistantPrivate(this))
, d_ptr(new RenameAssistantPrivate(this))
{
}
......@@ -120,12 +120,16 @@ QString RenameAssistant::title() const
bool RenameAssistant::isUseful() const
{
Q_D(const RenameAssistant);
return d->m_isUseful;
}
void RenameAssistant::textChanged(KTextEditor::Document* doc, const KTextEditor::Range& invocationRange,
const QString& removedText)
{
Q_D(RenameAssistant);
clearActions();
d->m_lastChangedLocation = invocationRange.end();
d->m_lastChangedDocument = doc;
......@@ -222,7 +226,8 @@ void RenameAssistant::textChanged(KTextEditor::Document* doc, const KTextEditor:
} else {
action = new RenameAction(d->m_oldDeclarationName, d->m_newDeclarationName, d->m_oldDeclarationUses);
}
connect(action.data(), &IAssistantAction::executed, this, [&] {
connect(action.data(), &IAssistantAction::executed, this, [this] {
Q_D(RenameAssistant);
d->reset();
});
addAction(action);
......@@ -231,6 +236,8 @@ void RenameAssistant::textChanged(KTextEditor::Document* doc, const KTextEditor:
KTextEditor::Range KDevelop::RenameAssistant::displayRange() const
{
Q_D(const RenameAssistant);
if (!d->m_lastChangedDocument) {
return {};
}
......
......@@ -29,6 +29,8 @@ class View;
}
namespace KDevelop {
class RenameAssistantPrivate;
class KDEVPLATFORMLANGUAGE_EXPORT RenameAssistant
: public StaticAssistant
{
......@@ -46,7 +48,8 @@ public:
QString title() const override;
private:
const QScopedPointer<class RenameAssistantPrivate> d;
const QScopedPointer<class RenameAssistantPrivate> d_ptr;
Q_DECLARE_PRIVATE(RenameAssistant)
};
}
......
......@@ -41,8 +41,10 @@ public:
};
RenameFileAction::RenameFileAction(BasicRefactoring* refactoring, const QUrl& file, const QString& newName)
: d(new RenameFileActionPrivate)
: d_ptr(new RenameFileActionPrivate)
{
Q_D(RenameFileAction);
d->m_refactoring = refactoring;
d->m_file = file;
d->m_newName = newName;
......@@ -54,12 +56,16 @@ RenameFileAction::~RenameFileAction()
QString RenameFileAction::description() const
{
Q_D(const RenameFileAction);
return i18n("Rename file from \"%1\" to \"%2\".",
d->m_file.fileName(), d->m_refactoring->newFileName(d->m_file, d->m_newName));
}
void RenameFileAction::execute()
{
Q_D(RenameFileAction);
// save document to prevent unwanted dialogs
IDocument* doc = ICore::self()->documentController()->documentForUrl(d->m_file);
if (!doc) {
......
......@@ -27,6 +27,7 @@
namespace KDevelop {
class BasicRefactoring;
}
class RenameFileActionPrivate;
class RenameFileAction
: public KDevelop::IAssistantAction
......@@ -41,7 +42,8 @@ public:
void execute() override;
private:
const QScopedPointer<class RenameFileActionPrivate> d;
const QScopedPointer<class RenameFileActionPrivate> d_ptr;
Q_DECLARE_PRIVATE(RenameFileAction)
};
#endif // KDEVPLATFORM_RENAMEFILEACTION_H
......@@ -32,8 +32,10 @@ public:
};
StaticAssistant::StaticAssistant(ILanguageSupport* supportedLanguage)
: d(new StaticAssistantPrivate)
: d_ptr(new StaticAssistantPrivate)
{
Q_D(StaticAssistant);
d->m_supportedLanguage = supportedLanguage;
}
......@@ -43,5 +45,7 @@ StaticAssistant::~StaticAssistant()
ILanguageSupport* StaticAssistant::supportedLanguage() const
{
Q_D(const StaticAssistant);
return d->m_supportedLanguage;
}
......@@ -36,6 +36,7 @@ class Range;
namespace KDevelop {
class ILanguageSupport;
class StaticAssistantPrivate;
/**
* @brief This class serves as a base for long-living assistants
......@@ -94,7 +95,8 @@ public:
virtual void updateReady(const IndexedString&, const KDevelop::ReferencedTopDUContext&) { }
private:
const QScopedPointer<class StaticAssistantPrivate> d;
const QScopedPointer<class StaticAssistantPrivate> d_ptr;
Q_DECLARE_PRIVATE(StaticAssistant)
};
}
......
......@@ -58,11 +58,14 @@ public:
StaticAssistantsManager::StaticAssistantsManager(QObject* parent)
: QObject(parent)
, d(new StaticAssistantsManagerPrivate(this))
, d_ptr(new StaticAssistantsManagerPrivate(this))
{
Q_D(StaticAssistantsManager);
connect(KDevelop::ICore::self()->documentController(),
&IDocumentController::documentLoaded,
this, [&](IDocument* document) {
this, [this](IDocument* document) {
Q_D(StaticAssistantsManager);
d->documentLoaded(document);
});
const auto documents = ICore::self()->documentController()->openDocuments();
......@@ -80,6 +83,8 @@ StaticAssistantsManager::~StaticAssistantsManager()
void StaticAssistantsManager::registerAssistant(const StaticAssistant::Ptr& assistant)
{
Q_D(StaticAssistantsManager);
if (d->m_registeredAssistants.contains(assistant))
return;
......@@ -88,11 +93,15 @@ void StaticAssistantsManager::registerAssistant(const StaticAssistant::Ptr& assi
void StaticAssistantsManager::unregisterAssistant(const StaticAssistant::Ptr& assistant)
{
Q_D(StaticAssistantsManager);
d->m_registeredAssistants.removeOne(assistant);
}
QVector<StaticAssistant::Ptr> StaticAssistantsManager::registeredAssistants() const
{
Q_D(const StaticAssistantsManager);
return d->m_registeredAssistants;
}
......@@ -148,14 +157,18 @@ void StaticAssistantsManagerPrivate::textRemoved(Document* doc, const Range& ran
void StaticAssistantsManager::notifyAssistants(const IndexedString& url,
const KDevelop::ReferencedTopDUContext& context)
{
Q_D(StaticAssistantsManager);
for (auto& assistant : qAsConst(d->m_registeredAssistants)) {
assistant->updateReady(url, context);
}
}
QVector<KDevelop::Problem::Ptr> KDevelop::StaticAssistantsManager::problemsForContext(
const KDevelop::ReferencedTopDUContext& top)
const KDevelop::ReferencedTopDUContext& top) const
{
Q_D(const StaticAssistantsManager);
View* view = ICore::self()->documentController()->activeTextDocumentView();
if (!view || !top || IndexedString(view->document()->url()) != top->url()) {
return {};
......
......@@ -37,6 +37,7 @@ namespace KDevelop {
class IDocument;
class DUContext;
class TopDUContext;
class StaticAssistantsManagerPrivate;
/**
* @brief Class managing instances of StaticAssistant
......@@ -59,13 +60,14 @@ public:
QVector<StaticAssistant::Ptr> registeredAssistants() const;
void notifyAssistants(const IndexedString& url, const KDevelop::ReferencedTopDUContext& context);
QVector<KDevelop::Problem::Ptr> problemsForContext(const ReferencedTopDUContext& top);
QVector<KDevelop::Problem::Ptr> problemsForContext(const ReferencedTopDUContext& top) const;
Q_SIGNALS:
void problemsChanged(const IndexedString& url);
private:
const QScopedPointer<class StaticAssistantsManagerPrivate> d;
const QScopedPointer<class StaticAssistantsManagerPrivate> d_ptr;
Q_DECLARE_PRIVATE(StaticAssistantsManager)
};
}
......
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