1
/***************************************************************************
2
File : AbstractImportFilter.h
4
--------------------------------------------------------------------
5
Copyright : (C) 2008-2009 Knut Franke
6
Email (use @ for *) : Knut.Franke*gmx.net
7
Description : Interface for import operations.
9
***************************************************************************/
11
/***************************************************************************
13
* This program is free software; you can redistribute it and/or modify *
14
* it under the terms of the GNU General Public License as published by *
15
* the Free Software Foundation; either version 2 of the License, or *
16
* (at your option) any later version. *
18
* This program is distributed in the hope that it will be useful, *
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21
* GNU General Public License for more details. *
23
* You should have received a copy of the GNU General Public License *
24
* along with this program; if not, write to the Free Software *
25
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26
* Boston, MA 02110-1301 USA *
28
***************************************************************************/
30
#ifndef ABSTRACT_IMPORT_FILTER_H
31
#define ABSTRACT_IMPORT_FILTER_H
34
#include <QStringList>
39
// This works just like attr_reader in Ruby (except that you also have to declare the member
40
// variable), i.e. it declares a get method for a (private) member variable.
41
#define READER(type, name) \
42
type name() const { return d_ ## name; }
44
// This works just like attr_accessor in Ruby (except that you also have to declare the member
45
// variable), i.e. it declares get and set methods for a (private) member variable.
46
// TODO: find a better home for this macro as well as READER
47
// TODO: Due to technical limitations, this violates the method naming conventions in
48
// doc/coding.dox. Maybe we should add a special rule for accessor methods. Unless someone knows how
49
// to let the preprocessor do case conversion.
50
#define ACCESSOR(type, name) \
51
type name() const { return d_ ## name; }; \
52
void set_ ## name(const type value) { d_ ## name = value; }
54
//! Interface for import operations.
56
* The least common denominator of all import operations is that they read data from a device
57
* (typically, but not necessarily, a file), interpret it in a filter-specific way (as project files
58
* in SciDAVis/QtiPlot legacy format, Origin project, CSV table, image, ...) and convert it to the
59
* corresponding internal representation (Project, Table, Graph, ...). The application kernel takes
60
* care of all the pesky details, such as letting the user choose one or more files to import or
61
* adding the resulting Aspect either to the current project or a newly created one.
63
* The main design goal was to make implementing import filters as easy as possible. Therefore,
64
* filter options are simply declared as Qt properties; the implementation does not have to bother
65
* with providing a GUI for its options (this task is taken over by ImportDialog). This approach
66
* allows fast prototyping of import filters, but leaves some things to be desired usability-wise
67
* (localized option labels, tool tips, intelligent layout, etc.). Some of these deficiencies could
68
* be overcome by adding extra methods to filters
69
* (e.g. Qstring labelText(const char * property_name)), but presumably one will want to replace the
70
* auto-generated GUI with a custom one once the filter is completely implemented and tested. This
71
* is done by providing a method "QWidget * makeOptionsGui();". The result of calling
72
* this method is then used by ImportDialog instead of the auto-generated GUI. The filter still has
73
* to inherit from QObject and use the Q_OBJECT macro, since otherwise there's no way of testing for
74
* the presence of this method.
76
class AbstractImportFilter : public QObject
81
virtual ~AbstractImportFilter() {}
82
//! Import an object from the specified device and convert it to an Aspect.
84
* May return 0 if import failed.
86
virtual AbstractAspect * importAspect(QIODevice * input) = 0;
87
//! The file extension(s) typically associated with the handled format.
88
virtual QStringList fileExtensions() const = 0;
89
//! A (localized) name for the filter.
90
virtual QString name() const = 0;
91
//! Uses name() and fileExtensions() to produce a filter specification as used by QFileDialog.
92
QString nameAndPatterns() const {
93
return name() + " (*." + fileExtensions().join(" *.") + ")";
97
#endif // ifndef ABSTRACT_IMPORT_FILTER_H