~valavanisalex/ubuntu/maverick/scidavis/fix-604811

« back to all changes in this revision

Viewing changes to scidavis/src/future/core/AbstractImportFilter.h

  • Committer: Bazaar Package Importer
  • Author(s): Ruben Molina
  • Date: 2009-09-06 11:34:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090906113404-4awaey82l3686w4q
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : AbstractImportFilter.h
 
3
    Project              : SciDAVis
 
4
    --------------------------------------------------------------------
 
5
    Copyright            : (C) 2008-2009 Knut Franke
 
6
    Email (use @ for *)  : Knut.Franke*gmx.net
 
7
    Description          : Interface for import operations.
 
8
 
 
9
 ***************************************************************************/
 
10
 
 
11
/***************************************************************************
 
12
 *                                                                         *
 
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.                                    *
 
17
 *                                                                         *
 
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.                           *
 
22
 *                                                                         *
 
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                                           *
 
27
 *                                                                         *
 
28
 ***************************************************************************/
 
29
 
 
30
#ifndef ABSTRACT_IMPORT_FILTER_H
 
31
#define ABSTRACT_IMPORT_FILTER_H
 
32
 
 
33
#include <QObject>
 
34
#include <QStringList>
 
35
 
 
36
class AbstractAspect;
 
37
class QIODevice;
 
38
 
 
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; }
 
43
 
 
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; }
 
53
 
 
54
//! Interface for import operations.
 
55
/**
 
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.
 
62
 *
 
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.
 
75
 */
 
76
class AbstractImportFilter : public QObject
 
77
{
 
78
        Q_OBJECT
 
79
 
 
80
        public:
 
81
                virtual ~AbstractImportFilter() {}
 
82
                //! Import an object from the specified device and convert it to an Aspect.
 
83
                /**
 
84
                 * May return 0 if import failed.
 
85
                 */
 
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(" *.") + ")";
 
94
                }
 
95
};
 
96
 
 
97
#endif // ifndef ABSTRACT_IMPORT_FILTER_H
 
98
 
 
99