SeExpr

ExprCompletionModel.h
Go to the documentation of this file.
1 /*
2 * Copyright Disney Enterprises, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License
6 * and the following modification to it: Section 6 Trademarks.
7 * deleted and replaced with:
8 *
9 * 6. Trademarks. This License does not grant permission to use the
10 * trade names, trademarks, service marks, or product names of the
11 * Licensor and its affiliates, except as required for reproducing
12 * the content of the NOTICE file.
13 *
14 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * @file ExprCompletionModel.h
18 * @brief Provides a model for providing completion items
19 * @author aselle
20 */
21
22 #ifndef ExprCompletionModel_h
23 #define ExprCompletionModel_h
24
25 #include <QtCore/QAbstractItemModel>
26 #include <QtCore/QString>
27 #include <QtCore/QSize>
28 #include <vector>
29
30 class ExprCompletionModel : public QAbstractItemModel // ItemModel
31 {
32 public:
33 // clear/add functions (these are ones that will be resolved with resolveFunc()
34 void clearFunctions();
35 void addFunction(const QString& function, const QString& docString);
36
37 // clear/add user variables (these are ones that will be resolved with resolveVar()
38 void clearVariables();
39 void addVariable(const QString& str, const QString& comment);
40
41 // add extras
42 void syncExtras(const ExprCompletionModel& otherModel);
43
44 ExprCompletionModel(QObject* parent = 0);
45
46 QModelIndex index(int row, int column, const QModelIndex&) const { return createIndex(row, column, nullptr); }
47
48 QModelIndex parent(const QModelIndex&) const { return QModelIndex(); }
49
50 int rowCount(const QModelIndex& parent = QModelIndex()) const {
51 Q_UNUSED(parent);
52 int count = builtins.size() + functions.size() + variables.size() + local_variables.size();
53 return count;
54 }
55
56 int columnCount(const QModelIndex& parent) const {
57 Q_UNUSED(parent);
58 return 2;
59 }
60
61 QString getFirstLine(const std::string& all) const {
62 size_t newline = all.find("\n");
63 if (newline != std::string::npos)
64 return QString(all.substr(0, newline).c_str());
65 else
66 return QString(all.c_str());
67 }
68
69 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
70
71 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const {
72 Q_UNUSED(orientation);
73 if (role == Qt::DisplayRole)
74 return QVariant("");
75 else if (role == Qt::SizeHintRole) {
76 if (section == 0)
77 return QVariant(QSize(100, 1));
78 else
79 return QVariant(QSize(200, 1));
80 } else
81 return QVariant();
82 }
83 std::vector<QString> local_variables; // only the expression editor itself should modify these
84
85 QString getDocString(const QString& s);
86
87 private:
88 static std::vector<QString> builtins;
89 std::vector<QString> functions, functions_comment;
90 std::map<QString, int> functionNameToFunction;
91 std::vector<QString> variables, variables_comment;
92 };
93
94 #endif
ExprCompletionModel::getDocString
QString getDocString(const QString &s)
Definition: ExprCompletionModel.cpp:125
ExprCompletionModel::clearVariables
void clearVariables()
Definition: ExprCompletionModel.cpp:36
ExprCompletionModel::columnCount
int columnCount(const QModelIndex &parent) const
Definition: ExprCompletionModel.h:56
ExprCompletionModel::getFirstLine
QString getFirstLine(const std::string &all) const
Definition: ExprCompletionModel.h:61
ExprCompletionModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: ExprCompletionModel.h:71
ExprCompletionModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: ExprCompletionModel.h:50
ExprCompletionModel::functionNameToFunction
std::map< QString, int > functionNameToFunction
Definition: ExprCompletionModel.h:90
ExprCompletionModel::functions_comment
std::vector< QString > functions_comment
Definition: ExprCompletionModel.h:89
ExprCompletionModel::local_variables
std::vector< QString > local_variables
Definition: ExprCompletionModel.h:83
ExprCompletionModel::addVariable
void addVariable(const QString &str, const QString &comment)
Definition: ExprCompletionModel.cpp:41
ExprCompletionModel::index
QModelIndex index(int row, int column, const QModelIndex &) const
Definition: ExprCompletionModel.h:46
ExprCompletionModel::clearFunctions
void clearFunctions()
Definition: ExprCompletionModel.cpp:46
ExprCompletionModel::ExprCompletionModel
ExprCompletionModel(QObject *parent=0)
Definition: ExprCompletionModel.cpp:28
ExprCompletionModel::parent
QModelIndex parent(const QModelIndex &) const
Definition: ExprCompletionModel.h:48
ExprCompletionModel::variables
std::vector< QString > variables
Definition: ExprCompletionModel.h:91
ExprCompletionModel
Definition: ExprCompletionModel.h:30
ExprCompletionModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: ExprCompletionModel.cpp:66
ExprCompletionModel::functions
std::vector< QString > functions
Definition: ExprCompletionModel.h:89
ExprCompletionModel::builtins
static std::vector< QString > builtins
Definition: ExprCompletionModel.h:88
ExprCompletionModel::addFunction
void addFunction(const QString &function, const QString &docString)
Definition: ExprCompletionModel.cpp:52
ExprCompletionModel::variables_comment
std::vector< QString > variables_comment
Definition: ExprCompletionModel.h:91
ExprCompletionModel::syncExtras
void syncExtras(const ExprCompletionModel &otherModel)
Definition: ExprCompletionModel.cpp:58