Document model: Use optional for "indexOf" kind of methods

Change-Id: Iaffbb0b695f96b5b44c9fd0df63891c2797181b7
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2018-02-14 12:05:55 +01:00
parent 64233a4fae
commit 3060ddbcf3
6 changed files with 60 additions and 39 deletions

View File

@@ -320,7 +320,9 @@ void EditorToolBar::setMenuProvider(const EditorToolBar::MenuProvider &provider)
void EditorToolBar::setCurrentEditor(IEditor *editor)
{
IDocument *document = editor ? editor->document() : 0;
d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(document));
const Utils::optional<int> index = DocumentModel::rowOfDocument(document);
if (QTC_GUARD(index))
d->m_editorList->setCurrentIndex(index.value());
// If we never added the toolbar from the editor, we will never change
// the editor, so there's no need to update the toolbar either.
@@ -332,8 +334,11 @@ void EditorToolBar::setCurrentEditor(IEditor *editor)
void EditorToolBar::updateEditorListSelection(IEditor *newSelection)
{
if (newSelection)
d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(newSelection->document()));
if (newSelection) {
const Utils::optional<int> index = DocumentModel::rowOfDocument(newSelection->document());
if (QTC_GUARD(index))
d->m_editorList->setCurrentIndex(index.value());
}
}
void EditorToolBar::changeActiveEditor(int row)
@@ -403,7 +408,9 @@ void EditorToolBar::updateDocumentStatus(IDocument *document)
return;
}
d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(document));
const Utils::optional<int> index = DocumentModel::rowOfDocument(document);
if (QTC_GUARD(index))
d->m_editorList->setCurrentIndex(index.value());
if (document->filePath().isEmpty()) {
d->m_lockButton->setIcon(QIcon());