summaryrefslogtreecommitdiffstats
path: root/src/variant.h
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 01:49:02 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 01:49:02 +0000
commit5de3dd4762ca33a0f92e79ffa4fe2ff67069d531 (patch)
treebad482b7afa4cdf47422d60a5dd2c61c7e333b09 /src/variant.h
downloadktechlab-5de3dd4762ca33a0f92e79ffa4fe2ff67069d531.tar.gz
ktechlab-5de3dd4762ca33a0f92e79ffa4fe2ff67069d531.zip
Added KDE3 version of ktechlab
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/ktechlab@1095338 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/variant.h')
-rw-r--r--src/variant.h175
1 files changed, 175 insertions, 0 deletions
diff --git a/src/variant.h b/src/variant.h
new file mode 100644
index 0000000..8367026
--- /dev/null
+++ b/src/variant.h
@@ -0,0 +1,175 @@
+/***************************************************************************
+ * Copyright (C) 2003-2004 by David Saxton *
+ * david@bluehaze.org *
+ * *
+ * 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