Code

store default size in lpe::ArrayParam
[inkscape.git] / src / live_effects / parameter / array.h
1 #ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_ARRAY_H
2 #define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ARRAY_H
4 /*
5  * Inkscape::LivePathEffectParameters
6  *
7 * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
8  *
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
12 #include <vector>
14 #include <glib/gtypes.h>
16 #include <gtkmm/tooltips.h>
18 #include "live_effects/parameter/parameter.h"
20 #include "svg/svg.h"
21 #include "svg/stringstream.h"
23 namespace Inkscape {
25 namespace LivePathEffect {
27 template <typename StorageType>
28 class ArrayParam : public Parameter {
29 public:
30     ArrayParam( const Glib::ustring& label,
31                 const Glib::ustring& tip,
32                 const Glib::ustring& key,
33                 Inkscape::UI::Widget::Registry* wr,
34                 Effect* effect,
35                 size_t n = 0 )
36         : Parameter(label, tip, key, wr, effect), _vector(n), _default_size(n)
37     {
39     }
41     virtual ~ArrayParam() {
43     };
45     std::vector<StorageType> const & data() const {
46         return _vector;
47     }
49     virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * /*tooltips*/) {
50         return NULL;
51     }
53     virtual bool param_readSVGValue(const gchar * strvalue) {
54         _vector.clear();
55         gchar ** strarray = g_strsplit(strvalue, "|", 0);
56         gchar ** iter = strarray;
57         while (*iter != NULL) {
58             _vector.push_back( readsvg(*iter) );
59             iter++;
60         }
61         g_strfreev (strarray);
62         return true;
63     }
65     virtual gchar * param_getSVGValue() const {
66         Inkscape::SVGOStringStream os;
67         writesvg(os, _vector);
68         gchar * str = g_strdup(os.str().c_str());
69         return str;
70     }
72     void param_setValue(std::vector<StorageType> const &new_vector) {
73         _vector = new_vector;
74     }
76     void param_set_default() {
77         param_setValue( std::vector<StorageType>(_default_size) );
78     }
80     void param_set_and_write_new_value(std::vector<StorageType> const &new_vector) {
81         Inkscape::SVGOStringStream os;
82         writesvg(os, new_vector);
83         gchar * str = g_strdup(os.str().c_str());
84         param_write_to_repr(str);
85         g_free(str);
86     }
88 private:
89     ArrayParam(const ArrayParam&);
90     ArrayParam& operator=(const ArrayParam&);
92     std::vector<StorageType> _vector;
93     size_t _default_size;
95     void writesvg(SVGOStringStream &str, std::vector<StorageType> const &vector) const {
96         for (unsigned int i = 0; i < vector.size(); ++i) {
97             if (i != 0) {
98                 // separate items with pipe symbol
99                 str << " | ";
100             }
101             str << vector[i];
102         }
103     }
105     StorageType readsvg(const gchar * str);
106 };
109 } //namespace LivePathEffect
111 } //namespace Inkscape
113 #endif
115 /*
116   Local Variables:
117   mode:c++
118   c-file-style:"stroustrup"
119   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
120   indent-tabs-mode:nil
121   fill-column:99
122   End:
123 */
124 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :