cppfindreferences.h 4.23 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Roberto Raggi's avatar
Roberto Raggi committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
Roberto Raggi's avatar
Roberto Raggi committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Roberto Raggi's avatar
Roberto Raggi committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
Roberto Raggi's avatar
Roberto Raggi committed
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
Roberto Raggi's avatar
Roberto Raggi committed
23
**
hjk's avatar
hjk committed
24 25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
Roberto Raggi's avatar
Roberto Raggi committed
29 30 31 32

#ifndef CPPFINDREFERENCES_H
#define CPPFINDREFERENCES_H

33 34 35
#include <cplusplus/DependencyTable.h>
#include <cplusplus/FindUsages.h>

36 37 38 39 40
#include <QMutex>
#include <QObject>
#include <QPointer>
#include <QFuture>
#include <QFutureWatcher>
Roberto Raggi's avatar
Roberto Raggi committed
41

42 43
QT_FORWARD_DECLARE_CLASS(QTimer)

44
namespace Core {
45 46
class SearchResultItem;
class SearchResult;
47
} // namespace Core
Roberto Raggi's avatar
Roberto Raggi committed
48

49
namespace CppTools {
50
class CppModelManagerInterface;
Roberto Raggi's avatar
Roberto Raggi committed
51

52
namespace Internal {
Roberto Raggi's avatar
Roberto Raggi committed
53

54 55 56
class CppFindReferencesParameters
{
public:
57 58
    QList<QByteArray> symbolId;
    QByteArray symbolFileName;
59 60
};

Roberto Raggi's avatar
Roberto Raggi committed
61 62 63 64 65
class CppFindReferences: public QObject
{
    Q_OBJECT

public:
66
    CppFindReferences(CppModelManagerInterface *modelManager);
Roberto Raggi's avatar
Roberto Raggi committed
67 68
    virtual ~CppFindReferences();

69
    QList<int> references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context) const;
70

Roberto Raggi's avatar
Roberto Raggi committed
71
public:
72
    void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
73 74
    void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
                      const QString &replacement = QString());
Roberto Raggi's avatar
Roberto Raggi committed
75

Christian Kamm's avatar
Christian Kamm committed
76
    void findMacroUses(const CPlusPlus::Macro &macro);
77
    void renameMacroUses(const CPlusPlus::Macro &macro, const QString &replacement = QString());
Christian Kamm's avatar
Christian Kamm committed
78

79 80
    CPlusPlus::DependencyTable updateDependencyTable(CPlusPlus::Snapshot snapshot);

81 82 83 84
public slots:
    void flushDependencyTable();

private slots:
Roberto Raggi's avatar
Roberto Raggi committed
85
    void displayResults(int first, int last);
Roberto Raggi's avatar
Roberto Raggi committed
86
    void searchFinished();
87
    void cancel();
88
    void setPaused(bool paused);
89 90
    void openEditor(const Core::SearchResultItem &item);
    void onReplaceButtonClicked(const QString &text, const QList<Core::SearchResultItem> &items, bool preserveCase);
91
    void searchAgain();
Roberto Raggi's avatar
Roberto Raggi committed
92

93
private:
94 95
    void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
                    const QString &replacement, bool replace);
96 97
    void findMacroUses(const CPlusPlus::Macro &macro, const QString &replacement,
                       bool replace);
98
    void findAll_helper(Core::SearchResult *search, CPlusPlus::Symbol *symbol,
99
                        const CPlusPlus::LookupContext &context);
100 101
    CPlusPlus::DependencyTable dependencyTable() const;
    void setDependencyTable(const CPlusPlus::DependencyTable &newTable);
102
    void createWatcher(const QFuture<CPlusPlus::Usage> &future, Core::SearchResult *search);
103 104
    CPlusPlus::Symbol *findSymbol(const CppFindReferencesParameters &parameters,
                    const CPlusPlus::Snapshot &snapshot, CPlusPlus::LookupContext *context);
105

Roberto Raggi's avatar
Roberto Raggi committed
106
private:
107
    QPointer<CppModelManagerInterface> m_modelManager;
108
    QMap<QFutureWatcher<CPlusPlus::Usage> *, QPointer<Core::SearchResult> > m_watchers;
109 110

    mutable QMutex m_depsLock;
111
    CPlusPlus::DependencyTable m_deps;
Roberto Raggi's avatar
Roberto Raggi committed
112 113
};

114 115
} // namespace Internal
} // namespace CppTools
Roberto Raggi's avatar
Roberto Raggi committed
116

117 118
Q_DECLARE_METATYPE(CppTools::Internal::CppFindReferencesParameters)

Roberto Raggi's avatar
Roberto Raggi committed
119
#endif // CPPFINDREFERENCES_H