itom
Loading...
Searching...
No Matches
IOHelper.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität 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#include <qlist.h>
35
36namespace ito {
37
38
39
40class IOHelper : public QObject
41{
42 Q_OBJECT
43public:
44
61 Q_DECLARE_FLAGS(IOFilters, IOFilter)
62
63
76 Q_DECLARE_FLAGS(SearchFolders, SearchFolder)
77
78
81 {
83 encodingName(""), displayName(""), displayNameShort(""), bom(""), userDefined(false)
84 {}
85
88 QString encodingName;
89
91 QString displayName;
92
95
97 QStringList aliases;
98
100 QByteArray bom;
101
103 bool userDefined;
104 };
105
106
107 static RetVal openGeneralFile(const QString &generalFileName, bool openUnknownsWithExternalApp = true, bool showMessages = false, QWidget* parent = NULL, const char* errorSlotMemberOfParent = NULL, bool globalNotLocalWorkspace = true);
108
109 static RetVal uiExportPyWorkspaceVars(bool globalNotLocal, const QStringList &varNames, QVector<int> compatibleParamBaseTypes, QString defaultPath = QString(), QWidget* parent = NULL);
110 static RetVal exportPyWorkspaceVars(const QString &filename, bool globalNotLocal, const QStringList &varNames);
111
112 static RetVal uiImportPyWorkspaceVars(bool globalNotLocal, const IOFilters &IOfilters, QString defaultPath = QString(), QWidget* parent = NULL);
113 static RetVal importPyWorkspaceVars(const QString &filename, bool globalNotLocal, QWidget* parent = NULL);
114
115 static RetVal openPythonScript(const QString &filename);
116
117 static RetVal uiOpenFileWithFilter(const ito::AddInAlgo::FilterDef *filter, const QString &filename, QWidget *parent = NULL, bool globalNotLocal = true);
118 static RetVal uiSaveFileWithFilter(QSharedPointer<ito::ParamBase> &value, const QString &filename, QWidget *parent = NULL);
119
120 static RetVal openUIFile(const QString &filename, QWidget* parent = NULL, const char* errorSlotMemberOfParent = NULL);
121
122 static QString getFileFilters(const IOFilters &IOfilters, QStringList *allPatterns = NULL);
123
124 static bool fileFitsToFileFilters(const QString &filename, const IOFilters &IOfilters);
125
126 static void elideFilepathMiddle(QString &path, int pixelLength);
127
128 static QIcon searchIcon(const QString &filename, const SearchFolders &searchFolders = SFAll, const QIcon &fallbackIcon = QIcon());
129
130 static QString getAllItomFilesName() { return allItomFilesName; }
132 static QList<CharsetEncodingItem> getSupportedScriptEncodings();
133 static CharsetEncodingItem getDefaultScriptEncoding();
134 static CharsetEncodingItem getEncodingFromAlias(const QString &alias, bool* found = nullptr);
135
136private:
137 IOHelper() {};
139 IOHelper(const IOHelper &) : QObject() {};
140
141 static QString allItomFilesName;
142 static QList<CharsetEncodingItem> supportedScriptEncodings;
143
144};
145
146} //end namespace ito
147
148Q_DECLARE_METATYPE(ito::IOHelper::CharsetEncodingItem)
149Q_DECLARE_OPERATORS_FOR_FLAGS(ito::IOHelper::IOFilters)
150
151#endif
container for publishing filters provided by any plugin
Definition addInInterface.h:974
This class contains several static methods to load or save various file formats.
Definition IOHelper.h:41
static RetVal uiImportPyWorkspaceVars(bool globalNotLocal, const IOFilters &IOfilters, QString defaultPath=QString(), 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:479
static QString getFileFilters(const IOFilters &IOfilters, QStringList *allPatterns=NULL)
Returns a list of all file endings that correspond to itom.
Definition IOHelper.cpp:1188
static QList< CharsetEncodingItem > supportedScriptEncodings
Definition IOHelper.h:142
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:112
IOFilter
Definition IOHelper.h:50
@ IOOutput
Definition IOHelper.h:52
@ IOAllFiles
Definition IOHelper.h:54
@ IOPlugin
Definition IOHelper.h:53
@ IOMimeAll
Definition IOHelper.h:59
@ IOMimeDataObject
Definition IOHelper.h:56
@ IOMimePolygonMesh
Definition IOHelper.h:58
@ IOWorkspace
Definition IOHelper.h:55
@ IOInput
Definition IOHelper.h:51
@ IOMimePointCloud
Definition IOHelper.h:57
static RetVal openPythonScript(const QString &filename)
open a given python file in a script editor window
Definition IOHelper.cpp:669
static void elideFilepathMiddle(QString &path, int pixelLength)
Shortens paths so that menus can display them without becoming too big.
Definition IOHelper.cpp:1348
static QString getAllItomFilesName()
Definition IOHelper.h:130
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:386
~IOHelper()
Definition IOHelper.h:138
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:845
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:531
static QList< CharsetEncodingItem > getSupportedScriptEncodings()
return a list of default encodings, that are officially supported by Qt (as well as Python).
Definition IOHelper.cpp:1483
static QString allItomFilesName
name of set of all itom files (used in file open dialog or file system dialog)
Definition IOHelper.h:141
static RetVal openUIFile(const QString &filename, QWidget *parent=NULL, const char *errorSlotMemberOfParent=NULL)
open ui file in an instance of QtDesigner
Definition IOHelper.cpp:722
SearchFolder
Definition IOHelper.h:68
@ SFAppDir
Definition IOHelper.h:72
@ SFDirect
Definition IOHelper.h:70
@ SFCurrent
Definition IOHelper.h:71
@ SFAppDirQItom
Definition IOHelper.h:73
@ SFResources
Definition IOHelper.h:69
@ SFAll
Definition IOHelper.h:74
static RetVal uiExportPyWorkspaceVars(bool globalNotLocal, const QStringList &varNames, QVector< int > compatibleParamBaseTypes, QString defaultPath=QString(), QWidget *parent=NULL)
export one or more variables from a python workspace
Definition IOHelper.cpp:267
IOHelper(const IOHelper &)
Definition IOHelper.h:139
static bool fileFitsToFileFilters(const QString &filename, const IOFilters &IOfilters)
Checks if a file fits to a filter.
Definition IOHelper.cpp:1311
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:1029
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:1393
Class for managing status values (like errors or warning)
Definition retVal.h:54
Definition apiFunctionsGraph.cpp:40
Definition IOHelper.h:81
CharsetEncodingItem()
Definition IOHelper.h:82
QByteArray bom
false if part of the officially supported list of encodings, else true
Definition IOHelper.h:100
QString displayNameShort
all possible aliases, e.g. in Python scripts (coding=...)
Definition IOHelper.h:94
QString displayName
the short version, e.g. for a status bar
Definition IOHelper.h:91
QString encodingName
the name used as display name in a config dialog
Definition IOHelper.h:88
QStringList aliases
the Byte-Order-Mark used to automatically detect this encoding (or empty, if not used)
Definition IOHelper.h:97