Mercurial > hg > octave-lyh
diff libgui/src/octave-qt-link.cc @ 16579:7f8db1942dc0
Add Qt link uigetfile dialog implementation.
* libgui/src/octave-qt-link.cc, libgui/src/octave-qt-link.h,
(octave_qt_link::do_file_dialog): New function.
(make_filter_list): New function.
* libinterp/interpfcn/octave-link.cc
(__octave_link_file_dialog__): New function.
* libinterp/interpfcn/octave-link.h:
(octave_link::file_dialog): New function.
(octave_link::do_file_dialog): New virtual function.
* scripts/plot/uigetfile.m: update to call octave_link file dialog if octave link is present.
* libgui/src/dialog.cc, libgui/src/dialog.h
(class FileDialog): New class.
(QUIWidgetCreator::QUIWidgetCreator): added initialization of new var path_name.
(QUIWidgetCreator::signal_filedialog): New function.
(QUIWidgetCreator::create_filedialog): New function.
(QUIWidgetCreator::filedialog_finished): New function.
(QUIWidgetCreator::get_dialog_path): New function.
* libgui/src/main-window.cc, libgui/src/main-window.h
(main_window::connect_uiwidget_links): Added connect for handle_file_dialog.
(main_window::handle_create_filedialog): New function.
author | John Donoghue <john.donoghue@ieee.org> |
---|---|
date | Sun, 28 Apr 2013 09:45:19 -0400 |
parents | d5ae5aa80d42 |
children | adc150db1809 |
line wrap: on
line diff
--- a/libgui/src/octave-qt-link.cc +++ b/libgui/src/octave-qt-link.cc @@ -128,6 +128,37 @@ return retval; } +static QStringList +make_filter_list (const std::list< std::pair<std::string, std::string> >& lst) +{ + QStringList retval; + + // we have pairs of data, first being the list of extensions exta;exb;extc etc + // second the name to use as filter name (optional). + // Qt wants a a list of filters in the format of 'FilterName (spacfe separated exts)' + + for (std::list< std::pair<std::string,std::string> >::const_iterator it = lst.begin (); + it != lst.end (); it++) + { + QString ext = QString::fromStdString ((*it).first); + QString name = QString::fromStdString ((*it).second); + + // strip out (exts) from name (if any) + name.replace(QRegExp("\\(.*\\)"), ""); + // replace ';' with spaces in ext list + ext.replace(";"," "); + + if (name.length() == 0) + { + // no name field - so need build one from teh extendiions + name = ext.toUpper() + " Files"; + } + + retval.append (name + " (" + ext + ")"); + } + + return retval; +} std::pair<std::list<int>, int> octave_qt_link::do_list_dialog (const std::list<std::string>& list, @@ -188,6 +219,39 @@ return retval; } +std::list<std::string> +octave_qt_link::do_file_dialog (const std::list< std::pair< std::string, std::string > > filter, + const std::string& title, + const std::string& filename, + const std::string& dirname, + bool multiselect) +{ + std::list<std::string> retval; + + uiwidget_creator.signal_filedialog ( make_filter_list (filter), + QString::fromStdString (title), + QString::fromStdString (filename), + QString::fromStdString (dirname), + multiselect); + + // Wait while the user is responding to dialog. + uiwidget_creator.wait (); + + // add all the file dialog result to a string list + const QStringList *inputLine = uiwidget_creator.get_string_list (); + + for (QStringList::const_iterator it = inputLine->begin (); + it != inputLine->end (); it++) + { + retval.push_back (it->toStdString ()); + } + + retval.push_back (uiwidget_creator.get_dialog_path ()->toStdString ()); + retval.push_back ((QString ("%1").arg (uiwidget_creator.get_dialog_result ())).toStdString ()); + + return retval; +} + int octave_qt_link::do_debug_cd_or_addpath_error (const std::string& file, const std::string& dir,