OSCAR-code/sleepyhead/SleepLib/schema.h

264 lines
7.3 KiB
C
Raw Normal View History

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sts=4 et sw=4 tw=99:
*
* Schema Header (Parse Channel XML data)
*
* Copyright (c) 2011-2014 Mark Watkins <jedimark@users.sourceforge.net>
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of the Linux
* distribution for more details. */
2011-09-17 12:39:00 +00:00
#ifndef SCHEMA_H
#define SCHEMA_H
#include <QColor>
#include <QHash>
#include <QVariant>
#include <QString>
2011-10-05 03:05:35 +00:00
#include "machine_common.h"
namespace GraphFlags {
const quint32 Shadow = 1;
const quint32 Foobar = 2;
const quint32 XTicker = 4;
const quint32 YTicker = 8;
const quint32 XGrid = 16;
const quint32 YGrid = 32;
2011-10-05 03:05:35 +00:00
}
2011-09-17 12:39:00 +00:00
namespace schema {
enum Function {
NONE = 0, AVG, WAVG, MIN, MAX, SUM, CNT, P90, CPH, SPH, HOURS, SET
2011-09-17 12:39:00 +00:00
};
enum ChanType {
DATA = 0, SETTING, FLAG, MINOR_FLAG, SPAN, WAVEFORM
2011-09-17 12:39:00 +00:00
};
enum DataType {
DEFAULT = 0, INTEGER, BOOL, DOUBLE, STRING, RICHTEXT, DATE, TIME, DATETIME, LOOKUP
2011-09-17 12:39:00 +00:00
};
enum ScopeType {
GLOBAL = 0, MACHINE, DAY, SESSION
2011-09-17 12:39:00 +00:00
};
class Channel;
extern Channel EmptyChannel;
/*! \class Channel
\brief Contains information about a SleepLib data Channel (aka signals)
*/
2011-09-17 12:39:00 +00:00
class Channel
{
public:
Channel() { m_id = 0; m_upperThreshold = 0; m_lowerThreshold = 0;}
Channel(ChannelID id, ChanType type, ScopeType scope, QString code, QString fullname,
QString description, QString label, QString unit, DataType datatype = DEFAULT, QColor = Qt::black,
int link = 0);
void addColor(Function f, QColor color) { m_colors[f] = color; }
void addOption(int i, QString option) { m_options[i] = option; }
const int &id() { return m_id; }
const ChanType &type() { return m_type; }
const DataType &datatype() { return m_datatype; }
const QString &code() { return m_code; }
const QString &fullname() { return m_fullname; }
const QString &description() { return m_description; }
const QString &label() { return m_label; }
const QString &units() { return m_unit; }
2014-05-15 22:48:51 +00:00
const EventDataType &upperThreshold() { return m_upperThreshold; }
const EventDataType &lowerThreshold() { return m_lowerThreshold; }
const QColor &upperThresholdColor() { return m_upperThresholdColor; }
const QColor &lowerThresholdColor() { return m_lowerThresholdColor; }
const int &linkid() { return m_link; }
void setLabel(QString label) { m_label = label; }
void setUnit(QString unit) { m_unit = unit; }
void setDescription(QString desc) { m_description = desc; }
void setUpperThreshold(EventDataType value) { m_upperThreshold = value; }
void setUpperThresholdColor(QColor color) { m_upperThresholdColor = color; }
void setLowerThreshold(EventDataType value) { m_lowerThreshold = value; }
void setLowerThresholdColor(QColor color) { m_lowerThresholdColor = color; }
QString option(int i) {
if (m_options.contains(i)) {
return m_options[i];
}
return QString();
}
QColor &defaultColor() { return m_defaultcolor; }
void setDefaultColor(QColor color) { m_defaultcolor = color; }
QHash<int, QString> m_options;
QHash<Function, QColor> m_colors;
2011-09-17 12:39:00 +00:00
QList<Channel *> m_links; // better versions of this data type
bool isNull();
protected:
2011-09-17 12:39:00 +00:00
int m_id;
ChanType m_type;
ScopeType m_scope;
QString m_code; // Untranslatable
QString m_fullname; // Translatable Name
2011-09-17 12:39:00 +00:00
QString m_description;
QString m_label;
QString m_unit;
DataType m_datatype;
QColor m_defaultcolor;
int m_link;
EventDataType m_upperThreshold;
EventDataType m_lowerThreshold;
QColor m_upperThresholdColor;
QColor m_lowerThresholdColor;
2011-09-17 12:39:00 +00:00
};
/*! \class ChannelList
\brief A list containing a group of Channel objects, and XML storage and retrieval capability
*/
2011-09-17 12:39:00 +00:00
class ChannelList
{
public:
2011-09-17 12:39:00 +00:00
ChannelList();
virtual ~ChannelList();
//! \brief Loads Channel list from XML file specified by filename
2011-09-17 12:39:00 +00:00
bool Load(QString filename);
//! \brief Stores Channel list to XML file specified by filename
2011-09-17 12:39:00 +00:00
bool Save(QString filename);
void add(QString group, Channel *chan);
//! \brief Looks up Channel in this List with the index idx, returns EmptyChannel if not found
Channel &operator[](ChannelID idx) {
if (channels.contains(idx)) {
return *channels[idx];
} else {
2011-09-17 12:39:00 +00:00
return EmptyChannel;
}
2011-09-17 12:39:00 +00:00
}
//! \brief Looks up Channel from this list by name, returns Empty Channel if not found.
Channel &operator[](QString name) {
if (names.contains(name)) {
2011-09-17 13:21:18 +00:00
return *names[name];
} else {
2011-09-17 12:39:00 +00:00
return EmptyChannel;
}
2011-09-17 12:39:00 +00:00
}
//! \brief Channel List indexed by integer ID
QHash<ChannelID, Channel *> channels;
//! \brief Channel List index by name
QHash<QString, Channel *> names;
//! \brief Channel List indexed by group
QHash<QString, QHash<QString, Channel *> > groups;
2011-09-17 12:39:00 +00:00
QString m_doctype;
};
extern ChannelList channel;
/*enum LayerType {
2011-10-05 03:05:35 +00:00
UnspecifiedLayer, Waveform, Flag, Overlay, Group
};
// ?????
2011-10-05 03:05:35 +00:00
class Layer
{
public:
Layer(ChannelID code, QColor colour, QString label=QString());
virtual ~Layer();
Layer *addLayer(Layer *layer);// { m_layers.push_back(layer); return layer; }
void setMin(EventDataType min) { m_min=min; m_hasmin=true; }
void setMax(EventDataType max) { m_max=max; m_hasmax=true; }
2011-12-17 14:38:15 +00:00
EventDataType Min() { return m_min; }
EventDataType Max() { return m_max; }
2011-10-05 03:05:35 +00:00
bool visible() { return m_visible; }
void setVisible(bool b) { m_visible=b; }
protected:
LayerType m_type;
ChannelID m_code;
QColor m_colour;
QString m_label;
EventDataType m_min;
EventDataType m_max;
bool m_hasmin;
bool m_hasmax;
bool m_visible;
QVector<Layer *> m_layers;
};
class WaveformLayer: public Layer
{
public:
WaveformLayer(ChannelID code, QColor colour, float min=0, float max=0);
virtual ~WaveformLayer();
};
enum FlagVisual { Bar, Span, Dot };
class OverlayLayer: public Layer
{
public:
OverlayLayer(ChannelID code, QColor colour, FlagVisual visual=Bar);
virtual ~OverlayLayer();
protected:
FlagVisual m_visual;
};
class GroupLayer: public Layer // Effectively an empty Layer container
{
public:
GroupLayer();
virtual ~GroupLayer();
};
class FlagGroupLayer: public GroupLayer
{
public:
FlagGroupLayer();
virtual ~FlagGroupLayer();
};
class FlagLayer: public Layer
{
public:
FlagLayer(ChannelID code, QColor colour, FlagVisual visual=Bar);
virtual ~FlagLayer();
protected:
FlagVisual m_visual;
};
class Graph
{
public:
Graph(QString name,quint32 flags=GraphFlags::XTicker | GraphFlags::YTicker | GraphFlags::XGrid);
Layer *addLayer(Layer *layer) { m_layers.push_back(layer); return layer; }
int height() { if (m_visible) return m_height; else return 0;}
void setHeight(int h) { m_height=h; }
2011-10-05 03:05:35 +00:00
bool visible() { return m_visible; }
void setVisible(bool b) { m_visible=b; }
protected:
QString m_name;
int m_height;
QVector<Layer *> m_layers;
bool m_visible;
};
class GraphGroup
{
public:
GraphGroup(QString name);
GraphGroup();
Graph *addGraph(Graph *graph) { m_graphs.push_back(graph); return graph; }
protected:
QVector<Graph *>m_graphs;
}; */
2011-10-05 03:05:35 +00:00
2011-09-17 12:39:00 +00:00
void init();
} // namespace
#endif // SCHEMA_H