Пример #1
0
void Manager::gotoLocations(const QList<QVariant> &list)
{
    QSet<SymbolLocation> locations = Utils::roleToLocations(list);

    if (locations.count() == 0)
        return;

    QString fileName;
    int line = 0;
    int column = 0;
    bool currentPositionAvailable = false;

    // what is open now?
    Core::IEditor *editor = Core::EditorManager::instance()->currentEditor();
    if (editor) {
        // get current file name
        Core::IDocument *document = editor->document();
        if (document)
            fileName = document->fileName();

        // if text file - what is current position?
        TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor *>(editor);
        if (textEditor) {
            // there is open currently text editor
            int position = textEditor->position();
            textEditor->convertPosition(position, &line, &column);
            currentPositionAvailable = true;
        }
    }

    // if there is something open - try to check, is it currently activated symbol?
    if (currentPositionAvailable) {
        SymbolLocation current(fileName, line, column);
        QSet<SymbolLocation>::const_iterator it = locations.find(current);
        QSet<SymbolLocation>::const_iterator end = locations.constEnd();
        // is it known location?
        if (it != end) {
            // found - do one additional step
            ++it;
            if (it == end)
                it = locations.begin();
            const SymbolLocation &found = *it;
            gotoLocation(found.fileName(), found.line(), found.column());
            return;
        }
    }

    // no success - open first item in the list
    const SymbolLocation loc = *locations.constBegin();

    gotoLocation(loc.fileName(), loc.line(), loc.column());
}
Пример #2
0
void QTestOutputWidget::gotoLocation(QModelIndex index)
{
    if (!index.isValid())
        return;

    if (m_resultsView->model() == m_filterModel)
        index = m_filterModel->mapToSource(index);

    if (!index.isValid())
        return;

    const QAbstractItemModel *m = index.model();

    QModelIndex parent = index.parent();
    if (!parent.isValid())
        return;

    QModelIndex functionIndex = parent;
    QModelIndex failureIndex = index;

    QModelIndex grandParent = parent.parent();
    if (grandParent.isValid()) {
        functionIndex = grandParent;
        failureIndex = parent;
    }

    if (!functionIndex.isValid())
        return;

    QModelIndex locationIndex = m->index(failureIndex.row(), 1, functionIndex);
    if (!locationIndex.isValid())
        return;

    QVariant tag = locationIndex.data(Qt::UserRole + 1);
    if (tag.type() != QVariant::UserType
        || tag.userType() != qMetaTypeId<QTestLocation>())
        return;

    QTestLocation loc = tag.value<QTestLocation>();

    Core::ICore::instance()->editorManager()->openEditor(loc.file);
    Core::EditorInterface *edtIface = Core::ICore::instance()->editorManager()->currentEditor();
    if (!edtIface)
        return;
    TextEditor::ITextEditor *editor =
        qobject_cast<TextEditor::ITextEditor*>(edtIface->qObject());
    if (!editor)
        return;

    editor->gotoLine(loc.line.toInt());
}
Пример #3
0
void QmlProfilerTool::gotoSourceLocation(const QString &fileUrl, int lineNumber)
{
    if (lineNumber < 0 || fileUrl.isEmpty())
        return;

#if 0
    const QString fileName = QUrl(fileUrl).toLocalFile();
    const QString projectFileName = d->m_projectFinder.findFile(fileName);

    Core::EditorManager *editorManager = Core::EditorManager::instance();
    Core::IEditor *editor = editorManager->openEditor(projectFileName);
    TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor);

    if (textEditor) {
        editorManager->addCurrentPositionToNavigationHistory();
        textEditor->gotoLine(lineNumber);
        textEditor->widget()->setFocus();
    }
#endif
}