QtMultiFileDialog.C

Go to the documentation of this file.
00001 // @(#)root/qt:$Name:  $:$Id: QtMultiFileDialog.C,v 1.6 2008/09/28 02:22:23 fine Exp $
00002 // Author: Valeri Fine   23/03/2006
00003 #ifndef __CINT__
00004 #  include <QApplication>
00005 #  include <QStyle>
00006 #  include <QFileDialog>
00007 #  include <QStringList>
00008 #  include <QString>
00009 #  include "TObjString.h"
00010 #  include "TList.h"
00011 #  include <string>
00012 #endif
00013 TList *QtMultiFileDialog(const char *style="") {
00014   // This is a small ROOT macro to use Qt 3.3 class :begin_html <a href="http://doc.trolltech.com/3.3/qfiledialog.html">QFileDialog</a> end_html
00015   // See: begin_html <a href="http://doc.trolltech.com/3.3/qfiledialog.html#getOpenFileNames">http://doc.trolltech.com/3.3/qfiledialog.html#getOpenFileNames</a> end_html
00016   //
00017   // To use, invoke ACLiC from the ROOT prompt:
00018   // root [] .x QtMultiFileDialog.C++
00019   //
00020   // To use it with no ACLiC, omit the trailing "++"
00021   // root [] .x QtMultiFileDialog.C
00022   //
00023   // The QtMultiFileDialog creates TList of TObjString objects and 
00024   // returns its pointer. 
00025   //
00026   // The "QtFileDialog.C" macro provides the simplified version of the "QtMultiFileDialog.C"
00027   //
00028   // Option: you can change the look and feel of the Qt file dialog
00029   // ======= by providing the optional parameter "style":
00030   //         The number of the available styles is defined by your local
00031   //         Qt installation. 
00032   //         Try: "windows", "motif", "kde", "platinum" etc
00033   //
00034   // The full list of the Qt classes available from Cint is defined by
00035   // begin_html <a href="http://root.bnl.gov/QtRoot/htmldoc/src/qtclasses.h.html">by $ROOTSYS/cint/lib/qtclasses.h</a> end_html
00036   //
00037   // All Qt classes can be used from ACLiC though.
00038 
00039 #ifdef __CINT__
00040   // Load the qt cint dictionary.
00041   // One is recommended to do that at once somewhere.
00042   // For example  from his/her custom rootlogon.C script
00043   gSystem->Load("$ROOTSYS/cint/cint/include/qtcint");
00044 #endif   
00045   QStyle *saveStyle =  0;
00046   if (!QString(style).isEmpty()) { 
00047      saveStyle = QApplication::style();
00048      QApplication::setStyle(style);
00049   }
00050   TList *listOfNames = new TList();
00051   QStringList files = QFileDialog::getOpenFileNames ();
00052   QStringList::Iterator it = files.begin();
00053   while ( it != files.end() ) {
00054       std::string flnm = (*it).toStdString();
00055       printf ("Next file selected: %s\n", flnm.c_str() );
00056       // Convert QString to TObjString and add it to the output
00057       listOfNames->Add(new TObjString(flnm.c_str()));
00058       ++it;
00059   }
00060   // Restore the style
00061   if (saveStyle) QApplication::setStyle(saveStyle);
00062   printf ("\nThe TList of the file names contains:");
00063   printf ("\n-------------------------------------\n");
00064   listOfNames->ls();
00065   return listOfNames;
00066 }

Generated on Tue Jul 5 15:44:26 2011 for ROOT_528-00b_version by  doxygen 1.5.1