2021-08-29 00:48:23 +08:00
|
|
|
#ifndef CODECOMPLETIONPOPUP_H
|
|
|
|
#define CODECOMPLETIONPOPUP_H
|
2021-08-23 21:50:53 +08:00
|
|
|
|
2021-08-24 09:59:44 +08:00
|
|
|
#include <QListView>
|
2021-08-23 21:50:53 +08:00
|
|
|
#include <QWidget>
|
2021-08-24 15:05:10 +08:00
|
|
|
#include "parser/cppparser.h"
|
2021-08-29 00:48:23 +08:00
|
|
|
#include "codecompletionlistview.h"
|
2021-08-28 09:01:40 +08:00
|
|
|
|
2021-08-25 08:48:33 +08:00
|
|
|
class CodeCompletionListModel : public QAbstractListModel {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2021-08-29 00:48:23 +08:00
|
|
|
explicit CodeCompletionListModel(const StatementList* statements,QObject *parent = nullptr);
|
2021-08-25 08:48:33 +08:00
|
|
|
int rowCount(const QModelIndex &parent) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
void notifyUpdated();
|
2021-08-28 09:01:40 +08:00
|
|
|
const ColorCallback &colorCallback() const;
|
|
|
|
void setColorCallback(const ColorCallback &newColorCallback);
|
|
|
|
|
2021-08-25 08:48:33 +08:00
|
|
|
private:
|
|
|
|
const StatementList* mStatements;
|
2021-08-28 09:01:40 +08:00
|
|
|
ColorCallback mColorCallback;
|
2021-08-25 08:48:33 +08:00
|
|
|
};
|
|
|
|
|
2021-08-29 00:48:23 +08:00
|
|
|
class CodeCompletionPopup : public QWidget
|
2021-08-23 21:50:53 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2021-08-29 00:48:23 +08:00
|
|
|
explicit CodeCompletionPopup(QWidget *parent = nullptr);
|
|
|
|
~CodeCompletionPopup();
|
2021-08-23 21:50:53 +08:00
|
|
|
|
2021-08-24 09:59:44 +08:00
|
|
|
void setKeypressedCallback(const KeyPressedCallback &newKeypressedCallback);
|
2021-08-25 00:20:07 +08:00
|
|
|
void prepareSearch(const QString& phrase, const QString& filename, int line);
|
2021-08-25 08:48:33 +08:00
|
|
|
bool search(const QString& phrase, bool autoHideOnSingleResult);
|
2021-08-25 00:20:07 +08:00
|
|
|
|
2021-08-26 17:48:23 +08:00
|
|
|
PStatement selectedStatement();
|
2021-08-24 09:59:44 +08:00
|
|
|
|
2021-08-25 23:53:35 +08:00
|
|
|
const PCppParser &parser() const;
|
|
|
|
void setParser(const PCppParser &newParser);
|
|
|
|
|
|
|
|
int showCount() const;
|
|
|
|
void setShowCount(int newShowCount);
|
|
|
|
|
|
|
|
bool onlyGlobals() const;
|
|
|
|
void setOnlyGlobals(bool newOnlyGlobals);
|
|
|
|
|
|
|
|
bool recordUsage() const;
|
|
|
|
void setRecordUsage(bool newRecordUsage);
|
|
|
|
|
|
|
|
bool showKeywords() const;
|
|
|
|
void setShowKeywords(bool newShowKeywords);
|
|
|
|
|
|
|
|
bool showCodeIns() const;
|
|
|
|
void setShowCodeIns(bool newShowCodeIns);
|
|
|
|
|
|
|
|
bool ignoreCase() const;
|
|
|
|
void setIgnoreCase(bool newIgnoreCase);
|
|
|
|
|
|
|
|
bool sortByScope() const;
|
|
|
|
void setSortByScope(bool newSortByScope);
|
|
|
|
|
|
|
|
bool useCppKeyword() const;
|
|
|
|
void setUseCppKeyword(bool newUseCppKeyword);
|
|
|
|
|
|
|
|
const PStatement ¤tStatement() const;
|
|
|
|
void setCurrentStatement(const PStatement &newCurrentStatement);
|
2021-08-28 09:01:40 +08:00
|
|
|
QHash<StatementKind, QColor>& colors();
|
2021-08-25 23:53:35 +08:00
|
|
|
|
2021-08-24 15:05:10 +08:00
|
|
|
private:
|
|
|
|
void addChildren(PStatement scopeStatement, const QString& fileName,
|
|
|
|
int line);
|
|
|
|
void addStatement(PStatement statement, const QString& fileName, int line);
|
|
|
|
void filterList(const QString& member);
|
|
|
|
void getCompletionFor(const QString& fileName,const QString& phrase, int line);
|
|
|
|
bool isIncluded(const QString& fileName);
|
2021-08-23 21:50:53 +08:00
|
|
|
private:
|
2021-08-24 09:59:44 +08:00
|
|
|
CodeCompletionListView * mListView;
|
2021-08-25 08:48:33 +08:00
|
|
|
CodeCompletionListModel* mModel;
|
2021-08-24 15:05:10 +08:00
|
|
|
QList<PCodeIns> mCodeInsList; //(Code template list)
|
|
|
|
//QList<PStatement> mCodeInsStatements; //temporary (user code template) statements created when show code suggestion
|
2021-08-25 08:48:33 +08:00
|
|
|
StatementList mFullCompletionStatementList;
|
|
|
|
StatementList mCompletionStatementList;
|
2021-08-24 15:05:10 +08:00
|
|
|
QSet<QString> mIncludedFiles;
|
|
|
|
QSet<QString> mUsings;
|
|
|
|
QSet<QString> mAddedStatements;
|
|
|
|
QString mPhrase;
|
|
|
|
QHash<QString,int> mSymbolUsage;
|
2021-08-25 23:53:35 +08:00
|
|
|
QRecursiveMutex mMutex;
|
2021-08-28 09:01:40 +08:00
|
|
|
QHash<StatementKind, QColor> mColors;
|
2021-08-25 23:53:35 +08:00
|
|
|
|
|
|
|
PCppParser mParser;
|
|
|
|
PStatement mCurrentStatement;
|
|
|
|
int mShowCount;
|
|
|
|
bool mOnlyGlobals;
|
2021-08-24 15:05:10 +08:00
|
|
|
bool mRecordUsage;
|
|
|
|
bool mShowKeywords;
|
|
|
|
bool mShowCodeIns;
|
|
|
|
bool mIgnoreCase;
|
|
|
|
bool mSortByScope;
|
|
|
|
bool mUseCppKeyword;
|
2021-08-25 00:20:07 +08:00
|
|
|
|
|
|
|
// QWidget interface
|
|
|
|
protected:
|
2021-08-26 17:48:23 +08:00
|
|
|
void showEvent(QShowEvent *event) override;
|
2021-08-25 00:20:07 +08:00
|
|
|
void hideEvent(QHideEvent *event) override;
|
2021-08-27 08:52:20 +08:00
|
|
|
|
|
|
|
// QObject interface
|
|
|
|
public:
|
|
|
|
bool event(QEvent *event) override;
|
2021-08-23 21:50:53 +08:00
|
|
|
};
|
|
|
|
|
2021-08-29 00:48:23 +08:00
|
|
|
#endif // CODECOMPLETIONPOPUP_H
|