24#include <QTreeWidgetItem>
29#include <QTextBrowser>
33#include <QSortFilterProxyModel>
41#define P3D_CONFIG_ENVVAR "P3D_CONFIG_PATH"
53 if (this->path ==
path)
57 for (
unsigned int i = 0; i <
children.size(); i++) {
66 for (
unsigned int i = 0; i <
children.size(); i++) {
77 QFileInfoList infos = QDir(
path).entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
80 for (QList<QFileInfo>::ConstIterator
it = infos.constBegin();
it != infos.constEnd(); ++
it) {
81 const QFileInfo* fi = &*
it;
82 if (fi->isDir() || fi->fileName().endsWith(
".se")) {
108 std::vector<QString> labels, paths;
109 for (
unsigned int i = 0; i <
children.size(); i++) {
116 for (
unsigned int i = 0; i < labels.size(); i++)
addChild(
new ExprTreeItem(
this, labels[i], paths[i]));
152 if (!
index.isValid())
return QModelIndex();
155 if (parentItem ==
root)
156 return QModelIndex();
158 return createIndex(parentItem->
row, 0, parentItem);
161 QModelIndex
index(
int row,
int column,
const QModelIndex&
parent = QModelIndex())
const {
162 if (!hasIndex(row, column,
parent))
163 return QModelIndex();
164 else if (!
parent.isValid())
168 return createIndex(row, column, item->
getChild(row));
189 QVariant
data(
const QModelIndex&
index,
int role = Qt::DisplayRole)
const {
190 if (!
index.isValid())
return QVariant();
191 if (role != Qt::DisplayRole)
return QVariant();
196 return QVariant(item->
label);
199 QModelIndex
find(QString path) {
208 std::cerr <<
"found it " << std::endl;
209 return createIndex(item->
row, 0, item);
212 return QModelIndex();
227 if (sourceParent.isValid() && sourceModel()->data(sourceParent).toString().contains(filterRegExp()))
229 QString data = sourceModel()->data(sourceModel()->
index(sourceRow, 0, sourceParent)).toString();
230 bool keep = data.contains(filterRegExp());
232 QModelIndex subIndex = sourceModel()->index(sourceRow, 0, sourceParent);
233 if (subIndex.isValid()) {
234 for (
int i = 0; i < sourceModel()->rowCount(subIndex); ++i) keep = keep ||
filterAcceptsRow(i, subIndex);
243 : QWidget(parent), editor(editor), _context(
""), _searchPath(
""), _applyOnSelect(true) {
244 QVBoxLayout* rootLayout =
new QVBoxLayout;
245 rootLayout->setMargin(0);
246 this->setLayout(rootLayout);
248 QHBoxLayout* searchAndClearLayout =
new QHBoxLayout();
251 searchAndClearLayout->addWidget(
exprFilter, 2);
252 QPushButton* clearFilterButton =
new QPushButton(
"X");
253 clearFilterButton->setFixedWidth(24);
254 searchAndClearLayout->addWidget(clearFilterButton, 1);
255 rootLayout->addLayout(searchAndClearLayout);
256 connect(clearFilterButton, SIGNAL(clicked()), SLOT(
clearFilter()));
265 treeNew->setHeaderHidden(
true);
266 rootLayout->addWidget(
treeNew);
268 treeNew->setSelectionMode(QAbstractItemView::SingleSelection);
269 connect(
treeNew->selectionModel(),
270 SIGNAL(currentChanged(
const QModelIndex&,
const QModelIndex&)),
275 labels.append(QString::fromStdString(name));
276 paths.append(QString::fromStdString(path));
286 QModelIndex sel =
treeNew->currentIndex();
288 QModelIndex realCurrent =
proxyModel->mapToSource(sel);
290 return item->
path.toStdString();
292 return std::string(
"");
307 if (current.isValid()) {
308 QModelIndex realCurrent =
proxyModel->mapToSource(current);
310 QString path = item->
path;
311 if (path.endsWith(
".se")) {
312 std::ifstream
file(path.toStdString().c_str());
313 std::string fileContents((std::istreambuf_iterator<char>(
file)), std::istreambuf_iterator<char>());
342 QString path = QFileDialog::getSaveFileName(
this,
"Save Expression", QString::fromStdString(
_userExprDir),
"*.se");
344 if (path.length() > 0) {
345 std::ofstream
file(path.toStdString().c_str());
347 QString msg = QString(
"Could not open file %1 for writing").arg(path);
348 QMessageBox::warning(
this,
"Error", QString(
"<font face=fixed>%1</font>").arg(msg));
351 file << editor->getExpr();
360 QString path = QFileDialog::getSaveFileName(
this,
"Save Expression", QString::fromStdString(
_localExprDir),
"*.se");
362 if (path.length() > 0) {
363 std::ofstream
file(path.toStdString().c_str());
365 QString msg = QString(
"Could not open file %1 for writing").arg(path);
366 QMessageBox::warning(
this,
"Error", QString(
"<font face=fixed>%1</font>").arg(msg));
369 file << editor->getExpr();
379 if (path.length() == 0) {
383 std::ofstream
file(path.c_str());
386 QString(
"Could not open file %1 for writing. Is it read-only?").arg(QString::fromStdString(path));
387 QMessageBox::warning(
this,
"Error", QString(
"<font face=fixed>%1</font>").arg(msg));
390 file << editor->getExpr();
400 char* homepath = getenv(
"HOME");
402 std::string path = std::string(homepath) +
"/" +
context +
"/expressions/";
403 if (QDir(QString(path.c_str())).exists()) {
405 addPath(
"My Expressions", path);
417 bool enableLocal =
false;
425 if (!env)
return enableLocal;
436 std::string configFile = std::string(env) +
"/config.txt";
437 std::ifstream
file(configFile.c_str());
446 file.getline(buffer, 1024);
448 if (key ==
"ExpressionDir") {
449 std::string label, path;
452 if (QDir(QString(path.c_str())).exists())
addPath(label, path);
453 }
else if (key ==
"ExpressionSubDir") {
457 if (QDir(QString(path.c_str())).exists()) {
464 }
else if (key ==
"GlobalRepo") {
467 path +=
"/expressions/";
468 if (QDir(QString(path.c_str())).exists())
addPath(
"Global", path);
469 }
else if (key ==
"LocalRepo") {
472 path +=
"/expressions/";
474 if (QDir(QString(path.c_str())).exists()) {
508 file.getline(buffer, 1024);
#define P3D_CONFIG_ENVVAR
file(GLOB io_cpp "*.cpp") file(GLOB to_remove "ExprLLVMCodeGeneration.cpp") list(REMOVE_ITEM io_cpp $
void expandToDepth(int depth)
void setSearchPath(const QString &context, const QString &path)
void handleSelection(const QModelIndex ¤t, const QModelIndex &previous)
void saveLocalExpressionAs()
void filterChanged(const QString &str)
ExprBrowser(QWidget *parent, ExprEditor *editor)
void addUserExpressionPath(const std::string &context)
void addPath(const std::string &name, const std::string &path)
std::string getSelectedPath()
ExprTreeFilterModel * proxyModel
void selectPath(const char *path)
std::string _localExprDir
ExprTreeModel * treeModel
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
ExprTreeFilterModel(QWidget *parent=0)
ExprTreeItem * getChild(const int row)
ExprTreeItem(ExprTreeItem *parent, const QString &label, const QString &path)
void addChild(ExprTreeItem *child)
std::vector< ExprTreeItem * > children
ExprTreeItem * find(QString path)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
int columnCount(const QModelIndex &parent) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
int rowCount(const QModelIndex &parent=QModelIndex()) const
QModelIndex find(QString path)
QModelIndex parent(const QModelIndex &index) const
void addPath(const char *label, const char *path)
you may not use this file except in compliance with the License and the following modification to it
If a scalar is used in a vector context
The result is computed int int< br >< div style="margin-left: 40px;"> Picks values randomly between loRange and hiRange based on supplied index(which is automatically hashed).