13 #include <QCoreApplication>
19 : QAbstractItemModel(parent)
21 std::vector<std::string> builtins_std;
23 for (
const auto &func : builtins_std) {
66 static QColor variableColor = QColor(100, 200, 250);
67 static QColor functionColor = QColor(100, 250, 200);
68 static QColor backgroundColor(50, 50, 50);
72 auto row =
static_cast<size_t>(
index.row());
73 auto column =
index.column();
75 auto functions_offset =
builtins.size();
76 auto variables_offset = functions_offset +
functions.size();
77 auto local_variables_offset = variables_offset +
variables.size();
79 if (role == Qt::BackgroundRole)
80 return backgroundColor;
82 if (role == Qt::FontRole && column == 0) {
88 if (row < functions_offset) {
90 if (role == Qt::DisplayRole || role == Qt::EditRole) {
95 }
else if (role == Qt::ForegroundRole)
97 }
else if (row < variables_offset) {
98 auto index = row - functions_offset;
99 if (role == Qt::DisplayRole || role == Qt::EditRole) {
102 else if (column == 1)
104 }
else if (role == Qt::ForegroundRole)
105 return functionColor;
106 }
else if (row < local_variables_offset) {
107 auto index = row - variables_offset;
108 if (role == Qt::DisplayRole || role == Qt::EditRole) {
111 else if (column == 1)
113 }
else if (role == Qt::ForegroundRole)
114 return variableColor;
116 auto index = row - local_variables_offset;
117 if (role == Qt::DisplayRole || role == Qt::EditRole) {
120 else if (column == 1)
121 return QVariant(tr(
"Local"));
122 }
else if (role == Qt::ForegroundRole)
123 return variableColor;
static const char * CONTEXT
QModelIndex index(int row, int column, const QModelIndex &) const override
std::vector< QString > local_variables
static QString getFirstLine(const std::string &all)
std::vector< QString > functions
std::vector< QString > variables
std::vector< QString > functions_comment
QString getDocString(const QString &s)
ExprCompletionModel(QObject *parent=0)
void syncExtras(const ExprCompletionModel &otherModel)
void addVariable(const QString &str, const QString &comment)
void addFunction(const QString &, const QString &)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
std::vector< QString > variables_comment
std::vector< QString > builtins
std::map< QString, int > functionNameToFunction
static void getFunctionNames(std::vector< std::string > &names)
Get a list of registered builtin and DSO generated functions.
static std::string getDocString(const char *functionName)
Get doc string for a specific function.