Commit b95bdf21 authored by Laurent Montel's avatar Laurent Montel 😁

Modernize code. Use nullptr where it's possible

Summary:
Remove extra ';'
Use override everywhere as we already use it in some part of code
Fix potential crash when we delete a pointer

Test Plan: build/using :)

Reviewers: hein

Reviewed By: hein

Subscribers: broulik, ngraham, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D8473
parent 9d0b117f
......@@ -42,7 +42,7 @@ QUrl DirectoryPicker::url() const
void DirectoryPicker::open()
{
if (!m_dialog) {
m_dialog = new QFileDialog(0, i18n("Select Folder"),
m_dialog = new QFileDialog(nullptr, i18n("Select Folder"),
QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0));
m_dialog->setFileMode(QFileDialog::Directory);
m_dialog->setOption(QFileDialog::ShowDirsOnly, true);
......
......@@ -96,11 +96,11 @@ FolderModel::FolderModel(QObject *parent) : QSortFilterProxyModel(parent),
m_dirWatch(nullptr),
m_dragInProgress(false),
m_urlChangedWhileDragging(false),
m_previewGenerator(0),
m_viewAdapter(0),
m_previewGenerator(nullptr),
m_viewAdapter(nullptr),
m_actionCollection(this),
m_newMenu(0),
m_fileItemActions(0),
m_newMenu(nullptr),
m_fileItemActions(nullptr),
m_usedByContainment(false),
m_locked(true),
m_sortMode(0),
......@@ -115,7 +115,7 @@ FolderModel::FolderModel(QObject *parent) : QSortFilterProxyModel(parent),
qmlRegisterType<KIO::DropJob>();
DirLister *dirLister = new DirLister(this);
dirLister->setDelayedMimeTypes(true);
dirLister->setAutoErrorHandlingEnabled(false, 0);
dirLister->setAutoErrorHandlingEnabled(false, nullptr);
connect(dirLister, &DirLister::error, this, &FolderModel::dirListFailed);
connect(dirLister, &KCoreDirLister::itemsDeleted, this, &FolderModel::evictFromIsDirCache);
......@@ -210,6 +210,7 @@ void FolderModel::setUrl(const QString& url)
if (m_dirWatch) {
delete m_dirWatch;
m_dirWatch = nullptr;
}
if (resolvedUrl.isValid()) {
......@@ -235,7 +236,7 @@ QUrl FolderModel::resolve(const QString& url)
{
QUrl resolvedUrl;
if (url.startsWith('~')) {
if (url.startsWith(QLatin1Char('~'))) {
resolvedUrl = QUrl::fromLocalFile(KShell::tildeExpand(url));
} else {
resolvedUrl = QUrl::fromUserInput(url);
......@@ -482,7 +483,7 @@ void FolderModel::setFilterPattern(const QString &pattern)
m_filterPattern = pattern;
m_filterPatternMatchAll = (pattern == QLatin1String("*"));
const QStringList patterns = pattern.split(' ');
const QStringList patterns = pattern.split(QLatin1Char(' '));
m_regExps.clear();
m_regExps.reserve(patterns.count());
......@@ -569,7 +570,7 @@ void FolderModel::run(int row)
url.setScheme(QStringLiteral("file"));
}
KRun *run = new KRun(url, 0);
KRun *run = new KRun(url, nullptr);
// On desktop:/ we want to be able to run .desktop files right away,
// otherwise ask for security reasons. We also don't use the targetUrl()
// from above since we don't want the resolved /home/foo/Desktop URL.
......@@ -1027,7 +1028,7 @@ void FolderModel::selectionChanged(QItemSelection selected, QItemSelection desel
QVector<int> roles;
roles.append(SelectedRole);
foreach(const QModelIndex index, indices) {
foreach(const QModelIndex &index, indices) {
emit dataChanged(index, index, roles);
}
......@@ -1355,7 +1356,7 @@ void FolderModel::createActions()
m_newMenu = new KNewFileMenu(&m_actionCollection, QStringLiteral("newMenu"), QApplication::desktop());
m_newMenu->setModal(false);
m_copyToMenu = new KFileCopyToMenu(Q_NULLPTR);
m_copyToMenu = new KFileCopyToMenu(nullptr);
}
QAction* FolderModel::action(const QString &name) const
......@@ -1538,7 +1539,7 @@ void FolderModel::openContextMenu(QQuickItem *visualParent)
QAction *act = new QAction(menu);
act->setText(i18n("&Properties"));
QObject::connect(act, &QAction::triggered, [this, items]() {
KPropertiesDialog::showDialog(items, Q_NULLPTR, false /*non modal*/);
KPropertiesDialog::showDialog(items, nullptr, false /*non modal*/);
});
menu->addAction(act);
}
......@@ -1655,7 +1656,7 @@ void FolderModel::openSelected()
const QList<QUrl> urls = selectedUrls(false);
for (const QUrl &url : urls) {
(void) new KRun(url, Q_NULLPTR);
(void) new KRun(url, nullptr);
}
}
......
......@@ -125,7 +125,7 @@ class FolderModel : public QSortFilterProxyModel
explicit FolderModel(QObject *parent = nullptr);
~FolderModel();
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
QHash<int, QByteArray> roleNames() const override;
static QHash<int, QByteArray> staticRoleNames();
QString url() const;
......@@ -216,11 +216,11 @@ class FolderModel : public QSortFilterProxyModel
Q_INVOKABLE void linkHere(const QUrl &sourceUrl);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
int indexForUrl(const QUrl &url) const;
KFileItem itemForIndex(const QModelIndex &index) const;
bool isDir(const QModelIndex &index, const KDirModel *dirModel) const;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
Qt::DropActions supportedDragActions() const override;
Q_INVOKABLE void paste();
......@@ -257,7 +257,7 @@ class FolderModel : public QSortFilterProxyModel
void popupMenuAboutToShow(KIO::DropJob *dropJob, QMimeData *mimeData, int x, int y);
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
bool matchMimeType(const KFileItem &item) const;
bool matchPattern(const KFileItem &item) const;
......
......@@ -126,14 +126,14 @@ QString LabelGenerator::displayLabel() const
label = label.right(label.length() - root.length());
if (!label.isEmpty()) {
if (label.at(0) == '/') {
if (label.at(0) == QLatin1Char('/')) {
label.remove(0, 1);
}
if (m_rtl) {
label.prepend(" < ");
label.prepend(QStringLiteral(" < "));
} else {
label.prepend(" > ");
label.prepend(QStringLiteral(" > "));
}
}
......
......@@ -36,12 +36,12 @@ class MimeTypesModel : public QAbstractListModel
~MimeTypesModel();
QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
bool setData(const QModelIndex &index, const QVariant &value, int role) Q_DECL_OVERRIDE;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
Q_INVOKABLE void checkAll();
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE { Q_UNUSED(parent) return m_mimeTypesList.size(); }
int rowCount(const QModelIndex &parent = QModelIndex()) const override { Q_UNUSED(parent) return m_mimeTypesList.size(); }
QStringList checkedTypes() const;
void setCheckedTypes(const QStringList &list);
......
......@@ -44,7 +44,7 @@ class PlacesModel : public QSortFilterProxyModel
void placesChanged() const;
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
private:
KFilePlacesModel *m_sourceModel;
......
......@@ -121,7 +121,7 @@ QStringList Positioner::positions() const
return m_positions;
}
void Positioner::setPositions(QStringList positions)
void Positioner::setPositions(const QStringList &positions)
{
if (m_positions != positions) {
m_positions = positions;
......
......@@ -49,7 +49,7 @@ class Positioner : public QAbstractItemModel
void setPerStripe(int perStripe);
QStringList positions() const;
void setPositions(QStringList positions);
void setPositions(const QStringList &positions);
Q_INVOKABLE int map(int row) const;
......@@ -66,13 +66,13 @@ class Positioner : public QAbstractItemModel
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
Q_SIGNALS:
void enabledChanged() const;
......
......@@ -109,7 +109,7 @@ void PreviewPluginsModel::setCheckedPlugins(const QStringList &list)
QStringList PreviewPluginsModel::checkedPlugins() const
{
QStringList list;
for (int i =0; i < m_checkedRows.size(); ++i) {
for (int i = 0; i < m_checkedRows.size(); ++i) {
if (m_checkedRows.at(i)) {
list.append(m_plugins.at(i)->desktopEntryName());
}
......
......@@ -37,10 +37,10 @@ class PreviewPluginsModel : public QAbstractListModel
~PreviewPluginsModel();
QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
bool setData(const QModelIndex &index, const QVariant &value, int role) Q_DECL_OVERRIDE;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE { Q_UNUSED(parent) return m_plugins.size(); }
int rowCount(const QModelIndex &parent = QModelIndex()) const override { Q_UNUSED(parent) return m_plugins.size(); }
QStringList checkedPlugins() const;
void setCheckedPlugins(const QStringList &list);
......
......@@ -30,12 +30,12 @@ class RubberBand : public QQuickPaintedItem
explicit RubberBand(QQuickItem *parent = nullptr);
~RubberBand();
void paint(QPainter* painter) Q_DECL_OVERRIDE;
void paint(QPainter* painter) override;
Q_INVOKABLE bool intersects(const QRectF &rect);
protected:
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
private:
QRectF m_geometry;
......
......@@ -49,7 +49,7 @@ Q_SIGNALS:
void moveToTrash();
protected:
bool eventFilter(QObject *obj, QEvent *e) Q_DECL_OVERRIDE;
bool eventFilter(QObject *obj, QEvent *e) override;
};
#endif // SHORTCUT_H
......@@ -92,7 +92,7 @@ ViewPropertiesMenu::ViewPropertiesMenu(QObject *parent) : QObject(parent)
action->setCheckable(true);
action->setData(i);
m_iconSize->addAction(action);
};
}
m_locked = m_menu->addAction(i18n("Locked"), this, SIGNAL(lockedChanged()));
m_locked->setCheckable(true);
......
......@@ -30,7 +30,7 @@ class ViewPropertiesMenu : public QObject
{
Q_OBJECT
Q_PROPERTY(QObject* menu READ menu CONSTANT);
Q_PROPERTY(QObject* menu READ menu CONSTANT)
Q_PROPERTY(bool showLayoutActions READ showLayoutActions WRITE setShowLayoutActions NOTIFY showLayoutActionsChanged)
Q_PROPERTY(bool showLockAction READ showLockAction WRITE setShowLockAction NOTIFY showLockActionChanged)
......@@ -45,7 +45,7 @@ class ViewPropertiesMenu : public QObject
Q_PROPERTY(int iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged)
public:
ViewPropertiesMenu(QObject *parent = 0);
explicit ViewPropertiesMenu(QObject *parent = nullptr);
~ViewPropertiesMenu();
QObject* menu() const;
......
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