cppfindreferences.h 3.5 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Roberto Raggi's avatar
Roberto Raggi committed
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
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
** 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
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
Roberto Raggi's avatar
Roberto Raggi committed
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
con's avatar
con committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
Roberto Raggi's avatar
Roberto Raggi committed
25

26
#pragma once
Roberto Raggi's avatar
Roberto Raggi committed
27

28 29
#include <cplusplus/FindUsages.h>

30 31 32 33 34
#include <QMutex>
#include <QObject>
#include <QPointer>
#include <QFuture>
#include <QFutureWatcher>
Roberto Raggi's avatar
Roberto Raggi committed
35

36 37
QT_FORWARD_DECLARE_CLASS(QTimer)

38
namespace Core {
39 40
class SearchResultItem;
class SearchResult;
41
} // namespace Core
Roberto Raggi's avatar
Roberto Raggi committed
42

43
namespace CppTools {
44
class CppModelManager;
Roberto Raggi's avatar
Roberto Raggi committed
45

46
namespace Internal {
Roberto Raggi's avatar
Roberto Raggi committed
47

48 49 50
class CppFindReferencesParameters
{
public:
51 52
    QList<QByteArray> symbolId;
    QByteArray symbolFileName;
53 54
};

Roberto Raggi's avatar
Roberto Raggi committed
55 56 57 58 59
class CppFindReferences: public QObject
{
    Q_OBJECT

public:
60
    CppFindReferences(CppModelManager *modelManager);
Roberto Raggi's avatar
Roberto Raggi committed
61 62
    virtual ~CppFindReferences();

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

Roberto Raggi's avatar
Roberto Raggi committed
65
public:
66
    void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
67 68
    void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
                      const QString &replacement = QString());
Roberto Raggi's avatar
Roberto Raggi committed
69

Christian Kamm's avatar
Christian Kamm committed
70
    void findMacroUses(const CPlusPlus::Macro &macro);
71
    void renameMacroUses(const CPlusPlus::Macro &macro, const QString &replacement = QString());
Christian Kamm's avatar
Christian Kamm committed
72

73
private:
Roberto Raggi's avatar
Roberto Raggi committed
74
    void displayResults(int first, int last);
Roberto Raggi's avatar
Roberto Raggi committed
75
    void searchFinished();
76
    void cancel();
77
    void setPaused(bool paused);
78 79
    void openEditor(const Core::SearchResultItem &item);
    void onReplaceButtonClicked(const QString &text, const QList<Core::SearchResultItem> &items, bool preserveCase);
80
    void searchAgain();
Roberto Raggi's avatar
Roberto Raggi committed
81

82 83
    void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
                    const QString &replacement, bool replace);
84 85
    void findMacroUses(const CPlusPlus::Macro &macro, const QString &replacement,
                       bool replace);
86
    void findAll_helper(Core::SearchResult *search, CPlusPlus::Symbol *symbol,
87
                        const CPlusPlus::LookupContext &context);
88
    void createWatcher(const QFuture<CPlusPlus::Usage> &future, Core::SearchResult *search);
89 90
    CPlusPlus::Symbol *findSymbol(const CppFindReferencesParameters &parameters,
                    const CPlusPlus::Snapshot &snapshot, CPlusPlus::LookupContext *context);
91

Roberto Raggi's avatar
Roberto Raggi committed
92
private:
93
    QPointer<CppModelManager> m_modelManager;
94
    QMap<QFutureWatcher<CPlusPlus::Usage> *, QPointer<Core::SearchResult> > m_watchers;
Roberto Raggi's avatar
Roberto Raggi committed
95 96
};

97 98
} // namespace Internal
} // namespace CppTools
Roberto Raggi's avatar
Roberto Raggi committed
99

100
Q_DECLARE_METATYPE(CppTools::Internal::CppFindReferencesParameters)