0030690: Draw Harness - provide XDisplay command for displaying XDE document
[occt.git] / tools / ShapeView / ShapeView_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 ShapeView_OpenFileDialog_H
17 #define ShapeView_OpenFileDialog_H
18
19 #include <Standard.hxx>
20 #include <Standard_Macro.hxx>
21 #include <TCollection_AsciiString.hxx>
22
23 #include <Standard_WarningsDisable.hxx>
24 #include <QDialog>
25 #include <QItemSelection>
26 #include <QStringList>
27 #include <Standard_WarningsRestore.hxx>
28
29 #include <map>
30
31 class QAbstractItemModel;
32 class QLineEdit;
33 class QPushButton;
34 class QTableView;
35 class QToolButton;
36 class QWidget;
37
38 //! \class ShapeView_OpenButton
39 //! Class that contains push button and the button processing. It obtains a file name from the default or current
40 //! directory and gives the name into TInspector communicator
41 //! Object name of the button is the name of the plugin to get the default directory, or the current directory is used.
42 class ShapeView_OpenButton : public QObject
43 {
44   Q_OBJECT
45 public:
46
47   //! Constructor
48   ShapeView_OpenButton (QObject* theParent) : QObject (theParent), myStartButton (0) {}
49
50   //! Destructor
51   virtual ~ShapeView_OpenButton() {}
52
53   //! Returns the start button, if this is the first call, it creates the button and connect it to the slot
54   Standard_EXPORT QPushButton* StartButton();
55
56   //! Sets the default directory of plugin.
57   void SetPluginDir (const TCollection_AsciiString& thePluginName, const TCollection_AsciiString& theDefaultDir)
58   { myDefaultDirs[thePluginName] = theDefaultDir; }
59
60 private slots:
61
62   //! Processes the button click, open default/current directory to select open file, calls OpenFile of communicator
63   void onStartButtonClicked();
64
65 signals:
66
67   //! Signals about opening file clicked
68   //! \param theFileName an output file name
69   void OpenFile (const QString& theFileName);
70
71 private:
72
73   QPushButton* myStartButton; //!< processed button
74   std::map<TCollection_AsciiString, TCollection_AsciiString> myDefaultDirs; //!< plugins default directories
75 };
76
77 //! \class ShapeView_OpenFileDialog
78 //! Control that contains table view of samples and line to select a file name from other directory.
79 //! Click on element of samples table view calls this sample opening else after entering(or opening) file name
80 //! the import becomes active. Click on the button will open selected file if it is possible
81 class ShapeView_OpenFileDialog : public QDialog
82 {
83   Q_OBJECT
84 private:
85
86   //! Constructor
87   ShapeView_OpenFileDialog (QWidget* theParent, const QString& theDataDirName);
88
89 public:
90
91   //! Destructor
92   virtual ~ShapeView_OpenFileDialog() Standard_OVERRIDE {}
93
94   //! Opens this file dialog using for samples view the given directory and try to open new file
95   //! \param theParent a parent for the new dialog
96   //! \param theDataDirName path to default samples directory
97   //! \returns a file name from the open file dialog
98   static QString OpenFile (QWidget* theParent, const QString& theDataDirName);
99
100   //! Returns selection name from the dialog
101   QString GetFileName() const { return myFileName; }
102
103 private slots:
104
105   //! Stores name of selected sample file
106   void onSampleSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected);
107
108   //! Updates enabling state of Open file button, it is enabled if the file by the entered path exists
109   //! \param theText a file name text in line edit
110   void onNameChanged (const QString& theText);
111
112   //! Open file dialog to select a file name. Fills file name line, enable import button
113   void onSelectClicked();
114
115   //! Accepts open file dialog
116   void onApplySelectClicked();
117
118 private:
119
120   //! Creates view of file names in samples directory
121   //! \param theFileNames a container of names
122   //! \return table view
123   QTableView* createTableView (const QStringList& theFileNames);
124
125   //! Creates view model and fills it by the file names
126   //! \param theFileNames a container of names
127   //! \return model
128   QAbstractItemModel* createModel (const QStringList& theFileNames);
129
130   //! Generates container of file names in samples directory
131   //! \return container of names
132   QStringList readSampleNames();
133
134 private:
135
136   QString myDataDir; //!< samples directory
137   QString myFileName; //!< result file name
138   QTableView* mySamplesView; //! <view of sample file names
139   QLineEdit* mySelectedName; //!< alternative control to open file
140   QToolButton* myFolderApplyOpen; //! button to open file
141 };
142
143 #endif