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