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
30class 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
std::vector< QString > local_variables
static std::vector< QString > builtins
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
std::vector< QString > functions
std::vector< QString > variables
std::vector< QString > functions_comment
int columnCount(const QModelIndex &parent) const
QString getFirstLine(const std::string &all) const
QModelIndex index(int row, int column, const QModelIndex &) const
QString getDocString(const QString &s)
ExprCompletionModel(QObject *parent=0)
void syncExtras(const ExprCompletionModel &otherModel)
void addVariable(const QString &str, const QString &comment)
QModelIndex parent(const QModelIndex &) const
std::vector< QString > variables_comment
void addFunction(const QString &function, const QString &docString)
int rowCount(const QModelIndex &parent=QModelIndex()) const
std::map< QString, int > functionNameToFunction
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const