Cherry-pick that revision, to restore scripts in the demo:

| ------------------------------------------------------------------------
  | r70911 | lrineau | 2012-07-31 17:30:38 +0200 (Tue, 31 Jul 2012) | 4 lines
  | Changed paths:
  |    M /branches/features/Mesh_3-experimental-GF/Polyhedron/demo/Polyhedron/MainWindow.cpp
  |    M /branches/features/Mesh_3-experimental-GF/Polyhedron/demo/Polyhedron/MainWindow.h
  |    M /branches/features/Mesh_3-experimental-GF/Polyhedron/demo/Polyhedron/MainWindow.ui
  |    M /branches/features/Mesh_3-experimental-GF/Polyhedron/demo/Polyhedron/geomodel.js
  |    M /branches/features/Mesh_3-experimental-GF/Polyhedron/demo/Polyhedron/testsuite.js
  | 
  | Restore the handling of scripts
  | 
  | + add a shortcut to the new "load script" action.
  | 
  |
  ------------------------------------------------------------------------
The .js files are not commited in next.
This commit is contained in:
Laurent Rineau 2012-07-31 15:45:47 +00:00
parent 96506df9c1
commit 5e9afc49f7
3 changed files with 69 additions and 9 deletions

View File

@ -667,6 +667,34 @@ void MainWindow::open(QString filename)
QFileInfo fileinfo(filename);
QString filename_striped=fileinfo.fileName();
#ifdef QT_SCRIPT_LIB
// Handles the loading of script file from the command line arguments,
// and the special command line arguments that start with "javascript:"
// or "qtscript:"
QString program;
if(filename.startsWith("javascript:")) {
program=filename.right(filename.size() - 11);
}
if(filename.startsWith("qtscript:")) {
program=filename.right(filename.size() - 9);
}
if(filename.endsWith(".js")) {
load_script(fileinfo);
return;
}
if(!program.isEmpty())
{
{
QTextStream(stderr) << "Execution of script \""
<< filename << "\"\n";
// << filename << "\", with following content:\n"
// << program;
}
evaluate_script(program, filename);
return;
}
#endif
//match all filters between ()
QRegExp all_filters_rx("\\((.*)\\)");
@ -713,10 +741,29 @@ void MainWindow::open(QString filename)
if(!ok || loader_name.isEmpty()) { return; }
Scene_item* scene_item = load_item(filename, find_loader(loader_name));
Scene_item* scene_item = load_item(fileinfo, find_loader(loader_name));
selectSceneItem(scene->addItem(scene_item));
}
bool MainWindow::open(QString filename, QString loader_name) {
QFileInfo fileinfo(filename);
Scene_item* item;
try {
item = load_item(fileinfo, find_loader(loader_name));
}
catch(std::logic_error e) {
std::cerr << e.what() << std::endl;
return false;
}
catch(std::invalid_argument e) {
std::cerr << e.what() << std::endl;
return false;
}
selectSceneItem(scene->addItem(item));
return true;
}
Scene_item* MainWindow::load_item(QFileInfo fileinfo, Polyhedron_demo_io_plugin_interface* loader) {
Scene_item* item = NULL;
if(!fileinfo.isFile() || !fileinfo.isReadable()) {
@ -925,7 +972,13 @@ void MainWindow::closeEvent(QCloseEvent *event)
event->accept();
}
void MainWindow::load_script(QFileInfo info)
bool MainWindow::load_script(QString filename)
{
QFileInfo fileinfo(filename);
return load_script(fileinfo);
}
bool MainWindow::load_script(QFileInfo info)
{
#if defined(QT_SCRIPT_LIB)
QString program;
@ -939,8 +992,10 @@ void MainWindow::load_script(QFileInfo info)
<< "Execution of script \""
<< filename << "\"\n";
evaluate_script(program, filename);
return true;
}
#endif
return false;
}
void MainWindow::on_actionLoad_Script_triggered()

View File

@ -40,11 +40,6 @@ public:
MainWindow(QWidget* parent = 0);
~MainWindow();
public slots:
void updateViewerBBox();
void open(QString);
/// Find an IO plugin.
/// @throws `std::invalid_argument` if no loader with that argument can be found
/// @returns the IO plugin associated with `loader_name`
@ -56,12 +51,22 @@ public slots:
/// `std::invalid_argument` if `fileinfo` specifies an invalid file
Scene_item* load_item(QFileInfo fileinfo, Polyhedron_demo_io_plugin_interface*);
public slots:
void updateViewerBBox();
void open(QString);
/// Open a file with a given loader, and return true iff it was successful.
///
/// This slot is for use by scripts.
bool open(QString filename, QString loader_name);
/// Reloads an item. Expects to be called by a QAction with the
/// index of the item to be reloaded as data attached to the action.
/// The index must identify a valid `Scene_item`.
void reload_item();
void load_script(QFileInfo);
bool load_script(QString filename);
bool load_script(QFileInfo);
void selectSceneItem(int i);
void showSelectedPoint(double, double, double);

View File

@ -627,7 +627,7 @@
</action>
<action name="actionLoad_Script">
<property name="text">
<string>Load Script</string>
<string>Load &amp;Script</string>
</property>
</action>
</widget>