diff --git a/sleepyhead/SleepLib/loader_plugins/intellipap_loader.cpp b/sleepyhead/SleepLib/loader_plugins/intellipap_loader.cpp
index e540899c..9adc6285 100644
--- a/sleepyhead/SleepLib/loader_plugins/intellipap_loader.cpp
+++ b/sleepyhead/SleepLib/loader_plugins/intellipap_loader.cpp
@@ -581,16 +581,8 @@ int IntellipapLoader::Open(QString path)
return c;
}
-bool intellipap_initialized = false;
-void IntellipapLoader::Register()
+void IntellipapLoader::initChannels()
{
- if (intellipap_initialized) { return; }
-
- qDebug() << "Registering IntellipapLoader";
- RegisterLoader(new IntellipapLoader());
- //InitModelMap();
- intellipap_initialized = true;
-
using namespace schema;
Channel * chan = nullptr;
channel.add(GRP_CPAP, chan = new Channel(INTP_SmartFlexMode = 0x1165, SETTING, SESSION,
@@ -610,3 +602,15 @@ void IntellipapLoader::Register()
QObject::tr("SmartFlex Level"),
"", DEFAULT, Qt::green));
}
+
+bool intellipap_initialized = false;
+void IntellipapLoader::Register()
+{
+ if (intellipap_initialized) { return; }
+
+ qDebug() << "Registering IntellipapLoader";
+ RegisterLoader(new IntellipapLoader());
+ //InitModelMap();
+ intellipap_initialized = true;
+
+}
diff --git a/sleepyhead/SleepLib/loader_plugins/intellipap_loader.h b/sleepyhead/SleepLib/loader_plugins/intellipap_loader.h
index 45adc508..4e3eb8e2 100644
--- a/sleepyhead/SleepLib/loader_plugins/intellipap_loader.h
+++ b/sleepyhead/SleepLib/loader_plugins/intellipap_loader.h
@@ -75,6 +75,8 @@ class IntellipapLoader : public CPAPLoader
virtual MachineInfo newInfo() {
return MachineInfo(MT_CPAP, 0, intellipap_class_name, QObject::tr("DeVilbiss"), QString(), QString(), QString(), QObject::tr("Intellipap"), QDateTime::currentDateTime(), intellipap_data_version);
}
+ virtual void initChannels();
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Now for some CPAPLoader overrides
diff --git a/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp b/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp
index 74bfd5df..92828a59 100644
--- a/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp
+++ b/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp
@@ -1447,7 +1447,7 @@ bool PRS1Import::ParseSummaryF5()
session->settings[CPAP_RampPressure] = ramp_pressure;
- int duration=data[0x1B] | data[0x1C] << 8;
+ int duration=data[0x18] | data[0x19] << 8;
session->set_last(qint64(summary->timestamp+duration) * 1000L);
return true;
@@ -1985,14 +1985,9 @@ using namespace schema;
Channel PRS1Channels;
-void PRS1Loader::Register()
+void PRS1Loader::initChannels()
{
- if (initialized) { return; }
-
- qDebug() << "Registering PRS1Loader";
- RegisterLoader(new PRS1Loader());
- InitModelMap();
- initialized = true;
+ Channel * chan = nullptr;
channel.add(GRP_CPAP, new Channel(CPAP_PressurePulse = 0x1009, MINOR_FLAG, SESSION,
"PressurePulse",
@@ -2001,9 +1996,6 @@ void PRS1Loader::Register()
QObject::tr("PP"),
STR_UNIT_EventsPerHour, DEFAULT, QColor("dark red")));
-
-
- Channel * chan = nullptr;
channel.add(GRP_CPAP, chan = new Channel(PRS1_FlexMode = 0xe105, SETTING, SESSION,
"PRS1FlexMode", QObject::tr("Flex Mode"),
QObject::tr("PRS1 pressure relief mode."),
@@ -2137,8 +2129,6 @@ void PRS1Loader::Register()
//
//
-
-
QString unknowndesc=QObject::tr("Unknown PRS1 Code %1");
QString unknownname=QObject::tr("PRS1_%1");
QString unknownshort=QObject::tr("PRS1_%1");
@@ -2206,13 +2196,21 @@ void PRS1Loader::Register()
channel.add(GRP_CPAP, new Channel(PRS1_TimedBreath = 0x1180, MINOR_FLAG, SESSION,
"PRS1TimedBreath",
- QObject::tr("Timed Breath").arg(0x12,2,16,QChar('0')),
- QObject::tr("").arg(0x12,2,16,QChar('0')),
- QObject::tr("TB").arg(0x12,2,16,QChar('0')),
+ QObject::tr("Timed Breath"),
+ QObject::tr("Machine Initiated Breath"),
+ QObject::tr("TB"),
STR_UNIT_Unknown,
DEFAULT, QColor("black")));
+}
+void PRS1Loader::Register()
+{
+ if (initialized) { return; }
+ qDebug() << "Registering PRS1Loader";
+ RegisterLoader(new PRS1Loader());
+ InitModelMap();
+ initialized = true;
}
diff --git a/sleepyhead/SleepLib/loader_plugins/prs1_loader.h b/sleepyhead/SleepLib/loader_plugins/prs1_loader.h
index ffc6a07d..11290309 100644
--- a/sleepyhead/SleepLib/loader_plugins/prs1_loader.h
+++ b/sleepyhead/SleepLib/loader_plugins/prs1_loader.h
@@ -179,6 +179,8 @@ class PRS1Loader : public CPAPLoader
virtual ChannelID HumidifierConnected() { return PRS1_HumidStatus; }
virtual ChannelID HumidifierLevel() { return PRS1_HumidLevel; }
+ void initChannels();
+
QHash sesstasks;
diff --git a/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp b/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp
index 00c1bb93..95e3f4a2 100644
--- a/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp
+++ b/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp
@@ -2334,6 +2334,7 @@ void ResInitModelMap()
// to signal names crop short
// Read this from a table?
+ resmed_codes.clear();
resmed_codes[CPAP_FlowRate].push_back("Flow");
resmed_codes[CPAP_MaskPressureHi].push_back("Mask Pres");
@@ -2418,30 +2419,11 @@ void ResInitModelMap()
resmed_codes[CPAP_PressureMin].push_back("Min tryck");
}
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-
ChannelID ResmedLoader::PresReliefMode() { return RMS9_EPR; }
ChannelID ResmedLoader::PresReliefLevel() { return RMS9_EPRLevel; }
-bool resmed_initialized = false;
-void ResmedLoader::Register()
+void ResmedLoader::initChannels()
{
- if (resmed_initialized) { return; }
-
- qDebug() << "Registering ResmedLoader";
- RegisterLoader(new ResmedLoader());
-
using namespace schema;
Channel * chan = nullptr;
channel.add(GRP_CPAP, chan = new Channel(RMS9_EPR = 0xe201, SETTING, SESSION,
@@ -2454,6 +2436,7 @@ void ResmedLoader::Register()
chan->addOption(0, STR_TR_Off);
chan->addOption(1, QObject::tr("Ramp Only"));
chan->addOption(2, QObject::tr("Full Time"));
+ chan->addOption(3, QObject::tr("Patient???"));
channel.add(GRP_CPAP, chan = new Channel(RMS9_EPRLevel = 0xe202, SETTING, SESSION,
"EPRLevel", QObject::tr("EPR Level"),
@@ -2465,9 +2448,20 @@ void ResmedLoader::Register()
chan->addOption(1, QObject::tr("1cmH2O"));
chan->addOption(2, QObject::tr("2cmH2O"));
chan->addOption(3, QObject::tr("3cmH2O"));
- chan->addOption(4, QObject::tr("Patient")); // Think this isn't real..
+ // Modelmap needs channels initalized above!!!
ResInitModelMap();
+
+}
+
+bool resmed_initialized = false;
+void ResmedLoader::Register()
+{
+ if (resmed_initialized) { return; }
+
+ qDebug() << "Registering ResmedLoader";
+ RegisterLoader(new ResmedLoader());
+
resmed_initialized = true;
}
diff --git a/sleepyhead/SleepLib/loader_plugins/resmed_loader.h b/sleepyhead/SleepLib/loader_plugins/resmed_loader.h
index 6312ceff..94591660 100644
--- a/sleepyhead/SleepLib/loader_plugins/resmed_loader.h
+++ b/sleepyhead/SleepLib/loader_plugins/resmed_loader.h
@@ -380,6 +380,8 @@ class ResmedLoader : public CPAPLoader
return MachineInfo(MT_CPAP, 0, resmed_class_name, QObject::tr("ResMed"), QString(), QString(), QString(), QObject::tr("S9"), QDateTime::currentDateTime(), resmed_data_version);
}
+ virtual void initChannels();
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Now for some CPAPLoader overrides
diff --git a/sleepyhead/SleepLib/loader_plugins/weinmann_loader.cpp b/sleepyhead/SleepLib/loader_plugins/weinmann_loader.cpp
index 39cba416..db40a946 100644
--- a/sleepyhead/SleepLib/loader_plugins/weinmann_loader.cpp
+++ b/sleepyhead/SleepLib/loader_plugins/weinmann_loader.cpp
@@ -571,16 +571,8 @@ int WeinmannLoader::Open(QString path)
return 1;*/
}
-bool weinmann_initialized = false;
-void WeinmannLoader::Register()
+void WeinmannLoader::initChannels()
{
- if (weinmann_initialized) { return; }
-
- qDebug() << "Registering WeinmannLoader";
- RegisterLoader(new WeinmannLoader());
- //InitModelMap();
- weinmann_initialized = true;
-
using namespace schema;
Channel * chan = nullptr;
// channel.add(GRP_CPAP, chan = new Channel(INTP_SmartFlex = 0x1165, SETTING, SESSION,
@@ -592,3 +584,14 @@ void WeinmannLoader::Register()
// chan->addOption(1, STR_TR_None);
}
+
+bool weinmann_initialized = false;
+void WeinmannLoader::Register()
+{
+ if (weinmann_initialized) { return; }
+
+ qDebug() << "Registering WeinmannLoader";
+ RegisterLoader(new WeinmannLoader());
+ //InitModelMap();
+ weinmann_initialized = true;
+}
diff --git a/sleepyhead/SleepLib/loader_plugins/weinmann_loader.h b/sleepyhead/SleepLib/loader_plugins/weinmann_loader.h
index 05697c82..b837ffc3 100644
--- a/sleepyhead/SleepLib/loader_plugins/weinmann_loader.h
+++ b/sleepyhead/SleepLib/loader_plugins/weinmann_loader.h
@@ -118,6 +118,8 @@ class WeinmannLoader : public CPAPLoader
virtual MachineInfo newInfo() {
return MachineInfo(MT_CPAP, 0, weinmann_class_name, QObject::tr("Weinmann"), QObject::tr("SOMNOsoft2"), QString(), QString(), QObject::tr(""), QDateTime::currentDateTime(), weinmann_data_version);
}
+ virtual void initChannels();
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Now for some CPAPLoader overrides
diff --git a/sleepyhead/SleepLib/machine_loader.cpp b/sleepyhead/SleepLib/machine_loader.cpp
index 23d410ce..04c44b96 100644
--- a/sleepyhead/SleepLib/machine_loader.cpp
+++ b/sleepyhead/SleepLib/machine_loader.cpp
@@ -116,6 +116,7 @@ Machine * MachineLoader::CreateMachine(MachineInfo info, MachineID id)
void RegisterLoader(MachineLoader *loader)
{
+ loader->initChannels();
m_loaders.push_back(loader);
}
void DestroyLoaders()
diff --git a/sleepyhead/SleepLib/machine_loader.h b/sleepyhead/SleepLib/machine_loader.h
index bfe520f5..32cbdb9c 100644
--- a/sleepyhead/SleepLib/machine_loader.h
+++ b/sleepyhead/SleepLib/machine_loader.h
@@ -86,6 +86,8 @@ class MachineLoader: public QObject
void removeMachine(Machine * m);
+ virtual void initChannels() {}
+
signals:
void updateProgress(int cnt, int total);
@@ -126,7 +128,7 @@ public:
virtual ChannelID PresReliefLevel() { return NoChannel; }
virtual ChannelID HumidifierConnected() { return NoChannel; }
virtual ChannelID HumidifierLevel() { return CPAP_HumidSetting; }
-
+ virtual void initChannels() {}
};
struct ImportPath
diff --git a/sleepyhead/SleepLib/schema.cpp b/sleepyhead/SleepLib/schema.cpp
index 1d7ceeda..3825152f 100644
--- a/sleepyhead/SleepLib/schema.cpp
+++ b/sleepyhead/SleepLib/schema.cpp
@@ -21,9 +21,13 @@
#include "schema.h"
#include "common_gui.h"
+#include "SleepLib/profiles.h"
+
namespace schema {
+void resetChannels();
+
ChannelList channel;
Channel EmptyChannel;
Channel *SessionEnabledChannel;
@@ -190,13 +194,13 @@ void init()
// This Large Leak record is just a flag marker, used by Intellipap for one
schema::channel.add(GRP_CPAP, new Channel(CPAP_LeakFlag = 0x100a, FLAG, SESSION,
- "LeakFlag", QObject::tr("Large Leak"),
+ "LeakFlag", QObject::tr("Leak Flag"),
QObject::tr("A large mask leak affecting machine performance."),
- QObject::tr("LL"), STR_UNIT_EventsPerHour, DEFAULT, QColor("light gray")));
+ QObject::tr("LF"), STR_UNIT_EventsPerHour, DEFAULT, QColor("light gray")));
// The following is a Large Leak record that references a waveform span
schema::channel.add(GRP_CPAP, new Channel(CPAP_LargeLeak = 0x1158, SPAN, SESSION,
- "LeakFlagSpan", QObject::tr("Large Leak"),
+ "LeakSpan", QObject::tr("Large Leak"),
QObject::tr("A large mask leak affecting machine performance."),
QObject::tr("LL"), STR_UNIT_EventsPerHour, DEFAULT, QColor("light gray")));
@@ -509,6 +513,24 @@ void init()
ZEO_TimeToZ = schema::channel["TimeToZ"].id();
}
+
+void resetChannels()
+{
+ schema::channel.channels.clear();
+ schema::channel.names.clear();
+ schema::channel.groups.clear();
+
+ schema_initialized = false;
+ init();
+
+ QList list = GetLoaders();
+ for (int i=0; i< list.size(); ++i) {
+ MachineLoader * loader = list.at(i);
+ loader->initChannels();
+ }
+}
+
+
Channel::Channel(ChannelID id, ChanType type, ScopeType scope, QString code, QString fullname,
QString description, QString label, QString unit, DataType datatype, QColor color, int link):
m_id(id),
diff --git a/sleepyhead/SleepLib/schema.h b/sleepyhead/SleepLib/schema.h
index 3fd88e25..5b02e930 100644
--- a/sleepyhead/SleepLib/schema.h
+++ b/sleepyhead/SleepLib/schema.h
@@ -28,6 +28,7 @@ const quint32 YGrid = 32;
}
namespace schema {
+void resetChannels();
enum Function {
NONE = 0, AVG, WAVG, MIN, MAX, SUM, CNT, P90, CPH, SPH, HOURS, SET
@@ -76,6 +77,7 @@ class Channel
inline ChannelID linkid() const { return m_link; }
+ void setFullname(QString fullname) { m_fullname = fullname; }
void setLabel(QString label) { m_label = label; }
void setUnit(QString unit) { m_unit = unit; }
void setDescription(QString desc) { m_description = desc; }
diff --git a/sleepyhead/docs/channels.xml b/sleepyhead/docs/channels.xml
index 0b881578..b02f53db 100644
--- a/sleepyhead/docs/channels.xml
+++ b/sleepyhead/docs/channels.xml
@@ -92,11 +92,6 @@ Important: One id code per item, DO NOT CHANGE ID NUMBERS!!!
-
-
-
-
-
diff --git a/sleepyhead/mainwindow.cpp b/sleepyhead/mainwindow.cpp
index 3c86848c..c743ebb5 100644
--- a/sleepyhead/mainwindow.cpp
+++ b/sleepyhead/mainwindow.cpp
@@ -123,6 +123,9 @@ void MainWindow::logMessage(QString msg)
ui->logText->appendPlainText(msg);
}
+void loadChannels();
+void saveChannels();
+
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
@@ -325,6 +328,7 @@ MainWindow::MainWindow(QWidget *parent) :
wtimer.setParent(this);
warnidx = 0;
wtimer.singleShot(0, this, SLOT(on_changeWarningMessage()));
+ loadChannels();
}
void MainWindow::on_changeWarningMessage()
@@ -335,8 +339,133 @@ void MainWindow::on_changeWarningMessage()
wtimer.singleShot(10000, this, SLOT(on_changeWarningMessage()));
}
+
+quint16 chandata_version = 0;
+
+void saveChannels()
+{
+ QString filename = p_profile->Get("{DataFolder}/") + "channels.dat";
+ QFile f(filename);
+ qDebug() << "Saving Channel States";
+ f.open(QFile::WriteOnly);
+ QDataStream out(&f);
+ out.setVersion(QDataStream::Qt_4_6);
+ out.setByteOrder(QDataStream::LittleEndian);
+
+ out << (quint32)magic;
+ out << (quint16)chandata_version;
+
+ quint16 size = schema::channel.channels.size();
+ out << size;
+
+ QHash::iterator it;
+ QHash::iterator it_end = schema::channel.channels.end();
+
+ for (it = schema::channel.channels.begin(); it != it_end; ++it) {
+ schema::Channel * chan = it.value();
+ out << it.key();
+ out << chan->code();
+ out << chan->enabled();
+ out << chan->defaultColor();
+ out << chan->fullname();
+ out << chan->label();
+ out << chan->description();
+ out << chan->lowerThreshold();
+ out << chan->lowerThresholdColor();
+ out << chan->upperThreshold();
+ out << chan->upperThresholdColor();
+ }
+
+ f.close();
+
+}
+
+
+void loadChannels()
+{
+ QString filename = p_profile->Get("{DataFolder}/") + "channels.dat";
+ QFile f(filename);
+ if (!f.open(QFile::ReadOnly)) {
+ return;
+ }
+ qDebug() << "Loading Channel States";
+
+ QDataStream in(&f);
+ in.setVersion(QDataStream::Qt_4_6);
+ in.setByteOrder(QDataStream::LittleEndian);
+
+ quint32 mag;
+ in >> mag;
+
+ if (magic != mag) {
+ qDebug() << "LoadChannels: Faulty data";
+ return;
+ }
+ quint16 version;
+ in >> version;
+
+ if (version < chandata_version) {
+ return;
+ //upgrade here..
+ }
+
+ quint16 size;
+ in >> size;
+
+ QString name;
+ ChannelID code;
+ bool enabled;
+ QColor color;
+ EventDataType lowerThreshold;
+ QColor lowerThresholdColor;
+ EventDataType upperThreshold;
+ QColor upperThresholdColor;
+
+ QString fullname;
+ QString label;
+ QString description;
+
+ for (int i=0; i < size; i++) {
+ in >> code;
+ schema::Channel * chan = &schema::channel[code];
+ in >> name;
+ if (chan->code() != name) {
+ qDebug() << "Looking up channel" << name << "by name, as it's ChannedID must have changed";
+ chan = &schema::channel[name];
+ }
+ in >> enabled;
+ in >> color;
+ in >> fullname;
+ in >> label;
+ in >> description;
+ in >> lowerThreshold;
+ in >> lowerThresholdColor;
+ in >> upperThreshold;
+ in >> upperThresholdColor;
+ if (!chan) {
+ qDebug() << "loadChannels has idea about channel" << name;
+ if (in.atEnd()) return;
+ continue;
+ }
+ chan->setEnabled(enabled);
+ chan->setDefaultColor(color);
+ chan->setFullname(fullname);
+ chan->setLabel(label);
+ chan->setDescription(description);
+ chan->setLowerThreshold(lowerThreshold);
+ chan->setLowerThresholdColor(lowerThresholdColor);
+ chan->setUpperThreshold(upperThreshold);
+ chan->setUpperThresholdColor(upperThresholdColor);
+ if (in.atEnd()) return;
+ }
+
+ f.close();
+}
+
void MainWindow::closeEvent(QCloseEvent * event)
{
+ saveChannels();
+
if (daily) {
daily->close();
daily->deleteLater();
diff --git a/sleepyhead/preferencesdialog.cpp b/sleepyhead/preferencesdialog.cpp
index 02519527..91e7604f 100644
--- a/sleepyhead/preferencesdialog.cpp
+++ b/sleepyhead/preferencesdialog.cpp
@@ -96,7 +96,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Profile *_profile) :
ui->startedUsingMask->calendarWidget()->setFirstDayOfWeek(dow);
- ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->colourTab));
+ //ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->colourTab));
// Stop both calendar drop downs highlighting weekends in red
QTextCharFormat format = ui->startedUsingMask->calendarWidget()->weekdayTextFormat(Qt::Saturday);
@@ -252,38 +252,6 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Profile *_profile) :
ui->showUserFlagsInPie->setChecked(profile->cpap->userEventPieChart());
- ui->eventTable->setColumnWidth(0, 40);
- ui->eventTable->setColumnWidth(1, 55);
- ui->eventTable->setColumnHidden(3, true);
- int row = 0;
- QTableWidgetItem *item;
- QHash::iterator ci;
-
- for (ci = schema::channel.names.begin(); ci != schema::channel.names.end(); ci++) {
- if (ci.value()->type() == schema::DATA) {
- ui->eventTable->insertRow(row);
- int id = ci.value()->id();
- ui->eventTable->setItem(row, 3, new QTableWidgetItem(QString::number(id)));
- item = new QTableWidgetItem(ci.value()->description());
- ui->eventTable->setItem(row, 2, item);
- QCheckBox *c = new QCheckBox(ui->eventTable);
- c->setChecked(true);
- QLabel *pb = new QLabel(ui->eventTable);
- pb->setText("foo");
- ui->eventTable->setCellWidget(row, 0, c);
- ui->eventTable->setCellWidget(row, 1, pb);
-
-
- QColor a = ci.value()->defaultColor(); //(rand() % 255, rand() % 255, rand() % 255, 255);
- QPalette p(a, a, a, a, a, a, a);
-
- pb->setPalette(p);
- pb->setAutoFillBackground(true);
- pb->setBackgroundRole(QPalette::Background);
- row++;
- }
- }
-
/* QLocale locale=QLocale::system();
QString shortformat=locale.dateFormat(QLocale::ShortFormat);
if (!shortformat.toLower().contains("yyyy")) {
@@ -299,9 +267,107 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Profile *_profile) :
resetGraphModel();
- // tree->sortByColumn(0,Qt::AscendingOrder);
+ chanFilterModel = new MySortFilterProxyModel(this);
+ chanModel = new QStandardItemModel(this);
+ chanFilterModel->setSourceModel(chanModel);
+ chanFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
+ chanFilterModel->setFilterKeyColumn(0);
+ ui->chanView->setModel(chanFilterModel);
+
+ InitChanInfo();
+
}
+void PreferencesDialog::InitChanInfo()
+{
+ QHash toprows;
+
+ chanModel->clear();
+ toplevel.clear();
+ toprows.clear();
+
+ QStandardItem *hdr = nullptr;
+
+ toplevel[schema::SPAN] = hdr = new QStandardItem(tr("Span Events"));
+ hdr->setEditable(false);
+ chanModel->appendRow(hdr);
+
+ toplevel[schema::FLAG] = hdr = new QStandardItem(tr("Flags"));
+ hdr->setEditable(false);
+ chanModel->appendRow(hdr);
+
+ toplevel[schema::MINOR_FLAG] = hdr = new QStandardItem(tr("Minor Flags"));
+ hdr->setEditable(false);
+ chanModel->appendRow(hdr);
+
+ toplevel[schema::WAVEFORM] = hdr = new QStandardItem(tr("Waveforms"));
+ hdr->setEditable(false);
+ chanModel->appendRow(hdr);
+
+ toplevel[schema::DATA] = hdr = new QStandardItem(tr("Data Channels"));
+ hdr->setEditable(false);
+ chanModel->appendRow(hdr);
+
+ toplevel[schema::SETTING] = hdr = new QStandardItem(tr("Settings Channels"));
+ hdr->setEditable(false);
+ chanModel->appendRow(hdr);
+
+ ui->chanView->setAlternatingRowColors(true);
+
+ // ui->graphView->setFirstColumnSpanned(0,daily->index(),true); // Crashes on windows.. Why do I need this again?
+ chanModel->setColumnCount(5);
+ QStringList headers;
+ headers.append(tr("Name"));
+ headers.append(tr("Color"));
+ headers.append(tr("Label"));
+ headers.append(tr("Details"));
+ headers.append(tr("ID"));
+ chanModel->setHorizontalHeaderLabels(headers);
+ ui->chanView->setColumnWidth(0, 200);
+ ui->chanView->setColumnWidth(1, 50);
+ ui->chanView->setColumnWidth(2, 150);
+ ui->chanView->setSelectionMode(QAbstractItemView::SingleSelection);
+ ui->chanView->setSelectionBehavior(QAbstractItemView::SelectItems);
+
+ QHash::iterator ci;
+
+ int row = 0;
+ for (ci = schema::channel.names.begin(); ci != schema::channel.names.end(); ci++) {
+ schema::Channel * chan = ci.value();
+
+ QList items;
+ QStandardItem *it = new QStandardItem(chan->fullname());
+ it->setCheckable(true);
+ it->setCheckState(chan->enabled() ? Qt::Checked : Qt::Unchecked);
+ it->setEditable(true);
+ it->setData(chan->id(), Qt::UserRole);
+ items.push_back(it);
+
+
+ it = new QStandardItem();
+ it->setBackground(QBrush(chan->defaultColor()));
+ it->setEditable(false);
+ it->setData(chan->defaultColor().rgba(), Qt::UserRole);
+ it->setSelectable(false);
+ items.push_back(it);
+
+ it = new QStandardItem(chan->label());
+ it->setEditable(true);
+ items.push_back(it);
+
+ it = new QStandardItem(chan->description());
+ it->setEditable(true);
+ items.push_back(it);
+
+ it = new QStandardItem(QString().number(chan->id(),16));
+ it->setEditable(false);
+ items.push_back(it);
+
+ row = toprows[chan->type()]++;
+ toplevel[chan->type()]->insertRow(row, items);
+ }
+ ui->chanView->expandAll();
+}
PreferencesDialog::~PreferencesDialog()
{
@@ -310,29 +376,6 @@ PreferencesDialog::~PreferencesDialog()
delete ui;
}
-void PreferencesDialog::on_eventTable_doubleClicked(const QModelIndex &index)
-{
- int row = index.row();
- int col = index.column();
- bool ok;
- int id = ui->eventTable->item(row, 3)->text().toInt(&ok);
-
- if (col == 1) {
- QWidget *w = ui->eventTable->cellWidget(row, col);
- QColorDialog a;
- QColor color = w->palette().background().color();
- a.setCurrentColor(color);
-
- if (a.exec() == QColorDialog::Accepted) {
- QColor c = a.currentColor();
- QPalette p(c, c, c, c, c, c, c);
- w->setPalette(p);
- m_new_colors[id] = c;
- //qDebug() << "Color accepted" << col << id;
- }
- }
-}
-
bool PreferencesDialog::Save()
{
bool recalc_events = false;
@@ -555,13 +598,27 @@ bool PreferencesDialog::Save()
bigfont->setWeight(ui->bigFontBold->isChecked() ? QFont::Bold : QFont::Normal);
bigfont->setItalic(ui->bigFontItalic->isChecked());
- // Process color changes
- for (QHash::iterator i = m_new_colors.begin(); i != m_new_colors.end(); i++) {
- schema::Channel &chan = schema::channel[i.key()];
- if (!chan.isNull()) {
- qDebug() << "TODO: Change" << chan.code() << "color to" << i.value();
- chan.setDefaultColor(i.value());
+ int toprows = chanModel->rowCount();
+
+ bool ok;
+ for (int i=0; i < toprows; i++) {
+ QStandardItem * topitem = chanModel->item(i,0);
+
+ if (!topitem) continue;
+ int rows = topitem->rowCount();
+ for (int j=0; j< rows; ++j) {
+ QStandardItem * item = topitem->child(j, 0);
+ if (!item) continue;
+
+ ChannelID id = item->data(Qt::UserRole).toUInt(&ok);
+ schema::Channel & chan = schema::channel[id];
+ if (chan.isNull()) continue;
+ chan.setEnabled(item->checkState() == Qt::Checked ? true : false);
+ chan.setFullname(item->text());
+ chan.setDefaultColor(QColor(topitem->child(j,1)->data(Qt::UserRole).toUInt()));
+ chan.setLabel(topitem->child(j,2)->text());
+ chan.setDescription(topitem->child(j,3)->text());
}
}
@@ -805,6 +862,7 @@ void PreferencesDialog::resetGraphModel()
SLOT(graphModel_changed(QStandardItem *)));
ui->graphView->expandAll();
+
}
void PreferencesDialog::on_resetGraphButton_clicked()
@@ -929,6 +987,14 @@ void PreferencesDialog::on_tooltipTimeoutSlider_valueChanged(int value)
ui->tooltipMS->display(value * 50);
}
+void PreferencesDialog::on_resetChannelDefaults_clicked()
+{
+ if (QMessageBox::question(this, STR_MessageBox_Warning, QObject::tr("Are you sure you want to reset all your channel colors and settings to defaults?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) {
+ schema::resetChannels();
+ InitChanInfo();
+ }
+}
+
void PreferencesDialog::on_createSDBackups_clicked(bool checked)
{
if (!checked && p_profile->session->backupCardData()) {
@@ -939,3 +1005,28 @@ void PreferencesDialog::on_createSDBackups_clicked(bool checked)
}
}
}
+
+void PreferencesDialog::on_channelSearch_textChanged(const QString &arg1)
+{
+ chanFilterModel->setFilterFixedString(arg1);
+}
+
+void PreferencesDialog::on_chanView_doubleClicked(const QModelIndex &index)
+{
+ if (index.column() == 1) {
+ QColorDialog a;
+
+ quint32 color = index.data(Qt::UserRole).toUInt();
+
+ a.setCurrentColor(QColor((QRgb)color));
+
+ if (a.exec() == QColorDialog::Accepted) {
+ quint32 cv = a.currentColor().rgba();
+
+ chanFilterModel->setData(index, cv, Qt::UserRole);
+ chanFilterModel->setData(index, a.currentColor(), Qt::BackgroundRole);
+
+ }
+
+ }
+}
diff --git a/sleepyhead/preferencesdialog.h b/sleepyhead/preferencesdialog.h
index 5740a709..db13fe10 100644
--- a/sleepyhead/preferencesdialog.h
+++ b/sleepyhead/preferencesdialog.h
@@ -69,7 +69,6 @@ class PreferencesDialog : public QDialog
void RefreshLastChecked();
private slots:
- void on_eventTable_doubleClicked(const QModelIndex &index);
void on_combineSlider_valueChanged(int value);
void on_IgnoreSlider_valueChanged(int value);
@@ -98,18 +97,30 @@ class PreferencesDialog : public QDialog
void on_createSDBackups_clicked(bool checked);
+ void on_resetChannelDefaults_clicked();
+
+ void on_channelSearch_textChanged(const QString &arg1);
+
+ void on_chanView_doubleClicked(const QModelIndex &index);
+
private:
//! \brief Populates the Graph Model view with data from the Daily, Overview & Oximetry gGraphView objects
void resetGraphModel();
+ void InitChanInfo();
+ QHash toplevel;
Ui::PreferencesDialog *ui;
Profile *profile;
- QHash m_new_colors;
+ QHash m_new_colors;
+
QStringList importLocations;
QStringListModel *importModel;
MySortFilterProxyModel *graphFilterModel;
QStandardItemModel *graphModel;
+
+ MySortFilterProxyModel * chanFilterModel;
+ QStandardItemModel *chanModel;
};
diff --git a/sleepyhead/preferencesdialog.ui b/sleepyhead/preferencesdialog.ui
index f2d5e76e..c37f9a0c 100644
--- a/sleepyhead/preferencesdialog.ui
+++ b/sleepyhead/preferencesdialog.ui
@@ -51,7 +51,7 @@
-
- 2
+ 1
@@ -1163,7 +1163,7 @@ Try to sync it to your PC's clock (which should be synced to a timeserver)
- &Events
+ C&hannels
@@ -1173,7 +1173,7 @@ Try to sync it to your PC's clock (which should be synced to a timeserver)0
- 4
+ 0
0
@@ -1182,53 +1182,54 @@ Try to sync it to your PC's clock (which should be synced to a timeserver)0
-
-
-
- Not entirely sure if this will get to live or not..
-
-
+
+
-
+
+
+ Search
+
+
+
+ -
+
+
+
-
-
-
- true
-
-
- 0
-
-
- 4
-
-
- true
-
-
-
- Show
-
-
- AlignHCenter|AlignVCenter|AlignCenter
-
-
-
-
- Colour
-
-
- AlignHCenter|AlignVCenter|AlignCenter
-
-
-
-
- Event
-
-
-
-
- ID
-
-
-
+
+
+ -
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+ Reset &Defaults
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ <html><head/><body><p><span style=" font-weight:600;">Warning: </span>Just because you can, does not mean it's good practice.</p></body></html>
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+
@@ -1297,7 +1298,7 @@ Try to sync it to your PC's clock (which should be synced to a timeserver)
- &Defaults
+ Reset &Defaults
@@ -1306,6 +1307,9 @@ Try to sync it to your PC's clock (which should be synced to a timeserver)
Double click on the (Y-axis) min/max values to edit them
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+