Commit 98ae1bf6 authored by Eike Ziller's avatar Eike Ziller Committed by hjk

Make document model API more consistent with entry vs document

Change-Id: Iae2fe480d9fcb564d566f1dcca142c21c99c2d5b
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent e828f60c
......@@ -67,7 +67,7 @@ private:
const QIcon m_lockedIcon;
const QIcon m_unlockedIcon;
QList<DocumentModel::Entry *> m_documents;
QList<DocumentModel::Entry *> m_entries;
QMap<IDocument *, QList<IEditor *> > m_editors;
};
......@@ -79,7 +79,7 @@ DocumentModelPrivate::DocumentModelPrivate() :
DocumentModelPrivate::~DocumentModelPrivate()
{
qDeleteAll(m_documents);
qDeleteAll(m_entries);
}
static DocumentModelPrivate *d;
......@@ -143,7 +143,7 @@ int DocumentModelPrivate::columnCount(const QModelIndex &parent) const
int DocumentModelPrivate::rowCount(const QModelIndex &parent) const
{
if (!parent.isValid())
return m_documents.count() + 1/*<no document>*/;
return m_entries.count() + 1/*<no document>*/;
return 0;
}
......@@ -184,11 +184,11 @@ void DocumentModel::addRestoredDocument(const QString &fileName, const QString &
d->addEntry(entry);
}
DocumentModel::Entry *DocumentModel::firstRestoredDocument()
DocumentModel::Entry *DocumentModel::firstRestoredEntry()
{
for (int i = 0; i < d->m_documents.count(); ++i)
if (!d->m_documents.at(i)->document)
return d->m_documents.at(i);
for (int i = 0; i < d->m_entries.count(); ++i)
if (!d->m_entries.at(i)->document)
return d->m_entries.at(i);
return 0;
}
......@@ -199,9 +199,9 @@ void DocumentModelPrivate::addEntry(DocumentModel::Entry *entry)
// replace a non-loaded entry (aka 'restored') if possible
int previousIndex = indexOfFilePath(fileName);
if (previousIndex >= 0) {
if (entry->document && m_documents.at(previousIndex)->document == 0) {
DocumentModel::Entry *previousEntry = m_documents.at(previousIndex);
m_documents[previousIndex] = entry;
if (entry->document && m_entries.at(previousIndex)->document == 0) {
DocumentModel::Entry *previousEntry = m_entries.at(previousIndex);
m_entries[previousIndex] = entry;
delete previousEntry;
connect(entry->document, SIGNAL(changed()), this, SLOT(itemChanged()));
} else {
......@@ -212,13 +212,13 @@ void DocumentModelPrivate::addEntry(DocumentModel::Entry *entry)
int index;
QString displayName = entry->displayName();
for (index = 0; index < m_documents.count(); ++index) {
if (displayName < m_documents.at(index)->displayName())
for (index = 0; index < m_entries.count(); ++index) {
if (displayName < m_entries.at(index)->displayName())
break;
}
int row = index + 1/*<no document>*/;
beginInsertRows(QModelIndex(), row, row);
m_documents.insert(index, entry);
m_entries.insert(index, entry);
if (entry->document)
connect(entry->document, SIGNAL(changed()), this, SLOT(itemChanged()));
endInsertRows();
......@@ -234,8 +234,8 @@ int DocumentModelPrivate::indexOfFilePath(const QString &filePath) const
if (filePath.isEmpty())
return -1;
const QString fixedPath = DocumentManager::fixFileName(filePath, DocumentManager::KeepLinks);
for (int i = 0; i < d->m_documents.count(); ++i) {
if (DocumentManager::fixFileName(d->m_documents.at(i)->fileName(), DocumentManager::KeepLinks) == fixedPath)
for (int i = 0; i < d->m_entries.count(); ++i) {
if (DocumentManager::fixFileName(d->m_entries.at(i)->fileName(), DocumentManager::KeepLinks) == fixedPath)
return i;
}
return -1;
......@@ -244,7 +244,7 @@ int DocumentModelPrivate::indexOfFilePath(const QString &filePath) const
void DocumentModel::removeEntry(DocumentModel::Entry *entry)
{
QTC_ASSERT(!entry->document, return); // we wouldn't know what to do with the associated editors
int index = d->m_documents.indexOf(entry);
int index = d->m_entries.indexOf(entry);
d->removeDocument(index);
}
......@@ -267,7 +267,7 @@ void DocumentModel::removeEditor(IEditor *editor, bool *lastOneForDocument)
void DocumentModel::removeDocument(const QString &fileName)
{
int index = indexOfFilePath(fileName);
QTC_ASSERT(!d->m_documents.at(index)->document, return); // we wouldn't know what to do with the associated editors
QTC_ASSERT(!d->m_entries.at(index)->document, return); // we wouldn't know what to do with the associated editors
d->removeDocument(index);
}
......@@ -275,23 +275,23 @@ void DocumentModelPrivate::removeDocument(int idx)
{
if (idx < 0)
return;
QTC_ASSERT(idx < d->m_documents.size(), return);
IDocument *document = d->m_documents.at(idx)->document;
QTC_ASSERT(idx < d->m_entries.size(), return);
IDocument *document = d->m_entries.at(idx)->document;
int row = idx + 1/*<no document>*/;
beginRemoveRows(QModelIndex(), row, row);
delete d->m_documents.takeAt(idx);
delete d->m_entries.takeAt(idx);
endRemoveRows();
if (document)
disconnect(document, SIGNAL(changed()), this, SLOT(itemChanged()));
}
void DocumentModel::removeAllRestoredDocuments()
void DocumentModel::removeAllRestoredEntries()
{
for (int i = d->m_documents.count()-1; i >= 0; --i) {
if (!d->m_documents.at(i)->document) {
for (int i = d->m_entries.count()-1; i >= 0; --i) {
if (!d->m_entries.at(i)->document) {
int row = i + 1/*<no document>*/;
d->beginRemoveRows(QModelIndex(), row, row);
delete d->m_documents.takeAt(i);
delete d->m_entries.takeAt(i);
d->endRemoveRows();
}
}
......@@ -322,8 +322,8 @@ int DocumentModel::indexOfDocument(IDocument *document)
int DocumentModelPrivate::indexOfDocument(IDocument *document) const
{
for (int i = 0; i < m_documents.count(); ++i)
if (m_documents.at(i)->document == document)
for (int i = 0; i < m_entries.count(); ++i)
if (m_entries.at(i)->document == document)
return i;
return -1;
}
......@@ -333,7 +333,7 @@ DocumentModel::Entry *DocumentModel::entryForDocument(IDocument *document)
int index = indexOfDocument(document);
if (index < 0)
return 0;
return d->m_documents.at(index);
return d->m_entries.at(index);
}
QList<IDocument *> DocumentModel::openedDocuments()
......@@ -346,7 +346,7 @@ IDocument *DocumentModel::documentForFilePath(const QString &filePath)
int index = indexOfFilePath(filePath);
if (index < 0)
return 0;
return d->m_documents.at(index)->document;
return d->m_entries.at(index)->document;
}
QList<IEditor *> DocumentModel::editorsForFilePath(const QString &filePath)
......@@ -360,22 +360,22 @@ QList<IEditor *> DocumentModel::editorsForFilePath(const QString &filePath)
QModelIndex DocumentModelPrivate::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent)
if (column < 0 || column > 1 || row < 0 || row >= m_documents.count() + 1/*<no document>*/)
if (column < 0 || column > 1 || row < 0 || row >= m_entries.count() + 1/*<no document>*/)
return QModelIndex();
return createIndex(row, column);
}
DocumentModel::Entry *DocumentModel::documentAtRow(int row)
DocumentModel::Entry *DocumentModel::entryAtRow(int row)
{
int entryIndex = row - 1/*<no document>*/;
if (entryIndex < 0)
return 0;
return d->m_documents[entryIndex];
return d->m_entries[entryIndex];
}
int DocumentModel::documentCount()
int DocumentModel::entryCount()
{
return d->m_documents.count();
return d->m_entries.count();
}
QVariant DocumentModelPrivate::data(const QModelIndex &index, int role) const
......@@ -394,7 +394,7 @@ QVariant DocumentModelPrivate::data(const QModelIndex &index, int role) const
return QVariant();
}
}
const DocumentModel::Entry *e = m_documents.at(entryIndex);
const DocumentModel::Entry *e = m_entries.at(entryIndex);
switch (role) {
case Qt::DisplayRole:
return (e->document && e->document->isModified())
......@@ -440,9 +440,9 @@ void DocumentModelPrivate::itemChanged()
emit dataChanged(mindex, mindex);
}
QList<DocumentModel::Entry *> DocumentModel::documents()
QList<DocumentModel::Entry *> DocumentModel::entries()
{
return d->m_documents;
return d->m_entries;
}
} // namespace Core
......
......@@ -64,11 +64,11 @@ public:
Id m_id;
};
static Entry *documentAtRow(int row);
static Entry *entryAtRow(int row);
static int rowOfDocument(IDocument *document);
static int documentCount();
static QList<Entry *> documents();
static int entryCount();
static QList<Entry *> entries();
static int indexOfDocument(IDocument *document);
static int indexOfFilePath(const QString &filePath);
static Entry *entryForDocument(IDocument *document);
......@@ -77,18 +77,18 @@ public:
static IDocument *documentForFilePath(const QString &filePath);
static QList<IEditor *> editorsForFilePath(const QString &filePath);
static QList<IEditor *> editorsForDocument(IDocument *document);
static QList<IEditor *> editorsForDocuments(const QList<IDocument *> &documents);
static QList<IEditor *> editorsForDocuments(const QList<IDocument *> &entries);
static QList<IEditor *> oneEditorForEachOpenedDocument();
static QList<IEditor *> editorsForOpenedDocuments();
// editor manager related functions, nobody else should call it
static void addEditor(IEditor *editor, bool *isNewDocument);
static void addRestoredDocument(const QString &fileName, const QString &displayName, const Id &id);
static Entry *firstRestoredDocument();
static Entry *firstRestoredEntry();
static void removeEditor(IEditor *editor, bool *lastOneForDocument);
static void removeDocument(const QString &fileName);
static void removeEntry(Entry *entry);
static void removeAllRestoredDocuments();
static void removeAllRestoredEntries();
private:
DocumentModel();
......
......@@ -721,7 +721,7 @@ void EditorManager::closeView(Core::Internal::EditorView *view)
bool EditorManager::closeAllEditors(bool askAboutModifiedEditors)
{
DocumentModel::removeAllRestoredDocuments();
DocumentModel::removeAllRestoredEntries();
if (closeDocuments(DocumentModel::openedDocuments(), askAboutModifiedEditors))
return true;
return false;
......@@ -729,7 +729,7 @@ bool EditorManager::closeAllEditors(bool askAboutModifiedEditors)
void EditorManager::closeAllEditorsExceptVisible()
{
DocumentModel::removeAllRestoredDocuments();
DocumentModel::removeAllRestoredEntries();
QList<IDocument *> documentsToClose = DocumentModel::openedDocuments();
foreach (IEditor *editor, visibleEditors())
documentsToClose.removeAll(editor->document());
......@@ -738,7 +738,7 @@ void EditorManager::closeAllEditorsExceptVisible()
void EditorManager::closeOtherEditors(IDocument *document)
{
DocumentModel::removeAllRestoredDocuments();
DocumentModel::removeAllRestoredEntries();
QList<IDocument *> documentsToClose = DocumentModel::openedDocuments();
documentsToClose.removeAll(document);
closeDocuments(documentsToClose, true);
......@@ -800,8 +800,8 @@ void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentMod
: tr("Close Other Editors"));
d->m_closeCurrentEditorContextAction->setEnabled(entry != 0);
d->m_closeOtherEditorsContextAction->setEnabled(entry != 0);
d->m_closeAllEditorsContextAction->setEnabled(!DocumentModel::documents().isEmpty());
d->m_closeAllEditorsExceptVisibleContextAction->setEnabled(visibleDocumentsCount() < DocumentModel::documents().count());
d->m_closeAllEditorsContextAction->setEnabled(!DocumentModel::entries().isEmpty());
d->m_closeAllEditorsExceptVisibleContextAction->setEnabled(visibleDocumentsCount() < DocumentModel::entries().count());
contextMenu->addAction(d->m_closeCurrentEditorContextAction);
contextMenu->addAction(d->m_closeAllEditorsContextAction);
contextMenu->addAction(d->m_closeOtherEditorsContextAction);
......@@ -1139,12 +1139,12 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
if (newCurrent) {
activateEditor(view, newCurrent, flags);
} else {
DocumentModel::Entry *entry = DocumentModel::firstRestoredDocument();
DocumentModel::Entry *entry = DocumentModel::firstRestoredEntry();
if (entry) {
activateEditorForEntry(view, entry, flags);
} else {
// no "restored" ones, so any entry left should have a document
const QList<DocumentModel::Entry *> documents = DocumentModel::documents();
const QList<DocumentModel::Entry *> documents = DocumentModel::entries();
if (!documents.isEmpty()) {
IDocument *document = documents.last()->document;
if (document)
......@@ -1691,7 +1691,7 @@ IEditor *EditorManager::openEditorWithContents(const Id &editorId,
if (base.contains(dollar)) {
int i = 1;
QSet<QString> docnames;
foreach (DocumentModel::Entry *entry, DocumentModel::documents()) {
foreach (DocumentModel::Entry *entry, DocumentModel::entries()) {
QString name = entry->fileName();
if (name.isEmpty())
name = entry->displayName();
......@@ -2024,7 +2024,7 @@ void EditorManager::setupSaveActions(IDocument *document, QAction *saveAction, Q
void EditorManager::updateActions()
{
IDocument *curDocument = currentDocument();
const int openedCount = DocumentModel::documentCount();
const int openedCount = DocumentModel::entryCount();
if (curDocument) {
if (HostOsInfo::isMacHost())
......@@ -2210,7 +2210,7 @@ QByteArray EditorManager::saveState()
stream << d->m_editorStates;
QList<DocumentModel::Entry *> entries = DocumentModel::documents();
QList<DocumentModel::Entry *> entries = DocumentModel::entries();
int entriesCount = 0;
foreach (DocumentModel::Entry *entry, entries) {
// The editor may be 0 if it was not loaded yet: In that case it is not temporary
......
......@@ -302,7 +302,7 @@ IEditor *EditorView::currentEditor() const
void EditorView::listSelectionActivated(int index)
{
EditorManager::activateEditorForEntry(this, DocumentModel::documentAtRow(index));
EditorManager::activateEditorForEntry(this, DocumentModel::entryAtRow(index));
}
void EditorView::splitHorizontally()
......@@ -801,7 +801,7 @@ void SplitterOrView::restoreState(const QByteArray &state)
| Core::EditorManager::DoNotChangeCurrentEditor);
if (!e) {
DocumentModel::Entry *entry = DocumentModel::firstRestoredDocument();
DocumentModel::Entry *entry = DocumentModel::firstRestoredEntry();
if (entry)
EditorManager::activateEditorForEntry(view(), entry, Core::EditorManager::IgnoreNavigationHistory
| Core::EditorManager::DoNotChangeCurrentEditor);
......
......@@ -189,13 +189,13 @@ void OpenEditorsWidget::activateEditor(const QModelIndex &index)
{
selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
EditorManager::activateEditorForEntry(
DocumentModel::documentAtRow(m_model->mapToSource(index).row()));
DocumentModel::entryAtRow(m_model->mapToSource(index).row()));
}
void OpenEditorsWidget::closeEditor(const QModelIndex &index)
{
EditorManager::closeEditor(
DocumentModel::documentAtRow(m_model->mapToSource(index).row()));
DocumentModel::entryAtRow(m_model->mapToSource(index).row()));
// work around selection changes
updateCurrentItem(EditorManager::currentEditor());
}
......@@ -204,7 +204,7 @@ void OpenEditorsWidget::contextMenuRequested(QPoint pos)
{
QMenu contextMenu;
QModelIndex editorIndex = indexAt(pos);
DocumentModel::Entry *entry = DocumentModel::documentAtRow(
DocumentModel::Entry *entry = DocumentModel::entryAtRow(
m_model->mapToSource(editorIndex).row());
EditorManager::addSaveAndCloseEditorActions(&contextMenu, entry);
contextMenu.addSeparator();
......
......@@ -236,7 +236,7 @@ void OpenEditorsWindow::addHistoryItems(const QList<EditLocation> &history, Edit
void OpenEditorsWindow::addRestoredItems()
{
foreach (DocumentModel::Entry *entry, DocumentModel::documents()) {
foreach (DocumentModel::Entry *entry, DocumentModel::entries()) {
if (entry->document)
continue;
QTreeWidgetItem *item = new QTreeWidgetItem();
......
......@@ -308,12 +308,12 @@ void EditorToolBar::updateEditorListSelection(IEditor *newSelection)
void EditorToolBar::changeActiveEditor(int row)
{
EditorManager::activateEditorForEntry(DocumentModel::documentAtRow(row));
EditorManager::activateEditorForEntry(DocumentModel::entryAtRow(row));
}
void EditorToolBar::listContextMenu(QPoint pos)
{
DocumentModel::Entry *entry = DocumentModel::documentAtRow(
DocumentModel::Entry *entry = DocumentModel::entryAtRow(
d->m_editorList->currentIndex());
QString fileName = entry ? entry->fileName() : QString();
QString shortFileName = entry ? QFileInfo(fileName).fileName() : QString();
......@@ -361,7 +361,7 @@ void EditorToolBar::checkDocumentStatus()
{
IDocument *document = qobject_cast<IDocument *>(sender());
QTC_ASSERT(document, return);
DocumentModel::Entry *entry = DocumentModel::documentAtRow(
DocumentModel::Entry *entry = DocumentModel::entryAtRow(
d->m_editorList->currentIndex());
if (entry && entry->document && entry->document == document)
......
......@@ -91,7 +91,7 @@ QList<LocatorFilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<Core:
void OpenDocumentsFilter::refreshInternally()
{
m_editors.clear();
foreach (DocumentModel::Entry *e, DocumentModel::documents()) {
foreach (DocumentModel::Entry *e, DocumentModel::entries()) {
DocumentModel::Entry entry;
// create copy with only the information relevant to use
// to avoid model deleting entries behind our back
......
......@@ -2154,12 +2154,12 @@ int FakeVimPluginPrivate::currentFile() const
void FakeVimPluginPrivate::switchToFile(int n)
{
int size = DocumentModel::documentCount();
int size = DocumentModel::entryCount();
QTC_ASSERT(size, return);
n = n % size;
if (n < 0)
n += size;
EditorManager::activateEditorForEntry(DocumentModel::documents().at(n));
EditorManager::activateEditorForEntry(DocumentModel::entries().at(n));
}
ExCommandMap &FakeVimExCommandsPage::exCommandMap()
......
......@@ -171,7 +171,7 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex
void ShortCutManager::updateActions(Core::IEditor* currentEditor)
{
int openedCount = Core::DocumentModel::documentCount();
int openedCount = Core::DocumentModel::entryCount();
Core::IDocument *document = 0;
if (currentEditor)
......
......@@ -68,7 +68,7 @@ Utils::FileIterator *FindInOpenFiles::files(const QStringList &nameFilters,
QStringList fileNames;
QList<QTextCodec *> codecs;
foreach (Core::DocumentModel::Entry *entry,
Core::DocumentModel::documents()) {
Core::DocumentModel::entries()) {
QString fileName = entry->fileName();
if (!fileName.isEmpty()) {
fileNames.append(fileName);
......@@ -100,7 +100,7 @@ QString FindInOpenFiles::toolTip() const
bool FindInOpenFiles::isEnabled() const
{
return Core::DocumentModel::documentCount() > 0;
return Core::DocumentModel::entryCount() > 0;
}
void FindInOpenFiles::writeSettings(QSettings *settings)
......
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