1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/***************************************************************************
* Copyright (C) 2003-2004 by David Saxton *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef VARIANT_H
#define VARIANT_H
#include <qobject.h>
#include <qvariant.h>
class QColor;
class QString;
/**
For information:
QVariant::type() returns an enum for the current data type
contained. e.g. returns QVariant::Color or QVariant::Rect
@author Daniel Clarke
@author David Saxton
*/
class Variant : public QObject
{
Q_OBJECT
public:
class Type
{
public:
enum Value
{
None,
Int, // Integer
Raw, // QByteArray
Double, // Real number
String, // Editable string
Multiline, // String that may contain linebreaks
Select, // Selection of strings
Combo, // Editable combination of strings
FileName, // Filename
Color, // Color
Bool, // Boolean
VarName, // Variable name
Port, // Port name
Pin, // Pin name
PenStyle, // Pen Style
PenCapStyle, // Pen Cap Style
SevenSegment, // Pin Map for Seven Segment Display
KeyPad // Pin Map for Keypad
};
};
Variant( Type::Value type );
virtual ~Variant();
/**
* Returns the type of Variant (see Variant::Type::Value)
*/
Variant::Type::Value type() const { return m_type; }
/**
* Sets the variant type
*/
void setType( Type::Value type );
/**
* Returns the filter used for file dialogs (if this is of type Type::FileName)
*/
QString filter() const { return m_filter; }
void setFilter( const QString & filter ) { m_filter = filter; }
/**
* The selection of colours to be used in the combo box - e.g.
* ColorCombo::LED.
* @see ColorCombo::ColorScheme
*/
int colorScheme() const { return m_colorScheme; }
void setColorScheme( int colorScheme ) { m_colorScheme = colorScheme; }
/**
* This function is for convenience; it sets both the toolbar and editor
* caption.
*/
void setCaption( const QString & caption ) { setToolbarCaption(caption); setEditorCaption(caption); }
/**
* This text is displayed to the left of the entry widget in the toolbar
*/
QString toolbarCaption() const { return m_toolbarCaption; }
void setToolbarCaption( const QString & caption ) { m_toolbarCaption = caption; }
/**
* This text is displayed to the left of the entry widget in the item editor
*/
QString editorCaption() const { return m_editorCaption; }
void setEditorCaption( const QString & caption ) { m_editorCaption = caption; }
/**
* Unit of number, (e.g. V (volts) / F (farads))
*/
QString unit() const { return m_unit; }
void setUnit( const QString & unit ) { m_unit = unit; }
/**
* The smallest (as in negative, not absoluteness) value that the user can
* set this to.
*/
double minValue() const { return m_minValue; }
void setMinValue( double value );
/**
* The largest (as in positive, not absoluteness) value that the user can
* set this to.
*/
double maxValue() const { return m_maxValue; }
void setMaxValue( double value );
/**
* The smallest absolute value that the user can set this to, before the
* value is considered zero.
*/
double minAbsValue() const { return m_minAbsValue; }
void setMinAbsValue( double val );
QVariant defaultValue() const { return m_defaultValue; }
void setDefaultValue( QVariant val );
/**
* If this data is marked as advanced, it will only display in the item
* editor (and not in the toolbar)
*/
void setAdvanced( bool advanced ) { m_bAdvanced = advanced; }
bool isAdvanced() const { return m_bAdvanced; }
/**
* If this data is marked as hidden, it will not be editable from anywhere
* in the user interface
*/
void setHidden( bool hidden ) { m_bHidden = hidden; }
bool isHidden() const { return m_bHidden; }
/**
* Returns the best possible attempt at representing the data in a string
* for display. Used by the properties list view.
*/
QString displayString() const;
/**
* The list of values that the data is allowed to take (if it is string)
*/
QStringList allowed() const { return m_allowed; }
void setAllowed(QStringList stringList);
void appendAllowed(QString string);
QVariant value() const { return m_value; }
void setValue( const QVariant& val );
void resetToDefault();
signals:
/**
* Emitted when the value changes.
* NOTE: The order of data given is the new value, and then the old value
* This is done so that slots that don't care about the old value don't
* have to accept it
*/
void valueChanged( QVariant newValue, QVariant oldValue );
private:
QVariant m_value; // the actual data
QVariant m_defaultValue;
QString m_unit;
double m_minAbsValue;
double m_minValue;
double m_maxValue;
QString m_toolbarCaption; // Short description shown in e.g. properties dialog
QString m_editorCaption; // Text displayed before the data entry widget in the toolbar
bool m_bAdvanced; // If advanced, only display data in item editor
bool m_bHidden; // If hidden, do not allow user to change data
QString m_filter; // If type() == Type::FileName this is the filter used in file dialogs.
bool m_bSetDefault; // If false, then the default will be set to the first thing this variant is set to
Type::Value m_type;
QStringList m_allowed;
int m_colorScheme;
};
#endif
|