Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
attr-widget.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Authors:
4 * Nicholas Bishop <nicholasbishop@gmail.com>
5 * Rodrigo Kumpera <kumpera@gmail.com>
6 *
7 * Copyright (C) 2007 Authors
8 *
9 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10 */
11
12#ifndef INKSCAPE_UI_WIDGET_ATTR_WIDGET_H
13#define INKSCAPE_UI_WIDGET_ATTR_WIDGET_H
14
15#include "attributes.h"
16#include "object/sp-object.h"
17#include "xml/node.h"
18
19namespace Inkscape {
20namespace UI {
21namespace Widget {
22
32
37{
39 union {
40 double d_val;
41 std::vector<double>* vt_val;
42 bool b_val;
43 unsigned int uint_val;
44 char* cptr_val;
46
47 //FIXME remove copy ctor and assignment operator as private to avoid double free of the vector
48public:
52
53 DefaultValueHolder (double d) {
54 type = T_DOUBLE;
55 value.d_val = d;
56 }
57
58 DefaultValueHolder (std::vector<double>* d) {
60 value.vt_val = d;
61 }
62
65 value.cptr_val = c;
66 }
67
69 type = T_BOOL;
70 value.b_val = d;
71 }
72
73 DefaultValueHolder (unsigned int ui) {
74 type = T_UINT;
75 value.uint_val = ui;
76 }
77
79 if (type == T_VECT_DOUBLE)
80 delete value.vt_val;
81 }
82
83 unsigned int as_uint() {
84 g_assert (type == T_UINT);
85 return value.uint_val;
86 }
87
88 bool as_bool() {
89 g_assert (type == T_BOOL);
90 return value.b_val;
91 }
92
93 double as_double() {
94 g_assert (type == T_DOUBLE);
95 return value.d_val;
96 }
97
98 std::vector<double>* as_vector() {
99 g_assert (type == T_VECT_DOUBLE);
100 return value.vt_val;
101 }
102
103 char* as_charptr() {
104 g_assert (type == T_CHARPTR);
105 return value.cptr_val;
106 }
107};
108
110{
111public:
112 AttrWidget(const SPAttr a, unsigned int value)
113 : _attr(a),
114 _default(value)
115 {}
116
117 AttrWidget(const SPAttr a, double value)
118 : _attr(a),
119 _default(value)
120 {}
121
122 AttrWidget(const SPAttr a, bool value)
123 : _attr(a),
124 _default(value)
125 {}
126
127 AttrWidget(const SPAttr a, char* value)
128 : _attr(a),
129 _default(value)
130 {}
131
133 : _attr(a),
134 _default()
135 {}
136
137 virtual ~AttrWidget()
138 = default;
139
140 virtual Glib::ustring get_as_attribute() const = 0;
141 virtual void set_from_attribute(SPObject*) = 0;
142
144 {
145 return _attr;
146 }
147
148 sigc::signal<void ()>& signal_attr_changed()
149 {
150 return _signal;
151 }
152protected:
154 const gchar* attribute_value(SPObject* o) const
155 {
156 const gchar* name = (const gchar*)sp_attribute_name(_attr);
157 if(name && o) {
158 const gchar* val = o->getRepr()->attribute(name);
159 return val;
160 }
161 return nullptr;
162 }
163
164private:
167 sigc::signal<void ()> _signal;
168};
169
170}
171}
172}
173
174#endif
175
176/*
177 Local Variables:
178 mode:c++
179 c-file-style:"stroustrup"
180 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
181 indent-tabs-mode:nil
182 fill-column:99
183 End:
184*/
185// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
gchar const * sp_attribute_name(SPAttr id)
Get attribute name by id.
Lookup dictionary for attributes/properties.
SPAttr
Definition attributes.h:27
sigc::signal< void()> _signal
virtual Glib::ustring get_as_attribute() const =0
AttrWidget(const SPAttr a, double value)
AttrWidget(const SPAttr a, bool value)
DefaultValueHolder * get_default()
AttrWidget(const SPAttr a, unsigned int value)
const gchar * attribute_value(SPObject *o) const
AttrWidget(const SPAttr a, char *value)
sigc::signal< void()> & signal_attr_changed()
virtual void set_from_attribute(SPObject *)=0
Very basic interface for classes that control attributes.
Definition attr-widget.h:37
std::vector< double > * as_vector()
Definition attr-widget.h:98
union Inkscape::UI::Widget::DefaultValueHolder::@55 value
DefaultValueHolder(std::vector< double > *d)
Definition attr-widget.h:58
virtual char const * attribute(char const *key) const =0
Get the string representation of a node's attribute.
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
double c[8][4]
Helper class to stream background task notifications as a series of messages.
Glib::ustring name
Definition toolbars.cpp:55
Interface for XML nodes.