diff --git a/sleepyhead/Graphs/gGraphView.cpp b/sleepyhead/Graphs/gGraphView.cpp index 5df75c78..7c3076d6 100644 --- a/sleepyhead/Graphs/gGraphView.cpp +++ b/sleepyhead/Graphs/gGraphView.cpp @@ -1698,7 +1698,7 @@ void gGraphView::populateMenu(gGraph * graph) connect(chbox, SIGNAL(toggled(bool)), widget, SLOT(setChecked(bool))); connect(chbox, SIGNAL(clicked()), widget, SLOT(trigger())); - bool b = chan.calc[dot.type].enabled; + bool b = lc->m_dot_enabled[dot.code][dot.type]; //chan.calc[dot.type].enabled; chbox->setChecked(b); lines_menu->addAction(widget); @@ -1712,6 +1712,8 @@ void gGraphView::populateMenu(gGraph * graph) } + lines_menu->menuAction()->setVisible(lines_menu->actions().size() > 0); + if (lines_menu->actions().size() > 0) { lines_menu->insertSeparator(lines_menu->actions()[0]); action = new QAction(QObject::tr("%1").arg(graph->title()), lines_menu); @@ -1722,7 +1724,6 @@ void gGraphView::populateMenu(gGraph * graph) } - lines_menu->menuAction()->setVisible(lines_menu->actions().size() > 0); ////////////////////////////////////////////////////////////////////////////////////// @@ -1731,7 +1732,7 @@ void gGraphView::populateMenu(gGraph * graph) plots_menu->clear(); - if (lc->m_codes.size() > 0) { + if (lc->m_codes.size() > 1) { for (int i=0; i m_codes.size(); ++i) { ChannelID code = lc->m_codes[i]; if (lc->m_day && !lc->m_day->channelHasData(code)) continue; @@ -1762,6 +1763,8 @@ void gGraphView::populateMenu(gGraph * graph) } } + plots_menu->menuAction()->setVisible((plots_menu->actions().size() > 1)); + if (plots_menu->actions().size() > 0) { plots_menu->insertSeparator(plots_menu->actions()[0]); action = new QAction(QObject::tr("%1").arg(graph->title()), plots_menu); @@ -1771,7 +1774,6 @@ void gGraphView::populateMenu(gGraph * graph) action->setData(QString("")); action->setEnabled(false); } - plots_menu->menuAction()->setVisible((plots_menu->actions().size() > 0)); ////////////////////////////////////////////////////////////////////////////////////// // Populate Event Menus @@ -1822,6 +1824,9 @@ void gGraphView::populateMenu(gGraph * graph) QString HideAllEvents = QObject::tr("Hide All Events"); QString ShowAllEvents = QObject::tr("Show All Events"); + oximeter_menu->menuAction()->setVisible(oximeter_menu->actions().size() > 0); + cpap_menu->menuAction()->setVisible(cpap_menu->actions().size() > 0); + if (cpap_menu->actions().size() > 0) { cpap_menu->addSeparator(); @@ -1860,10 +1865,6 @@ void gGraphView::populateMenu(gGraph * graph) action->setEnabled(false); } - oximeter_menu->menuAction()->setVisible(oximeter_menu->actions().size() > 0); - cpap_menu->menuAction()->setVisible(cpap_menu->actions().size() > 0); - - } else { lines_menu->clear(); lines_menu->menuAction()->setVisible(false); @@ -1984,10 +1985,9 @@ void gGraphView::onLinesClicked(QAction *action) DottedLine & dot = lc->m_dotlines[i]; schema::Channel &chan = schema::channel[dot.code]; -// if (chan.calc[dot.type].label() == action->text()) { - chan.calc[dot.type].enabled = !chan.calc[dot.type].enabled; - dot.enabled = !dot.enabled; -// } + chan.calc[dot.type].enabled = !chan.calc[dot.type].enabled; + lc->m_dot_enabled[dot.code][dot.type] = !lc->m_dot_enabled[dot.code][dot.type]; + } timedRedraw(0); } @@ -2736,7 +2736,7 @@ void gGraphView::deselect() } const quint32 gvmagic = 0x41756728; -const quint16 gvversion = 3; +const quint16 gvversion = 4; void gGraphView::SaveSettings(QString title) { @@ -2753,15 +2753,28 @@ void gGraphView::SaveSettings(QString title) out << (qint16)size(); for (qint16 i = 0; i < size(); i++) { - if (!m_graphs[i]) continue; + gGraph * graph = m_graphs[i]; + if (!graph) continue; + + out << graph->name(); + out << graph->height(); + out << graph->visible(); + out << graph->RecMinY(); + out << graph->RecMaxY(); + out << graph->zoomY(); + out << (bool)graph->isPinned(); + + gLineChart * lc = dynamic_cast(findLayer(graph, LT_LineChart)); + if (lc) { + out << (quint32)LT_LineChart; + out << lc->m_flags_enabled; + out << lc->m_enabled; + out << lc->m_dot_enabled; + } else { + out << (quint32)LT_Other; + } + - out << m_graphs[i]->name(); - out << m_graphs[i]->height(); - out << m_graphs[i]->visible(); - out << m_graphs[i]->RecMinY(); - out << m_graphs[i]->RecMaxY(); - out << m_graphs[i]->zoomY(); - out << (bool)m_graphs[i]->isPinned(); } f.close(); @@ -2825,6 +2838,21 @@ bool gGraphView::LoadSettings(QString title) in >> pinned; } + QHash flags_enabled; + QHash plots_enabled; + QHash > dot_enabled; + + // Warning: Do not break the follow section up!!! + quint32 layertype; + if (gvversion >= 4) { + in >> layertype; + if (layertype == LT_LineChart) { + in >> flags_enabled; + in >> plots_enabled; + in >> dot_enabled; + } + } + gGraph *g = nullptr; if (t2 <= 2) { @@ -2852,6 +2880,19 @@ bool gGraphView::LoadSettings(QString title) g->setRecMaxY(recmaxy); g->setZoomY(zoomy); g->setPinned(pinned); + + if (gvversion >= 4) { + if (layertype == LT_LineChart) { + gLineChart * lc = dynamic_cast(findLayer(g, LT_LineChart)); + if (lc) { + lc->m_flags_enabled = flags_enabled; + lc->m_enabled = plots_enabled; + + lc->m_dot_enabled = dot_enabled; + } + } + } + } } diff --git a/sleepyhead/Graphs/gLineChart.cpp b/sleepyhead/Graphs/gLineChart.cpp index 182b4e4f..41550f87 100644 --- a/sleepyhead/Graphs/gLineChart.cpp +++ b/sleepyhead/Graphs/gLineChart.cpp @@ -21,6 +21,28 @@ #define EXTRA_ASSERTS 1 +QDataStream & operator<<(QDataStream & stream, const DottedLine & dot) +{ + stream << dot.code; + stream << dot.type; + stream << dot.value; + stream << dot.visible; + stream << dot.available; + return stream; +} +QDataStream & operator>>(QDataStream & stream, DottedLine & dot) +{ + quint32 tmp; + stream >> dot.code; + stream >> tmp; + stream >> dot.value; + stream >> dot.visible; + stream >> dot.available; + dot.type = (ChannelCalcType)tmp; + return stream; +} + + QColor darken(QColor color, float p) { int r = qMin(int(color.red() * p), 255); @@ -202,6 +224,7 @@ skipcheck: flags[code] = lob; } } + m_dotlines.clear(); for (int i=0; i< m_codes.size(); i++) { @@ -226,6 +249,22 @@ skipcheck: if (m_day) { for (int i=0; i < m_dotlines.size(); i++) { m_dotlines[i].calc(m_day); + + ChannelID code = m_dotlines[i].code; + ChannelCalcType type = m_dotlines[i].type; + + bool b = false; // default value + + QHash >::iterator cit = m_dot_enabled.find(code); + + if (cit == m_dot_enabled.end()) { + m_dot_enabled[code].insert(type, b); + } else { + QHash::iterator it = cit.value().find(type); + if (it == cit.value().end()) { + cit.value().insert(type, b); + } + } } } @@ -511,7 +550,7 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) if (showDottedLines) { for (int i=0; i < dotlinesize; i++) { DottedLine & dot = m_dotlines[i]; - if ((dot.code != code) || (!dot.enabled) || (!dot.available) || (!m_enabled[dot.code])) { + if ((dot.code != code) || (!m_dot_enabled[dot.code][dot.type]) || (!dot.available) || (!m_enabled[dot.code])) { continue; } schema::Channel & chan = schema::channel[code]; diff --git a/sleepyhead/Graphs/gLineChart.h b/sleepyhead/Graphs/gLineChart.h index b63cec3e..77d9813e 100644 --- a/sleepyhead/Graphs/gLineChart.h +++ b/sleepyhead/Graphs/gLineChart.h @@ -29,7 +29,6 @@ public: code = NoChannel; type = Calc_Zero; value = 0; - enabled = true; visible = false; available = false; } @@ -38,11 +37,10 @@ public: type = copy.type; value = copy.value; available = copy.available; - enabled = copy.enabled; visible = copy.visible; } - DottedLine(ChannelID code, ChannelCalcType type, bool enabled = true, bool available = false): - code(code), type(type), enabled(enabled), available(available) {} + DottedLine(ChannelID code, ChannelCalcType type, bool available = false): + code(code), type(type), available(available) {} EventDataType calc(Day * day) { Q_ASSERT(day != nullptr); @@ -55,10 +53,12 @@ public: ChannelID code; ChannelCalcType type; EventDataType value; - bool enabled; bool visible; bool available; }; +QDataStream & operator<<(QDataStream &, const DottedLine &); +QDataStream & operator>>(QDataStream &, DottedLine &); + /*! \class gLineChart \brief Draws a 2D linechart from all Session data in a day. EVL_Waveforms typed EventLists are accelerated. @@ -123,6 +123,7 @@ class gLineChart: public Layer void addDotLine(DottedLine dot) { m_dotlines.append(dot); } QList m_dotlines; QHash m_flags_enabled; + QHash > m_dot_enabled; protected: //! \brief Mouse moved over this layers area (shows the hover-over tooltips here) diff --git a/sleepyhead/Graphs/layer.h b/sleepyhead/Graphs/layer.h index 0d00971e..ec26aea1 100644 --- a/sleepyhead/Graphs/layer.h +++ b/sleepyhead/Graphs/layer.h @@ -26,7 +26,7 @@ enum LayerPosition { LayerLeft, LayerRight, LayerTop, LayerBottom, LayerCenter, enum ToolTipAlignment { TT_AlignCenter, TT_AlignLeft, TT_AlignRight }; -enum LayerType { LT_Other = 0, LT_LineChart, LT_SummaryChart }; +enum LayerType { LT_Other = 0, LT_LineChart, LT_SummaryChart, LT_EventFlags }; /*! \class Layer \brief The base component for all individual Graph layers