QWT API (中文) 7.0.1
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt3d_io.h
1#ifndef __qwt3d_io__
2#define __qwt3d_io__
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
32class QWT3D_EXPORT IO
33{
34
35public:
36 // The function type that can be processed by the define... members
37 using Function = bool (*)(Plot3D*, QString const& fname);
38
51 class Functor
52 {
53 public:
54 virtual ~Functor()
55 {
56 }
57 // Must clone the content of *this for an object of a derived class
58 virtual Functor* clone() const = 0;
59 // The workhorse of the user-defined implementation
60 virtual bool operator()(Plot3D* plot, QString const& fname) = 0;
61 };
62
63 // Define an input handler for a format with a function
64 static bool defineInputHandler(QString const& format, Function func);
65 // Define an output handler for a format with a function
66 static bool defineOutputHandler(QString const& format, Function func);
67 // Define an input handler for a format with a functor
68 static bool defineInputHandler(QString const& format, Functor const& func);
69 // Define an output handler for a format with a functor
70 static bool defineOutputHandler(QString const& format, Functor const& func);
71 // Save plot to file in specified format
72 static bool save(Plot3D*, QString const& fname, QString const& format);
73 // Load plot from file in specified format
74 static bool load(Plot3D*, QString const& fname, QString const& format);
75 // Returns list of available input formats
76 static QStringList inputFormatList();
77 // Returns list of available output formats
78 static QStringList outputFormatList();
79 // Returns output handler for a format
80 static Functor* outputHandler(QString const& format);
81 // Returns input handler for a format
82 static Functor* inputHandler(QString const& format);
83
84private:
85 IO()
86 {
87 }
88
89 // Lightweight Functor encapsulating an IO::Function
90 class Wrapper : public Functor
91 {
92 public:
93 // Performs actual input
94 Functor* clone() const
95 {
96 return new Wrapper(*this);
97 }
98 // Creates a Wrapper object from a function pointer
99 explicit Wrapper(Function h) : hdl(h)
100 {
101 }
102 // Returns a pointer to the wrapped function
103 bool operator()(Plot3D* plot, QString const& fname)
104 {
105 return (hdl) ? (*hdl)(plot, fname) : false;
106 }
107
108 private:
109 Function hdl;
110 };
111
112 struct Entry
113 {
114 Entry();
115 ~Entry();
116
117 Entry(Entry const& e);
118 void operator=(Entry const& e);
119
120 Entry(QString const& s, Functor const& f);
121 Entry(QString const& s, Function f);
122
123 QString fmt;
124 Functor* iofunc;
125 };
126
127 struct FormatCompare
128 {
129 explicit FormatCompare(Entry const& e);
130 bool operator()(Entry const& e);
131
132 Entry e_;
133 };
134
135 struct FormatCompare2
136 {
137 explicit FormatCompare2(QString s);
138 bool operator()(Entry const& e);
139
140 QString s_;
141 };
142
143 using Container = std::vector< Entry >;
144 using IT = Container::iterator;
145
146 static bool add_unique(Container& l, Entry const& e);
147 static IT find(Container& l, QString const& fmt);
148 static Container& rlist();
149 static Container& wlist();
150 static void setupHandler();
151};
152
162class QWT3D_EXPORT PixmapWriter : public IO::Functor
163{
164 friend class IO;
165
166public:
167 PixmapWriter() : quality_(-1)
168 {
169 }
170 // Set output quality
171 void setQuality(int val);
172
173private:
174 IO::Functor* clone() const
175 {
176 return new PixmapWriter(*this);
177 }
178 bool operator()(Plot3D* plot, QString const& fname);
179 QString fmt_;
180 int quality_;
181};
182
183} // ns
184
185#endif
更灵活的 IO 处理器实现的 Functor 类
Definition qwt3d_io.h:52
标准和用户自定义 I/O 处理器的通用接口
Definition qwt3d_io.h:33
提供 Qt 的 Pixmap 输出功能
Definition qwt3d_io.h:163
所有绘图控件的基类
Definition qwt3d_plot.h:31