File: ShapeView_OpenFileDialog.hxx

package info (click to toggle)
opencascade 7.9.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 301,932 kB
  • sloc: cpp: 1,523,264; tcl: 10,159; cs: 5,173; java: 1,554; sh: 1,342; ansic: 827; xml: 699; makefile: 31; javascript: 22
file content (149 lines) | stat: -rw-r--r-- 5,063 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.

#ifndef ShapeView_OpenFileDialog_H
#define ShapeView_OpenFileDialog_H

#include <Standard.hxx>
#include <Standard_Macro.hxx>
#include <TCollection_AsciiString.hxx>

#include <Standard_WarningsDisable.hxx>
#include <QDialog>
#include <QItemSelection>
#include <QStringList>
#include <Standard_WarningsRestore.hxx>

#include <map>

class QAbstractItemModel;
class QLineEdit;
class QPushButton;
class QTableView;
class QToolButton;
class QWidget;

//! \class ShapeView_OpenButton
//! Class that contains push button and the button processing. It obtains a file name from the
//! default or current directory and gives the name into TInspector communicator Object name of the
//! button is the name of the plugin to get the default directory, or the current directory is used.
class ShapeView_OpenButton : public QObject
{
  Q_OBJECT
public:
  //! Constructor
  ShapeView_OpenButton(QObject* theParent)
      : QObject(theParent),
        myStartButton(0)
  {
  }

  //! Destructor
  virtual ~ShapeView_OpenButton() {}

  //! Returns the start button, if this is the first call, it creates the button and connect it to
  //! the slot
  Standard_EXPORT QPushButton* StartButton();

  //! Sets the default directory of plugin.
  void SetPluginDir(const TCollection_AsciiString& thePluginName,
                    const TCollection_AsciiString& theDefaultDir)
  {
    myDefaultDirs[thePluginName] = theDefaultDir;
  }

private slots:

  //! Processes the button click, open default/current directory to select open file, calls OpenFile
  //! of communicator
  void onStartButtonClicked();

signals:

  //! Signals about opening file clicked
  //! \param theFileName an output file name
  void OpenFile(const QString& theFileName);

private:
  QPushButton* myStartButton; //!< processed button
  std::map<TCollection_AsciiString, TCollection_AsciiString>
    myDefaultDirs; //!< plugins default directories
};

//! \class ShapeView_OpenFileDialog
//! Control that contains table view of samples and line to select a file name from other directory.
//! Click on element of samples table view calls this sample opening else after entering(or opening)
//! file name the import becomes active. Click on the button will open selected file if it is
//! possible
class ShapeView_OpenFileDialog : public QDialog
{
  Q_OBJECT
private:
  //! Constructor
  ShapeView_OpenFileDialog(QWidget* theParent, const QString& theDataDirName);

public:
  //! Destructor
  virtual ~ShapeView_OpenFileDialog() Standard_OVERRIDE {}

  //! Opens this file dialog using for samples view the given directory and try to open new file
  //! \param theParent a parent for the new dialog
  //! \param theDataDirName path to default samples directory
  //! \returns a file name from the open file dialog
  static QString OpenFile(QWidget* theParent, const QString& theDataDirName);

  //! Returns selection name from the dialog
  QString GetFileName() const { return myFileName; }

private slots:

  //! Stores name of selected sample file
  void onSampleSelectionChanged(const QItemSelection& theSelected,
                                const QItemSelection& theDeselected);

  //! Updates enabling state of Open file button, it is enabled if the file by the entered path
  //! exists \param theText a file name text in line edit
  void onNameChanged(const QString& theText);

  //! Open file dialog to select a file name. Fills file name line, enable import button
  void onSelectClicked();

  //! Accepts open file dialog
  void onApplySelectClicked();

private:
  //! Creates view of file names in samples directory
  //! \param theFileNames a container of names
  //! \return table view
  QTableView* createTableView(const QStringList& theFileNames);

  //! Creates view model and fills it by the file names
  //! \param theFileNames a container of names
  //! \return model
  QAbstractItemModel* createModel(const QStringList& theFileNames);

  //! Generates container of file names in samples directory
  //! \return container of names
  QStringList readSampleNames();

private:
  QString      myDataDir;         //!< samples directory
  QString      myFileName;        //!< result file name
  QTableView*  mySamplesView;     //!< view of sample file names
  QLineEdit*   mySelectedName;    //!< alternative control to open file
  QToolButton* myFolderApplyOpen; //!< button to open file
};

#endif