EditorManager: Fix various compiler & clazy warnings

Change-Id: Ie2318fd5ab2188b8e4bbcd0b77b2c978b52e1b30
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2018-03-05 14:15:59 +01:00
parent cd7f53e4e2
commit 1640555145
2 changed files with 14 additions and 13 deletions

View File

@@ -78,6 +78,7 @@
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QFileInfo> #include <QFileInfo>
#include <QHash>
#include <QMap> #include <QMap>
#include <QRegularExpression> #include <QRegularExpression>
#include <QRegularExpressionMatch> #include <QRegularExpressionMatch>
@@ -343,7 +344,7 @@ void EditorManagerPrivate::init()
connect(m_openTerminalAction, &QAction::triggered, this, &EditorManagerPrivate::openTerminal); connect(m_openTerminalAction, &QAction::triggered, this, &EditorManagerPrivate::openTerminal);
connect(m_findInDirectoryAction, &QAction::triggered, connect(m_findInDirectoryAction, &QAction::triggered,
this, &EditorManagerPrivate::findInDirectory); this, &EditorManagerPrivate::findInDirectory);
connect(m_filePropertiesAction, &QAction::triggered, []() { connect(m_filePropertiesAction, &QAction::triggered, this, []() {
if (!d->m_contextMenuEntry || d->m_contextMenuEntry->fileName().isEmpty()) if (!d->m_contextMenuEntry || d->m_contextMenuEntry->fileName().isEmpty())
return; return;
DocumentManager::showFilePropertiesDialog(d->m_contextMenuEntry->fileName()); DocumentManager::showFilePropertiesDialog(d->m_contextMenuEntry->fileName());
@@ -592,7 +593,7 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN
Utils::MimeType mimeType = Utils::mimeTypeForFile(fn); Utils::MimeType mimeType = Utils::mimeTypeForFile(fn);
QMessageBox msgbox(QMessageBox::Critical, EditorManager::tr("File Error"), QMessageBox msgbox(QMessageBox::Critical, EditorManager::tr("File Error"),
tr("Could not open \"%1\": Cannot open files of type \"%2\".") tr("Could not open \"%1\": Cannot open files of type \"%2\".")
.arg(FileName::fromString(realFn).toUserOutput()).arg(mimeType.name()), .arg(FileName::fromString(realFn).toUserOutput(), mimeType.name()),
QMessageBox::Ok, ICore::dialogParent()); QMessageBox::Ok, ICore::dialogParent());
msgbox.exec(); msgbox.exec();
return nullptr; return nullptr;
@@ -655,7 +656,7 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN
QMenu *menu = new QMenu(button); QMenu *menu = new QMenu(button);
foreach (IEditorFactory *factory, factories) { foreach (IEditorFactory *factory, factories) {
QAction *action = menu->addAction(factory->displayName()); QAction *action = menu->addAction(factory->displayName());
connect(action, &QAction::triggered, [&selectedFactory, factory, &msgbox]() { connect(action, &QAction::triggered, &msgbox, [&selectedFactory, factory, &msgbox]() {
selectedFactory = factory; selectedFactory = factory;
msgbox.done(QMessageBox::Open); msgbox.done(QMessageBox::Open);
}); });
@@ -1021,7 +1022,7 @@ void EditorManagerPrivate::readSettings()
} }
if (settings->contains(reloadBehaviorKey)) { if (settings->contains(reloadBehaviorKey)) {
d->m_reloadSetting = (IDocument::ReloadSetting)settings->value(reloadBehaviorKey).toInt(); d->m_reloadSetting = IDocument::ReloadSetting(settings->value(reloadBehaviorKey).toInt());
settings->remove(reloadBehaviorKey); settings->remove(reloadBehaviorKey);
} }
@@ -1033,7 +1034,7 @@ void EditorManagerPrivate::readSettings()
} }
if (qs->contains(reloadBehaviorKey)) if (qs->contains(reloadBehaviorKey))
d->m_reloadSetting = (IDocument::ReloadSetting)qs->value(reloadBehaviorKey).toInt(); d->m_reloadSetting = IDocument::ReloadSetting(qs->value(reloadBehaviorKey).toInt());
if (qs->contains(autoSaveEnabledKey)) { if (qs->contains(autoSaveEnabledKey)) {
d->m_autoSaveEnabled = qs->value(autoSaveEnabledKey).toBool(); d->m_autoSaveEnabled = qs->value(autoSaveEnabledKey).toBool();
@@ -1328,7 +1329,7 @@ bool EditorManagerPrivate::closeEditors(const QList<IEditor*> &editors, CloseFla
// 1. ask all core listeners to check whether the editor can be closed // 1. ask all core listeners to check whether the editor can be closed
// 2. keep track of the document and all the editors that might remain open for it // 2. keep track of the document and all the editors that might remain open for it
QSet<IEditor*> acceptedEditors; QSet<IEditor*> acceptedEditors;
QMap<IDocument *, QList<IEditor *> > documentMap; QHash<IDocument *, QList<IEditor *> > editorsForDocuments;
foreach (IEditor *editor, editors) { foreach (IEditor *editor, editors) {
bool editorAccepted = true; bool editorAccepted = true;
foreach (const std::function<bool(IEditor*)> listener, d->m_closeEditorListeners) { foreach (const std::function<bool(IEditor*)> listener, d->m_closeEditorListeners) {
@@ -1341,10 +1342,10 @@ bool EditorManagerPrivate::closeEditors(const QList<IEditor*> &editors, CloseFla
if (editorAccepted) { if (editorAccepted) {
acceptedEditors.insert(editor); acceptedEditors.insert(editor);
IDocument *document = editor->document(); IDocument *document = editor->document();
if (!documentMap.contains(document)) // insert the document to track if (!editorsForDocuments.contains(document)) // insert the document to track
documentMap.insert(document, DocumentModel::editorsForDocument(document)); editorsForDocuments.insert(document, DocumentModel::editorsForDocument(document));
// keep track that we'll close this editor for the document // keep track that we'll close this editor for the document
documentMap[document].removeAll(editor); editorsForDocuments[document].removeAll(editor);
} }
} }
if (acceptedEditors.isEmpty()) if (acceptedEditors.isEmpty())
@@ -1354,7 +1355,7 @@ bool EditorManagerPrivate::closeEditors(const QList<IEditor*> &editors, CloseFla
if (flag == CloseFlag::CloseWithAsking) { if (flag == CloseFlag::CloseWithAsking) {
// Check for which documents we will close all editors, and therefore might have to ask the user // Check for which documents we will close all editors, and therefore might have to ask the user
QList<IDocument *> documentsToClose; QList<IDocument *> documentsToClose;
for (auto i = documentMap.constBegin(); i != documentMap.constEnd(); ++i) { for (auto i = editorsForDocuments.constBegin(); i != editorsForDocuments.constEnd(); ++i) {
if (i.value().isEmpty()) if (i.value().isEmpty())
documentsToClose.append(i.key()); documentsToClose.append(i.key());
} }
@@ -2782,7 +2783,7 @@ IEditor *EditorManager::openEditorWithContents(Id editorId,
if (!uniqueId.isEmpty()) { if (!uniqueId.isEmpty()) {
foreach (IDocument *document, DocumentModel::openedDocuments()) foreach (IDocument *document, DocumentModel::openedDocuments())
if (document->property(scratchBufferKey).toString() == uniqueId) { if (document->property(scratchBufferKey).toString() == uniqueId) {
edt = DocumentModel::editorsForDocument(document).first(); edt = DocumentModel::editorsForDocument(document).constFirst();
document->setContents(contents); document->setContents(contents);
if (!title.isEmpty()) if (!title.isEmpty())
@@ -2911,7 +2912,7 @@ QByteArray EditorManager::saveState()
QList<IDocument *> documents = DocumentModel::openedDocuments(); QList<IDocument *> documents = DocumentModel::openedDocuments();
foreach (IDocument *document, documents) { foreach (IDocument *document, documents) {
if (!document->filePath().isEmpty() && !document->isTemporary()) { if (!document->filePath().isEmpty() && !document->isTemporary()) {
IEditor *editor = DocumentModel::editorsForDocument(document).first(); IEditor *editor = DocumentModel::editorsForDocument(document).constFirst();
QByteArray state = editor->saveState(); QByteArray state = editor->saveState();
if (!state.isEmpty()) if (!state.isEmpty())
d->m_editorStates.insert(document->filePath().toString(), QVariant(state)); d->m_editorStates.insert(document->filePath().toString(), QVariant(state));

View File

@@ -64,7 +64,7 @@ class CORE_EXPORT EditorManagerPlaceHolder : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit EditorManagerPlaceHolder(QWidget *parent = nullptr); explicit EditorManagerPlaceHolder(QWidget *parent = nullptr);
~EditorManagerPlaceHolder(); ~EditorManagerPlaceHolder() final;
protected: protected:
void showEvent(QShowEvent *event) override; void showEvent(QShowEvent *event) override;