From ad7738646da5f8b7a621f654299f16607dafcfb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 31 Jan 2013 17:38:44 +0100 Subject: [PATCH 1/4] add a mechanism to set a default loader for a given filetype for one run only --- Polyhedron/demo/Polyhedron/CMakeLists.txt | 7 +- .../demo/Polyhedron/FileLoaderDialog.ui | 140 ++++++++++++++++++ .../demo/Polyhedron/File_loader_dialog.h | 29 ++++ Polyhedron/demo/Polyhedron/MainWindow.cpp | 68 +++++---- Polyhedron/demo/Polyhedron/MainWindow.h | 2 +- 5 files changed, 217 insertions(+), 29 deletions(-) create mode 100644 Polyhedron/demo/Polyhedron/FileLoaderDialog.ui create mode 100644 Polyhedron/demo/Polyhedron/File_loader_dialog.h diff --git a/Polyhedron/demo/Polyhedron/CMakeLists.txt b/Polyhedron/demo/Polyhedron/CMakeLists.txt index 5e998d6ad6e..1508f293b76 100644 --- a/Polyhedron/demo/Polyhedron/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/CMakeLists.txt @@ -98,6 +98,7 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) endif(NOT EIGEN3_FOUND AND NOT LAPACK_FOUND) qt4_wrap_ui( MainWindowUI_files MainWindow.ui ) + qt4_wrap_ui( FileLoaderDialogUI_files FileLoaderDialog.ui ) qt4_wrap_ui( Show_point_dialogUI_FILES Show_point_dialog.ui ) qt4_wrap_ui( remeshingUI_FILES Remeshing_dialog.ui) qt4_wrap_ui( meshingUI_FILES Meshing_dialog.ui Meshing_pause_widget.ui ) @@ -107,7 +108,9 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) qt4_wrap_ui( funcUI_FILES Function_dialog.ui ) qt4_generate_moc( "MainWindow.h" "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp" ) + qt4_generate_moc( "File_loader_dialog.h" "${CMAKE_CURRENT_BINARY_DIR}/File_loader_dialog_moc.cpp" ) add_file_dependencies( MainWindow_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/MainWindow.h" ) + add_file_dependencies( File_loader_dialog_moc_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/File_loader_dialog.h" ) qt4_generate_moc( "Viewer.h" "${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" ) add_file_dependencies( Viewer_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/Viewer.h" ) @@ -227,8 +230,9 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) # Scene.cpp # MainWindow_curvature_estimation.cpp MainWindow_moc.cpp + File_loader_dialog_moc.cpp # Viewer_moc.cpp - ${MainWindowUI_files} ${PreferencesUI_FILES} ${RESOURCE_FILES} ) + ${FileLoaderDialogUI_files} ${MainWindowUI_files} ${PreferencesUI_FILES} ${RESOURCE_FILES} ) add_to_cached_list( CGAL_EXECUTABLE_TARGETS Polyhedron_3 ) if(EIGEN3_FOUND OR TAUCS_FOUND) # add_executable( Polyhedron_3 Scene_tex_rendering.cpp Scene_tex_polyhedron_operations.cpp ) @@ -236,6 +240,7 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) # else(POLYHEDRON_DEMO_ENABLE_FORWARD_DECL) # add_file_dependencies( Polyhedron_3.cpp "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp" # "${CMAKE_CURRENT_BINARY_DIR}/Scene_moc.cpp" +# "${CMAKE_CURRENT_BINARY_DIR}/File_loader_dialog_moc.cpp" # "${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" ) # add_executable ( Polyhedron_3 Polyhedron_3.cpp ${UI_FILES} ${RESOURCE_FILES} ) # endif(POLYHEDRON_DEMO_ENABLE_FORWARD_DECL) diff --git a/Polyhedron/demo/Polyhedron/FileLoaderDialog.ui b/Polyhedron/demo/Polyhedron/FileLoaderDialog.ui new file mode 100644 index 00000000000..54b02d0eebc --- /dev/null +++ b/Polyhedron/demo/Polyhedron/FileLoaderDialog.ui @@ -0,0 +1,140 @@ + + + FileLoaderDialog + + + + 0 + 0 + 353 + 144 + + + + + 0 + 0 + + + + Select a loader + + + Qt::LeftToRight + + + false + + + + + 170 + 80 + 181 + 32 + + + + Qt::LeftToRight + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 30 + 40 + 321 + 31 + + + + + + + + + + + + + + + + 30 + 120 + 281 + 26 + + + + + 0 + 0 + + + + + + + + + + 0 + 10 + 371 + 21 + + + + + 0 + 0 + + + + TextLabel + + + + + + + buttonBox + accepted() + FileLoaderDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + FileLoaderDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/Polyhedron/demo/Polyhedron/File_loader_dialog.h b/Polyhedron/demo/Polyhedron/File_loader_dialog.h new file mode 100644 index 00000000000..b6d512c6112 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/File_loader_dialog.h @@ -0,0 +1,29 @@ +#include +#include +#include "ui_FileLoaderDialog.h" + +class File_loader_dialog : public QDialog, private Ui::FileLoaderDialog +{ + Q_OBJECT + public: + File_loader_dialog() + { + setupUi(this); + } + static + std::pair + getItem(QString filename, const QStringList& item_list, bool* ok) + { + File_loader_dialog dialog; + dialog.pluginBox->addItems(item_list); + dialog.label->setText(tr("Available loaders for %1 :").arg(filename)); + QFileInfo fileinfo(filename); + dialog.alwaysUse->setText(tr("use for &all *.%1 files in this session").arg(fileinfo.completeSuffix()) ); + *ok = dialog.exec(); + return std::make_pair( + dialog.pluginBox->currentText(), + dialog.alwaysUse->isChecked() + ); + } + +}; diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 065ddec7db7..05ab13636c0 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -43,6 +43,7 @@ #include "ui_Preferences.h" #include "Show_point_dialog.h" +#include "File_loader_dialog.h" #ifdef QT_SCRIPT_LIB # include @@ -713,57 +714,70 @@ void MainWindow::open(QString filename) return; } - //match all filters between () - QRegExp all_filters_rx("\\((.*)\\)"); - - // collect all io_plugins and offer them to load if the file extension match one name filter - // also collect all available plugin in case of a no extension match + QStringList selected_items; QStringList all_items; - Q_FOREACH(Polyhedron_demo_io_plugin_interface* io_plugin, io_plugins) { - all_items << io_plugin->name(); - QStringList split_filters = io_plugin->nameFilters().split(";;"); - bool stop=false; - Q_FOREACH(const QString& filter, split_filters) { - //extract filters - if ( all_filters_rx.indexIn(filter)!=-1 ){ - Q_FOREACH(const QString& pattern,all_filters_rx.cap(1).split(' ')){ - QRegExp rx(pattern); - rx.setPatternSyntax(QRegExp::Wildcard); - if ( rx.exactMatch(filename_striped) ){ - selected_items << io_plugin->name(); - stop=true; - break; + + QMap::iterator dfs_it = + default_plugin_selection.find( fileinfo.completeSuffix() ); + + if ( dfs_it==default_plugin_selection.end() ) + { + //match all filters between () + QRegExp all_filters_rx("\\((.*)\\)"); + // collect all io_plugins and offer them to load if the file extension match one name filter + // also collect all available plugin in case of a no extension match + Q_FOREACH(Polyhedron_demo_io_plugin_interface* io_plugin, io_plugins) { + all_items << io_plugin->name(); + QStringList split_filters = io_plugin->nameFilters().split(";;"); + bool stop=false; + Q_FOREACH(const QString& filter, split_filters) { + //extract filters + if ( all_filters_rx.indexIn(filter)!=-1 ){ + Q_FOREACH(const QString& pattern,all_filters_rx.cap(1).split(' ')){ + QRegExp rx(pattern); + rx.setPatternSyntax(QRegExp::Wildcard); + if ( rx.exactMatch(filename_striped) ){ + selected_items << io_plugin->name(); + stop=true; + break; + } } + if (stop) break; } - if (stop) break; } } } + else + selected_items << *dfs_it; bool ok; - QString loader_name; - + std::pair load_pair; + switch( selected_items.size() ) { case 1: - loader_name=selected_items.first(); + load_pair = std::make_pair(selected_items.first(), false); ok=true; break; case 0: - loader_name=QInputDialog::getItem(this, tr("Select a loader"), tr("Available loaders for %1 :").arg(fileinfo.fileName()), all_items, 0, false, &ok); + load_pair = File_loader_dialog::getItem(fileinfo.fileName(), all_items, &ok); break; default: - loader_name=QInputDialog::getItem(this, tr("Select a loader"), tr("Available loaders for %1 :").arg(fileinfo.fileName()), selected_items, 0, false, &ok); + load_pair = File_loader_dialog::getItem(fileinfo.fileName(), selected_items, &ok); } - if(!ok || loader_name.isEmpty()) { return; } + if(!ok || load_pair.first.isEmpty()) { return; } + + if (load_pair.second) + default_plugin_selection[fileinfo.completeSuffix()]=load_pair.first; + QSettings settings; settings.setValue("OFF open directory", fileinfo.absoluteDir().absolutePath()); - Scene_item* scene_item = load_item(fileinfo, find_loader(loader_name)); + Scene_item* scene_item = load_item(fileinfo, find_loader(load_pair.first)); selectSceneItem(scene->addItem(scene_item)); } diff --git a/Polyhedron/demo/Polyhedron/MainWindow.h b/Polyhedron/demo/Polyhedron/MainWindow.h index cc8fd1575be..f88a74cd025 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.h +++ b/Polyhedron/demo/Polyhedron/MainWindow.h @@ -162,7 +162,7 @@ private: QTreeView* sceneView; Ui::MainWindow* ui; QVector io_plugins; - + QMap default_plugin_selection; // typedef to make Q_FOREACH work typedef QPair PluginNamePair; QVector plugins; From f04cfc327a11b16940050300b0e33d8dfea9c3cb Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 1 Feb 2013 09:29:48 +0100 Subject: [PATCH 2/4] Add a layout in the dialog That way, the dialog, and its content, resizes itself when needed. + Capitalize a sentence in the dialog --- .../demo/Polyhedron/FileLoaderDialog.ui | 134 ++++++++---------- .../demo/Polyhedron/File_loader_dialog.h | 2 +- 2 files changed, 57 insertions(+), 79 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/FileLoaderDialog.ui b/Polyhedron/demo/Polyhedron/FileLoaderDialog.ui index 54b02d0eebc..fab7d8e5cc3 100644 --- a/Polyhedron/demo/Polyhedron/FileLoaderDialog.ui +++ b/Polyhedron/demo/Polyhedron/FileLoaderDialog.ui @@ -6,8 +6,8 @@ 0 0 - 353 - 144 + 339 + 105 @@ -25,82 +25,60 @@ false - - - - 170 - 80 - 181 - 32 - - - - Qt::LeftToRight - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - 30 - 40 - 321 - 31 - - - - - - - - - - - - - - - - 30 - 120 - 281 - 26 - - - - - 0 - 0 - - - - - - - - - - 0 - 10 - 371 - 21 - - - - - 0 - 0 - - - - TextLabel - - + + + + + + 0 + 0 + + + + TextLabel + + + + + + + + + + + + + + + + + + + + Qt::LeftToRight + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + 0 + 0 + + + + + + + + diff --git a/Polyhedron/demo/Polyhedron/File_loader_dialog.h b/Polyhedron/demo/Polyhedron/File_loader_dialog.h index b6d512c6112..8011ab71b0d 100644 --- a/Polyhedron/demo/Polyhedron/File_loader_dialog.h +++ b/Polyhedron/demo/Polyhedron/File_loader_dialog.h @@ -18,7 +18,7 @@ class File_loader_dialog : public QDialog, private Ui::FileLoaderDialog dialog.pluginBox->addItems(item_list); dialog.label->setText(tr("Available loaders for %1 :").arg(filename)); QFileInfo fileinfo(filename); - dialog.alwaysUse->setText(tr("use for &all *.%1 files in this session").arg(fileinfo.completeSuffix()) ); + dialog.alwaysUse->setText(tr("Use for &all *.%1 files in this session").arg(fileinfo.completeSuffix()) ); *ok = dialog.exec(); return std::make_pair( dialog.pluginBox->currentText(), From 94ce32c561587bea957aadbdaf0ec741af6f23f5 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 1 Feb 2013 09:48:38 +0100 Subject: [PATCH 3/4] Make the OK button the default one --- Polyhedron/demo/Polyhedron/File_loader_dialog.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Polyhedron/demo/Polyhedron/File_loader_dialog.h b/Polyhedron/demo/Polyhedron/File_loader_dialog.h index 8011ab71b0d..1ac070b0be9 100644 --- a/Polyhedron/demo/Polyhedron/File_loader_dialog.h +++ b/Polyhedron/demo/Polyhedron/File_loader_dialog.h @@ -1,5 +1,8 @@ #include #include +#include +#include + #include "ui_FileLoaderDialog.h" class File_loader_dialog : public QDialog, private Ui::FileLoaderDialog @@ -15,6 +18,7 @@ class File_loader_dialog : public QDialog, private Ui::FileLoaderDialog getItem(QString filename, const QStringList& item_list, bool* ok) { File_loader_dialog dialog; + dialog.buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); dialog.pluginBox->addItems(item_list); dialog.label->setText(tr("Available loaders for %1 :").arg(filename)); QFileInfo fileinfo(filename); From f8496f7a763683c16051f06d21cf602c4e027057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 1 Feb 2013 09:53:34 +0100 Subject: [PATCH 4/4] always use the same plugin by default --- Polyhedron/demo/Polyhedron/FileLoaderDialog.ui | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Polyhedron/demo/Polyhedron/FileLoaderDialog.ui b/Polyhedron/demo/Polyhedron/FileLoaderDialog.ui index fab7d8e5cc3..ab4b8c0ee34 100644 --- a/Polyhedron/demo/Polyhedron/FileLoaderDialog.ui +++ b/Polyhedron/demo/Polyhedron/FileLoaderDialog.ui @@ -76,6 +76,9 @@ + + true +