From 5e622a32032079a8fc1a1018d21be54b434e6217 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Fri, 29 Sep 2017 11:42:26 +0200 Subject: [PATCH] Use nullptr and member initialization in document manager Change-Id: Iddd446d10cf3fd0a59d46d6ed3ba335f0c93e118 Reviewed-by: Tobias Hunger --- src/plugins/coreplugin/documentmanager.cpp | 39 +++++++++--------- src/plugins/coreplugin/documentmanager.h | 47 +++++++++++++--------- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp index 536252845d5..43b6cb212f2 100644 --- a/src/plugins/coreplugin/documentmanager.cpp +++ b/src/plugins/coreplugin/documentmanager.cpp @@ -153,20 +153,20 @@ public: QList m_recentFiles; static const int m_maxRecentFiles = 7; - QFileSystemWatcher *m_fileWatcher; // Delayed creation. - QFileSystemWatcher *m_linkWatcher; // Delayed creation (only UNIX/if a link is seen). - bool m_blockActivated; + QFileSystemWatcher *m_fileWatcher = nullptr; // Delayed creation. + QFileSystemWatcher *m_linkWatcher = nullptr; // Delayed creation (only UNIX/if a link is seen). + bool m_blockActivated = false; bool m_checkOnFocusChange = false; - QString m_lastVisitedDirectory; + QString m_lastVisitedDirectory = QDir::currentPath(); QString m_defaultLocationForNewFiles; FileName m_projectsDirectory; - bool m_useProjectsDirectory; + bool m_useProjectsDirectory = true; QString m_buildDirectory; // When we are calling into an IDocument // we don't want to receive a changed() // signal // That makes the code easier - IDocument *m_blockedIDocument; + IDocument *m_blockedIDocument = nullptr; }; static DocumentManager *m_instance; @@ -210,13 +210,7 @@ void DocumentManagerPrivate::onApplicationFocusChange() m_instance->checkForReload(); } -DocumentManagerPrivate::DocumentManagerPrivate() : - m_fileWatcher(0), - m_linkWatcher(0), - m_blockActivated(false), - m_lastVisitedDirectory(QDir::currentPath()), - m_useProjectsDirectory(true), - m_blockedIDocument(0) +DocumentManagerPrivate::DocumentManagerPrivate() { connect(qApp, &QApplication::focusChanged, this, &DocumentManagerPrivate::onApplicationFocusChange); } @@ -273,7 +267,7 @@ static void addFileInfo(IDocument *document, const QString &filePath, const QString watchedFilePath = d->m_states.value(filePathKey).watchedFilePath; qCDebug(log) << "adding (" << (isLink ? "link" : "full") << ") watch for" << watchedFilePath; - QFileSystemWatcher *watcher = 0; + QFileSystemWatcher *watcher = nullptr; if (isLink) watcher = d->linkWatcher(); else @@ -432,7 +426,7 @@ void DocumentManager::renamedFile(const QString &from, const QString &to) removeFileInfo(document); document->setFilePath(FileName::fromString(to)); addFileInfo(document); - d->m_blockedIDocument = 0; + d->m_blockedIDocument = nullptr; } emit m_instance->allDocumentsRenamed(from, to); } @@ -620,7 +614,7 @@ static bool saveModifiedFilesHelper(const QList &documents, // There can be several IDocuments pointing to the same file // Prefer one that is not readonly // (even though it *should* not happen that the IDocuments are inconsistent with readonly) - if (!modifiedDocumentsMap.key(name, 0) || !document->isFileReadOnly()) + if (!modifiedDocumentsMap.key(name, nullptr) || !document->isFileReadOnly()) modifiedDocumentsMap.insert(document, name); } } @@ -830,10 +824,17 @@ bool DocumentManager::saveAllModifiedDocumentsSilently(bool *canceled, \a FailedToClose will contain a list of documents that could not be saved if passed into the method. */ -bool DocumentManager::saveModifiedDocumentsSilently(const QList &documents, bool *canceled, +bool DocumentManager::saveModifiedDocumentsSilently(const QList &documents, + bool *canceled, QList *failedToClose) { - return saveModifiedFilesHelper(documents, QString(), canceled, true, QString(), 0, failedToClose); + return saveModifiedFilesHelper(documents, + QString(), + canceled, + true, + QString(), + nullptr, + failedToClose); } /*! @@ -1181,7 +1182,7 @@ void DocumentManager::checkForReload() errorStrings << errorString; } - d->m_blockedIDocument = 0; + d->m_blockedIDocument = nullptr; } if (!filesToDiff.isEmpty()) { diff --git a/src/plugins/coreplugin/documentmanager.h b/src/plugins/coreplugin/documentmanager.h index 3cf9b47bfe7..0714cdf7bf3 100644 --- a/src/plugins/coreplugin/documentmanager.h +++ b/src/plugins/coreplugin/documentmanager.h @@ -80,38 +80,47 @@ public: static QString cleanAbsoluteFilePath(const QString &filePath, ResolveMode resolveMode); static QString filePathKey(const QString &filePath, ResolveMode resolveMode); - static bool saveDocument(IDocument *document, const QString &fileName = QString(), bool *isReadOnly = 0); + static bool saveDocument(IDocument *document, + const QString &fileName = QString(), + bool *isReadOnly = nullptr); static QStringList getOpenFileNames(const QString &filters, const QString &path = QString(), - QString *selectedFilter = 0); - static QString getSaveFileName(const QString &title, const QString &pathIn, - const QString &filter = QString(), QString *selectedFilter = 0); + QString *selectedFilter = nullptr); + static QString getSaveFileName(const QString &title, + const QString &pathIn, + const QString &filter = QString(), + QString *selectedFilter = nullptr); static QString getSaveFileNameWithExtension(const QString &title, const QString &pathIn, const QString &filter); static QString getSaveAsFileName(const IDocument *document); - static bool saveAllModifiedDocumentsSilently(bool *canceled = 0, - QList *failedToClose = 0); - static bool saveModifiedDocumentsSilently(const QList &documents, bool *canceled = 0, - QList *failedToClose = 0); - static bool saveModifiedDocumentSilently(IDocument *document, bool *canceled = 0, - QList *failedToClose = 0); + static bool saveAllModifiedDocumentsSilently(bool *canceled = nullptr, + QList *failedToClose = nullptr); + static bool saveModifiedDocumentsSilently(const QList &documents, + bool *canceled = nullptr, + QList *failedToClose = nullptr); + static bool saveModifiedDocumentSilently(IDocument *document, + bool *canceled = nullptr, + QList *failedToClose = nullptr); - static bool saveAllModifiedDocuments(const QString &message = QString(), bool *canceled = 0, + static bool saveAllModifiedDocuments(const QString &message = QString(), + bool *canceled = nullptr, const QString &alwaysSaveMessage = QString(), - bool *alwaysSave = 0, - QList *failedToClose = 0); + bool *alwaysSave = nullptr, + QList *failedToClose = nullptr); static bool saveModifiedDocuments(const QList &documents, - const QString &message = QString(), bool *canceled = 0, + const QString &message = QString(), + bool *canceled = nullptr, const QString &alwaysSaveMessage = QString(), - bool *alwaysSave = 0, - QList *failedToClose = 0); + bool *alwaysSave = nullptr, + QList *failedToClose = nullptr); static bool saveModifiedDocument(IDocument *document, - const QString &message = QString(), bool *canceled = 0, + const QString &message = QString(), + bool *canceled = nullptr, const QString &alwaysSaveMessage = QString(), - bool *alwaysSave = 0, - QList *failedToClose = 0); + bool *alwaysSave = nullptr, + QList *failedToClose = nullptr); static QString fileDialogLastVisitedDirectory(); static void setFileDialogLastVisitedDirectory(const QString &);