0030268: Inspectors - improvements in VInspector plugin
[occt.git] / tools / TInspector / TInspector_OpenFileDialog.hxx
1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement. 
15
16 #ifndef TInspectorEXE_OpenFileDialog_H
17 #define TInspectorEXE_OpenFileDialog_H
18
19 #include <inspector/TInspectorAPI_PreferencesDataMap.hxx>
20
21 #include <NCollection_DataMap.hxx>
22 #include <NCollection_List.hxx>
23 #include <TCollection_AsciiString.hxx>
24
25 #include <Standard_WarningsDisable.hxx>
26 #include <QDialog>
27 #include <QItemSelection>
28 #include <QStringList>
29 #include <Standard_WarningsRestore.hxx>
30
31 class TInspector_Communicator;
32
33 class QAbstractItemModel;
34 class QLineEdit;
35 class QPushButton;
36 class QTableView;
37 class QToolButton;
38 class QWidget;
39
40 //! \class TInspector_OpenFileDialog
41 //! Control that contains table view of samples and line to select a file name from other directory.
42 //! Click on element of samples table view calls this sample opening else after entering(or opening) file name
43 //! the import becomes active. Click on the button will open selected file if it is possible
44 class TInspector_OpenFileDialog : public QDialog
45 {
46   Q_OBJECT
47 private:
48
49   //! Constructor
50   Standard_EXPORT TInspector_OpenFileDialog (QWidget* theParent, const QStringList& theRecentlyOpenedFiles);
51
52 public:
53
54   //! Destructor
55   virtual ~TInspector_OpenFileDialog() Standard_OVERRIDE {}
56
57   //! Opens this file dialog using for samples view the given directory and try to open new file
58   //! \param theParent a parent for the new dialog
59   //! \param theDataDirName path to default samples directory
60   //! \returns a file name from the open file dialog
61   Standard_EXPORT static QString OpenFile (QWidget* theParent, const QStringList& theRecentlyOpenedFiles);
62
63   //! Returns selection name from the dialog
64   QString GetFileName() const { return myFileName; }
65
66   //! Returns communicator, if this is the first call, create a communicator instance
67   Standard_EXPORT static TInspector_Communicator* Communicator();
68
69   //! Returns preferences: previous opened documents.
70   //! \param thePluginName name of the plugin
71   //! \param theCommunicator source of preferences
72   //! \param theFileNames [out] container of recently opened file names
73   Standard_EXPORT static void GetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName,
74                                                             TInspector_Communicator* theCommunicator,
75                                                             QStringList& theFileNames);
76
77   //! Sets preferences: previous opened documents.
78   //! \param thePluginName name of the plugin
79   //! \param theCommunicator source of preferences
80   //! \param theFileNames container of recently opened file names to be set into communicator preferences
81   Standard_EXPORT static void SetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName,
82                                                             TInspector_Communicator* theCommunicator,
83                                                             QStringList& theFileNames);
84
85 private slots:
86
87   //! Stores name of selected sample file
88   void onSampleSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected);
89
90   //! Opens file dialog to select a file name. Fills file name line, enable import button
91   void onSelectClicked();
92
93   //! Accepts open file dialog
94   void onApplySelectClicked();
95
96 private:
97
98   //! Creates view of file names in samples directory
99   //! \param theFileNames a container of names
100   //! \return table view
101   QTableView* createTableView (const QStringList& theFileNames);
102
103   //! Creates view model and fills it by the file names
104   //! \param theFileNames a container of names
105   //! \return model
106   QAbstractItemModel* createModel (const QStringList& theFileNames);
107
108 private:
109
110   QStringList myRecentlyOpenedFiles; //!< recently opened files
111   QString myFileName; //!< result file name
112   QTableView* mySamplesView; //!< view of sample file names
113   QLineEdit* mySelectedName; //!< alternative control to open file
114 };
115
116 #endif