1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef ShapeView_OpenFileDialog_H
17 #define ShapeView_OpenFileDialog_H
19 #include <Standard.hxx>
20 #include <Standard_Macro.hxx>
21 #include <TCollection_AsciiString.hxx>
23 #include <Standard_WarningsDisable.hxx>
25 #include <QItemSelection>
26 #include <QStringList>
27 #include <Standard_WarningsRestore.hxx>
31 class QAbstractItemModel;
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
48 ShapeView_OpenButton (QObject* theParent) : QObject (theParent), myStartButton (0) {}
51 virtual ~ShapeView_OpenButton() {}
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();
56 //! Sets the default directory of plugin.
57 void SetPluginDir (const TCollection_AsciiString& thePluginName, const TCollection_AsciiString& theDefaultDir)
58 { myDefaultDirs[thePluginName] = theDefaultDir; }
62 //! Processes the button click, open default/current directory to select open file, calls OpenFile of communicator
63 void onStartButtonClicked();
67 //! Signals about opening file clicked
68 //! \param theFileName an output file name
69 void OpenFile (const QString& theFileName);
73 QPushButton* myStartButton; //!< processed button
74 std::map<TCollection_AsciiString, TCollection_AsciiString> myDefaultDirs; //!< plugins default directories
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
87 ShapeView_OpenFileDialog (QWidget* theParent, const QString& theDataDirName);
92 virtual ~ShapeView_OpenFileDialog() Standard_OVERRIDE {}
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);
100 //! Returns selection name from the dialog
101 QString GetFileName() const { return myFileName; }
105 //! Stores name of selected sample file
106 void onSampleSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected);
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);
112 //! Open file dialog to select a file name. Fills file name line, enable import button
113 void onSelectClicked();
115 //! Accepts open file dialog
116 void onApplySelectClicked();
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);
125 //! Creates view model and fills it by the file names
126 //! \param theFileNames a container of names
128 QAbstractItemModel* createModel (const QStringList& theFileNames);
130 //! Generates container of file names in samples directory
131 //! \return container of names
132 QStringList readSampleNames();
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