QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt3d_io.h
1#ifndef QWT3D_IO_H
2#define QWT3D_IO_H
3
4#include <vector>
5#include <algorithm>
6
7#include <qstring.h>
8#include <qstringlist.h>
9#include "qwt3d_global.h"
10
11namespace Qwt3D
12{
13
14class Plot3D;
15
23class QWT3D_EXPORT IO
24{
25
26public:
27 // The function type that can be processed by the define... members
28 using Function = bool (*)(Plot3D*, QString const& fname);
29
35 class Functor
36 {
37 public:
38 virtual ~Functor()
39 {
40 }
41 // Must clone the content of *this for an object of a derived class
42 virtual Functor* clone() const = 0;
43 // The workhorse of the user-defined implementation
44 virtual bool operator()(Plot3D* plot, QString const& fname) = 0;
45 };
46
47 // Define an input handler for a format with a function
48 static bool defineInputHandler(QString const& format, Function func);
49 // Define an output handler for a format with a function
50 static bool defineOutputHandler(QString const& format, Function func);
51 // Define an input handler for a format with a functor
52 static bool defineInputHandler(QString const& format, Functor const& func);
53 // Define an output handler for a format with a functor
54 static bool defineOutputHandler(QString const& format, Functor const& func);
55 // Save plot to file in specified format
56 static bool save(Plot3D*, QString const& fname, QString const& format);
57 // Load plot from file in specified format
58 static bool load(Plot3D*, QString const& fname, QString const& format);
59 // Returns list of available input formats
60 static QStringList inputFormatList();
61 // Returns list of available output formats
62 static QStringList outputFormatList();
63 // Returns output handler for a format
64 static Functor* outputHandler(QString const& format);
65 // Returns input handler for a format
66 static Functor* inputHandler(QString const& format);
67
68private:
69 IO()
70 {
71 }
72
73 // Lightweight Functor encapsulating an IO::Function
74 class Wrapper : public Functor
75 {
76 public:
77 // Performs actual input
78 Functor* clone() const override
79 {
80 return new Wrapper(*this);
81 }
82 // Creates a Wrapper object from a function pointer
83 explicit Wrapper(Function h) : hdl(h)
84 {
85 }
86 // Returns a pointer to the wrapped function
87 bool operator()(Plot3D* plot, QString const& fname) override
88 {
89 return (hdl) ? (*hdl)(plot, fname) : false;
90 }
91
92 private:
93 Function hdl;
94 };
95
96 struct Entry
97 {
98 Entry();
99 ~Entry();
100
101 Entry(Entry const& e);
102 void operator=(Entry const& e);
103
104 Entry(QString const& s, Functor const& f);
105 Entry(QString const& s, Function f);
106
107 QString fmt;
108 Functor* iofunc;
109 };
110
111 struct FormatCompare
112 {
113 explicit FormatCompare(Entry const& e);
114 bool operator()(Entry const& e);
115
116 Entry e_;
117 };
118
119 struct FormatCompare2
120 {
121 explicit FormatCompare2(QString s);
122 bool operator()(Entry const& e);
123
124 QString s_;
125 };
126
127 using Container = std::vector< Entry >;
128 using IT = Container::iterator;
129
130 static bool add_unique(Container& l, Entry const& e);
131 static IT find(Container& l, QString const& fmt);
132 static Container& rlist();
133 static Container& wlist();
134 static void setupHandler();
135};
136
140class QWT3D_EXPORT PixmapWriter : public IO::Functor
141{
142 friend class IO;
143 QWT_DECLARE_PRIVATE(PixmapWriter)
144
145public:
146 PixmapWriter();
147 ~PixmapWriter() override;
148
149 // Set output quality
150 void setQuality(int val);
151
152private:
153 IO::Functor* clone() const override;
154 bool operator()(Plot3D* plot, QString const& fname) override;
155};
156
157} // ns
158
159#endif
Functor class for more flexible IO handler implementation
Definition qwt3d_io.h:36
Generic interface for standard and user written I/O handlers
Definition qwt3d_io.h:24
Provides Qt's Pixmap output facilities
Definition qwt3d_io.h:141
Base class for all plotting widgets
Definition qwt3d_plot.h:22