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
47  {return createIndex(row,column,0);}
48 
49  QModelIndex parent(const QModelIndex&) const
50  {return QModelIndex();}
51 
52  int rowCount(const QModelIndex& parent=QModelIndex()) const
53  {
54  Q_UNUSED(parent);
55  int count= builtins.size()+functions.size()+variables.size()+local_variables.size();
56  return count;
57  }
58 
59  int columnCount(const QModelIndex& parent) const
60  {Q_UNUSED(parent); return 2;}
61 
62  QString getFirstLine(const std::string& all) const
63  {
64  size_t newline=all.find("\n");
65  if(newline!=std::string::npos) return QString(all.substr(0,newline).c_str());
66  else 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  {
73  Q_UNUSED(orientation);
74  if(role==Qt::DisplayRole) return QVariant("");
75  else if(role==Qt::SizeHintRole){
76  if(section==0) return QVariant(QSize(100,1));
77  else return QVariant(QSize(200,1));
78  }else return QVariant();
79  }
80  std::vector<QString> local_variables; // only the expression editor itself should modify these
81 
82  QString getDocString(const QString& s);
83 private:
84  static std::vector<QString> builtins;
85  std::vector<QString> functions,functions_comment;
86  std::map<QString,int> functionNameToFunction;
87  std::vector<QString> variables,variables_comment;
88 };
89 
90 
91 
92 #endif
std::vector< QString > variables
void addVariable(const QString &str, const QString &comment)
std::vector< QString > local_variables
void addFunction(const QString &function, const QString &docString)
QModelIndex parent(const QModelIndex &) const
int rowCount(const QModelIndex &parent=QModelIndex()) const
std::map< QString, int > functionNameToFunction
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
ExprCompletionModel(QObject *parent=0)
int columnCount(const QModelIndex &parent) const
QModelIndex index(int row, int column, const QModelIndex &) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
std::vector< QString > functions_comment
std::vector< QString > functions
std::vector< QString > variables_comment
QString getFirstLine(const std::string &all) const
void syncExtras(const ExprCompletionModel &otherModel)
static std::vector< QString > builtins
QString getDocString(const QString &s)