diff options
author | Eike Ziller <eike.ziller@digia.com> | 2013-07-03 17:18:06 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@digia.com> | 2013-07-09 09:38:03 +0200 |
commit | 3557603b1ef30edb57901948c6d1038d6b49b7ad (patch) | |
tree | 83b101e186eba2ed9b91580a0cd430c70e404554 /src/plugins/coreplugin/editormanager/openeditorsview.cpp | |
parent | 02512e234eeb2621ba7d370a190df05fa6083db7 (diff) | |
download | qt-creator-3557603b1ef30edb57901948c6d1038d6b49b7ad.tar.gz |
Editors: Don't use model index outside of model/view.
The model index is an internal detail of the model/view and shouldn't be
used outside that context.
Change-Id: I2c1f742fff427484f6ff244dd3e0d8428a7318d3
Reviewed-by: hjk <hjk121@nokiamail.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
Diffstat (limited to 'src/plugins/coreplugin/editormanager/openeditorsview.cpp')
-rw-r--r-- | src/plugins/coreplugin/editormanager/openeditorsview.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/plugins/coreplugin/editormanager/openeditorsview.cpp b/src/plugins/coreplugin/editormanager/openeditorsview.cpp index 0b6dacba5b..c0b1858fe3 100644 --- a/src/plugins/coreplugin/editormanager/openeditorsview.cpp +++ b/src/plugins/coreplugin/editormanager/openeditorsview.cpp @@ -124,12 +124,13 @@ OpenEditorsWidget::~OpenEditorsWidget() void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor) { - if (!editor) { + EditorManager *em = EditorManager::instance(); + QModelIndex index = model()->index(em->openedEditorsModel()->rowOfEditor(editor), 0); + if (!index.isValid()) { clearSelection(); return; } - EditorManager *em = EditorManager::instance(); - setCurrentIndex(em->openedEditorsModel()->indexOf(editor)); + setCurrentIndex(index); selectionModel()->select(currentIndex(), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); scrollTo(currentIndex()); @@ -189,12 +190,14 @@ void OpenEditorsWidget::handleClicked(const QModelIndex &index) void OpenEditorsWidget::activateEditor(const QModelIndex &index) { selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); - EditorManager::instance()->activateEditorForIndex(index); + EditorManager *em = EditorManager::instance(); + em->activateEditorForEntry(em->openedEditorsModel()->entryAtRow(index.row())); } void OpenEditorsWidget::closeEditor(const QModelIndex &index) { - EditorManager::instance()->closeEditor(index); + EditorManager *em = EditorManager::instance(); + em->closeEditor(em->openedEditorsModel()->entryAtRow(index.row())); // work around selection changes updateCurrentItem(EditorManager::currentEditor()); } @@ -203,9 +206,11 @@ void OpenEditorsWidget::contextMenuRequested(QPoint pos) { QMenu contextMenu; QModelIndex editorIndex = indexAt(pos); - EditorManager::instance()->addSaveAndCloseEditorActions(&contextMenu, editorIndex); + OpenEditorsModel::Entry *entry = EditorManager::instance()->openedEditorsModel()->entryAtRow( + editorIndex.row()); + EditorManager::instance()->addSaveAndCloseEditorActions(&contextMenu, entry); contextMenu.addSeparator(); - EditorManager::instance()->addNativeDirActions(&contextMenu, editorIndex); + EditorManager::instance()->addNativeDirActions(&contextMenu, entry); contextMenu.exec(mapToGlobal(pos)); } |