21 #include <QtGui/QTreeWidget>
22 #include <QtGui/QTreeWidgetItem>
23 #include <QtGui/QVBoxLayout>
24 #include <QtGui/QTabWidget>
25 #include <QtGui/QHeaderView>
26 #include <QtGui/QLabel>
27 #include <QtGui/QTextBrowser>
28 #include <QtGui/QPushButton>
29 #include <QtGui/QSpacerItem>
30 #include <QtGui/QSizePolicy>
31 #include <QtGui/QSortFilterProxyModel>
32 #include <QtCore/QDir>
33 #include <QtCore/QFileInfo>
34 #include <QtGui/QFileDialog>
35 #include <QtGui/QMessageBox>
40 #define P3D_CONFIG_ENVVAR "P3D_CONFIG_PATH"
47 :
row(-1),parent(parent),label(label),path(path),
populated(parent==0)
52 for(
unsigned int i=0;i<
children.size();i++)
58 if(this->path==path)
return this;
61 for(
unsigned int i=0;i<
children.size();i++){
71 for(
unsigned int i=0;i<
children.size();i++) {
83 QFileInfoList infos=QDir(
path).entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
86 for(QList<QFileInfo>::ConstIterator
it=infos.constBegin();
it!=infos.constEnd();++
it){
87 const QFileInfo* fi=&*
it;
88 if(fi->isDir() || fi->fileName().endsWith(
".se")){
104 if(row<0 || row>(
int)
children.size()){
118 std::vector<QString> labels,paths;
119 for(
unsigned int i=0;i<
children.size();i++){
126 for(
unsigned int i=0;i<labels.size();i++)
164 void addPath(
const char* label,
const char* path)
171 if(!index.isValid())
return QModelIndex();
174 if(parentItem==
root)
return QModelIndex();
175 else return createIndex(parentItem->
row,0,parentItem);
178 QModelIndex
index(
int row,
int column,
const QModelIndex&
parent=QModelIndex())
const
180 if(!hasIndex(row,column,
parent))
181 return QModelIndex();
185 return createIndex(row,column,item->
getChild(row));
190 {Q_UNUSED(parent);
return 1;}
202 QVariant
data(
const QModelIndex&
index,
int role=Qt::DisplayRole)
const
204 if(!index.isValid())
return QVariant();
205 if(role!=Qt::DisplayRole)
return QVariant();
207 if(!item)
return QVariant();
208 else return QVariant(item->
label);
220 std::cerr<<
"found it "<<std::endl;
221 return createIndex(item->
row,0,item);
224 return QModelIndex();
233 :QSortFilterProxyModel(parent)
243 if(sourceParent.isValid() &&
244 sourceModel()->data(sourceParent).toString().contains(filterRegExp()))
return true;
245 QString data=sourceModel()->data(sourceModel()->
index(sourceRow,0,sourceParent)).toString();
246 bool keep=data.contains(filterRegExp());
248 QModelIndex subIndex=sourceModel()->index(sourceRow,0,sourceParent);
249 if(subIndex.isValid()){
250 for(
int i=0;i<sourceModel()->rowCount(subIndex);++i)
264 :QWidget(parent),editor(editor),
269 QVBoxLayout* rootLayout =
new QVBoxLayout;
270 rootLayout->setMargin(0);
271 this->setLayout(rootLayout);
273 QHBoxLayout* searchAndClearLayout=
new QHBoxLayout();
276 searchAndClearLayout->addWidget(
exprFilter,2);
277 QPushButton* clearFilterButton=
new QPushButton(
"X");
278 clearFilterButton->setFixedWidth(24);
279 searchAndClearLayout->addWidget(clearFilterButton,1);
280 rootLayout->addLayout(searchAndClearLayout);
281 connect(clearFilterButton,SIGNAL(clicked()),SLOT(
clearFilter()));
290 treeNew->setHeaderHidden(
true);
291 rootLayout->addWidget(
treeNew);
293 treeNew->setSelectionMode(QAbstractItemView::SingleSelection);
294 connect(
treeNew->selectionModel(),SIGNAL(currentChanged(
const QModelIndex&,
const QModelIndex&)),SLOT(
handleSelection(
const QModelIndex&,
const QModelIndex&)));
299 labels.append(QString::fromStdString(name));
300 paths.append(QString::fromStdString(path));
312 QModelIndex sel=
treeNew->currentIndex();
314 QModelIndex realCurrent=
proxyModel->mapToSource(sel);
316 return item->
path.toStdString();
318 return std::string(
"");
336 if(current.isValid()){
337 QModelIndex realCurrent=
proxyModel->mapToSource(current);
339 QString path=item->
path;
340 if(path.endsWith(
".se")){
341 std::ifstream file(path.toStdString().c_str());
342 std::string fileContents((std::istreambuf_iterator<char>(file)),std::istreambuf_iterator<char>());
381 QString path = QFileDialog::getSaveFileName(
382 this,
"Save Expression", QString::fromStdString(
_userExprDir),
385 if (path.length() > 0) {
386 std::ofstream file(path.toStdString().c_str());
388 QString msg = QString(
"Could not open file %1 for writing").arg(path);
389 QMessageBox::warning(
this,
"Error",
390 QString(
"<font face=fixed>%1</font>")
404 QString path = QFileDialog::getSaveFileName(
405 this,
"Save Expression", QString::fromStdString(
_localExprDir),
408 if (path.length() > 0) {
409 std::ofstream file(path.toStdString().c_str());
411 QString msg = QString(
"Could not open file %1 for writing").arg(path);
412 QMessageBox::warning(
this,
"Error",
413 QString(
"<font face=fixed>%1</font>")
429 if (path.length() == 0) {
433 std::ofstream file(path.c_str());
435 QString msg = QString(
"Could not open file %1 for writing. Is it read-only?").arg(QString::fromStdString(path));
436 QMessageBox::warning(
this,
"Error",
437 QString(
"<font face=fixed>%1</font>")
458 char* homepath = getenv(
"HOME");
460 std::string path= std::string(homepath) +
"/" + context +
"/expressions/";
461 if(QDir(QString(path.c_str())).exists()){
463 addPath(
"My Expressions",path);
476 bool enableLocal =
false;
496 std::string configFile=std::string(env)+
"/config.txt";
497 std::ifstream file(configFile.c_str());
506 file.getline(buffer,1024);
508 if (key==
"ExpressionDir"){
509 std::string label,path;
512 if(QDir(QString(path.c_str())).exists())
514 }
else if (key==
"ExpressionSubDir"){
518 if(QDir(QString(path.c_str())).exists()){
525 }
else if (key ==
"GlobalRepo") {
528 path +=
"/expressions/";
529 if(QDir(QString(path.c_str())).exists())
531 }
else if (key ==
"LocalRepo") {
534 path +=
"/expressions/";
536 if(QDir(QString(path.c_str())).exists()){
570 file.getline(buffer,1024);
void setSearchPath(const QString &context, const QString &path)
void selectPath(const char *path)
void addPath(const std::string &name, const std::string &path)
void addChild(ExprTreeItem *child)
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
QModelIndex parent(const QModelIndex &index) const
void filterChanged(const QString &str)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
std::vector< ExprTreeItem * > children
ExprTreeModel * treeModel
void addPath(const char *label, const char *path)
The result is computed int int< br >< divstyle="margin-left:40px;"> Picks values randomly between loRange and hiRange based on supplied index(which is automatically hashed). 
ExprTreeFilterModel * proxyModel
std::string getSelectedPath()
void saveLocalExpressionAs()
ExprTreeItem * find(QString path)
void addUserExpressionPath(const std::string &context)
ExprTreeItem * getChild(const int row)
If a scalar is used in a vector context
std::string _localExprDir
int rowCount(const QModelIndex &parent=QModelIndex()) const
int columnCount(const QModelIndex &parent) const
void expandToDepth(int depth)
ExprBrowser(QWidget *parent, ExprEditor *editor)
QModelIndex find(QString path)
void handleSelection(const QModelIndex ¤t, const QModelIndex &previous)
ExprTreeFilterModel(QWidget *parent=0)
#define P3D_CONFIG_ENVVAR
you may not use this file except in compliance with the License and the following modification to it
void setExpr(const std::string &expression, const bool apply=false)
ExprTreeItem(ExprTreeItem *parent, const QString &label, const QString &path)