generic: cast pointers with QObject as base class via qobject_cast<T>()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-06-01 18:06:11 +00:00
parent 06e562e271
commit 08f290fa8b
16 changed files with 34 additions and 31 deletions

View file

@ -299,7 +299,7 @@ QAction *KActionCollection::addAction(const QString &name, QAction *action)
connect(action, SIGNAL(destroyed(QObject*)), SLOT(_k_actionDestroyed(QObject*)));
// only our private class is a friend of KAction
if (KAction *kaction = dynamic_cast<KAction *>(action)) {
if (KAction *kaction = qobject_cast<KAction *>(action)) {
d->setComponentForAction(kaction);
}

View file

@ -45,6 +45,7 @@
class KDEUI_EXPORT KCategorizedSortFilterProxyModel
: public QSortFilterProxyModel
{
Q_OBJECT
public:
enum AdditionalRoles {
// Note: use printf "0x%08X\n" $(($RANDOM*$RANDOM))

View file

@ -518,7 +518,7 @@ void KCategorizedView::setModel(QAbstractItemModel *model)
disconnect(d->proxyModel, SIGNAL(layoutChanged()), this, SLOT(slotLayoutChanged()));
}
d->proxyModel = dynamic_cast<KCategorizedSortFilterProxyModel*>(model);
d->proxyModel = qobject_cast<KCategorizedSortFilterProxyModel*>(model);
if (d->proxyModel) {
connect(d->proxyModel, SIGNAL(layoutChanged()), this, SLOT(slotLayoutChanged()));

View file

@ -175,13 +175,13 @@ int KMultiTabBarButton::id() const
void KMultiTabBarButton::hideEvent( QHideEvent* he) {
QPushButton::hideEvent(he);
KMultiTabBar *tb=dynamic_cast<KMultiTabBar*>(parentWidget());
KMultiTabBar *tb=qobject_cast<KMultiTabBar*>(parentWidget());
if (tb) tb->updateSeparator();
}
void KMultiTabBarButton::showEvent( QShowEvent* he) {
QPushButton::showEvent(he);
KMultiTabBar *tb=dynamic_cast<KMultiTabBar*>(parentWidget());
KMultiTabBar *tb=qobject_cast<KMultiTabBar*>(parentWidget());
if (tb) tb->updateSeparator();
}

View file

@ -2078,7 +2078,7 @@ void KDirOperator::writeConfig(KConfigGroup& configGroup)
// don't save the preview when an application specific preview is in use.
bool appSpecificPreview = false;
if (d->preview) {
KImageFilePreview *tmp = dynamic_cast<KImageFilePreview*>(d->preview);
KImageFilePreview *tmp = qobject_cast<KImageFilePreview*>(d->preview);
appSpecificPreview = (tmp == 0);
}

View file

@ -59,6 +59,7 @@
class KFilePlacesViewDelegate : public QAbstractItemDelegate
{
Q_OBJECT
public:
KFilePlacesViewDelegate(KFilePlacesView *parent);
virtual ~KFilePlacesViewDelegate();
@ -555,7 +556,7 @@ void KFilePlacesView::keyPressEvent(QKeyEvent *event)
void KFilePlacesView::contextMenuEvent(QContextMenuEvent *event)
{
KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel*>(model());
KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate*>(itemDelegate());
KFilePlacesViewDelegate *delegate = qobject_cast<KFilePlacesViewDelegate*>(itemDelegate());
if (placesModel==0) return;
@ -730,7 +731,7 @@ void KFilePlacesView::dragEnterEvent(QDragEnterEvent *event)
QListView::dragEnterEvent(event);
d->dragging = true;
KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate*>(itemDelegate());
KFilePlacesViewDelegate *delegate = qobject_cast<KFilePlacesViewDelegate*>(itemDelegate());
delegate->setShowHoverIndication(false);
d->dropRect = QRect();
@ -741,7 +742,7 @@ void KFilePlacesView::dragLeaveEvent(QDragLeaveEvent *event)
QListView::dragLeaveEvent(event);
d->dragging = false;
KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate*>(itemDelegate());
KFilePlacesViewDelegate *delegate = qobject_cast<KFilePlacesViewDelegate*>(itemDelegate());
delegate->setShowHoverIndication(true);
setDirtyRegion(d->dropRect);
@ -792,7 +793,7 @@ void KFilePlacesView::dropEvent(QDropEvent *event)
QListView::dropEvent(event);
d->dragging = false;
KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate*>(itemDelegate());
KFilePlacesViewDelegate *delegate = qobject_cast<KFilePlacesViewDelegate*>(itemDelegate());
delegate->setShowHoverIndication(true);
}
@ -855,7 +856,7 @@ void KFilePlacesView::rowsInserted(const QModelIndex &parent, int start, int end
QListView::rowsInserted(parent, start, end);
setUrl(d->currentUrl);
KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate*>(itemDelegate());
KFilePlacesViewDelegate *delegate = qobject_cast<KFilePlacesViewDelegate*>(itemDelegate());
KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel*>(model());
for (int i=start; i<=end; ++i) {
@ -917,7 +918,7 @@ void KFilePlacesView::Private::setCurrentIndex(const QModelIndex &index)
void KFilePlacesView::Private::adaptItemSize()
{
KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate*>(q->itemDelegate());
KFilePlacesViewDelegate *delegate = qobject_cast<KFilePlacesViewDelegate*>(q->itemDelegate());
if (!delegate) return;
if (!autoResizeItems) {
@ -1121,14 +1122,14 @@ void KFilePlacesView::Private::_k_adaptItemsUpdate(qreal value)
int size = oldSize+add;
KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate*>(q->itemDelegate());
KFilePlacesViewDelegate *delegate = qobject_cast<KFilePlacesViewDelegate*>(q->itemDelegate());
delegate->setIconSize(size);
q->scheduleDelayedItemsLayout();
}
void KFilePlacesView::Private::_k_itemAppearUpdate(qreal value)
{
KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate*>(q->itemDelegate());
KFilePlacesViewDelegate *delegate = qobject_cast<KFilePlacesViewDelegate*>(q->itemDelegate());
delegate->setAppearingItemProgress(value);
q->scheduleDelayedItemsLayout();
@ -1136,7 +1137,7 @@ void KFilePlacesView::Private::_k_itemAppearUpdate(qreal value)
void KFilePlacesView::Private::_k_itemDisappearUpdate(qreal value)
{
KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate*>(q->itemDelegate());
KFilePlacesViewDelegate *delegate = qobject_cast<KFilePlacesViewDelegate*>(q->itemDelegate());
delegate->setDisappearingItemProgress(value);
@ -1193,5 +1194,6 @@ void KFilePlacesView::dataChanged(const QModelIndex &topLeft, const QModelIndex
d->adaptItemSize();
}
#include "kfileplacesview.moc"
#include "moc_kfileplacesview.cpp"
#include "moc_kfileplacesview_p.cpp"

View file

@ -1404,7 +1404,7 @@ void KFileWidgetPrivate::_k_urlEntered(const KUrl& url)
urlNavigator->setLocationUrl(url);
// is trigged in ctor before completion object is set
KUrlCompletion *completion = dynamic_cast<KUrlCompletion*>(locationEdit->completionObject());
KUrlCompletion *completion = qobject_cast<KUrlCompletion*>(locationEdit->completionObject());
if (completion) {
completion->setDir( url.path() );
}
@ -1882,7 +1882,7 @@ void KFileWidgetPrivate::readRecentFiles()
combo->setUrl(ops->url());
// since we delayed this moment, initialize the directory of the completion object to
// our current directory (that was very probably set on the constructor)
KUrlCompletion *completion = dynamic_cast<KUrlCompletion*>(locationEdit->completionObject());
KUrlCompletion *completion = qobject_cast<KUrlCompletion*>(locationEdit->completionObject());
if (completion) {
completion->setDir(ops->url().url());
}

View file

@ -344,7 +344,7 @@ void KPropertiesDialog::setFileSharingPage(QWidget* page) {
void KPropertiesDialog::setFileNameReadOnly( bool ro )
{
foreach(KPropertiesDialogPlugin *it, d->m_pageList) {
KFilePropsPlugin* plugin = dynamic_cast<KFilePropsPlugin*>(it);
KFilePropsPlugin* plugin = qobject_cast<KFilePropsPlugin*>(it);
if ( plugin ) {
plugin->setFileNameReadOnly( ro );
break;

View file

@ -1339,7 +1339,7 @@ void CopyJobPrivate::slotResultCopyingFiles( KJob * job )
//kDebug(7007) << files.count() << "files remaining";
// Merge metadata from subjob
KIO::Job* kiojob = dynamic_cast<KIO::Job*>(job);
KIO::Job* kiojob = qobject_cast<KIO::Job*>(job);
Q_ASSERT(kiojob);
m_incomingMetaData += kiojob->metaData();
q->removeSubjob( job );
@ -1837,7 +1837,7 @@ void CopyJobPrivate::slotResultRenaming( KJob* job )
int err = job->error();
const QString errText = job->errorText();
// Merge metadata from subjob
KIO::Job* kiojob = dynamic_cast<KIO::Job*>(job);
KIO::Job* kiojob = qobject_cast<KIO::Job*>(job);
Q_ASSERT(kiojob);
m_incomingMetaData += kiojob->metaData();
q->removeSubjob( job );

View file

@ -412,10 +412,10 @@ void DeleteJob::slotResult( KJob *job )
}
break;
case DELETEJOB_STATE_DELETING_FILES:
// Propagate the subjob's metadata (a SimpleJob) to the real DeleteJob
// FIXME: setMetaData() in the KIO API only allows access to outgoing metadata,
// but we need to alter the incoming one
d->m_incomingMetaData = dynamic_cast<KIO::Job*>(job)->metaData();
// Propagate the subjob's metadata (a SimpleJob) to the real DeleteJob
// FIXME: setMetaData() in the KIO API only allows access to outgoing metadata,
// but we need to alter the incoming one
d->m_incomingMetaData = qobject_cast<KIO::Job*>(job)->metaData();
if ( job->error() )
{

View file

@ -95,7 +95,7 @@ bool Job::addSubjob(KJob *jobBase)
//kDebug(7007) << "addSubjob(" << jobBase << ") this=" << this;
bool ok = KCompositeJob::addSubjob( jobBase );
KIO::Job *job = dynamic_cast<KIO::Job*>( jobBase );
KIO::Job *job = qobject_cast<KIO::Job*>( jobBase );
if (ok && job) {
// Copy metadata into subjob (e.g. window-id, user-timestamp etc.)
Q_D(Job);

View file

@ -60,7 +60,7 @@ KComponentData Factory::partComponentDataFromLibrary( const QString &libraryName
KPluginFactory *factory = loader.factory();
if ( !factory )
return KComponentData();
KParts::Factory *pfactory = dynamic_cast<KParts::Factory *>( factory );
KParts::Factory *pfactory = qobject_cast<KParts::Factory *>( factory );
if ( !pfactory )
return KComponentData();
return pfactory->partComponentData();

View file

@ -1480,7 +1480,7 @@ FormFactor Applet::formFactor() const
}
const PopupApplet *pa = dynamic_cast<const PopupApplet *>(this);
const PopupApplet *pa = qobject_cast<const PopupApplet *>(this);
//if the applet is in a widget that isn't a containment
//try to retrieve the formFactor from the parent size

View file

@ -1394,7 +1394,7 @@ void ContainmentPrivate::clearDataForMimeJob(KIO::Job *job)
void ContainmentPrivate::dropJobResult(KJob *job)
{
#ifndef PLASMA_NO_KIO
KIO::TransferJob* tjob = dynamic_cast<KIO::TransferJob*>(job);
KIO::TransferJob* tjob = qobject_cast<KIO::TransferJob*>(job);
if (!tjob) {
kDebug() << "job is not a KIO::TransferJob, won't handle the drop...";
clearDataForMimeJob(tjob);
@ -1413,7 +1413,7 @@ void ContainmentPrivate::mimeTypeRetrieved(KIO::Job *job, const QString &mimetyp
{
#ifndef PLASMA_NO_KIO
kDebug() << "Mimetype Job returns." << mimetype;
KIO::TransferJob* tjob = dynamic_cast<KIO::TransferJob*>(job);
KIO::TransferJob* tjob = qobject_cast<KIO::TransferJob*>(job);
if (!tjob) {
kDebug() << "job should be a TransferJob, but isn't";
clearDataForMimeJob(job);

View file

@ -140,11 +140,11 @@ DataEngine* DataContainer::getDataEngine()
DataEngine *de = NULL;
while (de == NULL)
{
o = dynamic_cast<QObject *> (o->parent());
o = qobject_cast<QObject *> (o->parent());
if (o == NULL) {
return NULL;
}
de = dynamic_cast<DataEngine *> (o);
de = qobject_cast<DataEngine *> (o);
}
return de;
}

View file

@ -139,7 +139,7 @@ void PopupApplet::setWidget(QWidget *widget)
QLayout *existingLayout = dialog->layout();
if (existingLayout) {
lay = dynamic_cast<QVBoxLayout *>(existingLayout);
lay = qobject_cast<QVBoxLayout *>(existingLayout);
if (!lay) {
delete existingLayout;
}