itom  4.1.0
IOHelper.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 #ifndef IOHELPER_H
24 #define IOHELPER_H
25 
26 #include "../global.h"
27 #include "../common/sharedStructures.h"
28 #include "../common/sharedStructuresQt.h"
29 #include "../../common/addInInterface.h"
30 
31 #include <qstring.h>
32 #include <qobject.h>
33 #include <qicon.h>
34 
35 namespace ito {
36 
37 
38 
39 class IOHelper : public QObject
40 {
41  Q_OBJECT
42 public:
43 
48  enum IOFilter
49  {
50  IOInput = 0x001,
51  IOOutput = 0x002,
52  IOPlugin = 0x004,
53  IOAllFiles = 0x008,
54  IOWorkspace = 0x010,
55  IOMimeDataObject = 0x020,
56  IOMimePointCloud = 0x040,
59  };
60  Q_DECLARE_FLAGS(IOFilters, IOFilter)
61 
62 
67  {
68  SFResources = 0x001,
69  SFDirect = 0x002,
70  SFCurrent = 0x004,
71  SFAppDir = 0x008,
72  SFAppDirQItom = 0x010,
74  };
75  Q_DECLARE_FLAGS(SearchFolders, SearchFolder)
76 
77 
78  static RetVal openGeneralFile(const QString &generalFileName, bool openUnknownsWithExternalApp = true, bool showMessages = false, QWidget* parent = NULL, const char* errorSlotMemberOfParent = NULL, bool globalNotLocalWorkspace = true);
79 
80  static RetVal uiExportPyWorkspaceVars(bool globalNotLocal, const QStringList &varNames, QVector<int> compatibleParamBaseTypes, QString defaultPath = QString::Null(), QWidget* parent = NULL);
81  static RetVal exportPyWorkspaceVars(const QString &filename, bool globalNotLocal, const QStringList &varNames);
82 
83  static RetVal uiImportPyWorkspaceVars(bool globalNotLocal, const IOFilters &IOfilters, QString defaultPath = QString::Null(), QWidget* parent = NULL);
84  static RetVal importPyWorkspaceVars(const QString &filename, bool globalNotLocal, QWidget* parent = NULL);
85 
86  static RetVal openPythonScript(const QString &filename);
87 
88  static RetVal uiOpenFileWithFilter(const ito::AddInAlgo::FilterDef *filter, const QString &filename, QWidget *parent = NULL, bool globalNotLocal = true);
89  static RetVal uiSaveFileWithFilter(QSharedPointer<ito::ParamBase> &value, const QString &filename, QWidget *parent = NULL);
90 
91  static RetVal openUIFile(const QString &filename, QWidget* parent = NULL, const char* errorSlotMemberOfParent = NULL);
92 
93  static QString getFileFilters(const IOFilters &IOfilters, QStringList *allPatterns = NULL);
94 
95  static bool fileFitsToFileFilters(const QString &filename, const IOFilters &IOfilters);
96 
97  static void elideFilepathMiddle(QString &path, int pixelLength);
98 
99  static QIcon searchIcon(const QString &filename, const SearchFolders &searchFolders = SFAll, const QIcon &fallbackIcon = QIcon());
100 
101  static QString getAllItomFilesName() { return allItomFilesName; }
103 private:
104  IOHelper() {};
105  ~IOHelper() {};
106  IOHelper(const IOHelper &) : QObject() {};
107 
108  static QString allItomFilesName;
109 
110 };
111 
112 } //end namespace ito
113 
114 Q_DECLARE_OPERATORS_FOR_FLAGS(ito::IOHelper::IOFilters)
115 
116 #endif
Definition: IOHelper.h:57
Definition: IOHelper.h:53
Definition: IOHelper.h:73
IOHelper(const IOHelper &)
Definition: IOHelper.h:106
Definition: IOHelper.h:51
This class contains several static methods to load or save various file formats.
Definition: IOHelper.h:39
IOFilter
Definition: IOHelper.h:48
Definition: IOHelper.h:70
static RetVal openUIFile(const QString &filename, QWidget *parent=NULL, const char *errorSlotMemberOfParent=NULL)
open ui file in an instance of QtDesigner
Definition: IOHelper.cpp:693
Class for managing status values (like errors or warning)
Definition: retVal.h:54
Definition: IOHelper.h:50
static QString getFileFilters(const IOFilters &IOfilters, QStringList *allPatterns=NULL)
Returns a list of all file endings that correspond to itom.
Definition: IOHelper.cpp:1159
static RetVal uiExportPyWorkspaceVars(bool globalNotLocal, const QStringList &varNames, QVector< int > compatibleParamBaseTypes, QString defaultPath=QString::Null(), QWidget *parent=NULL)
export one or more variables from a python workspace
Definition: IOHelper.cpp:241
static void elideFilepathMiddle(QString &path, int pixelLength)
Shortens paths so that menus can display them without becoming too big.
Definition: IOHelper.cpp:1314
static QIcon searchIcon(const QString &filename, const SearchFolders &searchFolders=SFAll, const QIcon &fallbackIcon=QIcon())
search an icon file in different locations, open and return it
Definition: IOHelper.cpp:1344
base class for all "algorithm" plugin classes
Definition: addInInterface.h:929
Definition: IOHelper.h:56
static RetVal openPythonScript(const QString &filename)
open a given python file in a script editor window
Definition: IOHelper.cpp:640
static RetVal exportPyWorkspaceVars(const QString &filename, bool globalNotLocal, const QStringList &varNames)
export one or more variables from a python workspace to an idc or mat file
Definition: IOHelper.cpp:360
Definition: apiFunctionsGraph.cpp:39
static RetVal uiImportPyWorkspaceVars(bool globalNotLocal, const IOFilters &IOfilters, QString defaultPath=QString::Null(), QWidget *parent=NULL)
open a file load dialog and let the user selected a file that is opened and load to a python workspac...
Definition: IOHelper.cpp:453
SearchFolder
Definition: IOHelper.h:66
Definition: IOHelper.h:68
Definition: IOHelper.h:58
static RetVal openGeneralFile(const QString &generalFileName, bool openUnknownsWithExternalApp=true, bool showMessages=false, QWidget *parent=NULL, const char *errorSlotMemberOfParent=NULL, bool globalNotLocalWorkspace=true)
method to load any supported file
Definition: IOHelper.cpp:101
Definition: IOHelper.h:71
Definition: IOHelper.h:55
static RetVal uiOpenFileWithFilter(const ito::AddInAlgo::FilterDef *filter, const QString &filename, QWidget *parent=NULL, bool globalNotLocal=true)
open a file using a filter method from an algorithm plugin and shows an import dialog ...
Definition: IOHelper.cpp:816
static QString allItomFilesName
name of set of all itom files (used in file open dialog or file system dialog)
Definition: IOHelper.h:106
static bool fileFitsToFileFilters(const QString &filename, const IOFilters &IOfilters)
Checks if a file fits to a filter.
Definition: IOHelper.cpp:1279
static QString getAllItomFilesName()
Definition: IOHelper.h:101
Definition: IOHelper.h:72
Definition: IOHelper.h:69
static RetVal importPyWorkspaceVars(const QString &filename, bool globalNotLocal, QWidget *parent=NULL)
import an idc or mat file and load the content to a python workspace
Definition: IOHelper.cpp:505
~IOHelper()
Definition: IOHelper.h:105
static RetVal uiSaveFileWithFilter(QSharedPointer< ito::ParamBase > &value, const QString &filename, QWidget *parent=NULL)
save a file using a filter method from an algorithm plugin and shows an export dialog ...
Definition: IOHelper.cpp:1000
Definition: param.h:67
Definition: IOHelper.h:52
Definition: IOHelper.h:54