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

Consistently use qobject_cast with declared interfaces for QObject subclasses

parent bbd6966b
......@@ -114,7 +114,7 @@ void BreakpointModel::slotPartAdded(KParts::Part* part)
{
if (auto doc = qobject_cast<KTextEditor::Document*>(part))
{
auto *iface = dynamic_cast<MarkInterface*>(doc);
auto *iface = qobject_cast<MarkInterface*>(doc);
if( !iface )
return;
......
......@@ -495,7 +495,7 @@ void VariableCollection::viewCreated(KTextEditor::Document* doc,
{
Q_UNUSED(doc);
using namespace KTextEditor;
auto *iface = dynamic_cast<TextHintInterface*>(view);
auto* iface = qobject_cast<TextHintInterface*>(view);
if( !iface )
return;
......
......@@ -95,7 +95,7 @@ DocumentChangeTracker::DocumentChangeTracker(KTextEditor::Document* document)
connect(document, &Document::destroyed, this, &DocumentChangeTracker::documentDestroyed);
connect(document, &Document::documentSavedOrUploaded, this, &DocumentChangeTracker::documentSavedOrUploaded);
m_moving = dynamic_cast<KTextEditor::MovingInterface*>(document);
m_moving = qobject_cast<KTextEditor::MovingInterface*>(document);
Q_ASSERT(m_moving);
// can't use new connect syntax here, MovingInterface is not a QObject
......
......@@ -75,7 +75,7 @@ void CodeCompletion::viewCreated(KTextEditor::Document* document, KTextEditor::V
{
Q_UNUSED(document);
if (auto* cc = dynamic_cast<CodeCompletionInterface*>(view)) {
if (auto* cc = qobject_cast<CodeCompletionInterface*>(view)) {
cc->registerCompletionModel(m_model);
qCDebug(LANGUAGE) << "Registered completion model";
emit registeredToView(view);
......@@ -102,7 +102,7 @@ void CodeCompletion::unregisterDocument(Document* textDocument)
{
const auto views = textDocument->views();
for (KTextEditor::View* view : views) {
if (auto* cc = dynamic_cast<CodeCompletionInterface*>(view)) {
if (auto* cc = qobject_cast<CodeCompletionInterface*>(view)) {
cc->unregisterCompletionModel(m_model);
emit unregisteredFromView(view);
}
......
......@@ -174,7 +174,7 @@ VariableCollection* DebugController::variableCollection()
void DebugController::partAdded(KParts::Part* part)
{
if (auto* doc = qobject_cast<KTextEditor::Document*>(part)) {
auto *iface = dynamic_cast<KTextEditor::MarkInterface*>(doc);
auto* iface = qobject_cast<KTextEditor::MarkInterface*>(doc);
if( !iface )
return;
......@@ -322,7 +322,7 @@ void DebugController::clearExecutionPoint()
qCDebug(SHELL);
const auto documents = KDevelop::ICore::self()->documentController()->openDocuments();
for (KDevelop::IDocument* document : documents) {
auto *iface = dynamic_cast<KTextEditor::MarkInterface*>(document->textDocument());
auto* iface = qobject_cast<KTextEditor::MarkInterface*>(document->textDocument());
if (!iface)
continue;
......@@ -352,7 +352,7 @@ void DebugController::showStepInSource(const QUrl &url, int lineNum)
if( !document )
return;
auto *iface = dynamic_cast<KTextEditor::MarkInterface*>(document->textDocument());
auto* iface = qobject_cast<KTextEditor::MarkInterface*>(document->textDocument());
if( !iface )
return;
......
......@@ -70,7 +70,7 @@ void LanguagePreferences::apply()
if (Document* textDoc = doc->textDocument()) {
const auto views = textDoc->views();
for (View* view : views) {
if (auto* cc = dynamic_cast<CodeCompletionInterface*>(view)) {
if (auto* cc = qobject_cast<CodeCompletionInterface*>(view)) {
cc->setAutomaticInvocationEnabled(preferencesDialog->kcfg_automaticInvocation->isChecked());
}
}
......
......@@ -117,7 +117,7 @@ void TestShellDocumentOperation::testKateDocumentAndViewCreation()
//assure we have only one kate view for the newly created document
KTextEditor::Document *doc = documentController->openDocuments().at(0)->textDocument();
QCOMPARE(doc->views().count(), 1);
QCOMPARE(dynamic_cast<KTextEditor::MovingInterface*>(doc)->revision(), qint64(0));
QCOMPARE(qobject_cast<KTextEditor::MovingInterface*>(doc)->revision(), qint64(0));
//also assure the view's xmlgui is plugged in
KParts::MainWindow *main = Core::self()->uiControllerInternal()->activeMainWindow();
......
......@@ -356,7 +356,7 @@ QWidget *TextDocument::createViewWidget(QWidget *parent)
connect(view, &KTextEditor::View::contextMenuAboutToShow, this, &TextDocument::populateContextMenu);
if (auto* cc = dynamic_cast<KTextEditor::CodeCompletionInterface*>(view))
if (auto* cc = qobject_cast<KTextEditor::CodeCompletionInterface*>(view))
cc->setAutomaticInvocationEnabled(core()->languageController()->completionSettings()->automaticCompletionEnabled());
return view;
......
......@@ -242,7 +242,7 @@ void VcsPluginHelper::revert()
IDocument* doc=ICore::self()->documentController()->documentForUrl(url);
if(doc && doc->textDocument()) {
auto* modif = dynamic_cast<KTextEditor::ModificationInterface*>(doc->textDocument());
auto* modif = qobject_cast<KTextEditor::ModificationInterface*>(doc->textDocument());
if (modif) {
modif->setModifiedOnDiskWarning(false);
}
......@@ -277,7 +277,7 @@ void VcsPluginHelper::delayedModificationWarningOn()
if(doc) {
doc->reload();
auto* modif=dynamic_cast<KTextEditor::ModificationInterface*>(doc->textDocument());
auto* modif = qobject_cast<KTextEditor::ModificationInterface*>(doc->textDocument());
modif->setModifiedOnDiskWarning(true);
}
}
......
......@@ -207,8 +207,8 @@ bool BrowseManager::eventFilter(QObject* watched, QEvent* event)
}
if (keyEvent->key() == magicModifier) {
if (dynamic_cast<KTextEditor::CodeCompletionInterface*>(view) &&
dynamic_cast<KTextEditor::CodeCompletionInterface*>(view)->isCompletionActive()) {
if (qobject_cast<KTextEditor::CodeCompletionInterface*>(view) &&
qobject_cast<KTextEditor::CodeCompletionInterface*>(view)->isCompletionActive()) {
//Completion is active.
avoidMenuAltFocus();
m_delayedBrowsingTimer->stop();
......
......@@ -1029,7 +1029,7 @@ void ContextBrowserPlugin::viewCreated(KTextEditor::Document*, View* v)
connect(v->document(), &KTextEditor::Document::textInserted, this, &ContextBrowserPlugin::textInserted);
disconnect(v, &View::selectionChanged, this, &ContextBrowserPlugin::selectionChanged);
auto* iface = dynamic_cast<KTextEditor::TextHintInterface*>(v);
auto* iface = qobject_cast<KTextEditor::TextHintInterface*>(v);
if (!iface)
return;
......
......@@ -306,7 +306,7 @@ void PatchHighlighter::performContentChange( KTextEditor::Document* doc, const Q
}
qDeleteAll(removed);
auto* moving = dynamic_cast<KTextEditor::MovingInterface*>( doc );
auto* moving = qobject_cast<KTextEditor::MovingInterface*>(doc);
if ( !moving )
return;
......@@ -395,11 +395,11 @@ void PatchHighlighter::documentReloaded(KTextEditor::Document* doc)
//The document was loaded / reloaded
if ( !m_model->differences() )
return;
auto* moving = dynamic_cast<KTextEditor::MovingInterface*>( doc );
auto* moving = qobject_cast<KTextEditor::MovingInterface*>(doc);
if ( !moving )
return;
auto* markIface = dynamic_cast<KTextEditor::MarkInterface*>( doc );
auto* markIface = qobject_cast<KTextEditor::MarkInterface*>(doc);
if( !markIface )
return;
......@@ -553,11 +553,11 @@ PatchHighlighter::PatchHighlighter( Diff2::DiffModel* model, IDocument* kdoc, Pa
}
void PatchHighlighter::removeLineMarker( KTextEditor::MovingRange* range ) {
auto* moving = dynamic_cast<KTextEditor::MovingInterface*>( range->document() );
auto* moving = qobject_cast<KTextEditor::MovingInterface*>(range->document());
if ( !moving )
return;
auto* markIface = dynamic_cast<KTextEditor::MarkInterface*>( range->document() );
auto* markIface = qobject_cast<KTextEditor::MarkInterface*>(range->document());
if( !markIface )
return;
......@@ -577,11 +577,11 @@ void PatchHighlighter::removeLineMarker( KTextEditor::MovingRange* range ) {
}
void PatchHighlighter::addLineMarker( KTextEditor::MovingRange* range, Diff2::Difference* diff ) {
auto* moving = dynamic_cast<KTextEditor::MovingInterface*>( range->document() );
auto* moving = qobject_cast<KTextEditor::MovingInterface*>(range->document());
if ( !moving )
return;
auto* markIface = dynamic_cast<KTextEditor::MarkInterface*>( range->document() );
auto* markIface = qobject_cast<KTextEditor::MarkInterface*>(range->document());
if( !markIface )
return;
......@@ -654,11 +654,11 @@ void PatchHighlighter::clear() {
if( m_ranges.empty() )
return;
auto* moving = dynamic_cast<KTextEditor::MovingInterface*>( m_doc->textDocument() );
auto* moving = qobject_cast<KTextEditor::MovingInterface*>(m_doc->textDocument());
if ( !moving )
return;
auto* markIface = dynamic_cast<KTextEditor::MarkInterface*>( m_doc->textDocument() );
auto* markIface = qobject_cast<KTextEditor::MarkInterface*>(m_doc->textDocument());
if( !markIface )
return;
......
......@@ -365,7 +365,7 @@ void PatchReviewPlugin::closeReview()
// Revert modifications to the text document which we've done in updateReview
patchDocument->setPrettyName( QString() );
patchDocument->textDocument()->setReadWrite( true );
auto* modif = dynamic_cast<KTextEditor::ModificationInterface*>( patchDocument->textDocument() );
auto* modif = qobject_cast<KTextEditor::ModificationInterface*>(patchDocument->textDocument());
modif->setModifiedOnDiskWarning( true );
}
......@@ -460,7 +460,7 @@ void PatchReviewPlugin::updateReview()
futureActiveDoc->textDocument()->setReadWrite( false );
futureActiveDoc->setPrettyName( i18n( "Overview" ) );
auto* modif = dynamic_cast<KTextEditor::ModificationInterface*>( futureActiveDoc->textDocument() );
auto* modif = qobject_cast<KTextEditor::ModificationInterface*>(futureActiveDoc->textDocument());
modif->setModifiedOnDiskWarning( false );
docController->activateDocument( futureActiveDoc );
......
......@@ -134,7 +134,7 @@ void ProblemHighlighter::setProblems(const QVector<IProblem::Ptr>& problems)
TopDUContext* top = DUChainUtils::standardContextForUrl(m_document->url());
auto* iface = dynamic_cast<KTextEditor::MovingInterface*>(m_document.data());
auto* iface = qobject_cast<KTextEditor::MovingInterface*>(m_document.data());
Q_ASSERT(iface);
for (const IProblem::Ptr& problem : problems) {
......
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