Index: src/filewidgets/kfileplacesview.cpp =================================================================== --- src/filewidgets/kfileplacesview.cpp +++ src/filewidgets/kfileplacesview.cpp @@ -62,11 +62,11 @@ public: KFilePlacesViewDelegate(KFilePlacesView *parent); virtual ~KFilePlacesViewDelegate(); - virtual QSize sizeHint(const QStyleOptionViewItem &option, - const QModelIndex &index) const Q_DECL_OVERRIDE; - virtual void paint(QPainter *painter, - const QStyleOptionViewItem &option, - const QModelIndex &index) const Q_DECL_OVERRIDE; + QSize sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const Q_DECL_OVERRIDE; + void paint(QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const Q_DECL_OVERRIDE; int iconSize() const; void setIconSize(int newSize); @@ -492,7 +492,7 @@ bool smoothItemResizing; bool dropOnPlace; bool dragging; - Solid::StorageAccess *lastClickedStorage; + Solid::StorageAccess *lastClickedStorage = nullptr; QPersistentModelIndex lastClickedIndex; QRect dropRect; @@ -506,6 +506,8 @@ void fadeCapacityBar(const QModelIndex &index, FadeType fadeType); int sectionsCount() const; + void addDisappearingItem(KFilePlacesViewDelegate *delegate, const QModelIndex &index); + // based on dolphin urls QUrl convertUrl(const QUrl &url) const; QUrl createTimelineUrl(const QUrl &url) const; @@ -531,7 +533,7 @@ QTimeLine itemDisappearTimeline; KFilePlacesEventWatcher *const watcher; - KFilePlacesViewDelegate *delegate; + KFilePlacesViewDelegate *delegate = nullptr; QTimer pollDevices; int pollingRequestCount; }; @@ -633,7 +635,6 @@ void KFilePlacesView::setUrl(const QUrl &url) { - QUrl oldUrl = d->currentUrl; KFilePlacesModel *placesModel = qobject_cast(model()); if (placesModel == nullptr) { @@ -646,12 +647,7 @@ if (index.isValid()) { if (current != index && placesModel->isHidden(current) && !d->showAll) { KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); - delegate->addDisappearingItem(current); - - if (d->itemDisappearTimeline.state() != QTimeLine::Running) { - delegate->setDisappearingItemProgress(0.0); - d->itemDisappearTimeline.start(); - } + d->addDisappearingItem(delegate, current); } if (current != index && placesModel->isHidden(index) && !d->showAll) { @@ -733,14 +729,15 @@ void KFilePlacesView::contextMenuEvent(QContextMenuEvent *event) { KFilePlacesModel *placesModel = qobject_cast(model()); - KFilePlacesViewDelegate *delegate = dynamic_cast(itemDelegate()); - if (placesModel == nullptr) { + if (!placesModel) { return; } + KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); + QModelIndex index = indexAt(event->pos()); - QString label = placesModel->text(index).replace('&', QLatin1String("&&")); + const QString label = placesModel->text(index).replace(QLatin1Char('&'), QLatin1String("&&")); QMenu menu; @@ -826,7 +823,7 @@ QAction *result = menu.exec(event->globalPos()); - if (emptyTrash != nullptr && result == emptyTrash) { + if (emptyTrash && (result == emptyTrash)) { KIO::JobUiDelegate uiDelegate; uiDelegate.setWindow(window()); @@ -835,7 +832,7 @@ KJobWidgets::setWindow(job, window()); job->uiDelegate()->setAutoErrorHandlingEnabled(true); } - } else if (edit != nullptr && result == edit) { + } else if (edit && (result == edit)) { KBookmark bookmark = placesModel->bookmarkForIndex(index); QUrl url = bookmark.url(); QString label = bookmark.text(); @@ -859,31 +856,22 @@ placesModel->setPlaceGroupHidden(type, hideSection->isChecked()); if (!d->showAll && hideSection->isChecked()) { - delegate->addDisappearingItemGroup(index); - if (d->itemDisappearTimeline.state() != QTimeLine::Running) { - delegate->setDisappearingItemProgress(0.0); - d->itemDisappearTimeline.start(); - } + d->addDisappearingItem(delegate, index); } } else if (hide && (result == hide)) { placesModel->setPlaceHidden(index, hide->isChecked()); QModelIndex current = placesModel->closestItem(d->currentUrl); if (index != current && !d->showAll && hide->isChecked()) { - delegate->addDisappearingItem(index); - - if (d->itemDisappearTimeline.state() != QTimeLine::Running) { - delegate->setDisappearingItemProgress(0.0); - d->itemDisappearTimeline.start(); - } + d->addDisappearingItem(delegate, index); } - } else if (showAll != nullptr && result == showAll) { + } else if (showAll && (result == showAll)) { setShowAll(showAll->isChecked()); - } else if (teardown != nullptr && result == teardown) { + } else if (teardown && (result == teardown)) { placesModel->requestTeardown(index); - } else if (eject != nullptr && result == eject) { + } else if (eject && (result == eject)) { placesModel->requestEject(index); - } else if (add != nullptr && result == add) { + } else if (add && (result == add)) { QUrl url = d->currentUrl; QString label; QString iconName = QStringLiteral("folder"); @@ -926,7 +914,7 @@ QListView::dragEnterEvent(event); d->dragging = true; - KFilePlacesViewDelegate *delegate = dynamic_cast(itemDelegate()); + KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); delegate->setShowHoverIndication(false); d->dropRect = QRect(); @@ -937,7 +925,7 @@ QListView::dragLeaveEvent(event); d->dragging = false; - KFilePlacesViewDelegate *delegate = dynamic_cast(itemDelegate()); + KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); delegate->setShowHoverIndication(true); setDirtyRegion(d->dropRect); @@ -988,7 +976,7 @@ QListView::dropEvent(event); d->dragging = false; - KFilePlacesViewDelegate *delegate = dynamic_cast(itemDelegate()); + KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); delegate->setShowHoverIndication(true); } @@ -1071,8 +1059,8 @@ QListView::rowsInserted(parent, start, end); setUrl(d->currentUrl); - KFilePlacesViewDelegate *delegate = dynamic_cast(itemDelegate()); - KFilePlacesModel *placesModel = qobject_cast(model()); + KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); + KFilePlacesModel *placesModel = static_cast(model()); for (int i = start; i <= end; ++i) { QModelIndex index = placesModel->index(i, 0, parent); @@ -1112,6 +1100,15 @@ return QSize(iconSize + textWidth + fm.height() / 2, height); } +void KFilePlacesView::Private::addDisappearingItem(KFilePlacesViewDelegate *delegate, const QModelIndex &index) +{ + delegate->addDisappearingItem(index); + if (itemDisappearTimeline.state() != QTimeLine::Running) { + delegate->setDisappearingItemProgress(0.0); + itemDisappearTimeline.start(); + } +} + void KFilePlacesView::Private::setCurrentIndex(const QModelIndex &index) { KFilePlacesModel *placesModel = qobject_cast(q->model()); @@ -1136,13 +1133,10 @@ void KFilePlacesView::Private::adaptItemSize() { - KFilePlacesViewDelegate *delegate = dynamic_cast(q->itemDelegate()); - if (!delegate) { - return; - } + KFilePlacesViewDelegate *delegate = static_cast(q->itemDelegate()); if (!autoResizeItems) { - int size = q->iconSize().width(); // Assume width == height + const int size = q->iconSize().width(); // Assume width == height delegate->setIconSize(size); q->scheduleDelayedItemsLayout(); return; @@ -1353,11 +1347,11 @@ QString KFilePlacesView::Private::timelineDateString(int year, int month, int day) const { - const QString dateFormat("%1-%2%3"); + const QString dateFormat(QStringLiteral("%1-%2%3")); QString date = dateFormat.arg(year).arg(month, 2, 10, QChar('0')); if (day > 0) { - date = date.arg(QString("-%1").arg(day, 2, 10, QChar('0'))); + date = date.arg(QStringLiteral("-%1").arg(day, 2, 10, QChar('0'))); } else { date = date.arg(""); } @@ -1449,8 +1443,10 @@ KFilePlacesModel *placesModel = qobject_cast(q->model()); - QObject::disconnect(placesModel, SIGNAL(setupDone(QModelIndex,bool)), - q, SLOT(_k_storageSetupDone(QModelIndex,bool))); + if (placesModel) { + QObject::disconnect(placesModel, SIGNAL(setupDone(QModelIndex,bool)), + q, SLOT(_k_storageSetupDone(QModelIndex,bool))); + } if (success) { setCurrentIndex(lastClickedIndex); @@ -1467,14 +1463,14 @@ int size = oldSize + add; - KFilePlacesViewDelegate *delegate = dynamic_cast(q->itemDelegate()); + KFilePlacesViewDelegate *delegate = static_cast(q->itemDelegate()); delegate->setIconSize(size); q->scheduleDelayedItemsLayout(); } void KFilePlacesView::Private::_k_itemAppearUpdate(qreal value) { - KFilePlacesViewDelegate *delegate = dynamic_cast(q->itemDelegate()); + KFilePlacesViewDelegate *delegate = static_cast(q->itemDelegate()); delegate->setAppearingItemProgress(value); q->scheduleDelayedItemsLayout(); @@ -1482,7 +1478,7 @@ void KFilePlacesView::Private::_k_itemDisappearUpdate(qreal value) { - KFilePlacesViewDelegate *delegate = dynamic_cast(q->itemDelegate()); + KFilePlacesViewDelegate *delegate = static_cast(q->itemDelegate()); delegate->setDisappearingItemProgress(value);