-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileformat.cpp
More file actions
54 lines (46 loc) · 1.52 KB
/
fileformat.cpp
File metadata and controls
54 lines (46 loc) · 1.52 KB
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
#include "fileformat.h"
FileFormat::FileFormat()
{
// create a joint list of descriptions and file type id's
// the first entry is the fallback format for unmatched files
descr.clear(); ids.clear();
descr.append(tr("XY files (*.xy *.xye)"));
ids.append(PXV_XY_FILE);
descr.append(tr("ARL text files (*.txt)"));
ids.append(PXV_ARL_FILE);
descr.append(tr("Tab/space separated files (*.txt *.tsv)"));
ids.append(PXV_TSV_FILE);
descr.append(tr("CSV files (*.csv)"));
ids.append(PXV_CSV_FILE);
// create filter string
filter = descr.join(";;");
}
// return filter stting for use in QFileDialog
const QString & FileFormat::filterString()
{
return(filter);
}
// Guess format from file name
FileFormatIDX FileFormat::guessFromName(const QString & fn)
{
QString n(fn.toLower());
if (n.endsWith(".xy") || n.endsWith(".xye")) return(PXV_XY_FILE);
if (n.endsWith(".txt")) return(PXV_ARL_FILE);
if (n.endsWith(".tsv")) return(PXV_TSV_FILE);
if (n.endsWith(".csv")) return(PXV_CSV_FILE);
return(ids[0]); // unrecognised, treated as first in constructor
}
// determine format from selected filter
FileFormatIDX FileFormat::guessFromFilter(const QString & s)
{
for (int i=0; i < descr.size(); ++i)
{
if (s==descr[i]) return(ids[i]);
}
return(ids[0]); //fallback (should never be reached)
}
FileFormatIDX FileFormat::guess(const QString &name, const QString &filter)
{
if (filter.isEmpty()) return(guessFromName(name));
return(guessFromFilter(filter));
}